API documentation#
Module for conversion from tket to braket
- class pytket.extensions.braket.BraketBackend(local: bool = False, local_device: str = 'default', device: str | None = None, region: str = '', s3_bucket: str | None = None, s3_folder: str | None = None, device_type: str | None = None, provider: str | None = None, aws_session: AwsSession | None = None)#
Interface to Amazon Braket service
- __init__(local: bool = False, local_device: str = 'default', device: str | None = None, region: str = '', s3_bucket: str | None = None, s3_folder: str | None = None, device_type: str | None = None, provider: str | None = None, aws_session: AwsSession | None = None)#
Construct a new braket backend.
If local=True, other parameters are ignored.
All parameters except device can be set in config using
pytket.extensions.braket.set_braket_config()
. For device_type, provider and device if no parameter is specified as a keyword argument or in the config file the defaults specified below are used.- Parameters:
local – use simulator running on local machine, default: False
local_device – name of local device (ignored if local=False) – e.g. “braket_sv” (default) or “braket_dm”.
device – device name from device ARN (e.g. “ionQdevice”, “Aspen-8”, …), default: “sv1”
region – region from device ARN, default: “”
s3_bucket – name of S3 bucket to store results
s3_folder – name of folder (“key”) in S3 bucket to store results in
device_type – device type from device ARN (e.g. “qpu”), default: “quantum-simulator”
provider – provider name from device ARN (e.g. “ionq”, “rigetti”, “oqc”, …), default: “amazon”
aws_session – braket AwsSession object, to pass credentials in if not configured on local machine
- classmethod available_devices(**kwargs: Any) List[BackendInfo] #
See
pytket.backends.Backend.available_devices()
. Supported kwargs:region (default None). The particular AWS region to search for devices (e.g. us-east-1). Default to the region configured with AWS. See the Braket docs for more details.
aws_session (default None). The credentials of the provided session will be used to create a new session with the specified region. Otherwise, a default new session will be created
- cancel(handle: ResultHandle) None #
Cancel a job.
- Parameters:
handle (ResultHandle) – handle to job
- Raises:
NotImplementedError – If backend does not support job cancellation
- circuit_status(handle: ResultHandle) CircuitStatus #
Return a CircuitStatus reporting the status of the circuit execution corresponding to the ResultHandle
- default_compilation_pass(optimisation_level: int = 1) BasePass #
A suggested compilation pass that will will, if possible, produce an equivalent circuit suitable for running on this backend.
At a minimum it will ensure that compatible gates are used and that all two- qubit interactions are compatible with the backend’s qubit architecture. At higher optimisation levels, further optimisations may be applied.
This is a an abstract method which is implemented in the backend itself, and so is tailored to the backend’s requirements.
- Parameters:
optimisation_level (int, optional) –
The level of optimisation to perform during compilation.
Level 0 does the minimum required to solves the device constraints, without any optimisation.
Level 1 additionally performs some light optimisations.
Level 2 (the default) adds more computationally intensive optimisations that should give the best results from execution.
- Returns:
Compilation pass guaranteeing required predicates.
- Return type:
- get_amplitudes(circuit: Circuit, states: List[str], valid_check: bool = True, **kwargs: int | float | str | None) Dict[str, complex] #
Compute the complex coefficients of the final state.
Supported kwargs are as for BraketBackend.process_circuits.
- Parameters:
states – classical states of interest, as binary strings of ‘0’ and ‘1’
- Returns:
final complex amplitudes if initial state is all-zeros
- get_operator_expectation_value(state_circuit: Circuit, operator: QubitPauliOperator, n_shots: int = 0, valid_check: bool = True, **kwargs: int | float | str | None) float64 #
Compute the (exact or empirical) expectation of the observed eigenvalues.
See pytket.expectations.get_operator_expectation_value.
If n_shots > 0 the probabilities are calculated empirically by measurements. If n_shots = 0 (if supported) they are calculated exactly by simulation.
Supported kwargs are as for BraketBackend.get_pauli_expectation_value.
- get_operator_variance(state_circuit: Circuit, operator: QubitPauliOperator, n_shots: int = 0, valid_check: bool = True, **kwargs: int | float | str | None) float64 #
Compute the (exact or empirical) variance of the observed eigenvalues.
See pytket.expectations.get_operator_expectation_value.
If n_shots > 0 the probabilities are calculated empirically by measurements. If n_shots = 0 (if supported) they are calculated exactly by simulation.
Supported kwargs are as for BraketBackend.get_pauli_expectation_value.
- get_pauli_expectation_value(state_circuit: Circuit, pauli: QubitPauliString, n_shots: int = 0, valid_check: bool = True, **kwargs: int | float | str | None) float64 #
Compute the (exact or empirical) expectation of the observed eigenvalues.
See pytket.expectations.get_pauli_expectation_value.
If n_shots > 0 the probabilities are calculated empirically by measurements. If n_shots = 0 (if supported) they are calculated exactly by simulation.
Supported kwargs (not valid for local simulator):
poll_timeout_seconds (int) : Polling timeout for synchronous retrieval of result, in seconds (default: 5 days).
poll_interval_seconds (int) : Polling interval for synchronous retrieval of result, in seconds (default: 1 second).
- get_pauli_variance(state_circuit: Circuit, pauli: QubitPauliString, n_shots: int = 0, valid_check: bool = True, **kwargs: int | float | str | None) float64 #
Compute the (exact or empirical) variance of the observed eigenvalues.
See pytket.expectations.get_pauli_expectation_value.
If n_shots > 0 the probabilities are calculated empirically by measurements. If n_shots = 0 (if supported) they are calculated exactly by simulation.
Supported kwargs are as for BraketBackend.get_pauli_expectation_value.
- get_probabilities(circuit: Circuit, qubits: Iterable[int] | None = None, n_shots: int = 0, valid_check: bool = True, **kwargs: int | float | str | None) ndarray #
Compute the (exact or empirical) probability distribution of outcomes.
If n_shots > 0 the probabilities are calculated empirically by measurements. If n_shots = 0 (if supported) they are calculated exactly by simulation.
Supported kwargs are as for BraketBackend.process_circuits.
The order is big-endian with respect to the order of qubits in the argument. For example, if qubits=[0,1] then the order of probabilities is [p(0,0), p(0,1), p(1,0), p(1,1)], while if qubits=[1,0] the order is [p(0,0), p(1,0), p(0,1), p(1,1)], where p(i,j) is the probability of qubit 0 being in state i and qubit 1 being in state j.
- Parameters:
qubits – qubits of interest
- Returns:
list of probabilities of outcomes if initial state is all-zeros
- get_result(handle: ResultHandle, **kwargs: int | float | str | None) BackendResult #
See
pytket.backends.Backend.get_result()
. Supported kwargs: timeout (default none), wait (default 1s).
- process_circuits(circuits: Sequence[Circuit], n_shots: None | int | Sequence[int | None] = None, valid_check: bool = True, **kwargs: int | float | str | None) List[ResultHandle] #
Supported kwargs: - postprocess: apply end-of-circuit simplifications and classical
postprocessing to improve fidelity of results (bool, default False)
simplify_initial: apply the pytket
SimplifyInitial
pass to improve fidelity of results assuming all qubits initialized to zero (bool, default False)
- rebase_pass() BasePass #
A single compilation pass that when run converts all gates in a Circuit to an OpType supported by the Backend (ignoring architecture constraints).
- Returns:
Compilation pass that converts gates to primitives supported by Backend.
- Return type:
- property backend_info: BackendInfo#
Retrieve all Backend properties in a BackendInfo object, including device architecture, supported gate set, gate errors and other hardware-specific information.
- Returns:
The BackendInfo describing this backend if it exists.
- Return type:
Optional[BackendInfo]
- property required_predicates: List[Predicate]#
The minimum set of predicates that a circuit must satisfy before it can be successfully run on this backend.
- Returns:
Required predicates.
- Return type:
List[Predicate]
- property supports_amplitude: bool#
Whether the backend support calculation of final state amplitudes
- class pytket.extensions.braket.backends.config.BraketConfig(s3_bucket: str | None, s3_folder: str | None, device_type: str | None, provider: str | None)#
Holds config parameters for pytket-braket.
- classmethod from_extension_dict(ext_dict: Dict[str, Any]) BraketConfig #
Abstract method to build PytketExtConfig from dictionary serialized form.
- pytket.extensions.braket.backends.config.set_braket_config(s3_bucket: str | None = None, s3_folder: str | None = None, device_type: str | None = None, provider: str | None = None) None #
Set default values for any of s3_bucket, s3_folder, device_type or provider for AWS Braket. Can be overridden in backend construction.
Conversion from tket to braket
- pytket.extensions.braket.braket_convert.braket_to_tk(bkcirc: Circuit) Circuit #
Convert a braket circuit to a tket
Circuit
- Parameters:
bkcirc – circuit to be converted
- Returns:
circuit converted to tket
- pytket.extensions.braket.braket_convert.tk_to_braket(tkcirc: Circuit, mapped_qubits: bool = False, forced_qubits: List[int] | None = None, force_ops_on_target_qubits: bool = False) Tuple[Circuit, List[int], Dict[int, int]] #
Convert a tket
Circuit
to a braket circuit.- Parameters:
tkcirc – circuit to be converted
mapped_qubits – if True, tkcirc must have a single one-dimensional qubit register; the indices of the qubits in that register correspond directly to the qubit identifiers in the braket circuit
forced_qubits – optional list of braket qubit identifiers to include in the converted circuit even if they are unused
force_ops_on_target_qubits – if True, add no-ops to all target qubits
- Returns:
circuit converted to braket; list of braket qubit ids corresponding in order of corresponding positions in tkcirc.qubits; (partial) map from braket qubit ids to corresponding pytket bit indices holding measurement results