braket.circuits.instruction module¶
-
class
braket.circuits.instruction.
Instruction
(operator: braket.circuits.operator.Operator, 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.
- Parameters
- Raises
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
target
¶ Target qubits that the operator is applied to.
Note
Don’t mutate this property, any mutations can have unexpected consequences.
- Type
-
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, thenself.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
andtarget
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))