Gate

class braket.circuits.gate.Gate(qubit_count, ascii_symbols)[source]

Bases: QuantumOperator

Class Gate represents a quantum gate that operates on N qubits. Gates are considered the building blocks of quantum circuits. This class is considered the gate definition containing the metadata that defines what a gate is and what it does.

Parameters:
  • qubit_count (int | None)

  • ascii_symbols (Sequence[str])

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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != 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_ir(target, ir_type=IRType.JAQCD, serialization_properties=None, *, control=None, control_state=None, power=1)[source]

Returns IR object of quantum operator and target

Parameters:
  • target (QubitSet) – target qubit(s).

  • ir_type (IRType) – The IRType to use for converting the gate object to its IR representation. Defaults to IRType.JAQCD.

  • serialization_properties (SerializationProperties | None) – The serialization properties to use while serializing the object to the IR representation. The serialization properties supplied must correspond to the supplied ir_type. Defaults to None.

  • control (QubitSet | None) – Control qubit(s). Only supported for OpenQASM. 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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Any

Returns:

Any – IR object of the quantum operator and target

Raises:
  • ValueError – If the supplied ir_type is not supported, or if the supplied serialization

  • properties don't correspond to the ir_type.

  • ValueError – If gate modifiers are supplied with ir_type Jaqcd.

property ascii_symbols: tuple[str, ...]

Returns the ascii symbols for the quantum operator.

Type:

tuple[str, …]

classmethod register_gate(gate)[source]

Register a gate implementation by adding it into the Gate class.

Parameters:

gate (type[Gate]) – Gate class to register.

Return type:

None

class CCNot

Bases: Gate

CCNOT gate or Toffoli gate.

Unitary matrix:

\[\begin{split}\mathtt{CCNOT} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 ccnot(control1, control2, target, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Control state only applies to control qubits specified with the control argument, not control1 and control2. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Instruction

Returns:

Instruction – CCNot instruction.

Examples

>>> circ = Circuit().ccnot(0, 1, 2)
static fixed_qubit_count()

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.

to_matrix()

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

class CNot

Bases: Gate

Controlled NOT gate.

Unitary matrix:

\[\begin{split}\mathtt{CNOT} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 cnot(control, target, power=1)

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)
static fixed_qubit_count()

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.

to_matrix()

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

class CPhaseShift(angle)

Bases: AngledGate

Controlled phase shift gate.

Unitary matrix:

\[\begin{split}\mathtt{CPhaseShift}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & e^{i \phi} \end{bmatrix}.\end{split}\]
Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

Returns:

AngledGate – A new Gate of the same type with the requested parameters bound.

Raises:

NotImplementedError – Subclasses should implement this function.

static cphaseshift(control, target, angle, power=1)

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)
static fixed_qubit_count()

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.

to_matrix()

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

class CPhaseShift00(angle)

Bases: AngledGate

Controlled phase shift gate for phasing the |00> state.

Unitary matrix:

\[\begin{split}\mathtt{CPhaseShift00}(\phi) = \begin{bmatrix} e^{i \phi} & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}.\end{split}\]
Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

Returns:

AngledGate – A new Gate of the same type with the requested parameters bound.

Raises:

NotImplementedError – Subclasses should implement this function.

static cphaseshift00(control, target, angle, power=1)

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)
static fixed_qubit_count()

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.

to_matrix()

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

class CPhaseShift01(angle)

Bases: AngledGate

Controlled phase shift gate for phasing the |01> state.

Unitary matrix:

\[\begin{split}\mathtt{CPhaseShift01}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & e^{i \phi} & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}.\end{split}\]
Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

Returns:

AngledGate – A new Gate of the same type with the requested parameters bound.

Raises:

NotImplementedError – Subclasses should implement this function.

static cphaseshift01(control, target, angle, power=1)

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)
static fixed_qubit_count()

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.

to_matrix()

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

class CPhaseShift10(angle)

Bases: AngledGate

Controlled phase shift gate for phasing the \|10> state.

Unitary matrix:

\[\begin{split}\mathtt{CPhaseShift10}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{i \phi} & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}.\end{split}\]
Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

Returns:

AngledGate – A new Gate of the same type with the requested parameters bound.

Raises:

NotImplementedError – Subclasses should implement this function.

static cphaseshift10(control, target, angle, power=1)

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)
static fixed_qubit_count()

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.

to_matrix()

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

class CSwap

Bases: Gate

Controlled Swap gate.

Unitary matrix:

\[\begin{split}\mathtt{CSWAP} = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 cswap(control, target1, target2, power=1)

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)
static fixed_qubit_count()

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.

to_matrix()

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

class CV

Bases: Gate

Controlled Sqrt of X gate.

Unitary matrix:

\[\begin{split}\mathtt{CV} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0.5+0.5i & 0.5-0.5i \\ 0 & 0 & 0.5-0.5i & 0.5+0.5i \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 cv(control, target, power=1)

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)
static fixed_qubit_count()

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.

to_matrix()

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

class CY

Bases: Gate

Controlled Pauli-Y gate.

Unitary matrix:

\[\begin{split}\mathtt{CY} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & -i \\ 0 & 0 & i & 0 \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 cy(control, target, power=1)

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)
static fixed_qubit_count()

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.

to_matrix()

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

class CZ

Bases: Gate

Controlled Pauli-Z gate.

Unitary matrix:

\[\begin{split}\mathtt{CZ} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 cz(control, target, power=1)

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)
static fixed_qubit_count()

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.

to_matrix()

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

class ECR

Bases: Gate

An echoed RZX(pi/2) gate (ECR gate).

Unitary matrix:

\[\begin{split}\mathtt{ECR} = \begin{bmatrix} 0 & 0 & 1 & i \\ 0 & 0 & i & 1 \\ 1 & -i & 0 & 0 \\ -i & 1 & 0 & 0 \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 ecr(target1, target2, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Instruction

Returns:

Instruction – ECR instruction.

Examples

>>> circ = Circuit().ecr(0, 1)
static fixed_qubit_count()

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.

to_matrix()

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

class GPhase(angle)

Bases: AngledGate

Global 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 angle is 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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

adjoint()

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.

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

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()

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)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Instruction | Iterable[Instruction]

Returns:

Instruction | Iterable[Instruction] – GPhase instruction.

Examples

>>> circ = Circuit().gphase(0.45)
to_matrix()

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

class GPi(angle)

Bases: AngledGate

IonQ GPi gate.

Unitary matrix:

\[\begin{split}\mathtt{GPi}(\phi) = \begin{bmatrix} 0 & e^{-i \phi} \\ e^{i \phi} & 0 \end{bmatrix}.\end{split}\]
Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

adjoint()

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.

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

GPi

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()

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 gpi(target, angle, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction] – GPi instruction.

Examples

>>> circ = Circuit().gpi(0, 0.15)
to_matrix()

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

class GPi2(angle)

Bases: AngledGate

IonQ GPi2 gate.

Unitary matrix:

\[\begin{split}\mathtt{GPi2}(\phi) = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & -i e^{-i \phi} \\ -i e^{i \phi} & 1 \end{bmatrix}.\end{split}\]
Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

adjoint()

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.

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

GPi2

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()

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 gpi2(target, angle, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction] – GPi2 instruction.

Examples

>>> circ = Circuit().gpi2(0, 0.15)
to_matrix()

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

class H

Bases: Gate

Hadamard gate.

Unitary matrix:

\[\begin{split}\mathtt{H} = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction]Iterable of H instructions.

Examples

>>> circ = Circuit().h(0)
>>> circ = Circuit().h([0, 1, 2])
to_matrix()

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

class I

Bases: Gate

Identity gate.

Unitary matrix:

\[\begin{split}\mathtt{I} = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction]Iterable of I instructions.

Examples

>>> circ = Circuit().i(0)
>>> circ = Circuit().i([0, 1, 2])
to_matrix()

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

class ISwap

Bases: Gate

ISwap gate.

Unitary matrix:

\[\begin{split}\mathtt{iSWAP} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & i & 0 \\ 0 & i & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Instruction

Returns:

Instruction – ISwap instruction.

Examples

>>> circ = Circuit().iswap(0, 1)
to_matrix()

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

class MS(angle_1, angle_2, angle_3=1.5707963267948966)

Bases: TripleAngledGate

IonQ Mølmer-Sørensen gate.

Unitary matrix:

\[\begin{split}&\mathtt{MS}(\phi_0, \phi_1, \theta) =\\ &\begin{bmatrix} \cos{\frac{\theta}{2}} & 0 & 0 & -ie^{-i (\phi_0 + \phi_1)}\sin{\frac{\theta}{2}} \\ 0 & \cos{\frac{\theta}{2}} & -ie^{-i (\phi_0 - \phi_1)}\sin{\frac{\theta}{2}} & 0 \\ 0 & -ie^{i (\phi_0 - \phi_1)}\sin{\frac{\theta}{2}} & \cos{\frac{\theta}{2}} & 0 \\ -ie^{i (\phi_0 + \phi_1)}\sin{\frac{\theta}{2}} & 0 & 0 & \cos{\frac{\theta}{2}} \end{bmatrix}.\end{split}\]
Parameters:

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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle_1 or angle_2 or angle_3 is None

adjoint()

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.

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Parameters:

**kwargs (FreeParameterExpression | str) – The parameters that are being assigned.

Return type:

MS

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()

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 ms(target1, target2, angle_1, angle_2, angle_3=1.5707963267948966, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction] – MS instruction.

Examples

>>> circ = Circuit().ms(0, 1, 0.15, 0.34)
to_matrix()

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

class PRx(angle_1, angle_2)

Bases: DoubleAngledGate

Phase Rx gate.

Unitary matrix:

\[\begin{split}\mathtt{PRx}(\theta,\phi) = \begin{bmatrix} \cos{(\theta / 2)} & -i e^{-i \phi} \sin{(\theta / 2)} \\ -i e^{i \phi} \sin{(\theta / 2)} & \cos{(\theta / 2)} \end{bmatrix}.\end{split}\]
Parameters:
  • angle_1 (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle_1 or angle_2 is None

adjoint()

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.

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Parameters:

**kwargs (FreeParameterExpression | str) – The parameters that are being assigned.

Return type:

PRx

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()

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 prx(target, angle_1, angle_2, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction] – PhaseRx instruction.

Examples

>>> circ = Circuit().prx(0, 0.15, 0.25)
to_matrix()

Returns a matrix representation of this gate.

Return type:

ndarray

Returns:

np.ndarray – The matrix representation of this gate.

class PSwap(angle)

Bases: AngledGate

PSwap gate.

Unitary matrix:

\[\begin{split}\mathtt{PSWAP}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & e^{i \phi} & 0 \\ 0 & e^{i \phi} & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]
Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

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()

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)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Instruction

Returns:

Instruction – PSwap instruction.

Examples

>>> circ = Circuit().pswap(0, 1, 0.15)
to_matrix()

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

class PhaseShift(angle)

Bases: AngledGate

Phase shift gate.

Unitary matrix:

\[\begin{split}\mathtt{PhaseShift}(\phi) = \begin{bmatrix} 1 & 0 \\ 0 & e^{i \phi} \end{bmatrix}\end{split}\]
Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

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()

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)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction] – PhaseShift instruction.

Examples

>>> circ = Circuit().phaseshift(0, 0.15)
to_matrix()

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

class PulseGate(pulse_sequence, qubit_count, display_name='PG')

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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

bind_values(**kwargs)

Takes in parameters and returns an object with specified parameters replaced with their values.

Return type:

PulseGate

Returns:

PulseGate – A copy of this gate with the requested parameters bound.

property parameters: list[FreeParameter]

Returns the list of FreeParameter s associated with the gate.

static pulse_gate(targets, pulse_sequence, display_name='PG', *, control=None, control_state=None, power=1)
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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

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])
property pulse_sequence: PulseSequence

The underlying PulseSequence of this gate.

Type:

PulseSequence

property requires_physical_qubits: bool

Whether a circuit using this operator requires qubits to be physical.

Type:

bool

to_matrix()

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

class Rx(angle)

Bases: AngledGate

X-axis rotation gate.

Unitary matrix:

\[\begin{split}\mathtt{R_x}(\phi) = \begin{bmatrix} \cos{(\phi/2)} & -i \sin{(\phi/2)} \\ -i \sin{(\phi/2)} & \cos{(\phi/2)} \end{bmatrix}.\end{split}\]
Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

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()

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 rx(target, angle, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction] – Rx instruction.

Examples

>>> circ = Circuit().rx(0, 0.15)
to_matrix()

Returns a matrix representation of this gate.

Return type:

ndarray

Returns:

np.ndarray – The matrix representation of this gate.

class Ry(angle)

Bases: AngledGate

Y-axis rotation gate.

Unitary matrix:

\[\begin{split}\mathtt{R_y}(\phi) = \begin{bmatrix} \cos{(\phi/2)} & -\sin{(\phi/2)} \\ \sin{(\phi/2)} & \cos{(\phi/2)} \end{bmatrix}.\end{split}\]
Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

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()

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 ry(target, angle, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction] – Rx instruction.

Examples

>>> circ = Circuit().ry(0, 0.15)
to_matrix()

Returns a matrix representation of this gate.

Return type:

ndarray

Returns:

np.ndarray – The matrix representation of this gate.

class Rz(angle)

Bases: AngledGate

Z-axis rotation gate.

Unitary matrix:

\[\begin{split}\mathtt{R_z}(\phi) = \begin{bmatrix} e^{-i \phi/2} & 0 \\ 0 & e^{i \phi/2} \end{bmatrix}.\end{split}\]
Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

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()

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)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction] – Rx instruction.

Examples

>>> circ = Circuit().rz(0, 0.15)
to_matrix()

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

class S

Bases: Gate

S gate.

Unitary matrix:

\[\begin{split}\mathtt{S} = \begin{bmatrix} 1 & 0 \\ 0 & i \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction]Iterable of S instructions.

Examples

>>> circ = Circuit().s(0)
>>> circ = Circuit().s([0, 1, 2])
to_matrix()

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

class Si

Bases: Gate

Conjugate transpose of S gate.

Unitary matrix:

\[\begin{split}\mathtt{S}^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & -i \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction] – Iterable of Si instructions.

Examples

>>> circ = Circuit().si(0)
>>> circ = Circuit().si([0, 1, 2])
to_matrix()

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

class Swap

Bases: Gate

Swap gate.

Unitary matrix:

\[\begin{split}\mathtt{SWAP} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Instruction

Returns:

Instruction – Swap instruction.

Examples

>>> circ = Circuit().swap(0, 1)
to_matrix()

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

class T

Bases: Gate

T gate.

Unitary matrix:

\[\begin{split}\mathtt{T} = \begin{bmatrix} 1 & 0 \\ 0 & e^{i \pi/4} \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction]Iterable of T instructions.

Examples

>>> circ = Circuit().t(0)
>>> circ = Circuit().t([0, 1, 2])
to_matrix()

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

class Ti

Bases: Gate

Conjugate transpose of T gate.

Unitary matrix:

\[\begin{split}\mathtt{T}^\dagger = \begin{bmatrix} 1 & 0 \\ 0 & e^{-i \pi/4} \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction]Iterable of Ti instructions.

Examples

>>> circ = Circuit().ti(0)
>>> circ = Circuit().ti([0, 1, 2])
to_matrix()

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

class U(angle_1, angle_2, angle_3)

Bases: TripleAngledGate

Generalized single-qubit rotation gate.

Unitary matrix:

\[\begin{split}\mathtt{U}(\theta, \phi, \lambda) = \begin{bmatrix} \cos{(\theta/2)} & -e^{i \lambda} \sin{(\theta/2)} \\ e^{i \phi} \sin{(\theta/2)} & e^{i (\phi + \lambda)} \cos{(\theta/2)} \end{bmatrix}.\end{split}\]
Parameters:

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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle_1 or angle_2 or angle_3 is None

adjoint()

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.

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Parameters:

**kwargs (FreeParameterExpression | str) – The parameters that are being assigned.

Return type:

TripleAngledGate

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()

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.

to_matrix()

Returns a matrix representation of this gate.

Return type:

ndarray

Returns:

np.ndarray – The matrix representation of this gate.

static u(target, angle_1, angle_2, angle_3, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction] – U instruction.

Examples

>>> circ = Circuit().u(0, 0.15, 0.34, 0.52)
class Unitary(matrix, display_name='U')

Bases: Gate

Arbitrary unitary gate.

Parameters:
  • matrix (numpy.ndarray) – Unitary matrix which defines the gate.

  • display_name (str) – Name to be used for an instance of this unitary gate for circuit diagrams. Defaults to U.

Raises:

ValueError – If matrix is not a two-dimensional square matrix, or has a dimension length that is not a positive power of 2, or is not unitary.

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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()

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 unitary(targets, matrix, display_name='U')

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:

Instruction

Returns:

Instruction – Unitary instruction.

Raises:

ValueError – If matrix is not a two-dimensional square matrix, or has a dimension length that is not compatible with the targets, or is not unitary,

Examples

>>> circ = Circuit().unitary(matrix=np.array([[0, 1], [1, 0]]), targets=[0])
class V

Bases: Gate

Square root of X gate (V gate).

Unitary matrix:

\[\begin{split}\mathtt{V} = \frac{1}{2}\begin{bmatrix} 1+i & 1-i \\ 1-i & 1+i \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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.

to_matrix()

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 v(target, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction]Iterable of V instructions.

Examples

>>> circ = Circuit().v(0)
>>> circ = Circuit().v([0, 1, 2])
class Vi

Bases: Gate

Conjugate transpose of square root of X gate (conjugate transpose of V).

Unitary matrix:

\[\begin{split}\mathtt{V}^\dagger = \frac{1}{2}\begin{bmatrix} 1-i & 1+i \\ 1+i & 1-i \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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.

to_matrix()

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 vi(target, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction]Iterable of Vi instructions.

Examples

>>> circ = Circuit().vi(0)
>>> circ = Circuit().vi([0, 1, 2])
class X

Bases: Gate

Pauli-X gate.

Unitary matrix:

\[\begin{split}\mathtt{X} = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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.

to_matrix()

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 x(target, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction]Iterable of X instructions.

Examples

>>> circ = Circuit().x(0)
>>> circ = Circuit().x([0, 1, 2])
class XX(angle)

Bases: AngledGate

Ising XX coupling gate.

Unitary matrix:

\[\begin{split}\mathtt{XX}(\phi) = \begin{bmatrix} \cos{(\phi/2)} & 0 & 0 & -i \sin{(\phi/2)} \\ 0 & \cos{(\phi/2)} & -i \sin{(\phi/2)} & 0 \\ 0 & -i \sin{(\phi/2)} & \cos{(\phi/2)} & 0 \\ -i \sin{(\phi/2)} & 0 & 0 & \cos{(\phi/2)} \end{bmatrix}.\end{split}\]

Reference: https://arxiv.org/abs/1707.06356

Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

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()

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.

to_matrix()

Returns a matrix representation of this gate.

Return type:

ndarray

Returns:

np.ndarray – The matrix representation of this gate.

static xx(target1, target2, angle, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Instruction

Returns:

Instruction – XX instruction.

Examples

>>> circ = Circuit().xx(0, 1, 0.15)
class XY(angle)

Bases: AngledGate

XY gate.

Unitary matrix:

\[\begin{split}\mathtt{XY}(\phi) = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos{(\phi/2)} & i\sin{(\phi/2)} & 0 \\ 0 & i\sin{(\phi/2)} & \cos{(\phi/2)} & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix}.\end{split}\]

Reference: https://arxiv.org/abs/1912.04424v1

Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

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()

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.

to_matrix()

Returns a matrix representation of this gate.

Return type:

ndarray

Returns:

np.ndarray – The matrix representation of this gate.

static xy(target1, target2, angle, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Instruction

Returns:

Instruction – XY instruction.

Examples

>>> circ = Circuit().xy(0, 1, 0.15)
class Y

Bases: Gate

Pauli-Y gate.

Unitary matrix:

\[\begin{split}\mathtt{Y} = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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.

to_matrix()

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 y(target, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction]Iterable of Y instructions.

Examples

>>> circ = Circuit().y(0)
>>> circ = Circuit().y([0, 1, 2])
class YY(angle)

Bases: AngledGate

Ising YY coupling gate.

Unitary matrix:

\[\begin{split}\mathtt{YY}(\phi) = \begin{bmatrix} \cos{(\phi/2)} & 0 & 0 & i \sin{(\phi/2)} \\ 0 & \cos{(\phi/2)} & -i \sin{(\phi/2)} & 0 \\ 0 & -i \sin{(\phi/2)} & \cos{(\phi/2)} & 0 \\ i \sin{(\phi/2)} & 0 & 0 & \cos{(\phi/2)} \end{bmatrix}.\end{split}\]

Reference: https://arxiv.org/abs/1707.06356

Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

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()

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.

to_matrix()

Returns a matrix representation of this gate.

Return type:

ndarray

Returns:

np.ndarray – The matrix representation of this gate.

static yy(target1, target2, angle, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Instruction

Returns:

Instruction – YY instruction.

Examples

>>> circ = Circuit().yy(0, 1, 0.15)
class Z

Bases: Gate

Pauli-Z gate.

Unitary matrix:

\[\begin{split}\mathtt{Z} = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix}.\end{split}\]

Initializes a Gate.

Parameters:
  • qubit_count (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:

ValueErrorqubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count

adjoint()

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 fixed_qubit_count()

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.

to_matrix()

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 z(target, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Iterable[Instruction]

Returns:

Iterable[Instruction]Iterable of Z instructions.

Examples

>>> circ = Circuit().z(0)
>>> circ = Circuit().z([0, 1, 2])
class ZZ(angle)

Bases: AngledGate

Ising ZZ coupling gate.

Unitary matrix:

\[\begin{split}\mathtt{ZZ}(\phi) = \begin{bmatrix} e^{-i\phi/2} & 0 & 0 & 0 \\ 0 & e^{i\phi/2} & 0 & 0 \\ 0 & 0 & e^{i\phi/2} & 0 \\ 0 & 0 & 0 & e^{-i\phi/2} \end{bmatrix}.\end{split}\]

Reference: https://arxiv.org/abs/1707.06356

Parameters:

angle (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_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is None

bind_values(**kwargs)

Takes in parameters and attempts to assign them to values.

Return type:

AngledGate

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()

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.

to_matrix()

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 zz(target1, target2, angle, *, control=None, control_state=None, power=1)

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 if control is not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the \|0⟩ state and qubits 1 and 3 being in the \|1⟩ state. Default “1” * len(control).

  • power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.

Return type:

Instruction

Returns:

Instruction – ZZ instruction.

Examples

>>> circ = Circuit().zz(0, 1, 0.15)