Skip to main content

Strangeworks-Qiskit

PyPI version

The strangeworks-qiskit package provides a drop-in Qiskit Provider replacement for executing across all of our supported providers and backends.

šŸ“‘ Package Documentation

Installationā€‹

To get started, make sure you have Python 3.10 or above (installation) and are familiar with setting up and using virtual environments.

pip install -U pip && pip install strangeworks-qiskit

Usageā€‹

Here's a simple example of creating a Bell state with Qiskit.

Before running:

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