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

[v0.3.6] Remove references to QS2/3 and update README with polling timeout example #81

Merged
merged 3 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all 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. When you execute your task, Braket polls for a result. If it a result is not returned during the default polling time, such as when a QPU is unavailable, a local timeout error is returned. To avoid receiving timeout errors, you can include `poll_timeout_seconds` parameter and specify a longer polling time. In this example, `poll_timeout_seconds=86400` sets the polling time to one day (24 hours).
```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: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name="braket-sdk",
version="0.3.5",
version="0.3.6",
license="Apache License 2.0",
python_requires=">= 3.7.2",
packages=find_namespace_packages(where="src", exclude=("test",)),
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