ket.amazon¶
AmazonBraket Interface for Ket
The class AmazonBraket
provides a backend to connect Ket
with Amazon Braket, the fully managed quantum computing service from AWS.
This integration allows you to run quantum circuits developed in Ket on the diverse range of simulators and quantum processing units (QPUs) offered through the Braket service. By acting as a bridge between Ket’s high-level programming environment and Amazon’s cloud resources. This makes it an excellent choice for experiments that require high-performance simulation or access to different QPU architectures.
- Example:
from ket import *
from ket.amazon import AmazonBraket
from math import sqrt
device = AmazonBraket()
# device = AmazonBraket('arn:aws:braket:::device/quantum-simulator/amazon/tn1')
# device = AmazonBraket('arn:aws:braket:::device/quantum-simulator/amazon/dm1')
# device = AmazonBraket('arn:aws:braket:us-east-1::device/qpu/ionq/Aria-1')
# device = AmazonBraket('arn:aws:braket:us-east-1::device/qpu/ionq/Aria-2')
# device = AmazonBraket('arn:aws:braket:us-east-1::device/qpu/ionq/Forte-1')
# device = AmazonBraket('arn:aws:braket:us-east-1::device/qpu/ionq/Forte-Enterprise-1')
# device = AmazonBraket('arn:aws:braket:eu-north-1::device/qpu/iqm/Garnet')
# device = AmazonBraket('arn:aws:braket:us-west-1::device/qpu/rigetti/Ankaa-3')
process = Process(device)
a, b = process.alloc(2)
X(a + b)
CNOT(H(a), b)
with ham():
a0 = Z(a)
a1 = X(a)
b0 = -(X(b) + Z(b)) / sqrt(2)
b1 = (X(b) - Z(b)) / sqrt(2)
h = a0 * b0 + a0 * b1 + a1 * b0 - a1 * b1
print(exp_value(h).get())
To use the Braket QPUs and on demand simulators, you need to have an AWS account and the necessary permissions to access the Braket service. You can find more information on how to set up your AWS account and permissions in the Amazon Braket documentation.
Classes ket.amazon
¶
Amazon Braket Backend for Ket. |
- class AmazonBraket(device: str | None = None, shots: int | None = None, classical_shadows: dict | None = None, **kwargs)¶
Amazon Braket Backend for Ket.
This class provides an interface to run Ket quantum circuits on the Amazon Braket service. It enables access to a wide range of cloud-based simulators and real quantum hardware (QPUs), making it suitable for both small-scale tests and large-scale quantum experiments. Only Gate Model QPUs and simulators are supported.
The arguments
shots
andclassical_shadows
control how the execution is performed for estimating expectation values of an Hamiltonian term. Only one of these arguments can be specified at a time.If
shots
is specified, it will run the circuit multiple times (the number of shots) to estimate the expectation values. Ifclassical_shadows
is specified, it will use the classical shadows technique for state estimation. The dictionary should be in the format:{"bias": (int, int, int), "samples": int, "shots": int}
. Thebias
tuple represents the bias for the randomized measurements on the X, Y, and Z axes, respectively. Thesamples
is the number of classical shadows to be generated, andshots
is the number of shots for each sample.- Parameters:
device – The ARN (Amazon Resource Name) string of the Braket device (QPU or simulator) to be used for execution. If
None
, it defaults to using the local Braket simulator.shots – The number of shots for the execution to estimate the expectation values of an Hamiltonian term. If
classical_shadows
andshots
are not specified, it defaults to 2048.classical_shadows – If specified, it will use the classical shadows technique for state estimation.
kwargs – Additional keyword arguments to be passed to the Braket device.
- clear()¶
Clear the data to start a new execution.
Warning
This method is called by Libket and should not be called directly.
- submit_execution(circuit, parameters)¶
Get the quantum circuit to execute.
Warning
This method is called by Libket and should not be called directly.
- get_result()¶
Get the result of the quantum circuit execution.
Warning
This method is called by Libket and should not be called directly.
- pauli_x(target, control)¶
Apply a Pauli-X gate to the target qubit.
Warning
This method is called by Libket and should not be called directly.
- pauli_y(target, control)¶
Apply a Pauli-Y gate to the target qubit.
Warning
This method is called by Libket and should not be called directly.
- pauli_z(target, control)¶
Apply a Pauli-Z gate to the target qubit.
Warning
This method is called by Libket and should not be called directly.
- hadamard(target, control)¶
Apply a Hadamard gate to the target qubit.
Warning
This method is called by Libket and should not be called directly.
- rotation_x(target, control, **kwargs)¶
Apply a X-Rotation gate to the target qubit.
Warning
This method is called by Libket and should not be called directly.
- rotation_y(target, control, **kwargs)¶
Apply a Y-Rotation gate to the target qubit.
Warning
This method is called by Libket and should not be called directly.
- rotation_z(target, control, **kwargs)¶
Apply a Z-Rotation gate to the target qubit.
Warning
This method is called by Libket and should not be called directly.
- phase(target, control, **kwargs)¶
Apply a Phase gate to the target qubit.
Warning
This method is called by Libket and should not be called directly.