braket.circuits.gates module
- class braket.circuits.gates.H[source]
Bases:
Gate
Hadamard gate.
Unitary matrix:
\[\begin{split}\mathtt{H} = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static h(target: QubitSetInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Hadamard gate.
Unitary matrix:
\[\begin{split}\mathtt{H} = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] –
Iterable
of H instructions.
Examples
>>> circ = Circuit().h(0) >>> circ = Circuit().h([0, 1, 2])
- class braket.circuits.gates.I[source]
Bases:
Gate
Identity gate.
Unitary matrix:
\[\begin{split}\mathtt{I} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static i(target: QubitSetInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Identity gate.
Unitary matrix:
\[\begin{split}\mathtt{I} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] –
Iterable
of I instructions.
Examples
>>> circ = Circuit().i(0) >>> circ = Circuit().i([0, 1, 2])
- class braket.circuits.gates.GPhase(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
Global phase gate.
Unitary matrix:
\[\mathtt{gphase}(\gamma) = e^{i \gamma} I_1 = \begin{bmatrix} e^{i \gamma} \end{bmatrix}.\]- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
- Raises:
ValueError – If
angle
is not present
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- adjoint() list[Gate] [source]
Returns the adjoint of this gate as a singleton list.
- Returns:
list[Gate] – A list containing the gate with negated angle.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static gphase(angle: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Instruction | Iterable[Instruction] [source]
Global phase gate.
If the gate is applied with control/negative control modifiers, it is translated in an equivalent gate using the following definition:
phaseshift(λ) = ctrl @ gphase(λ)
. The rightmost control qubit is used for the translation. If the polarity of the rightmost control modifier is negative, the following identity is used:negctrl @ gphase(λ) q = x q; ctrl @ gphase(λ) q; x q
.Unitary matrix:
\[\mathtt{gphase}(\gamma) = e^{i \gamma} I_1 = \begin{bmatrix} e^{i \gamma} \end{bmatrix}.\]- Parameters:
angle (Union[FreeParameterExpression, float]) – Phase in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction | Iterable[Instruction] – GPhase instruction.
Examples
>>> circ = Circuit().gphase(0.45)
- class braket.circuits.gates.X[source]
Bases:
Gate
Pauli-X gate.
Unitary matrix:
\[\begin{split}\mathtt{X} = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static x(target: QubitSetInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Pauli-X gate.
Unitary matrix:
\[\begin{split}\mathtt{X} = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] –
Iterable
of X instructions.
Examples
>>> circ = Circuit().x(0) >>> circ = Circuit().x([0, 1, 2])
- class braket.circuits.gates.Y[source]
Bases:
Gate
Pauli-Y gate.
Unitary matrix:
\[\begin{split}\mathtt{Y} = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static y(target: QubitSetInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Pauli-Y gate.
Unitary matrix:
\[\begin{split}\mathtt{Y} = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] –
Iterable
of Y instructions.
Examples
>>> circ = Circuit().y(0) >>> circ = Circuit().y([0, 1, 2])
- class braket.circuits.gates.Z[source]
Bases:
Gate
Pauli-Z gate.
Unitary matrix:
\[\begin{split}\mathtt{Z} = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static z(target: QubitSetInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Pauli-Z gate.
\[\begin{split}\mathtt{Z} = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] –
Iterable
of Z instructions.
Examples
>>> circ = Circuit().z(0) >>> circ = Circuit().z([0, 1, 2])
- class braket.circuits.gates.S[source]
Bases:
Gate
S gate.
Unitary matrix:
\[\begin{split}\mathtt{S} = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static s(target: QubitSetInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
S gate.
\[\begin{split}\mathtt{S} = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] –
Iterable
of S instructions.
Examples
>>> circ = Circuit().s(0) >>> circ = Circuit().s([0, 1, 2])
- class braket.circuits.gates.Si[source]
Bases:
Gate
Conjugate transpose of S gate.
Unitary matrix:
\[\begin{split}\mathtt{S}^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & -i \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static si(target: QubitSetInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Conjugate transpose of S gate.
\[\begin{split}\mathtt{S}^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & -i \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] – Iterable of Si instructions.
Examples
>>> circ = Circuit().si(0) >>> circ = Circuit().si([0, 1, 2])
- class braket.circuits.gates.T[source]
Bases:
Gate
T gate.
Unitary matrix:
\[\begin{split}\mathtt{T} = \begin{bmatrix} 1 & 0 \\ 0 & e^{i \pi/4} \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static t(target: QubitSetInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
T gate.
\[\begin{split}\mathtt{T} = \begin{bmatrix} 1 & 0 \\ 0 & e^{i \pi/4} \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] –
Iterable
of T instructions.
Examples
>>> circ = Circuit().t(0) >>> circ = Circuit().t([0, 1, 2])
- class braket.circuits.gates.Ti[source]
Bases:
Gate
Conjugate transpose of T gate.
Unitary matrix:
\[\begin{split}\mathtt{T}^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & e^{-i \pi/4} \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static ti(target: QubitSetInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Conjugate transpose of T gate.
\[\begin{split}\mathtt{T}^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & e^{-i \pi/4} \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] –
Iterable
of Ti instructions.
Examples
>>> circ = Circuit().ti(0) >>> circ = Circuit().ti([0, 1, 2])
- class braket.circuits.gates.V[source]
Bases:
Gate
Square root of X gate (V gate).
Unitary matrix:
\[\begin{split}\mathtt{V} = \frac{1}{2}\begin{bmatrix} 1+i & 1-i \\ 1-i & 1+i \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static v(target: QubitSetInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Square root of X gate (V gate).
\[\begin{split}\mathtt{V} = \frac{1}{2}\begin{bmatrix} 1+i & 1-i \\ 1-i & 1+i \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] –
Iterable
of V instructions.
Examples
>>> circ = Circuit().v(0) >>> circ = Circuit().v([0, 1, 2])
- class braket.circuits.gates.Vi[source]
Bases:
Gate
Conjugate transpose of square root of X gate (conjugate transpose of V).
Unitary matrix:
\[\begin{split}\mathtt{V}^\dagger = \frac{1}{2}\begin{bmatrix} 1-i & 1+i \\ 1+i & 1-i \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static vi(target: QubitSetInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Conjugate transpose of square root of X gate (conjugate transpose of V).
\[\begin{split}\mathtt{V}^\dagger = \frac{1}{2}\begin{bmatrix} 1-i & 1+i \\ 1+i & 1-i \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] –
Iterable
of Vi instructions.
Examples
>>> circ = Circuit().vi(0) >>> circ = Circuit().vi([0, 1, 2])
- class braket.circuits.gates.Rx(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
X-axis rotation gate.
Unitary matrix:
\[\begin{split}\mathtt{R_x}(\phi) = \begin{bmatrix} \cos{(\phi/2)} & -i \sin{(\phi/2)} \\ -i \sin{(\phi/2)} & \cos{(\phi/2)} \end{bmatrix}.\end{split}\]- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of this gate.
- Returns:
np.ndarray – The matrix representation of this gate.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static rx(target: QubitSetInput, angle: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
X-axis rotation gate.
\[\begin{split}\mathtt{R_x}(\phi) = \begin{bmatrix} \cos{(\phi/2)} & -i \sin{(\phi/2)} \\ -i \sin{(\phi/2)} & \cos{(\phi/2)} \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s).
angle (Union[FreeParameterExpression, float]) – Angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] – Rx instruction.
Examples
>>> circ = Circuit().rx(0, 0.15)
- class braket.circuits.gates.Ry(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
Y-axis rotation gate.
Unitary matrix:
\[\begin{split}\mathtt{R_y}(\phi) = \begin{bmatrix} \cos{(\phi/2)} & -\sin{(\phi/2)} \\ \sin{(\phi/2)} & \cos{(\phi/2)} \end{bmatrix}.\end{split}\]- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of this gate.
- Returns:
np.ndarray – The matrix representation of this gate.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static ry(target: QubitSetInput, angle: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Y-axis rotation gate.
\[\begin{split}\mathtt{R_y}(\phi) = \begin{bmatrix} \cos{(\phi/2)} & -\sin{(\phi/2)} \\ \sin{(\phi/2)} & \cos{(\phi/2)} \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s).
angle (Union[FreeParameterExpression, float]) – Angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] – Rx instruction.
Examples
>>> circ = Circuit().ry(0, 0.15)
- class braket.circuits.gates.Rz(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
Z-axis rotation gate.
Unitary matrix:
\[\begin{split}\mathtt{R_z}(\phi) = \begin{bmatrix} e^{-i \phi/2} & 0 \\ 0 & e^{i \phi/2} \end{bmatrix}.\end{split}\]- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static rz(target: QubitSetInput, angle: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Z-axis rotation gate.
\[\begin{split}\mathtt{R_z}(\phi) = \begin{bmatrix} e^{-i \phi/2} & 0 \\ 0 & e^{i \phi/2} \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s).
angle (Union[FreeParameterExpression, float]) – Angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] – Rx instruction.
Examples
>>> circ = Circuit().rz(0, 0.15)
- class braket.circuits.gates.PhaseShift(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
Phase shift gate.
Unitary matrix:
\[\begin{split}\mathtt{PhaseShift}(\phi) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i \phi} \end{bmatrix}\end{split}\]- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static phaseshift(target: QubitSetInput, angle: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Phase shift gate.
\[\begin{split}\mathtt{PhaseShift}(\phi) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i \phi} \end{bmatrix}\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s).
angle (Union[FreeParameterExpression, float]) – angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] – PhaseShift instruction.
Examples
>>> circ = Circuit().phaseshift(0, 0.15)
- class braket.circuits.gates.U(angle_1: FreeParameterExpression | float, angle_2: FreeParameterExpression | float, angle_3: FreeParameterExpression | float)[source]
Bases:
TripleAngledGate
Generalized single-qubit rotation gate.
Unitary matrix:
\[\begin{split}\mathtt{U}(\theta, \phi, \lambda) = \begin{bmatrix} \cos{(\theta/2)} & -e^{i \lambda} \sin{(\theta/2)} \\ e^{i \phi} \sin{(\theta/2)} & -e^{i (\phi + \lambda)} \cos{(\theta/2)} \end{bmatrix}.\end{split}\]- Parameters:
angle_1 (Union[FreeParameterExpression, float]) – theta angle in radians.
angle_2 (Union[FreeParameterExpression, float]) – phi angle in radians.
angle_3 (Union[FreeParameterExpression, float]) – lambda angle in radians.
Inits a
TripleAngledGate
.- Parameters:
angle_1 (Union[FreeParameterExpression, float]) – The first angle of the gate in radians or expression representation.
angle_2 (Union[FreeParameterExpression, float]) – The second angle of the gate in radians or expression representation.
angle_3 (Union[FreeParameterExpression, float]) – The third angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle_1
orangle_2
orangle_3
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of this gate.
- Returns:
np.ndarray – The matrix representation of this gate.
- adjoint() list[Gate] [source]
Returns the adjoint of this gate as a singleton list.
- Returns:
list[Gate] – A list containing the gate with negated angle.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs) TripleAngledGate [source]
Takes in parameters and attempts to assign them to values.
- Parameters:
**kwargs (FreeParameterExpression | str) – The parameters that are being assigned.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static u(target: QubitSetInput, angle_1: FreeParameterExpression | float, angle_2: FreeParameterExpression | float, angle_3: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
Generalized single-qubit rotation gate.
Unitary matrix:
\[\begin{split}\mathtt{U}(\theta, \phi, \lambda) = \begin{bmatrix} \cos{(\theta/2)} & -e^{i \lambda} \sin{(\theta/2)} \\ e^{i \phi} \sin{(\theta/2)} & -e^{i (\phi + \lambda)} \cos{(\theta/2)} \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
angle_1 (Union[FreeParameterExpression, float]) – theta angle in radians.
angle_2 (Union[FreeParameterExpression, float]) – phi angle in radians.
angle_3 (Union[FreeParameterExpression, float]) – lambda angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] – U instruction.
Examples
>>> circ = Circuit().u(0, 0.15, 0.34, 0.52)
- class braket.circuits.gates.CNot[source]
Bases:
Gate
Controlled NOT gate.
Unitary matrix:
\[\begin{split}\mathtt{CNOT} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static cnot(control: QubitSetInput, target: QubitInput, power: float = 1) Instruction [source]
Controlled NOT gate.
\[\begin{split}\mathtt{CNOT} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{bmatrix}.\end{split}\]- Parameters:
control (QubitSetInput) – Control qubit(s). The last control qubit is absorbed into the target of the instruction.
target (QubitInput) – Target qubit index.
power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – CNot instruction.
Examples
>>> circ = Circuit().cnot(0, 1)
- class braket.circuits.gates.Swap[source]
Bases:
Gate
Swap gate.
Unitary matrix:
\[\begin{split}\mathtt{SWAP} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static swap(target1: QubitInput, target2: QubitInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Instruction [source]
Swap gate.
\[\begin{split}\mathtt{SWAP} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]- Parameters:
target1 (QubitInput) – Target qubit 1 index.
target2 (QubitInput) – Target qubit 2 index.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – Swap instruction.
Examples
>>> circ = Circuit().swap(0, 1)
- class braket.circuits.gates.ISwap[source]
Bases:
Gate
ISwap gate.
Unitary matrix:
\[\begin{split}\mathtt{iSWAP} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & i & 0 \\ 0 & i & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static iswap(target1: QubitInput, target2: QubitInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Instruction [source]
ISwap gate.
\[\begin{split}\mathtt{iSWAP} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & i & 0 \\ 0 & i & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]- Parameters:
target1 (QubitInput) – Target qubit 1 index.
target2 (QubitInput) – Target qubit 2 index.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – ISwap instruction.
Examples
>>> circ = Circuit().iswap(0, 1)
- class braket.circuits.gates.PSwap(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
PSwap gate.
Unitary matrix:
\[\begin{split}\mathtt{PSWAP}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & e^{i \phi} & 0 \\ 0 & e^{i \phi} & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static pswap(target1: QubitInput, target2: QubitInput, angle: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Instruction [source]
PSwap gate.
\[\begin{split}\mathtt{PSWAP}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & e^{i \phi} & 0 \\ 0 & e^{i \phi} & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]- Parameters:
target1 (QubitInput) – Target qubit 1 index.
target2 (QubitInput) – Target qubit 2 index.
angle (Union[FreeParameterExpression, float]) – angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – PSwap instruction.
Examples
>>> circ = Circuit().pswap(0, 1, 0.15)
- class braket.circuits.gates.XY(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
XY gate.
Unitary matrix:
\[\begin{split}\mathtt{XY}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos{(\phi/2)} & i\sin{(\phi/2)} & 0 \\ 0 & i\sin{(\phi/2)} & \cos{(\phi/2)} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]Reference: https://arxiv.org/abs/1912.04424v1
- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of this gate.
- Returns:
np.ndarray – The matrix representation of this gate.
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static xy(target1: QubitInput, target2: QubitInput, angle: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Instruction [source]
XY gate.
\[\begin{split}\mathtt{XY}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos{(\phi/2)} & i\sin{(\phi/2)} & 0 \\ 0 & i\sin{(\phi/2)} & \cos{(\phi/2)} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]- Parameters:
target1 (QubitInput) – Target qubit 1 index.
target2 (QubitInput) – Target qubit 2 index.
angle (Union[FreeParameterExpression, float]) – angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – XY instruction.
Examples
>>> circ = Circuit().xy(0, 1, 0.15)
- class braket.circuits.gates.CPhaseShift(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
Controlled phase shift gate.
Unitary matrix:
\[\begin{split}\mathtt{CPhaseShift}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{i \phi} \end{bmatrix}.\end{split}\]- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static cphaseshift(control: QubitSetInput, target: QubitInput, angle: FreeParameterExpression | float, power: float = 1) Instruction [source]
Controlled phase shift gate.
\[\begin{split}\mathtt{CPhaseShift}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{i \phi} \end{bmatrix}.\end{split}\]- Parameters:
control (QubitSetInput) – Control qubit(s). The last control qubit is absorbed into the target of the instruction.
target (QubitInput) – Target qubit index.
angle (Union[FreeParameterExpression, float]) – angle in radians.
power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – CPhaseShift instruction.
Examples
>>> circ = Circuit().cphaseshift(0, 1, 0.15)
- class braket.circuits.gates.CPhaseShift00(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
Controlled phase shift gate for phasing the |00> state.
Unitary matrix:
\[\begin{split}\mathtt{CPhaseShift00}(\phi) = \begin{bmatrix} e^{i \phi} & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}.\end{split}\]- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static cphaseshift00(control: QubitSetInput, target: QubitInput, angle: FreeParameterExpression | float, power: float = 1) Instruction [source]
Controlled phase shift gate for phasing the |00> state.
\[\begin{split}\mathtt{CPhaseShift00}(\phi) = \begin{bmatrix} e^{i \phi} & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}.\end{split}\]- Parameters:
control (QubitSetInput) – Control qubit(s). The last control qubit is absorbed into the target of the instruction.
target (QubitInput) – Target qubit index.
angle (Union[FreeParameterExpression, float]) – angle in radians.
power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – CPhaseShift00 instruction.
Examples
>>> circ = Circuit().cphaseshift00(0, 1, 0.15)
- class braket.circuits.gates.CPhaseShift01(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
Controlled phase shift gate for phasing the |01> state.
Unitary matrix:
\[\begin{split}\mathtt{CPhaseShift01}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & e^{i \phi} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}.\end{split}\]- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static cphaseshift01(control: QubitSetInput, target: QubitInput, angle: FreeParameterExpression | float, power: float = 1) Instruction [source]
Controlled phase shift gate for phasing the |01> state.
\[\begin{split}\mathtt{CPhaseShift01}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & e^{i \phi} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}.\end{split}\]- Parameters:
control (QubitSetInput) – Control qubit(s). The last control qubit is absorbed into the target of the instruction.
target (QubitInput) – Target qubit index.
angle (Union[FreeParameterExpression, float]) – angle in radians.
power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – CPhaseShift01 instruction.
Examples
>>> circ = Circuit().cphaseshift01(0, 1, 0.15)
- class braket.circuits.gates.CPhaseShift10(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
Controlled phase shift gate for phasing the \|10> state.
Unitary matrix:
\[\begin{split}\mathtt{CPhaseShift10}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{i \phi} & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}.\end{split}\]- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static cphaseshift10(control: QubitSetInput, target: QubitInput, angle: FreeParameterExpression | float, power: float = 1) Instruction [source]
Controlled phase shift gate for phasing the \|10> state.
\[\begin{split}\mathtt{CPhaseShift10}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{i \phi} & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}.\end{split}\]- Parameters:
control (QubitSetInput) – Control qubit(s). The last control qubit is absorbed into the target of the instruction.
target (QubitInput) – Target qubit index.
angle (Union[FreeParameterExpression, float]) – angle in radians.
power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – CPhaseShift10 instruction.
Examples
>>> circ = Circuit().cphaseshift10(0, 1, 0.15)
- class braket.circuits.gates.CV[source]
Bases:
Gate
Controlled Sqrt of X gate.
Unitary matrix:
\[\begin{split}\mathtt{CV} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0.5+0.5i & 0.5-0.5i \\ 0 & 0 & 0.5-0.5i & 0.5+0.5i \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static cv(control: QubitSetInput, target: QubitInput, power: float = 1) Instruction [source]
Controlled Sqrt of X gate.
\[\begin{split}\mathtt{CV} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0.5+0.5i & 0.5-0.5i \\ 0 & 0 & 0.5-0.5i & 0.5+0.5i \end{bmatrix}.\end{split}\]- Parameters:
control (QubitSetInput) – Control qubit(s). The last control qubit is absorbed into the target of the instruction.
target (QubitInput) – Target qubit index.
power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – CV instruction.
Examples
>>> circ = Circuit().cv(0, 1)
- class braket.circuits.gates.CY[source]
Bases:
Gate
Controlled Pauli-Y gate.
Unitary matrix:
\[\begin{split}\mathtt{CY} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & -i \\ 0 & 0 & i & 0 \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static cy(control: QubitSetInput, target: QubitInput, power: float = 1) Instruction [source]
Controlled Pauli-Y gate.
\[\begin{split}\mathtt{CY} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & -i \\ 0 & 0 & i & 0 \end{bmatrix}.\end{split}\]- Parameters:
control (QubitSetInput) – Control qubit(s). The last control qubit is absorbed into the target of the instruction.
target (QubitInput) – Target qubit index.
power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – CY instruction.
Examples
>>> circ = Circuit().cy(0, 1)
- class braket.circuits.gates.CZ[source]
Bases:
Gate
Controlled Pauli-Z gate.
Unitary matrix:
\[\begin{split}\mathtt{CZ} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static cz(control: QubitSetInput, target: QubitInput, power: float = 1) Instruction [source]
Controlled Pauli-Z gate.
\[\begin{split}\mathtt{CZ} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{bmatrix}.\end{split}\]- Parameters:
control (QubitSetInput) – Control qubit(s). The last control qubit is absorbed into the target of the instruction.
target (QubitInput) – Target qubit index.
power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – CZ instruction.
Examples
>>> circ = Circuit().cz(0, 1)
- class braket.circuits.gates.ECR[source]
Bases:
Gate
An echoed RZX(pi/2) gate (ECR gate).
Unitary matrix:
\[\begin{split}\mathtt{ECR} = \begin{bmatrix} 0 & 0 & 1 & i \\ 0 & 0 & i & 1 \\ 1 & -i & 0 & 0 \\ -i & 1 & 0 & 0 \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static ecr(target1: QubitInput, target2: QubitInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Instruction [source]
An echoed RZX(pi/2) gate (ECR gate).
\[\begin{split}\mathtt{ECR} = \begin{bmatrix} 0 & 0 & 1 & i \\ 0 & 0 & i & 1 \\ 1 & -i & 0 & 0 \\ -i & 1 & 0 & 0 \end{bmatrix}.\end{split}\]- Parameters:
target1 (QubitInput) – Target qubit 1 index.
target2 (QubitInput) – Target qubit 2 index.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – ECR instruction.
Examples
>>> circ = Circuit().ecr(0, 1)
- class braket.circuits.gates.XX(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
Ising XX coupling gate.
Unitary matrix:
\[\begin{split}\mathtt{XX}(\phi) = \begin{bmatrix} \cos{(\phi/2)} & 0 & 0 & -i \sin{(\phi/2)} \\ 0 & \cos{(\phi/2)} & -i \sin{(\phi/2)} & 0 \\ 0 & -i \sin{(\phi/2)} & \cos{(\phi/2)} & 0 \\ -i \sin{(\phi/2)} & 0 & 0 & \cos{(\phi/2)} \end{bmatrix}.\end{split}\]Reference: https://arxiv.org/abs/1707.06356
- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of this gate.
- Returns:
np.ndarray – The matrix representation of this gate.
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static xx(target1: QubitInput, target2: QubitInput, angle: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Instruction [source]
Ising XX coupling gate.
\[\begin{split}\mathtt{XX}(\phi) = \begin{bmatrix} \cos{(\phi/2)} & 0 & 0 & -i \sin{(\phi/2)} \\ 0 & \cos{(\phi/2)} & -i \sin{(\phi/2)} & 0 \\ 0 & -i \sin{(\phi/2)} & \cos{(\phi/2)} & 0 \\ -i \sin{(\phi/2)} & 0 & 0 & \cos{(\phi/2)} \end{bmatrix}.\end{split}\]- Parameters:
target1 (QubitInput) – Target qubit 1 index.
target2 (QubitInput) – Target qubit 2 index.
angle (Union[FreeParameterExpression, float]) – angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – XX instruction.
Examples
>>> circ = Circuit().xx(0, 1, 0.15)
- class braket.circuits.gates.YY(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
Ising YY coupling gate.
Unitary matrix:
\[\begin{split}\mathtt{YY}(\phi) = \begin{bmatrix} \cos{(\phi/2)} & 0 & 0 & i \sin{(\phi/2)} \\ 0 & \cos{(\phi/2)} & -i \sin{(\phi/2)} & 0 \\ 0 & -i \sin{(\phi/2)} & \cos{(\phi/2)} & 0 \\ i \sin{(\phi/2)} & 0 & 0 & \cos{(\phi/2)} \end{bmatrix}.\end{split}\]Reference: https://arxiv.org/abs/1707.06356
- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of this gate.
- Returns:
np.ndarray – The matrix representation of this gate.
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static yy(target1: QubitInput, target2: QubitInput, angle: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Instruction [source]
Ising YY coupling gate.
\[\begin{split}\mathtt{YY}(\phi) = \begin{bmatrix} \cos{(\phi/2)} & 0 & 0 & i \sin{(\phi/2)} \\ 0 & \cos{(\phi/2)} & -i \sin{(\phi/2)} & 0 \\ 0 & -i \sin{(\phi/2)} & \cos{(\phi/2)} & 0 \\ i \sin{(\phi/2)} & 0 & 0 & \cos{(\phi/2)} \end{bmatrix}.\end{split}\]- Parameters:
target1 (QubitInput) – Target qubit 1 index.
target2 (QubitInput) – Target qubit 2 index.
angle (Union[FreeParameterExpression, float]) – angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – YY instruction.
Examples
>>> circ = Circuit().yy(0, 1, 0.15)
- class braket.circuits.gates.ZZ(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
Ising ZZ coupling gate.
Unitary matrix:
\[\begin{split}\mathtt{ZZ}(\phi) = \begin{bmatrix} e^{-i\phi/2} & 0 & 0 & 0 \\ 0 & e^{i\phi/2} & 0 & 0 \\ 0 & 0 & e^{i\phi/2} & 0 \\ 0 & 0 & 0 & e^{-i\phi/2} \end{bmatrix}.\end{split}\]Reference: https://arxiv.org/abs/1707.06356
- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs) AngledGate [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static zz(target1: QubitInput, target2: QubitInput, angle: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Instruction [source]
Ising ZZ coupling gate.
\[\begin{split}\mathtt{ZZ}(\phi) = \begin{bmatrix} e^{-i\phi/2} & 0 & 0 & 0 \\ 0 & e^{i\phi/2} & 0 & 0 \\ 0 & 0 & e^{i\phi/2} & 0 \\ 0 & 0 & 0 & e^{-i\phi/2} \end{bmatrix}.\end{split}\]- Parameters:
target1 (QubitInput) – Target qubit 1 index.
target2 (QubitInput) – Target qubit 2 index.
angle (Union[FreeParameterExpression, float]) – angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – ZZ instruction.
Examples
>>> circ = Circuit().zz(0, 1, 0.15)
- class braket.circuits.gates.CCNot[source]
Bases:
Gate
CCNOT gate or Toffoli gate.
Unitary matrix:
\[\begin{split}\mathtt{CCNOT} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static ccnot(control1: QubitInput, control2: QubitInput, target: QubitInput, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Instruction [source]
CCNOT gate or Toffoli gate.
\[\begin{split}\mathtt{CCNOT} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ \end{bmatrix}.\end{split}\]- Parameters:
control1 (QubitInput) – Control qubit 1 index.
control2 (QubitInput) – Control qubit 2 index.
target (QubitInput) – Target qubit index.
control (Optional[QubitSetInput]) – Control qubit(s), in addition to control1 and control2. Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Control state only applies to control qubits specified with the control argument, not control1 and control2. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – CCNot instruction.
Examples
>>> circ = Circuit().ccnot(0, 1, 2)
- class braket.circuits.gates.CSwap[source]
Bases:
Gate
Controlled Swap gate.
Unitary matrix:
\[\begin{split}\mathtt{CSWAP} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- static cswap(control: QubitSetInput, target1: QubitInput, target2: QubitInput, power: float = 1) Instruction [source]
Controlled Swap gate.
\[\begin{split}\mathtt{CSWAP} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]- Parameters:
control (QubitSetInput) – Control qubit(s). The last control qubit is absorbed into the target of the instruction.
target1 (QubitInput) – Target qubit 1 index.
target2 (QubitInput) – Target qubit 2 index.
power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – CSwap instruction.
Examples
>>> circ = Circuit().cswap(0, 1, 2)
- class braket.circuits.gates.GPi(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
IonQ GPi gate.
Unitary matrix:
\[\begin{split}\mathtt{GPi}(\phi) = \begin{bmatrix} 0 & e^{-i \phi} \\ e^{i \phi} & 0 \end{bmatrix}.\end{split}\]- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- adjoint() list[Gate] [source]
Returns the adjoint of this gate as a singleton list.
- Returns:
list[Gate] – A list containing the gate with negated angle.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs) GPi [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static gpi(target: QubitSetInput, angle: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
IonQ GPi gate.
\[\begin{split}\mathtt{GPi}(\phi) = \begin{bmatrix} 0 & e^{-i \phi} \\ e^{i \phi} & 0 \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s).
angle (Union[FreeParameterExpression, float]) – Angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] – GPi instruction.
Examples
>>> circ = Circuit().gpi(0, 0.15)
- class braket.circuits.gates.PRx(angle_1: FreeParameterExpression | float, angle_2: FreeParameterExpression | float)[source]
Bases:
DoubleAngledGate
Phase Rx gate.
Unitary matrix:
\[\begin{split}\mathtt{PRx}(\theta,\phi) = \begin{bmatrix} \cos{(\theta / 2)} & -i e^{-i \phi} \sin{(\theta / 2)} \\ -i e^{i \phi} \sin{(\theta / 2)} & \cos{(\theta / 2)} \end{bmatrix}.\end{split}\]- Parameters:
angle_1 (Union[FreeParameterExpression, float]) – The first angle of the gate in radians or expression representation.
angle_2 (Union[FreeParameterExpression, float]) – The second angle of the gate in radians or expression representation.
Inits a
DoubleAngledGate
.- Parameters:
angle_1 (Union[FreeParameterExpression, float]) – The first angle of the gate in radians or expression representation.
angle_2 (Union[FreeParameterExpression, float]) – The second angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle_1
orangle_2
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of this gate.
- Returns:
np.ndarray – The matrix representation of this gate.
- adjoint() list[Gate] [source]
Returns the adjoint of this gate as a singleton list.
- Returns:
list[Gate] – A list containing the gate with negated angle.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs) PRx [source]
Takes in parameters and attempts to assign them to values.
- Parameters:
**kwargs (FreeParameterExpression | str) – The parameters that are being assigned.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static prx(target: QubitSetInput, angle_1: FreeParameterExpression | float, angle_2: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
PhaseRx gate.
\[\begin{split}\mathtt{PRx}(\theta,\phi) = \begin{bmatrix} \cos{(\theta / 2)} & -i e^{-i \phi} \sin{(\theta / 2)} \\ -i e^{i \phi} \sin{(\theta / 2)} & \cos{(\theta / 2)} \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s).
angle_1 (Union[FreeParameterExpression, float]) – First angle in radians.
angle_2 (Union[FreeParameterExpression, float]) – Second angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] – PhaseRx instruction.
Examples
>>> circ = Circuit().prx(0, 0.15, 0.25)
- class braket.circuits.gates.GPi2(angle: FreeParameterExpression | float)[source]
Bases:
AngledGate
IonQ GPi2 gate.
Unitary matrix:
\[\begin{split}\mathtt{GPi2}(\phi) = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & -i e^{-i \phi} \\ -i e^{i \phi} & 1 \end{bmatrix}.\end{split}\]- Parameters:
angle (Union[FreeParameterExpression, float]) – angle in radians.
Initializes an
AngledGate
.- Parameters:
angle (Union[FreeParameterExpression, float]) – The angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If the
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- adjoint() list[Gate] [source]
Returns the adjoint of this gate as a singleton list.
- Returns:
list[Gate] – A list containing the gate with negated angle.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs) GPi2 [source]
Takes in parameters and attempts to assign them to values.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static gpi2(target: QubitSetInput, angle: FreeParameterExpression | float, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
IonQ GPi2 gate.
\[\begin{split}\mathtt{GPi2}(\phi) = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & -i e^{-i \phi} \\ -i e^{i \phi} & 1 \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s).
angle (Union[FreeParameterExpression, float]) – Angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] – GPi2 instruction.
Examples
>>> circ = Circuit().gpi2(0, 0.15)
- class braket.circuits.gates.MS(angle_1: FreeParameterExpression | float, angle_2: FreeParameterExpression | float, angle_3: FreeParameterExpression | float = 1.5707963267948966)[source]
Bases:
TripleAngledGate
IonQ Mølmer-Sørensen gate.
Unitary matrix:
\[\begin{split}&\mathtt{MS}(\phi_0, \phi_1, \theta) =\\ &\begin{bmatrix} \cos{\frac{\theta}{2}} & 0 & 0 & -ie^{-i (\phi_0 + \phi_1)}\sin{\frac{\theta}{2}} \\ 0 & \cos{\frac{\theta}{2}} & -ie^{-i (\phi_0 - \phi_1)}\sin{\frac{\theta}{2}} & 0 \\ 0 & -ie^{i (\phi_0 - \phi_1)}\sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} & 0 \\ -ie^{i (\phi_0 + \phi_1)}\sin{\frac{\theta}{2}} & 0 & 0 & \cos{\frac{\theta}{2}} \end{bmatrix}.\end{split}\]- Parameters:
angle_1 (Union[FreeParameterExpression, float]) – angle in radians.
angle_2 (Union[FreeParameterExpression, float]) – angle in radians.
angle_3 (Union[FreeParameterExpression, float]) – angle in radians. Default value is angle_3=pi/2.
Inits a
TripleAngledGate
.- Parameters:
angle_1 (Union[FreeParameterExpression, float]) – The first angle of the gate in radians or expression representation.
angle_2 (Union[FreeParameterExpression, float]) – The second angle of the gate in radians or expression representation.
angle_3 (Union[FreeParameterExpression, float]) – The third angle of the gate in radians or expression representation.
qubit_count (Optional[int]) – The number of qubits that this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as
qubit_count
, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have["C", "X"]
to correlate a symbol with that index.
- Raises:
ValueError – If
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
, orangle_1
orangle_2
orangle_3
isNone
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- adjoint() list[Gate] [source]
Returns the adjoint of this gate as a singleton list.
- Returns:
list[Gate] – A list containing the gate with negated angle.
- static fixed_qubit_count() int [source]
Returns the number of qubits this quantum operator acts on, if instances are guaranteed to act on the same number of qubits.
If different instances can act on a different number of qubits, this method returns
NotImplemented
.- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs) MS [source]
Takes in parameters and attempts to assign them to values.
- Parameters:
**kwargs (FreeParameterExpression | str) – The parameters that are being assigned.
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static ms(target1: QubitInput, target2: QubitInput, angle_1: FreeParameterExpression | float, angle_2: FreeParameterExpression | float, angle_3: FreeParameterExpression | float = 1.5707963267948966, *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Iterable[Instruction] [source]
IonQ Mølmer-Sørensen gate.
\[\begin{split}&\mathtt{MS}(\phi_0, \phi_1, \theta) =\\ &\begin{bmatrix} \cos{\frac{\theta}{2}} & 0 & 0 & -ie^{-i (\phi_0 + \phi_1)}\sin{\frac{\theta}{2}} \\ 0 & \cos{\frac{\theta}{2}} & -ie^{-i (\phi_0 - \phi_1)}\sin{\frac{\theta}{2}} & 0 \\ 0 & -ie^{i (\phi_0 - \phi_1)}\sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} & 0 \\ -ie^{i (\phi_0 + \phi_1)}\sin{\frac{\theta}{2}} & 0 & 0 & \cos{\frac{\theta}{2}} \end{bmatrix}.\end{split}\]- Parameters:
target1 (QubitInput) – Target qubit 1 index.
target2 (QubitInput) – Target qubit 2 index.
angle_1 (Union[FreeParameterExpression, float]) – angle in radians.
angle_2 (Union[FreeParameterExpression, float]) – angle in radians.
angle_3 (Union[FreeParameterExpression, float]) – angle in radians.
control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Iterable[Instruction] – MS instruction.
Examples
>>> circ = Circuit().ms(0, 1, 0.15, 0.34)
- class braket.circuits.gates.Unitary(matrix: ndarray, display_name: str = 'U')[source]
Bases:
Gate
Arbitrary unitary gate.
- Parameters:
matrix (numpy.ndarray) – Unitary matrix which defines the gate.
display_name (str) – Name to be used for an instance of this unitary gate for circuit diagrams. Defaults to
U
.
- Raises:
ValueError – If
matrix
is not a two-dimensional square matrix, or has a dimension length that is not a positive power of 2, or is not unitary.
Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- adjoint() list[Gate] [source]
Returns a list of gates that implement the adjoint of this gate.
This is a list because some gates do not have an inverse defined by a single existing gate.
- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- static unitary(targets: QubitSet, matrix: ndarray, display_name: str = 'U') Instruction [source]
Arbitrary unitary gate.
- Parameters:
targets (QubitSet) – Target qubits.
matrix (numpy.ndarray) – Unitary matrix which defines the gate. Matrix should be compatible with the supplied targets, with
2 ** len(targets) == matrix.shape[0]
.display_name (str) – Name to be used for an instance of this unitary gate for circuit diagrams. Defaults to
U
.
- Returns:
Instruction – Unitary instruction.
- Raises:
ValueError – If
matrix
is not a two-dimensional square matrix, or has a dimension length that is not compatible with thetargets
, or is not unitary,
Examples
>>> circ = Circuit().unitary(matrix=np.array([[0, 1],[1, 0]]), targets=[0])
- class braket.circuits.gates.PulseGate(pulse_sequence: PulseSequence, qubit_count: int, display_name: str = 'PG')[source]
Bases:
Gate
,Parameterizable
- Arbitrary pulse gate which provides the ability to embed custom pulse sequences
within circuits.
- Parameters:
pulse_sequence (PulseSequence) – PulseSequence to embed within the circuit.
qubit_count (int) – The number of qubits this pulse gate operates on.
display_name (str) – Name to be used for an instance of this pulse gate for circuit diagrams. Defaults to
PG
.
Initializes a
Gate
.- Parameters:
qubit_count (Optional[int]) – Number of qubits this gate interacts with.
ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as
qubit_count
, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.
- Raises:
ValueError –
qubit_count
is less than 1,ascii_symbols
areNone
, orascii_symbols
length !=qubit_count
- property pulse_sequence: PulseSequence
The underlying PulseSequence of this gate.
- Type:
- property parameters: list[FreeParameter]
Returns the list of
FreeParameter
s associated with the gate.
- bind_values(**kwargs) PulseGate [source]
Takes in parameters and returns an object with specified parameters replaced with their values.
- Returns:
PulseGate – A copy of this gate with the requested parameters bound.
- to_matrix() ndarray [source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Returns:
np.ndarray – A matrix representation of the quantum operator
- static pulse_gate(targets: QubitSet, pulse_sequence: PulseSequence, display_name: str = 'PG', *, control: QubitSetInput | None = None, control_state: BasisStateInput | None = None, power: float = 1) Instruction [source]
- Arbitrary pulse gate which provides the ability to embed custom pulse sequences
within circuits.
- Parameters:
targets (QubitSet) – Target qubits. Note: These are only for representational purposes. The actual targets are determined by the frames used in the pulse sequence.
pulse_sequence (PulseSequence) – PulseSequence to embed within the circuit.
display_name (str) – Name to be used for an instance of this pulse gate for circuit diagrams. Defaults to
PG
.control (Optional[QubitSetInput]) – Control qubit(s). Default None.
control_state (Optional[BasisStateInput]) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control
. Will be ignored ifcontrol
is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Returns:
Instruction – Pulse gate instruction.
Examples
>>> pulse_seq = PulseSequence().set_frequency(frame, frequency).... >>> circ = Circuit().pulse_gate(pulse_sequence=pulse_seq, targets=[0])