API Reference
Run pyquil programs through Azure Quantum
Usage
- Instead of using
pyquil.get_qc()
usepyquil_for_azure_quantum.get_qpu()
for QPUs andpyquil_for_azure_quantum.get_qvm()
for QVM. - QVM and
quilc
do not need to be installed or running locally.
AzureJob
dataclass
AzureProgram
Bases: ObjectProxy
, Program
A wrapper around a Program
that is used to execute on Azure Quantum.
Source code in pyquil_for_azure_quantum/__init__.py
copy()
Perform a shallow copy of this program.
QuilAtom and AbstractInstruction objects should be treated as immutable to avoid strange behavior when performing a copy.
Source code in pyquil_for_azure_quantum/__init__.py
get_memory()
Retrieve the memory map for this program formatted in the way that Azure expects
Source code in pyquil_for_azure_quantum/__init__.py
AzureQuantumComputer
Bases: QuantumComputer
A pyquil.QuantumComputer
that runs on Azure Quantum.
Source code in pyquil_for_azure_quantum/__init__.py
compile(program, to_native_gates=True, optimize=True, *, protoquil=None)
Compile a program for Azure execution.
By default, this stage is a no-op and is here for better compatibility with pyquil programs. Azure will do all
compilation in the cloud. However, if you want to tell Azure to skip the quilc step, pass False
to
to_native_gates
. This is necessary when utilizing Quil-T. If you want to run quilc
locally in order to
check the Native Quil which will be executed, call compiler.quil_to_native_quil
and pass the result to this
function along with to_native_gates=False
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
program |
Program
|
The program to compile. |
required |
to_native_gates |
bool
|
Whether to convert the program to native gates by running |
True
|
optimize |
bool
|
Has no effect on Azure. |
True
|
protoquil |
Optional[bool]
|
Has no effect on Azure. |
None
|
Returns:
Type | Description |
---|---|
AzureProgram
|
An |
AzureProgram
|
done here. |
Source code in pyquil_for_azure_quantum/__init__.py
run_batch(executable, memory_map)
Run a sequence of memory values through the program.
See Also
Source code in pyquil_for_azure_quantum/__init__.py
AzureQuantumMachine
Bases: QAM[AzureJob]
An implementation of QAM which runs programs using Azure Quantum
These Azure Quantum configuration environment variables must be 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.
Credentials for communicating with Azure Quantum should be stored in the following environment variables. If they are not set, this will attempt to open a browser to authenticate: * AZURE_CLIENT_ID * AZURE_CLIENT_SECRET * AZURE_TENANT_ID
Raises:
Type | Description |
---|---|
KeyError
|
If required environment variables are not set. |
Source code in pyquil_for_azure_quantum/__init__.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
|
execute(executable, name='pyquil-azure-job')
Run an AzureProgram on Azure Quantum. Unlike normal QAM this does not accept a QuantumExecutable
.
You should build the AzureProgram
via AzureQuantumComputer.compile
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
executable |
AzureProgram
|
The AzureProgram to run. |
required |
name |
str
|
An optional name for the job which will show up in the Azure Quantum UI. |
'pyquil-azure-job'
|
Returns:
Type | Description |
---|---|
AzureJob
|
A |
AzureJob
|
|
Source code in pyquil_for_azure_quantum/__init__.py
get_result(execute_response)
Wait for a Job
to complete, then return the results
Raises:
Type | Description |
---|---|
RuntimeError
|
If the job fails. |
Source code in pyquil_for_azure_quantum/__init__.py
run(executable)
run_batch(executable, memory_map, name='pyquil-azure-job')
Run the executable for each set of parameters in the memory_map
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
executable |
AzureProgram
|
The AzureProgram to run. |
required |
memory_map |
Dict[str, List[List[float]]]
|
A dictionary mapping parameter names to lists of parameter values. Each value is a list as long
as the number of slots in the register. So if the register was |
required |
name |
str
|
An optional name for the job which will show up in the Azure Quantum UI. |
'pyquil-azure-job'
|
Returns:
Type | Description |
---|---|
List[QAMExecutionResult]
|
A list of |
>>> import numpy as np
>>> from pyquil import Program
>>> from pyquil.gates import CNOT, MEASURE, RX, H
>>> from pyquil.quilatom import MemoryReference
>>> from pyquil.quilbase import Declare
>>> from pyquil_for_azure_quantum import get_qvm
>>> qvm = get_qvm()
>>> program = Program( Declare("ro", "BIT", 1), Declare("theta", "REAL", 1), RX(MemoryReference("theta"), 0), MEASURE(0, ("ro", 0)), ).wrap_in_numshots_loop(1000)
>>> compiled = qvm.compile(program)
>>> results = qvm.run_batch(compiled, {"theta": [[0.0], [np.pi], [2 * np.pi]]})
>>> assert len(results) == 3 # 3 values for theta—each a list of length 1
>>> results_0 = results[0].readout_data["ro"]
>>> assert len(results_0) == 1000 # 1000 shots
>>> assert np.mean(results_0) == 0
>>> results_pi = results[1].readout_data["ro"]
>>> assert len(results_pi) == 1000
>>> assert np.mean(results_pi) == 1
Source code in pyquil_for_azure_quantum/__init__.py
get_qpu(qpu_name)
Get an AzureQuantumComputer targeting a real QPU
These Azure Quantum configuration environment variables must be 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.
If these are not set, this will attempt to open a browser to authenticate:
- AZURE_CLIENT_ID
- AZURE_CLIENT_SECRET
- AZURE_TENANT_ID
Raises:
Type | Description |
---|---|
KeyError
|
If required environment variables are not set. |
Source code in pyquil_for_azure_quantum/__init__.py
get_qvm()
Get an AzureQuantumComputer targeting a cloud-hosted QVM
These Azure Quantum configuration environment variables must be 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.
If these are not set, this will attempt to open a browser to authenticate:
- AZURE_CLIENT_ID
- AZURE_CLIENT_SECRET
- AZURE_TENANT_ID
Raises:
Type | Description |
---|---|
KeyError
|
If required environment variables are not set. |