Skip to main content

Strangeworks-Braket

PyPI version

The strangeworks-braket package provides a similar experience to Amazon Braket.

šŸ“‘ Package Documentation

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:

  1. Set up your environment and install strangeworks-braket
  2. In the portal, Activate Amazon Braket to create a Resource
  3. Replace your-api-key with your key from the Portal homepage
  4. 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!