Strangeworks-Braket
The strangeworks-braket
package provides a similar experience to Amazon Braket.
Installationā
To get started, make sure you have Python 3.9 or above (installation) and are familiar with setting up and using virtual environments.
pip install strangeworks-braket
Usageā
Here's a simple example of creating a Bell state with Amazon Braket.
Before running:
- Set up your environment and install
strangeworks-braket
- In the portal, Activate Amazon Braket to create a Resource
- Replace
your-api-key
with your key from the Portal homepage - Run the script!
Amazon Braket: Hello World
import strangeworks
from braket.circuits import Circuit
from strangeworks_braket import StrangeworksDevice
# get your API key from the Strangeworks Portal
strangeworks.authenticate(
api_key="your-api-key",
)
# Optional: If you have multiple instances (resources) of a product,
# you can set the resource to use here.
# strangeworks.set_resource_for_product('your-resource-slug', 'amazon-braket')
# Optional: You can list the Braket devices available on
# the Strangeworks Platform
devices = StrangeworksDevice.get_devices()
print("Available devices:")
for device in devices:
print(f" - {device.name} ({device.arn})")
# create a simple quantum circuit
bell_state = Circuit().h(0).cnot(0, 1)
# Choose a device (an AWS-hosted simulator in this case)
tn1 = StrangeworksDevice("arn:aws:braket:::device/quantum-simulator/amazon/tn1")
# Execute the circuit
print("\nš¤ Executing Circuit...\n")
task = tn1.run(bell_state, 1000)
# At this point, the job is running on the Strangeworks Platform.
# You can check the status of the job in the Portal, even if
# stop this script.
print(f"ā³ Job {task.id} submitted!\n")
# Lots of good info in here
result = task.result()
# View the counts (also visible in the Portal in a chart š)
print(f"š š Counts: {result.measurement_counts}\n")
š„³ Success! You may view your job in the portal.
š Something went wrong? Find us in Slack!