pyquil-for-azure-quantum
This library allows you to use pyQuil to run programs on Azure Quantum against Rigetti targets. Internally, it leverages the azure-quantum package.
Usage
Generally, you use pyQuil normally, with a few differences:
- Instead of
pyquil.get_qc(), you will use eitherpyquil_azure_quantum.get_qvm()orpyquil_azure_quantum.get_qpu(). - You do not need to have
qvmorquilcrunning in order to run programs throughpyquil_azure_quantum. You may still run them if you wish to run QVM locally instead of passing through Azure or if you wish to precompile your programs (e.g., to inspect the exact Quil that will run). - You do not need a QCS account or credentials unless you wish to manually inspect the details of the QPU (e.g., list all qubits).
- You must have these environment variables set:
AZURE_QUANTUM_SUBSCRIPTION_ID: The Azure subscription ID where the Quantum Workspace is located.AZURE_QUANTUM_WORKSPACE_RG: The Azure resource group where the Quantum Workspace is located.AZURE_QUANTUM_WORKSPACE_NAME: The name of the Quantum Workspace.AZURE_QUANTUM_WORKSPACE_LOCATION: The region where the Quantum Workspace is located.
- You may set environment variables to authenticate with Azure. If you do not, a browser will open to the Azure portal to authenticate.
- Whenever possible, you should prefer using
AzureQuantumComputer.run_batch()overProgram.write_memory(); AzureQuantumComputer.run()to run programs which have multiple parameters. Callingwrite_memory()followed byrun()will still work but will be much slower than running a batch of parameters all at once.
Examples
1. Leveraging Hosted QVM and quilc
With this program, you do not need to run qvm nor quilc locally in order to leverage them, as they can run through Azure Quantum.
from pyquil_for_azure_quantum import get_qpu, get_qvm
from pyquil.gates import CNOT, MEASURE, H
from pyquil.quil import Program
from pyquil.quilbase import Declare
program = Program(
Declare("ro", "BIT", 2),
H(0),
CNOT(0, 1),
MEASURE(0, ("ro", 0)),
MEASURE(1, ("ro", 1)),
).wrap_in_numshots_loop(1000)
qpu = get_qpu("Aspen-11")
qvm = get_qvm()
exe = qpu.compile(program) # This does not run quilc yet.
results = qpu.run(exe) # Quilc will run in the cloud before executing the program.
qvm_results = qvm.run(exe) # This runs the program on QVM in the cloud, not locally.
2. Running quilc Locally
You can optionally run quilc yourself and disable the use of quilc in the cloud.
from pyquil_for_azure_quantum import get_qpu
from pyquil.gates import CNOT, MEASURE, H
from pyquil.quil import Program
from pyquil.quilbase import Declare
program = Program(
Declare("ro", "BIT", 2),
H(0),
CNOT(0, 1),
MEASURE(0, ("ro", 0)),
MEASURE(1, ("ro", 1)),
).wrap_in_numshots_loop(1000)
qpu = get_qpu("Aspen-11")
native_quil = qpu.compiler.quil_to_native_quil(program) # quilc must be running locally to compile
exe = qpu.compile(native_quil, to_native_gates=False) # Skip quilc in the cloud
results = qpu.run(exe)
3. Running Parametrized Circuits in a Batch
When you have a program which should be run across multiple parameters, you can submit all the parameters at once to significantly improve performance.
import numpy as np
from pyquil_for_azure_quantum import get_qpu
from pyquil.gates import MEASURE, RX
from pyquil.quil import Program
from pyquil.quilbase import Declare
from pyquil.quilatom import MemoryReference
program = Program(
Declare("ro", "BIT", 1),
Declare("theta", "REAL", 1),
RX(MemoryReference("theta"), 0),
MEASURE(0, ("ro", 0)),
).wrap_in_numshots_loop(1000)
qpu = get_qpu("Aspen-11")
compiled = qpu.compile(program)
memory_map = {"theta": [[0.0], [np.pi], [2 * np.pi]]}
results = qpu.run_batch(compiled, memory_map) # This is a list of results, one for each parameter set.
results_0 = results[0].get_register_map().get("ro")
results_pi = results[1].get_register_map().get("ro")
results_2pi = results[2].get_register_map().get("ro")
Microsoft, Microsoft Azure, and Azure Quantum are trademarks of the Microsoft group of companies.
Metadata
Release files for pyquil-for-azure-quantum 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyquil_for_azure_quantum-0.1.0.tar.gz | 11.1 kB | Without provenance | Details for pyquil_for_azure_quantum-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyquil_for_azure_quantum-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for pyquil_for_azure_quantum-0.1.0-py3-none-any.whl |
Total release size: 23.7 kB
Release files / pyquil_for_azure_quantum-0.1.0.tar.gz
| Download URL | pyquil_for_azure_quantum-0.1.0.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6763e950d9b5c3c672dc0ac9a7a6aeb12b3d28d95b11aafed7d866ecd99e702
|
|
BLAKE2b-256 checksum How to use checksums |
b368992d11e5f6cbac691ef0f412427df7d1857be72e682e1f8942eb3c03f7a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.12.3 Linux/6.8.0-1017-azure
|
Release files / pyquil_for_azure_quantum-0.1.0-py3-none-any.whl
| Download URL | pyquil_for_azure_quantum-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b7833fc52d073397c4061a4ac921da1bbf8d8ab6aed8c68b33dadbf3c77554d3
|
|
BLAKE2b-256 checksum How to use checksums |
9c4f7b9719d4d56fedb5cdc6c4881e8a301a2cfd80a32675dea7d0a1b8ba29a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.12.3 Linux/6.8.0-1017-azure
|
Security for pyquil-for-azure-quantum 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.