API documentation¶
Module for conversion from tket to braket
- class pytket.extensions.braket.BraketBackend(local=False, local_device='default', device=None, region='', s3_bucket=None, s3_folder=None, device_type=None, provider=None, aws_session=None)[source]¶
Interface to Amazon Braket service
- __init__(local=False, local_device='default', device=None, region='', s3_bucket=None, s3_folder=None, device_type=None, provider=None, aws_session=None)[source]¶
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 (
bool
) – use simulator running on local machine, default: Falselocal_device (
str
) – name of local device (ignored if local=False) – e.g. “braket_sv” (default) or “braket_dm”.device (
Optional
[str
]) – device name from device ARN (e.g. “ionQdevice”, “Aspen-8”, …), default: “sv1”region (
str
) – region from device ARN, default: “”s3_bucket (
Optional
[str
]) – name of S3 bucket to store resultss3_folder (
Optional
[str
]) – name of folder (“key”) in S3 bucket to store results indevice_type (
Optional
[str
]) – device type from device ARN (e.g. “qpu”), default: “quantum-simulator”provider (
Optional
[str
]) – provider name from device ARN (e.g. “ionq”, “rigetti”, “oqc”, …), default: “amazon”aws_session (
Optional
[AwsSession
]) – braket AwsSession object, to pass credentials in if not configured on local machine
- classmethod available_devices(**kwargs)[source]¶
See
pytket.backends.Backend.available_devices()
. Supported kwargs: :rtype:List
[BackendInfo
]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)[source]¶
Cancel a job.
- Parameters:
handle (ResultHandle) – handle to job
- Raises:
NotImplementedError – If backend does not support job cancellation
- Return type:
- circuit_status(handle)[source]¶
Return a CircuitStatus reporting the status of the circuit execution corresponding to the ResultHandle
- Return type:
- default_compilation_pass(optimisation_level=1)[source]¶
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:
BasePass
- get_amplitudes(circuit, states, valid_check=True, **kwargs)[source]¶
Compute the complex coefficients of the final state.
Supported kwargs are as for BraketBackend.process_circuits.
- get_operator_expectation_value(state_circuit, operator, n_shots=0, valid_check=True, **kwargs)[source]¶
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.
- Return type:
float64
- get_operator_variance(state_circuit, operator, n_shots=0, valid_check=True, **kwargs)[source]¶
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.
- Return type:
float64
- get_pauli_expectation_value(state_circuit, pauli, n_shots=0, valid_check=True, **kwargs)[source]¶
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): :rtype:
float64
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, pauli, n_shots=0, valid_check=True, **kwargs)[source]¶
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.
- Return type:
float64
- get_probabilities(circuit, qubits=None, n_shots=0, valid_check=True, **kwargs)[source]¶
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.
- get_result(handle, **kwargs)[source]¶
See
pytket.backends.Backend.get_result()
. Supported kwargs: timeout (default none), wait (default 1s).- Return type:
- process_circuits(circuits, n_shots=None, valid_check=True, **kwargs)[source]¶
- Return type:
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()[source]¶
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:
BasePass
- 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, s3_folder, device_type, provider)[source]¶
Holds config parameters for pytket-braket.
- pytket.extensions.braket.backends.config.set_braket_config(s3_bucket=None, s3_folder=None, device_type=None, provider=None)[source]¶
Set default values for any of s3_bucket, s3_folder, device_type or provider for AWS Braket. Can be overridden in backend construction.
- Return type:
Conversion from tket to braket
- pytket.extensions.braket.braket_convert.braket_to_tk(bkcirc)[source]¶
Convert a braket circuit to a tket
Circuit
- Parameters:
bkcirc (
Circuit
) – circuit to be converted- Return type:
- Returns:
circuit converted to tket
- pytket.extensions.braket.braket_convert.tk_to_braket(tkcirc, mapped_qubits=False, forced_qubits=None, force_ops_on_target_qubits=False)[source]¶
Convert a tket
Circuit
to a braket circuit.- Parameters:
tkcirc (
Circuit
) – circuit to be convertedmapped_qubits (
bool
) – 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 circuitforced_qubits (
Optional
[List
[int
]]) – optional list of braket qubit identifiers to include in the converted circuit even if they are unusedforce_ops_on_target_qubits (
bool
) – if True, add no-ops to all target qubits
- Return type:
- 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