braket.circuits.instruction module

class braket.circuits.instruction.Instruction(operator: braket.circuits.gate.Gate, target: Union[Qubit, int, Iterable[Union[Qubit, int]]])[source]

Bases: object

An instruction is a quantum directive that describes the task to perform on a quantum device.

InstructionOperator includes objects of type Gate only.

Parameters
  • operator (InstructionOperator) – Operator for the instruction.

  • target (int, Qubit, or iterable of int / Qubit) – Target qubits that the operator is applied to.

Raises
  • ValueError – If operator is empty or any integer in target does not meet the Qubit or QubitSet class requirements.

  • TypeError – If a Qubit class can’t be constructed from target due to an incorrect

  • typing

Examples

>>> Instruction(Gate.CNot(), [0, 1])
Instruction('operator': CNOT, 'target': QubitSet(Qubit(0), Qubit(1)))
>>> instr = Instruction(Gate.CNot()), QubitSet([0, 1])])
Instruction('operator': CNOT, 'target': QubitSet(Qubit(0), Qubit(1)))
>>> instr = Instruction(Gate.H(), 0)
Instruction('operator': H, 'target': QubitSet(Qubit(0),))
>>> instr = Instruction(Gate.Rx(0.12), 0)
Instruction('operator': Rx, 'target': QubitSet(Qubit(0),))
property operator

The operator for the instruction, for example, Gate.

Type

Operator

property target

Target qubits that the operator is applied to.

Note

Don’t mutate this property, any mutations can have unexpected consequences.

Type

QubitSet

to_ir()[source]

Converts the operator into the canonical intermediate representation. If the operator is passed in a request, this method is called before it is passed.

copy(target_mapping: Dict[Union[Qubit, int], Union[Qubit, int]] = {}, target: Union[Qubit, int, Iterable[Union[Qubit, int]], None] = None)braket.circuits.instruction.Instruction[source]

Return a shallow copy of the instruction.

Note

If target_mapping is specified, then self.target is mapped to the specified qubits. This is useful apply an instruction to a circuit and change the target qubits.

Parameters
  • target_mapping (dictionary[int or Qubit, int or Qubit], optional) – A dictionary of qubit mappings to apply to the target. Key is the qubit in this target and the value is what the key is changed to. Default = {}.

  • target (int, Qubit, or iterable of int / Qubit, optional) – Target qubits for the new instruction.

Returns

Instruction – A shallow copy of the instruction.

Raises

TypeError – If both target_mapping and target are supplied.

Examples

>>> instr = Instruction(Gate.H(), 0)
>>> new_instr = instr.copy()
>>> new_instr.target
QubitSet(Qubit(0))
>>> new_instr = instr.copy(target_mapping={0: 5})
>>> new_instr.target
QubitSet(Qubit(5))
>>> new_instr = instr.copy(target=[5])
>>> new_instr.target
QubitSet(Qubit(5))