Strangeworks SDK Braket Extension¶
The service uses the Strangeworks API accessed through the Strangeworks python SDK. For more information on the general python sdk see our docs.
To get started you will need to install the SDK and authenticate using your API key. Your API key can be found on the dashboard page of the Strangeworks platform at https://portal.strangeworks.com.
Installation¶
The Strangeworks Braket SDK is installed using pip
pip install strangeworks-azure
Test your installation by running the following
$ python
>>> import strangeworks_azure
>>> print(strangeworks_azure.__version__)
Authentication¶
Authenticate using the strangeworks.authenticate()
method
$ python
>>> import strangeworks
>>> strangeworks.authenticate(api_key="<your-api-key>")
Basic Usage¶
The SDK provides an Azure extension that can be used to run quantum circuits on the Strangeworks platform.
import strangeworks
from qiskit import QuantumCircuit
from strangeworks_azure import StrangeworksBackend
# 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
backends = StrangeworksBackend.get_backends()
print("Available backends:")
for backend in backends:
print(f" - {backend.name} ({backend.status})")
# create a simple quantum circuit
circuit = QuantumCircuit(2, 2)
circuit.name = "GenerateRandomBit"
circuit.h(0)
circuit.cx(0,1)
circuit.measure([0,1], [0,1])
circuit.draw()
# Choose a device (an AWS-hosted simulator in this case)
ionq = StrangeworksBackend("ionq.simulator")
# Execute the circuit
print("\n🤖 Executing Circuit...\n")
task = ionq.run(circuit, 100)
# 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.get("counts")}\n")