Strangeworks-Qiskit
The strangeworks-qiskit
package provides a drop-in Qiskit Provider replacement for executing across all of our supported providers and backends.
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-qiskit
Usageā
Here's a simple example of creating a Bell state with Qiskit.
Before running:
- Set up your environment and install
strangeworks-qiskit
- In the portal, Activate IBM Quantum to create a Resource
- Replace
your-api-key
with your key from the Portal homepage - Run the script!
Qiskit: Hello World
import strangeworks
import qiskit
from strangeworks_qiskit import StrangeworksProvider
# 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', 'ibm-quantum')
# This is your replacement Qiskit Provider that allows you to use
# the Strangeworks Platform as a backend for Qiskit.
provider = StrangeworksProvider()
# Optional: You can list the Qiskit-compatible backends available on
# the Strangeworks Platform
backends = provider.backends()
print('Available backends:')
for backend in backends:
print(f' - {backend.name()}')
# create a simple quantum circuit
qc = qiskit.QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
# Choose a backend (the IBM-hosted simulator in this case)
backend = provider.get_backend("ibmq_qasm_simulator")
# Execute the circuit
print('\nš¤ Executing Circuit...\n')
job = qiskit.execute(qc, backend, shots=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 {job._job_slug} submitted!\n')
# Lots of good info in here
result = job.result()
# View the counts (also visible in the Portal in a chart š)
counts = result.get_counts()
print(f"š š Counts: {counts}\n")
š„³ Success! You may view your job in the portal.
š Something went wrong? Find us in Slack!
tip
While this example uses IBM's hosted simulator, you may use any supported Qiskit backend from IBM, Amazon Braket, Azure Quantum, and Rigetti.