Gates
- class braket.circuits.gates.H[source]
Bases:
GateHadamard 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static h(target, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] –
Iterableof H instructions.
Examples
>>> circ = Circuit().h(0) >>> circ = Circuit().h([0, 1, 2])
- class braket.circuits.gates.I[source]
Bases:
GateIdentity gate.
Unitary matrix:
\[\begin{split}\mathtt{I} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}.\end{split}\]Initializes a
Gate.- Parameters:
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static i(target, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] –
Iterableof I instructions.
Examples
>>> circ = Circuit().i(0) >>> circ = Circuit().i([0, 1, 2])
- class braket.circuits.gates.GPhase(angle)[source]
Bases:
AngledGateGlobal phase gate.
Unitary matrix:
\[\mathtt{gphase}(\gamma) = e^{i \gamma} I_1 = \begin{bmatrix} e^{i \gamma} \end{bmatrix}.\]- Parameters:
angle (float | FreeParameterExpression) – angle in radians.
- Raises:
ValueError – If
angleis not present
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- adjoint()[source]
Returns the adjoint of this gate as a singleton list.
- Return type:
list[Gate]- Returns:
list[Gate] – A list containing the gate with negated angle.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- 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()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static gphase(angle, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – Phase in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Instruction | Iterable[Instruction]
- Returns:
Instruction | Iterable[Instruction] – GPhase instruction.
Examples
>>> circ = Circuit().gphase(0.45)
- class braket.circuits.gates.X[source]
Bases:
GatePauli-X gate.
Unitary matrix:
\[\begin{split}\mathtt{X} = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}.\end{split}\]Initializes a
Gate.- Parameters:
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static x(target, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] –
Iterableof X instructions.
Examples
>>> circ = Circuit().x(0) >>> circ = Circuit().x([0, 1, 2])
- class braket.circuits.gates.Y[source]
Bases:
GatePauli-Y gate.
Unitary matrix:
\[\begin{split}\mathtt{Y} = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}.\end{split}\]Initializes a
Gate.- Parameters:
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static y(target, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] –
Iterableof Y instructions.
Examples
>>> circ = Circuit().y(0) >>> circ = Circuit().y([0, 1, 2])
- class braket.circuits.gates.Z[source]
Bases:
GatePauli-Z gate.
Unitary matrix:
\[\begin{split}\mathtt{Z} = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}.\end{split}\]Initializes a
Gate.- Parameters:
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static z(target, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] –
Iterableof Z instructions.
Examples
>>> circ = Circuit().z(0) >>> circ = Circuit().z([0, 1, 2])
- class braket.circuits.gates.S[source]
Bases:
GateS gate.
Unitary matrix:
\[\begin{split}\mathtt{S} = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix}.\end{split}\]Initializes a
Gate.- Parameters:
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static s(target, *, control=None, control_state=None, power=1)[source]
S gate.
\[\begin{split}\mathtt{S} = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix}.\end{split}\]- Parameters:
target (QubitSetInput) – Target qubit(s)
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] –
Iterableof S instructions.
Examples
>>> circ = Circuit().s(0) >>> circ = Circuit().s([0, 1, 2])
- class braket.circuits.gates.Si[source]
Bases:
GateConjugate 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static si(target, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- 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:
GateT 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static t(target, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] –
Iterableof T instructions.
Examples
>>> circ = Circuit().t(0) >>> circ = Circuit().t([0, 1, 2])
- class braket.circuits.gates.Ti[source]
Bases:
GateConjugate 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static ti(target, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] –
Iterableof Ti instructions.
Examples
>>> circ = Circuit().ti(0) >>> circ = Circuit().ti([0, 1, 2])
- class braket.circuits.gates.V[source]
Bases:
GateSquare 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static v(target, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] –
Iterableof V instructions.
Examples
>>> circ = Circuit().v(0) >>> circ = Circuit().v([0, 1, 2])
- class braket.circuits.gates.Vi[source]
Bases:
GateConjugate 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static vi(target, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] –
Iterableof Vi instructions.
Examples
>>> circ = Circuit().vi(0) >>> circ = Circuit().vi([0, 1, 2])
- class braket.circuits.gates.Rx(angle)[source]
Bases:
AngledGateX-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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of this gate.
- Return type:
ndarray- Returns:
np.ndarray – The matrix representation of this gate.
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static rx(target, angle, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – Angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] – Rx instruction.
Examples
>>> circ = Circuit().rx(0, 0.15)
- class braket.circuits.gates.Ry(angle)[source]
Bases:
AngledGateY-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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of this gate.
- Return type:
ndarray- Returns:
np.ndarray – The matrix representation of this gate.
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static ry(target, angle, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – Angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] – Rx instruction.
Examples
>>> circ = Circuit().ry(0, 0.15)
- class braket.circuits.gates.Rz(angle)[source]
Bases:
AngledGateZ-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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- 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()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static rz(target, angle, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – Angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] – Rx instruction.
Examples
>>> circ = Circuit().rz(0, 0.15)
- class braket.circuits.gates.PhaseShift(angle)[source]
Bases:
AngledGatePhase shift gate.
Unitary matrix:
\[\begin{split}\mathtt{PhaseShift}(\phi) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i \phi} \end{bmatrix}\end{split}\]- Parameters:
angle (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- 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()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static phaseshift(target, angle, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] – PhaseShift instruction.
Examples
>>> circ = Circuit().phaseshift(0, 0.15)
- class braket.circuits.gates.U(angle_1, angle_2, angle_3)[source]
Bases:
TripleAngledGateGeneralized 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 (float | FreeParameterExpression) – theta angle in radians.
angle_2 (float | FreeParameterExpression) – phi angle in radians.
angle_3 (float | FreeParameterExpression) – lambda angle in radians.
Inits a
TripleAngledGate.- Parameters:
angle_1 (float | FreeParameterExpression) – The first angle of the gate in radians or expression representation.
angle_2 (float | FreeParameterExpression) – The second angle of the gate in radians or expression representation.
angle_3 (float | FreeParameterExpression) – The third angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangle_1orangle_2orangle_3isNone
- to_matrix()[source]
Returns a matrix representation of this gate.
- Return type:
ndarray- Returns:
np.ndarray – The matrix representation of this gate.
- adjoint()[source]
Returns the adjoint of this gate as a singleton list.
- Return type:
list[Gate]- Returns:
list[Gate] – A list containing the gate with negated angle.
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Parameters:
**kwargs (FreeParameterExpression | str) – The parameters that are being assigned.
- Return type:
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static u(target, angle_1, angle_2, angle_3, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – theta angle in radians.
angle_2 (float | FreeParameterExpression) – phi angle in radians.
angle_3 (float | FreeParameterExpression) – lambda angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] – U instruction.
Examples
>>> circ = Circuit().u(0, 0.15, 0.34, 0.52)
- class braket.circuits.gates.CNot[source]
Bases:
GateControlled 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static cnot(control, target, power=1)[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.
- Return type:
Instruction
- Returns:
Instruction – CNot instruction.
Examples
>>> circ = Circuit().cnot(0, 1)
- class braket.circuits.gates.Swap[source]
Bases:
GateSwap 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static swap(target1, target2, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Instruction
- Returns:
Instruction – Swap instruction.
Examples
>>> circ = Circuit().swap(0, 1)
- class braket.circuits.gates.ISwap[source]
Bases:
GateISwap 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static iswap(target1, target2, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Instruction
- Returns:
Instruction – ISwap instruction.
Examples
>>> circ = Circuit().iswap(0, 1)
- class braket.circuits.gates.PSwap(angle)[source]
Bases:
AngledGatePSwap 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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- 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()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static pswap(target1, target2, angle, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Instruction
- Returns:
Instruction – PSwap instruction.
Examples
>>> circ = Circuit().pswap(0, 1, 0.15)
- class braket.circuits.gates.XY(angle)[source]
Bases:
AngledGateXY 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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of this gate.
- Return type:
ndarray- Returns:
np.ndarray – The matrix representation of this gate.
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- 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()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static xy(target1, target2, angle, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Instruction
- Returns:
Instruction – XY instruction.
Examples
>>> circ = Circuit().xy(0, 1, 0.15)
- class braket.circuits.gates.CPhaseShift(angle)[source]
Bases:
AngledGateControlled 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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- 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()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static cphaseshift(control, target, angle, power=1)[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 (float | FreeParameterExpression) – 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.
- Return type:
Instruction
- Returns:
Instruction – CPhaseShift instruction.
Examples
>>> circ = Circuit().cphaseshift(0, 1, 0.15)
- class braket.circuits.gates.CPhaseShift00(angle)[source]
Bases:
AngledGateControlled 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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- 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()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static cphaseshift00(control, target, angle, power=1)[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 (float | FreeParameterExpression) – 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.
- Return type:
Instruction
- Returns:
Instruction – CPhaseShift00 instruction.
Examples
>>> circ = Circuit().cphaseshift00(0, 1, 0.15)
- class braket.circuits.gates.CPhaseShift01(angle)[source]
Bases:
AngledGateControlled 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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- 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()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static cphaseshift01(control, target, angle, power=1)[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 (float | FreeParameterExpression) – 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.
- Return type:
Instruction
- Returns:
Instruction – CPhaseShift01 instruction.
Examples
>>> circ = Circuit().cphaseshift01(0, 1, 0.15)
- class braket.circuits.gates.CPhaseShift10(angle)[source]
Bases:
AngledGateControlled 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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- 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()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static cphaseshift10(control, target, angle, power=1)[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 (float | FreeParameterExpression) – 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.
- Return type:
Instruction
- Returns:
Instruction – CPhaseShift10 instruction.
Examples
>>> circ = Circuit().cphaseshift10(0, 1, 0.15)
- class braket.circuits.gates.CV[source]
Bases:
GateControlled 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static cv(control, target, power=1)[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.
- Return type:
Instruction
- Returns:
Instruction – CV instruction.
Examples
>>> circ = Circuit().cv(0, 1)
- class braket.circuits.gates.CY[source]
Bases:
GateControlled 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static cy(control, target, power=1)[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.
- Return type:
Instruction
- Returns:
Instruction – CY instruction.
Examples
>>> circ = Circuit().cy(0, 1)
- class braket.circuits.gates.CZ[source]
Bases:
GateControlled 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static cz(control, target, power=1)[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.
- Return type:
Instruction
- Returns:
Instruction – CZ instruction.
Examples
>>> circ = Circuit().cz(0, 1)
- class braket.circuits.gates.ECR[source]
Bases:
GateAn 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static ecr(target1, target2, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Instruction
- Returns:
Instruction – ECR instruction.
Examples
>>> circ = Circuit().ecr(0, 1)
- class braket.circuits.gates.XX(angle)[source]
Bases:
AngledGateIsing 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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of this gate.
- Return type:
ndarray- Returns:
np.ndarray – The matrix representation of this gate.
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- 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()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static xx(target1, target2, angle, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Instruction
- Returns:
Instruction – XX instruction.
Examples
>>> circ = Circuit().xx(0, 1, 0.15)
- class braket.circuits.gates.YY(angle)[source]
Bases:
AngledGateIsing 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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of this gate.
- Return type:
ndarray- Returns:
np.ndarray – The matrix representation of this gate.
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- 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()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static yy(target1, target2, angle, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Instruction
- Returns:
Instruction – YY instruction.
Examples
>>> circ = Circuit().yy(0, 1, 0.15)
- class braket.circuits.gates.ZZ(angle)[source]
Bases:
AngledGateIsing 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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- 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()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static zz(target1, target2, angle, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Instruction
- Returns:
Instruction – ZZ instruction.
Examples
>>> circ = Circuit().zz(0, 1, 0.15)
- class braket.circuits.gates.CCNot[source]
Bases:
GateCCNOT 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static ccnot(control1, control2, target, *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s), in addition to control1 and control2. Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Instruction
- Returns:
Instruction – CCNot instruction.
Examples
>>> circ = Circuit().ccnot(0, 1, 2)
- class braket.circuits.gates.CSwap[source]
Bases:
GateControlled 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 (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- static cswap(control, target1, target2, power=1)[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.
- Return type:
Instruction
- Returns:
Instruction – CSwap instruction.
Examples
>>> circ = Circuit().cswap(0, 1, 2)
- class braket.circuits.gates.GPi(angle)[source]
Bases:
AngledGateIonQ 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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- adjoint()[source]
Returns the adjoint of this gate as a singleton list.
- Return type:
list[Gate]- Returns:
list[Gate] – A list containing the gate with negated angle.
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static gpi(target, angle, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – Angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] – GPi instruction.
Examples
>>> circ = Circuit().gpi(0, 0.15)
- class braket.circuits.gates.PRx(angle_1, angle_2)[source]
Bases:
DoubleAngledGatePhase 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 (float | FreeParameterExpression) – The first angle of the gate in radians or expression representation.
angle_2 (float | FreeParameterExpression) – The second angle of the gate in radians or expression representation.
Inits a
DoubleAngledGate.- Parameters:
angle_1 (float | FreeParameterExpression) – The first angle of the gate in radians or expression representation.
angle_2 (float | FreeParameterExpression) – The second angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangle_1orangle_2isNone
- to_matrix()[source]
Returns a matrix representation of this gate.
- Return type:
ndarray- Returns:
np.ndarray – The matrix representation of this gate.
- adjoint()[source]
Returns the adjoint of this gate as a singleton list.
- Return type:
list[Gate]- Returns:
list[Gate] – A list containing the gate with negated angle.
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Parameters:
**kwargs (FreeParameterExpression | str) – The parameters that are being assigned.
- Return type:
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static prx(target, angle_1, angle_2, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – First angle in radians.
angle_2 (float | FreeParameterExpression) – Second angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] – PhaseRx instruction.
Examples
>>> circ = Circuit().prx(0, 0.15, 0.25)
- class braket.circuits.gates.GPi2(angle)[source]
Bases:
AngledGateIonQ 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 (float | FreeParameterExpression) – angle in radians.
Initializes an
AngledGate.- Parameters:
angle (float | FreeParameterExpression) – The angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangleisNone
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- adjoint()[source]
Returns the adjoint of this gate as a singleton list.
- Return type:
list[Gate]- Returns:
list[Gate] – A list containing the gate with negated angle.
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Return type:
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static gpi2(target, angle, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – Angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] – GPi2 instruction.
Examples
>>> circ = Circuit().gpi2(0, 0.15)
- class braket.circuits.gates.MS(angle_1, angle_2, angle_3=1.5707963267948966)[source]
Bases:
TripleAngledGateIonQ 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 (float | FreeParameterExpression) – angle in radians.
angle_2 (float | FreeParameterExpression) – angle in radians.
angle_3 (float | FreeParameterExpression) – angle in radians. Default value is angle_3=pi/2.
Inits a
TripleAngledGate.- Parameters:
angle_1 (float | FreeParameterExpression) – The first angle of the gate in radians or expression representation.
angle_2 (float | FreeParameterExpression) – The second angle of the gate in radians or expression representation.
angle_3 (float | FreeParameterExpression) – The third angle of the gate in radians or expression representation.
qubit_count (int | None) – 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_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count, orangle_1orangle_2orangle_3isNone
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- adjoint()[source]
Returns the adjoint of this gate as a singleton list.
- Return type:
list[Gate]- Returns:
list[Gate] – A list containing the gate with negated angle.
- static fixed_qubit_count()[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.- Return type:
int- Returns:
int – The number of qubits this quantum operator acts on.
- bind_values(**kwargs)[source]
Takes in parameters and attempts to assign them to values.
- Parameters:
**kwargs (FreeParameterExpression | str) – The parameters that are being assigned.
- Return type:
- Returns:
AngledGate – A new Gate of the same type with the requested parameters bound.
- Raises:
NotImplementedError – Subclasses should implement this function.
- static ms(target1, target2, angle_1, angle_2, angle_3=1.5707963267948966, *, control=None, control_state=None, power=1)[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 (float | FreeParameterExpression) – angle in radians.
angle_2 (float | FreeParameterExpression) – angle in radians.
angle_3 (float | FreeParameterExpression) – angle in radians.
control (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Iterable[Instruction]
- Returns:
Iterable[Instruction] – MS instruction.
Examples
>>> circ = Circuit().ms(0, 1, 0.15, 0.34)
- class braket.circuits.gates.Unitary(matrix, display_name='U')[source]
Bases:
GateArbitrary 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
matrixis 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 (int | None) – 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.matrix (
ndarray)display_name (
str)
- Raises:
ValueError –
qubit_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- adjoint()[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.
- Return type:
list[Gate]- Returns:
list[Gate] – The gates comprising the adjoint of this gate.
- static unitary(targets, matrix, display_name='U')[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.
- Return type:
- Returns:
Instruction – Unitary instruction.
- Raises:
ValueError – If
matrixis 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, qubit_count, display_name='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 (int | None) – 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.pulse_sequence (
PulseSequence)display_name (
str)
- Raises:
ValueError –
qubit_countis less than 1,ascii_symbolsareNone, orascii_symbolslength !=qubit_count
- property pulse_sequence: PulseSequence
The underlying PulseSequence of this gate.
- Type:
- property parameters: list[FreeParameter]
Returns the list of
FreeParameters associated with the gate.
- property requires_physical_qubits: bool
Whether a circuit using this operator requires qubits to be physical.
- Type:
bool
- bind_values(**kwargs)[source]
Takes in parameters and returns an object with specified parameters replaced with their values.
- Return type:
- Returns:
PulseGate – A copy of this gate with the requested parameters bound.
- to_matrix()[source]
Returns a matrix representation of the quantum operator.
- Parameters:
*args (Any) – Not Implemented.
**kwargs (Any) – Not Implemented.
- Raises:
NotImplementError – Not Implemented.
- Return type:
ndarray- Returns:
np.ndarray – A matrix representation of the quantum operator
- static pulse_gate(targets, pulse_sequence, display_name='PG', *, control=None, control_state=None, power=1)[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 (QubitSetInput | None) – Control qubit(s). Default None.
control_state (BasisStateInput | None) – 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 ifcontrolis 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.
- Return type:
Instruction
- Returns:
Instruction – Pulse gate instruction.
Examples
>>> pulse_seq = PulseSequence().set_frequency(frame, frequency).... >>> circ = Circuit().pulse_gate(pulse_sequence=pulse_seq, targets=[0])