Provider for running Qiskit circuits on Rigetti QPUs and simulators.
Project description
Rigetti Provider for Qiskit
Try It Out
To try out this library, you can run example notebooks in a pre-made binder. Alternately, you can run the following to build and run the image locally:
docker build -t qiskit-tutorials .
docker run --rm -p 8888:8888 qiskit-tutorials
then click on the link that is displayed after the container starts up.
Pre-requisites
- Install Docker
- Download qelib1.inc
- Place
qelib1.inc
in a folder calledinc
in the project root
Setup QVM and quilc
Using Docker Compose
Run docker compose up
to see service logs or docker compose up -d
to run in the background.
Using Docker Manually
-
Start the QVM:
docker run --rm -it -p 5000:5000 rigetti/qvm -S
-
Start the compiler:
docker run --rm -it -p 5555:5555 -v "$PWD"/inc:/inc rigetti/quilc -S -P --safe-include-directory /inc/
Usage
Example:
from qiskit import execute
from qiskit_rigetti import RigettiQCSProvider, QuilCircuit
# Get provider and backend
p = RigettiQCSProvider()
backend = p.get_simulator(num_qubits=2, noisy=True) # or p.get_backend(name='Aspen-9')
# Create a Bell state circuit
circuit = QuilCircuit(2, 2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure([0, 1], [0, 1])
# Execute the circuit on the backend
job = execute(circuit, backend, shots=10, coupling_map=backend.coupling_map)
# Grab results from the job
result = job.result()
# Return memory and counts
memory = result.get_memory(circuit)
counts = result.get_counts(circuit)
print("Result memory:", memory)
print("Result counts:", counts)
Rigetti Quantum Cloud Services (QCS)
Execution against a QPU requires a reservation via QCS. For more information on using QCS, see the QCS documentation.
Advanced
Lifecycle Hooks
For advanced QASM and Quil manipulation, before_compile
and before_execute
keyword arguments can be passed to
RigettiQCSBackend.run()
or to Qiskit's execute()
.
Pre-compilation Hooks
Any before_compile
hooks will apply, in order, just before compilation from QASM to native Quil.
For example:
...
def custom_hook_1(qasm: str) -> str:
new_qasm = ...
return new_qasm
def custom_hook_2(qasm: str) -> str:
new_qasm = ...
return new_qasm
job = execute(circuit, backend, shots=10, before_compile=[custom_hook_1, custom_hook_2])
...
Pre-execution Hooks
Any before_execute
hooks will apply, in order, just before execution (after translation from QASM to native Quil).
For example:
from pyquil import Program
...
def custom_hook_1(quil: Program) -> Program:
new_quil = ...
return new_quil
def custom_hook_2(quil: Program) -> Program:
new_quil = ...
return new_quil
job = execute(circuit, backend, shots=10, before_execute=[custom_hook_1, custom_hook_2])
...
Note:
Only certain forms of Quil can can be executed on a QPU. If pre-execution transformations produce a final program that is not QPU-compliant,
ensure_native_quil=True
can be passed toexecute()
orRigettiQCSBackend.run()
to recompile the final Quil program to native Quil prior to execution. If no pre-execution hooks were supplied, this setting is ignored. If this setting is omitted, a value ofFalse
is assumed.Example: Adding the Quil instruction
H 0
would result in an error ifensure_native_quil=False
and the QPU does not natively implement Hadamard gates.
Built-in Hooks
The hooks.pre_compilation
and hooks.pre_execution
packages provide a number of convenient hooks:
set_rewiring
Use set_rewiring
to provide a rewiring directive
to the Quil compiler. For example:
from qiskit_rigetti.hooks.pre_compilation import set_rewiring
...
job = execute(circuit, backend, shots=10, before_compile=[set_rewiring("NAIVE")])
...
Note: Rewiring directives require
quilc
version 1.25 or higher.
enable_active_reset
Use enable_active_reset
to enable active qubit reset,
an optimization that can significantly reduce the time between executions. For example:
from qiskit_rigetti.hooks.pre_execution import enable_active_reset
...
job = execute(circuit, backend, shots=10, before_execute=[enable_active_reset])
...
Development
Note: This module is developed in Python 3.8, 3.9, and 3.10, other versions will currently fail type checking.
Dependencies are managed with Poetry so you need to install that first. Once you've installed all dependencies (poetry install
) and activated the virtual environment (poetry shell
), you can use these rules from the Makefile
to run common tasks:
- Run tests:
make test
- Check style and types:
make check-all
- Check style only:
make check-style
- Check types only:
make check-types
- Reformat all code (to make
check-style
pass):make format
- Build documentation, serve locally, and watch for changes:
make watch-docs
(requiresdocs
extra:poetry install -E docs
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file qiskit_rigetti-0.4.7.tar.gz
.
File metadata
- Download URL: qiskit_rigetti-0.4.7.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.8.18 Linux/5.15.0-1028-aws
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b0703ef4bd63a7335f1803f3a97673c6297bf68ef74fa469029a6f2a757facc |
|
MD5 | 7620589b56ad9c3069812d936cef5b82 |
|
BLAKE2b-256 | 7fc537e1778cc65a81f813214de5aaaf1f3d988cb34ccb2e8481cfb601974970 |
File details
Details for the file qiskit_rigetti-0.4.7-py3-none-any.whl
.
File metadata
- Download URL: qiskit_rigetti-0.4.7-py3-none-any.whl
- Upload date:
- Size: 23.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.8.18 Linux/5.15.0-1028-aws
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 494f6f886b762366b3e7e6a9161c1d33a9ea944001deef5c9b1ef573a267f728 |
|
MD5 | 8066f8748cdc02c8ecf7a41bdb6ba17a |
|
BLAKE2b-256 | f7a698db78561b94ee3083c52f5667b39ada6d28606bcdd2e5914bb9194863ef |