qcs_sdk
An interface to Rigetti Quantum Cloud Services (QCS).
These APIs allow users to compile and run Quil programs on Rigetti quantum processors. Internally, it is powered by the QCS Rust SDK.
This package is still in development and breaking changes should be expected between minor versions.
1# This file is automatically generated by pyo3_stub_gen 2# ruff: noqa: F401 3 4from qcs_sdk import _tracing_subscriber 5from qcs_sdk._qcs_sdk import ExeParameter, Executable, ExecutionData, ExecutionError, JobHandle, QcsSdkError, RegisterData, RegisterMap, RegisterMapItemsIter, RegisterMapKeysIter, RegisterMapValuesIter, RegisterMatrix, RegisterMatrixConversionError, Service, __doc__, __version__, client, compiler, diagnostics, qpu, qvm, reset_logging 6from qcs_sdk._qcs_sdk.client import QCSClient 7__all__ = [ 8 "ExeParameter", 9 "Executable", 10 "ExecutionData", 11 "ExecutionError", 12 "JobHandle", 13 "QCSClient", 14 "QcsSdkError", 15 "RegisterData", 16 "RegisterMap", 17 "RegisterMapItemsIter", 18 "RegisterMapKeysIter", 19 "RegisterMapValuesIter", 20 "RegisterMatrix", 21 "RegisterMatrixConversionError", 22 "Service", 23 "__doc__", 24 "__version__", 25 "_tracing_subscriber", 26 "client", 27 "compiler", 28 "diagnostics", 29 "qpu", 30 "qvm", 31 "reset_logging", 32]
Program execution parameters.
Note: The validity of parameters is not checked until execution.
A builder interface for executing Quil programs on QVMs and QPUs.
Example
This example executes a program on a QVM, specified by the qvm_url in the QCSClient:
from qcs_sdk import Executable
from qcs_sdk.client import QCSClient
from qcs_sdk.qvm import QVMClient
PROGRAM = r'''
DECLARE ro BIT[2]
H 0
CNOT 0 1
MEASURE 0 ro[0]
MEASURE 1 ro[1]
'''
async def run():
client = QVMClient.new_http(QCSClient.load().qvm_url)
result = await Executable(PROGRAM, shots=4).execute_on_qvm_async()
let data = result.result_data
.to_register_map()
.expect("should convert to readout map")
.get_register_matrix("ro")
.expect("should have data in ro")
.as_integer()
.expect("should be integer matrix")
.to_owned();
// In this case, we ran the program for 4 shots, so we know the number of rows is 4.
assert_eq!(data.nrows(), 4);
for shot in data.rows() {
// Each shot will contain all the memory, in order, for the vector (or "register") we
// requested the results of. In this case, "ro" (the default).
assert_eq!(shot.len(), 2);
// In the case of this particular program, we know ro[0] should equal ro[1]
assert_eq!(shot[0], shot[1]);
}
def main():
import asyncio
asyncio.run(run())
# "ro" is the only source read from by default if you don't specify `registers`.
# We first convert the readout data to a ``RegisterMap`` to get a mapping of registers
# (ie. "ro") to a [`RegisterMatrix`], `M`, where M[`shot`][`index`] is the value for
# the memory offset `index` during shot `shot`.
# There are some programs where QPU readout data does not fit into a [`RegisterMap`], in
# which case you should build the matrix you need from [`QpuResultData`] directly. See
# the [`RegisterMap`] documentation for more information on when this transformation
# might fail.
Execute on a QVM which is accessible via the provided client.
Raises
ExecutionError: If the job fails to execute.
Execute on a QVM which is accessible via the provided client
(async analog of Executable.execute_on_qvm).
Raises
ExecutionError: If the job fails to execute.
Compile the program and execute it on a QPU, waiting for results.
Parameters
endpoint_id: execute the compiled program against an explicitly provided endpoint. IfNone, the default endpoint for the givenquantum_processor_idis used.
Raises
ExecutionError: If the job fails to execute.
Compile the program and execute it on a QPU, waiting for results
(async analog of Executable.execute_on_qpu).
Parameters
endpoint_id: execute the compiled program against an explicitly provided endpoint. IfNone, the default endpoint for the givenquantum_processor_idis used.
Raises
ExecutionError: If the job fails to execute.
Compile the program and execute it on a QPU, without waiting for results.
Parameters
endpoint_id: execute the compiled program against an explicitly provided endpoint. IfNone, the default endpoint for the givenquantum_processor_idis used.
Raises
ExecutionError: If the job fails to execute.
Compile the program and execute it on a QPU, without waiting for results
(async analog of Executable.submit_to_qpu).
Parameters
endpoint_id: execute the compiled program against an explicitly provided endpoint. IfNone, the default endpoint for the givenquantum_processor_idis used.
Raises
ExecutionError: If the job fails to execute.
Wait for the results of a job to complete
(async analog of Executable.retrieve_results).
Raises
ExecutionError: If the job fails to execute.
The result of executing an Executable
Errors which can occur when executing a program.
The result of submitting a job to a QPU.
Used to retrieve the results of a job.
A client providing helper functionality for accessing QCS APIs
Create a QCSClient configuration using an environment-based configuration.
Parameters
profile_name: The QCS setting's profile name to use. IfNone, the default value configured in your environment is used.
Raises
LoadClientError: If there is an issue loading the profile details from the environment.
Create a QCSClient configuration using an environment-based configuration.
If credentials are not found or stale, a PKCE login redirect flow will be initialized.
Note that this opens up a TCP port on your system to accept a browser HTTP redirect,
so you should not use this in environments where that is not possible,
such as hosted JupyterLab sessions.
Parameters
profile_name: The QCS setting's profile name to use. IfNone, the default value configured in your environment is used.
Raises
LoadClientError: If there is an issue loading the profile details from the environment or if the PKCE login flow fails.
See the QCS documentation for more details.
Create a QCSClient configuration using an environment-based configuration.
If credentials are not found or stale, a PKCE login redirect flow will be initialized.
Note that this opens up a TCP port on your system to accept a browser HTTP redirect,
so you should not use this in environments where that is not possible,
such as hosted JupyterLab sessions.
Parameters
profile_name: The QCS setting's profile name to use. IfNone, the default value configured in your environment is used.
Raises
LoadClientError: If there is an issue loading the profile details from the environment or if the PKCE login flow fails.
See the QCS documentation for more details.
Base exception type for errors raised by this package.
Data resulting from Executable::execute_on_qvm
This represents a single vector (or "register") of typed memory across some number of shots.
The register corresponds to the usage of a DECLARE instruction in Quil, and the name of that
register should be provided with Executable::read_from.
There is a variant of this enum for each type of data that a register could hold. The register
is represented as a 2-dimensional array M where the value M[shot_number][memory_index]
represents the value at memory_index for shot_number.
Usage
Typically, you will be interacting with this data through the [crate::ResultData] of an
[crate::ExecutionData] returned after running a program. In those cases, you'll probably
want to convert it to a readout map using [crate::ResultData.to_register_map()]. This
will give you each register in the form of a [crate::RegisterMatrix] which is similar
but backed by an [ndarray::Array2] and more convenient for working with matrices.
If you are interacting with [RegisterData] directly, then you should already know what type of data it _should_
have, so you can use the [mod@enum_as_inner] methods (e.g. [RegisterData::into_i8]) in order to
convert any variant type to its inner data.
Corresponds to the Quil BIT or OCTET types.
Corresponds to the Quil REAL type.
Corresponds to the Quil INTEGER type.
Results containing complex numbers.
A mapping of a register name (ie. "ro") to a [RegisterMatrix] containing the values for the
register.
Get the RegisterMatrix for the given register.
Returns None if the register doesn't exist.
A 2-dimensional matrix of register values.
Each variant corresponds to the possible data types a register can contain.
Integer register.
Real numbered register.
Complex numbered register.
Error that may occur when building a RegisterMatrix from execution data.
The external services that this SDK may connect to. Used to differentiate between networking
issues in [Error::Connection].
Reset all caches for logging configuration within this library, allowing the most recent Python-side changes to be applied.
See https://docs.rs/pyo3-log/latest/pyo3_log/ for more information.