Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove qs2/3 references #78

Merged
merged 7 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,8 @@ print(device.run(bell, s3_folder).result().measurement_counts)
The code sample imports the Amazon Braket framework, then defines the execution environment as the AWSQuantumSimulator and the device to use. The `s3_folder` statement defines the Amazon S3 bucket for job output and the folder in the bucket to store job output. This folder is created when you run the job. It then creates a Bell Pair circuit, executes the circuit on the simulator and prints the results of the job.

### Available Simulators
There are currently three simulators available for Amazon Braket. To specify which simulator to use, change the code sample to replace the value for the `AwsQuantumSimulator` to one of the following values:
There is currently one AwsQuantumSimulator available:
- `arn:aws:aqx:::quantum-simulator:aqx:qs1` – a Schrödinger simulator. Simulates exactly running a job on a quantum computer. Limit of 25 qubits. This simulator samples only from the state vector and outputs an array of bit strings that appears as though it came from a quantum computer. Does not provide a state vector.
- `arn:aws:aqx:::quantum-simulator:aqx:qs2` – a tensor network simulator. Provides an approximation of running a job on a quantum computer.
- `arn:aws:aqx:::quantum-simulator:aqx:qs3` – a Schrödinger simulator. Simulates exactly running a job on a quantum computer. Limit of 25 qubits. This simulator samples from the state vector but includes the entire state vector. This generates more data, and therefore incurs additional costs for storage of data in Amazon S3.

#### To validate your configuration using a Python file
1. Open a text editor with example file `../braket-python-sdk/examples/bell.py`.
Expand Down Expand Up @@ -254,7 +252,7 @@ Tasks sent to QPUs don't always run right away. For IonQ, jobs are run once ever
## Running a Quantum Algorithm on a Quantum Computer
With Amazon Braket, you can run your quantum circuit on a physical quantum computer. The steps to do so are the same as those described to validate your environment. Just replace the example code provided in this document with your own code.

The following example executes the same Bell Pair example described to validate your configuration against a Rigetti quantum computer.
The following example executes the same Bell Pair example described to validate your configuration against a Rigetti quantum computer. For the case when the specified QPU is unavailable and tasks are not immediately run, a `poll_timeout_seconds` parameter is included to set a longer polling time. With this parameter, the results are not returned until the task reaches a status of COMPLETE, FAILED, or CANCELLED, or 24 hours passes. When using the default polling time, local timeout errors occur in some cases while waiting for the QPU to process the task. This example sets the polling time to one day (24 hours). Since tasks typically run within 24 hours this keeps the local task from failing before the task is run on the QPU.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"this keeps the local task from failing before the task is run on the QPU." -> I think the task wouldn't fail. It would be the call to the .result() method which would return None.
Also the term local task might be confusing since there is a LocalQuantumTask class (used with LocalSimulator) which is different from the AwsQuantumTask class being used here.
The idea we want to convey is that the result() method on the AwsQuantumTask class polls the service to check if the task is in one of the terminal states (COMPLETE, FAILED, or CANCELLED) for poll_timeout_seconds(which has a default value of 2 minutes) before retrieving the results from S3. For QPUs the results might not be ready within that time frame so we can have our code execute the polling for a longer period of time, such as 24 hours.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please move these changes to a separate PR so that we can commit them separately.

# Cherry pick changes onto new branch (docs_update)
git checkout -b feature/docs_update origin/master
git cherry-pick 215df9d0ca213b073fd90ff319be45c476e6bd7c
# Make changes to docs and git push to create the PR as per usual flow

# Remove these changes from this PR
git checkout feature/deprecate_qs3
git revert 215df9d0ca213b073fd90ff319be45c476e6bd7c
git push

```python
import boto3
from braket.circuits import Circuit
Expand All @@ -266,7 +264,8 @@ device = AwsQpu(AwsQpuArns.RIGETTI)
s3_folder = (f"braket-output-{aws_account_id}", "RIGETTI")

bell = Circuit().h(0).cnot(0, 1)
print(device.run(bell, s3_folder).result().measurement_counts)
print(device.run(bell, s3_folder),
poll_timeout_seconds=86400).result().measurement_counts)
```

Specify which quantum computer hardware to use by changing the value of the `device_arn` to the value for quantum computer to use:
Expand Down
2 changes: 0 additions & 2 deletions src/braket/aws/aws_quantum_simulator_arns.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,3 @@

class AwsQuantumSimulatorArns(str, Enum):
QS1 = "arn:aws:aqx:::quantum-simulator:aqx:qs1"
QS2 = "arn:aws:aqx:::quantum-simulator:aqx:qs2"
QS3 = "arn:aws:aqx:::quantum-simulator:aqx:qs3"
7 changes: 1 addition & 6 deletions test/integ_tests/test_device_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ def test_device_across_regions(aws_session):


@pytest.mark.parametrize(
"simulator_arn,simulator_name",
[
(AwsQuantumSimulatorArns.QS1, "quantum-simulator-1"),
(AwsQuantumSimulatorArns.QS2, "quantum-simulator-2"),
(AwsQuantumSimulatorArns.QS3, "quantum-simulator-3"),
],
"simulator_arn,simulator_name", [(AwsQuantumSimulatorArns.QS1, "quantum-simulator-1"),],
)
def test_simulator_creation(simulator_arn, simulator_name, aws_session):
simulator = AwsQuantumSimulator(simulator_arn, aws_session=aws_session)
Expand Down
31 changes: 2 additions & 29 deletions test/integ_tests/test_simulator_quantum_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
from braket.circuits import Circuit


@pytest.mark.parametrize(
"simulator_arn", [AwsQuantumSimulatorArns.QS1, AwsQuantumSimulatorArns.QS3]
)
@pytest.mark.parametrize("simulator_arn", [AwsQuantumSimulatorArns.QS1])
def test_bell_pair(simulator_arn, aws_session, s3_destination_folder):
device = AwsQuantumSimulator(simulator_arn, aws_session)
bell = Circuit().h(0).cnot(0, 1)
Expand All @@ -31,9 +29,7 @@ def test_bell_pair(simulator_arn, aws_session, s3_destination_folder):
assert len(result.measurements) == 750


@pytest.mark.parametrize(
"simulator_arn", [AwsQuantumSimulatorArns.QS1, AwsQuantumSimulatorArns.QS3]
)
@pytest.mark.parametrize("simulator_arn", [AwsQuantumSimulatorArns.QS1])
def test_qubit_ordering(simulator_arn, aws_session, s3_destination_folder):
device = AwsQuantumSimulator(simulator_arn, aws_session)

Expand All @@ -46,26 +42,3 @@ def test_qubit_ordering(simulator_arn, aws_session, s3_destination_folder):
state_001 = Circuit().i(0).i(1).x(2)
result = device.run(state_001, s3_destination_folder).result()
assert result.measurement_counts.most_common(1)[0][0] == "001"


def test_state_vector(aws_session, s3_destination_folder):
device = AwsQuantumSimulator(AwsQuantumSimulatorArns.QS3, aws_session)
bell = Circuit().h(0).cnot(0, 1)
state_vector = device.run(bell, s3_destination_folder, shots=1).result().state_vector
assert state_vector["00"] == complex(1 / math.sqrt(2), 0)
assert state_vector["01"] == 0
assert state_vector["10"] == 0
assert state_vector["11"] == complex(1 / math.sqrt(2), 0)


def test_qs2_quantum_task(aws_session, s3_destination_folder):
device = AwsQuantumSimulator(AwsQuantumSimulatorArns.QS2, aws_session)

bell = Circuit().h(range(8))
measurements = device.run(bell, s3_destination_folder, shots=1).result().measurements

# 1 shot
assert len(measurements) == 1

# 8 qubits
assert len(measurements[0]) == 8