braket.circuits.gate module

class braket.circuits.gate.Gate(qubit_count: int, ascii_symbols: Sequence[str])[source]

Bases: braket.circuits.operator.Operator

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

property qubit_count

Returns number of qubits this gate interacts with.

Type

int

property ascii_symbols

Returns the ascii symbols for the gate.

Type

Tuple[str]

property name

Returns the name of the gate

Returns

The name of the gate as a string

to_ir(target: braket.circuits.qubit_set.QubitSet) → Any[source]

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix(*args, **kwargs) → Any[source]

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

matrix_equivalence(other)[source]

Return if the matrix form of two gates are equivalent

Parameters

other (Gate) – Gate instance to compare this gate to

Returns

True if matrix forms of this gate and the gate compared to are equivalent

classmethod register_gate(gate: braket.circuits.gate.Gate)[source]

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

Parameters

gate (Gate) – Gate instance to register.

class CCNot

Bases: braket.circuits.gate.Gate

CCNOT gate or Toffoli gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static ccnot(control1: Union[Qubit, int], control2: Union[Qubit, int], target: Union[Qubit, int])braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • control1 (Qubit or int) – Control qubit 1 index.

  • control2 (Qubit or int) – Control qubit 2 index.

  • target (Qubit or int) – Target qubit index.

Returns

Instruction – CCNot instruction.

Examples

>>> circ = Circuit().ccnot(0, 1, 2)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class CNot

Bases: braket.circuits.gate.Gate

Controlled NOT gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static cnot(control: Union[Qubit, int], target: Union[Qubit, int])braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • control (Qubit or int) – Control qubit index.

  • target (Qubit or int) – Target qubit index.

Returns

Instruction – CNot instruction.

Examples

>>> circ = Circuit().cnot(0, 1)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class CPhaseShift(angle: float)

Bases: braket.circuits.angled_gate.AngledGate

Controlled phase shift gate.

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

static cphaseshift(control: Union[Qubit, int], target: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • control (Qubit or int) – Control qubit index.

  • target (Qubit or int) – Target qubit index.

  • angle (float) – Angle in radians.

Returns

Instruction – CPhaseShift instruction.

Examples

>>> circ = Circuit().cphaseshift(0, 1, 0.15)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class CPhaseShift00(angle: float)

Bases: braket.circuits.angled_gate.AngledGate

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

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

static cphaseshift00(control: Union[Qubit, int], target: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • control (Qubit or int) – Control qubit index.

  • target (Qubit or int) – Target qubit index.

  • angle (float) – Angle in radians.

Returns

Instruction – CPhaseShift00 instruction.

Examples

>>> circ = Circuit().cphaseshift00(0, 1, 0.15)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class CPhaseShift01(angle: float)

Bases: braket.circuits.angled_gate.AngledGate

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

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

static cphaseshift01(control: Union[Qubit, int], target: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • control (Qubit or int) – Control qubit index.

  • target (Qubit or int) – Target qubit index.

  • angle (float) – Angle in radians.

Returns

Instruction – CPhaseShift01 instruction.

Examples

>>> circ = Circuit().cphaseshift01(0, 1, 0.15)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class CPhaseShift10(angle: float)

Bases: braket.circuits.angled_gate.AngledGate

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

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

static cphaseshift10(control: Union[Qubit, int], target: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • control (Qubit or int) – Control qubit index.

  • target (Qubit or int) – Target qubit index.

  • angle (float) – Angle in radians.

Returns

Instruction – CPhaseShift10 instruction.

Examples

>>> circ = Circuit().cphaseshift10(0, 1, 0.15)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class CSwap

Bases: braket.circuits.gate.Gate

Controlled Swap gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static cswap(control: Union[Qubit, int], target1: Union[Qubit, int], target2: Union[Qubit, int])braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • control (Qubit or int) – Control qubit index

  • target1 (Qubit or int) – Target qubit 1 index.

  • target2 (Qubit or int) – Target qubit 2 index.

Returns

Instruction – CSwap instruction.

Examples

>>> circ = Circuit().cswap(0, 1, 2)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class CY

Bases: braket.circuits.gate.Gate

Controlled Pauli-Y gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static cy(control: Union[Qubit, int], target: Union[Qubit, int])braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • control (Qubit or int) – Control qubit index.

  • target (Qubit or int) – Target qubit index.

Returns

Instruction – CY instruction.

Examples

>>> circ = Circuit().cy(0, 1)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class CZ

Bases: braket.circuits.gate.Gate

Controlled Pauli-Z gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static cz(control: Union[Qubit, int], target: Union[Qubit, int])braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • control (Qubit or int) – Control qubit index.

  • target (Qubit or int) – Target qubit index.

Returns

Instruction – CZ instruction.

Examples

>>> circ = Circuit().cz(0, 1)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class H

Bases: braket.circuits.gate.Gate

Hadamard gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static h(target: Union[Qubit, int, Iterable[Union[Qubit, int]]]) → Iterable[braket.circuits.instruction.Instruction]

Registers this function into the circuit class.

Parameters

target (Qubit, int, or iterable of Qubit / int) – Target qubit(s)

Returns

Iterable[Instruction]Iterable of H instructions.

Examples

>>> circ = Circuit().h(0)
>>> circ = Circuit().h([0, 1, 2])
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class I

Bases: braket.circuits.gate.Gate

Identity gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static i(target: Union[Qubit, int, Iterable[Union[Qubit, int]]]) → Iterable[braket.circuits.instruction.Instruction]

Registers this function into the circuit class.

Parameters

target (Qubit, int, or iterable of Qubit / int) – Target qubit(s)

Returns

Iterable[Instruction]Iterable of I instructions.

Examples

>>> circ = Circuit().i(0)
>>> circ = Circuit().i([0, 1, 2])
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class ISwap

Bases: braket.circuits.gate.Gate

ISwap gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static iswap(target1: Union[Qubit, int], target2: Union[Qubit, int])braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • target1 (Qubit or int) – Target qubit 1 index.

  • target2 (Qubit or int) – Target qubit 2 index.

Returns

Instruction – ISwap instruction.

Examples

>>> circ = Circuit().iswap(0, 1)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class PSwap(angle: float)

Bases: braket.circuits.angled_gate.AngledGate

PSwap gate.

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

static pswap(target1: Union[Qubit, int], target2: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • target1 (Qubit or int) – Target qubit 1 index.

  • target2 (Qubit or int) – Target qubit 2 index.

Returns

Instruction – PSwap instruction.

Examples

>>> circ = Circuit().pswap(0, 1, 0.15)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class PhaseShift(angle: float)

Bases: braket.circuits.angled_gate.AngledGate

Phase shift gate.

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

static phaseshift(target: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • target (Qubit or int) – Target qubit index.

  • angle (float) – Angle in radians.

Returns

Instruction – PhaseShift instruction.

Examples

>>> circ = Circuit().phaseshift(0, 0.15)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class Rx(angle: float)

Bases: braket.circuits.angled_gate.AngledGate

X-axis rotation gate.

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

static rx(target: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • target (Qubit or int) – Target qubit index.

  • angle (float) – Angle in radians.

Returns

Instruction – Rx instruction.

Examples

>>> circ = Circuit().rx(0, 0.15)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class Ry(angle: float)

Bases: braket.circuits.angled_gate.AngledGate

Y-axis rotation gate.

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

static ry(target: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • target (Qubit or int) – Target qubit index.

  • angle (float) – Angle in radians.

Returns

Instruction – Ry instruction.

Examples

>>> circ = Circuit().ry(0, 0.15)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class Rz(angle: float)

Bases: braket.circuits.angled_gate.AngledGate

Z-axis rotation gate.

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

static rz(target: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • target (Qubit or int) – Target qubit index.

  • angle (float) – Angle in radians.

Returns

Instruction – Rz instruction.

Examples

>>> circ = Circuit().rz(0, 0.15)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class S

Bases: braket.circuits.gate.Gate

S gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static s(target: Union[Qubit, int, Iterable[Union[Qubit, int]]]) → Iterable[braket.circuits.instruction.Instruction]

Registers this function into the circuit class.

Parameters

target (Qubit, int, or iterable of Qubit / int) – Target qubit(s)

Returns

Iterable[Instruction]Iterable of S instructions.

Examples

>>> circ = Circuit().s(0)
>>> circ = Circuit().s([0, 1, 2])
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class Si

Bases: braket.circuits.gate.Gate

Conjugate transpose of S gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static si(target: Union[Qubit, int, Iterable[Union[Qubit, int]]]) → Iterable[braket.circuits.instruction.Instruction]

Registers this function into the circuit class.

Parameters

target (Qubit, int, or iterable of Qubit / int) – Target qubit(s)

Returns

Iterable[Instruction] – Iterable of Si instructions.

Examples

>>> circ = Circuit().si(0)
>>> circ = Circuit().si([0, 1, 2])
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class Swap

Bases: braket.circuits.gate.Gate

Swap gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static swap(target1: Union[Qubit, int], target2: Union[Qubit, int])braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • target1 (Qubit or int) – Target qubit 1 index.

  • target2 (Qubit or int) – Target qubit 2 index.

Returns

Instruction – Swap instruction.

Examples

>>> circ = Circuit().swap(0, 1)
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class T

Bases: braket.circuits.gate.Gate

T gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static t(target: Union[Qubit, int, Iterable[Union[Qubit, int]]]) → Iterable[braket.circuits.instruction.Instruction]

Registers this function into the circuit class.

Parameters

target (Qubit, int, or iterable of Qubit / int) – Target qubit(s)

Returns

Iterable[Instruction]Iterable of T instructions.

Examples

>>> circ = Circuit().t(0)
>>> circ = Circuit().t([0, 1, 2])
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class Ti

Bases: braket.circuits.gate.Gate

Conjugate transpose of T gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

static ti(target: Union[Qubit, int, Iterable[Union[Qubit, int]]]) → Iterable[braket.circuits.instruction.Instruction]

Registers this function into the circuit class.

Parameters

target (Qubit, int, or iterable of Qubit / int) – Target qubit(s)

Returns

Iterable[Instruction]Iterable of Ti instructions.

Examples

>>> circ = Circuit().ti(0)
>>> circ = Circuit().ti([0, 1, 2])
to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

class Unitary(matrix: numpy.ndarray, display_name: str = 'U')

Bases: braket.circuits.gate.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.

  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises
  • ValueError – If matrix is not a two-dimensional square matrix, or has a dimension length which is not a positive exponent of 2, or is non-unitary.

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

to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix()

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

static unitary(targets: braket.circuits.qubit_set.QubitSet, matrix: numpy.ndarray, display_name: str = 'U')braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • targets (QubitSet) – Target qubits.

  • matrix (numpy.ndarray) – Unitary matrix which defines the gate. Matrix should be compatible with the supplied targets, with 2 ** len(targets) == matrix.shape[0].

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

Returns

Instruction – Unitary instruction.

Raises

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

Examples

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

Bases: braket.circuits.gate.Gate

Square root of not gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

static v(target: Union[Qubit, int, Iterable[Union[Qubit, int]]]) → Iterable[braket.circuits.instruction.Instruction]

Registers this function into the circuit class.

Parameters

target (Qubit, int, or iterable of Qubit / int) – Target qubit(s)

Returns

Iterable[Instruction]Iterable of V instructions.

Examples

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

Bases: braket.circuits.gate.Gate

Conjugate transpose of square root of not gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

static vi(target: Union[Qubit, int, Iterable[Union[Qubit, int]]]) → Iterable[braket.circuits.instruction.Instruction]

Registers this function into the circuit class.

Parameters

target (Qubit, int, or iterable of Qubit / int) – Target qubit(s)

Returns

Iterable[Instruction]Iterable of Vi instructions.

Examples

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

Bases: braket.circuits.gate.Gate

Pauli-X gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

static x(target: Union[Qubit, int, Iterable[Union[Qubit, int]]]) → Iterable[braket.circuits.instruction.Instruction]

Registers this function into the circuit class.

Parameters

target (Qubit, int, or iterable of Qubit / int) – Target qubit(s)

Returns

Iterable[Instruction]Iterable of X instructions.

Examples

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

Bases: braket.circuits.angled_gate.AngledGate

Ising XX coupling gate.

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

static xx(target1: Union[Qubit, int], target2: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • target1 (Qubit or int) – Target qubit 1 index.

  • target2 (Qubit or int) – Target qubit 2 index.

  • angle (float) – Angle in radians.

Returns

Instruction – XX instruction.

Examples

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

Bases: braket.circuits.angled_gate.AngledGate

XY gate.

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

static xy(target1: Union[Qubit, int], target2: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • target1 (Qubit or int) – Target qubit 1 index.

  • target2 (Qubit or int) – Target qubit 2 index.

Returns

Instruction – XY instruction.

Examples

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

Bases: braket.circuits.gate.Gate

Pauli-Y gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

static y(target: Union[Qubit, int, Iterable[Union[Qubit, int]]]) → Iterable[braket.circuits.instruction.Instruction]

Registers this function into the circuit class.

Parameters

target (Qubit, int, or iterable of Qubit / int) – Target qubit(s)

Returns

Iterable[Instruction]Iterable of Y instructions.

Examples

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

Bases: braket.circuits.angled_gate.AngledGate

Ising YY coupling gate.

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

static yy(target1: Union[Qubit, int], target2: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • target1 (Qubit or int) – Target qubit 1 index.

  • target2 (Qubit or int) – Target qubit 2 index.

  • angle (float) – Angle in radians.

Returns

Instruction – YY instruction.

Examples

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

Bases: braket.circuits.gate.Gate

Pauli-Z gate.

Parameters
  • qubit_count (int) – Number of qubits this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of circuits. Length must be the same as qubit_count, and index ordering is expected to correlate with target ordering on the instruction. For instance, if CNOT instruction has the control qubit on the first index and target qubit on the second index. Then ASCII symbols would have [“C”, “X”] to correlate a symbol with that index.

Raises

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

to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

static z(target: Union[Qubit, int, Iterable[Union[Qubit, int]]]) → Iterable[braket.circuits.instruction.Instruction]

Registers this function into the circuit class.

Parameters

target (Qubit, int, or iterable of Qubit / int) – Target qubit(s)

Returns

Iterable[Instruction]Iterable of Z instructions.

Examples

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

Bases: braket.circuits.angled_gate.AngledGate

Ising ZZ coupling gate.

Parameters
  • angle (float) – angle in radians.

  • angle – The angle of the gate in radians.

  • qubit_count (int) – The number of qubits that this gate interacts with.

  • ascii_symbols (Sequence[str]) – ASCII string symbols for the gate. These are used when printing a diagram of a circuit. The length must be the same as qubit_count, and index ordering is expected to correlate with the target ordering on the instruction. For instance, if a CNOT instruction has the control qubit on the first index and target qubit on the second index, the ASCII symbols should have ["C", "X"] to correlate a symbol with that index.

Raises

ValueError – If the qubit_count is less than 1, ascii_symbols are None, or ascii_symbols length != qubit_count, or angle is`None`

to_ir(target: braket.circuits.qubit_set.QubitSet)

Returns IR object of gate and target

Parameters

target (QubitSet) – target qubit(s)

Returns

IR object of the gate and target

to_matrix() → numpy.ndarray

Returns a matrix representation of the gate

Returns

np.ndarray – A matrix representation of the gate

static zz(target1: Union[Qubit, int], target2: Union[Qubit, int], angle: float)braket.circuits.instruction.Instruction

Registers this function into the circuit class.

Parameters
  • target1 (Qubit or int) – Target qubit 1 index.

  • target2 (Qubit or int) – Target qubit 2 index.

  • angle (float) – Angle in radians.

Returns

Instruction – ZZ instruction.

Examples

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