Instruction
- class braket.circuits.instruction.Instruction(operator, target=None, *, control=None, control_state=None, power=1)[source]
Bases:
objectAn instruction is a quantum directive that describes the quantum task to perform on a quantum device.
- Parameters:
operator (InstructionOperator)
target (QubitSetInput | None)
control (QubitSetInput | None)
control_state (BasisStateInput | None)
power (float)
InstructionOperator includes objects of type
GateandNoiseonly.- Parameters:
operator (InstructionOperator) – Operator for the instruction.
target (QubitSetInput | None) – Target qubits that the operator is applied to. Default is None.
control (QubitSetInput | None) – Target qubits that the operator is controlled on. Default is None.
control_state (BasisStateInput | None) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control. Will be ignored ifcontrolis not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the |0⟩ state and qubits 1 and 3 being in the |1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- 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),)) >>> instr = Instruction(Gate.Rx(0.12, control=1), 0) Instruction( 'operator': Rx, 'target': QubitSet(Qubit(0),), 'control': QubitSet(Qubit(1),), )
- property control_state: BasisState
Quantum state that the operator is controlled to.
- Type:
- property power: float
Power that the operator is raised to.
- Type:
float
- adjoint()[source]
Returns a list of Instructions implementing adjoint of this instruction’s own operator
This operation only works on Gate operators and compiler directives.
- Return type:
list[Instruction]- Returns:
list[Instruction] – A list of new instructions that comprise the adjoint of this operator
- Raises:
NotImplementedError – If
operatoris not of typeGateorCompilerDirective
- to_ir(ir_type=IRType.JAQCD, serialization_properties=None)[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.
- Parameters:
ir_type (IRType) – The IRType to use for converting the instruction object to its IR representation.
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.
- Return type:
Any- Returns:
Any – IR object of the instruction.
- property ascii_symbols: tuple[str, ...]
Returns the ascii symbols for the instruction’s operator.
- Type:
tuple[str, …]
- copy(target_mapping=None, target=None, control_mapping=None, control=None, control_state=None, power=1)[source]
Return a shallow copy of the instruction.
Note
If
target_mappingis specified, thenself.targetis mapped to the specified qubits. This is useful apply an instruction to a circuit and change the target qubits. Same relationship holds forcontrol_mapping.- Parameters:
target_mapping (dict[QubitInput, QubitInput] | None) – A dictionary of qubit mappings to apply to the target. Key is the qubit in this
targetand the value is what the key is changed to. Default =None.target (QubitSetInput | None) – Target qubits for the new instruction. Default is None.
control_mapping (dict[QubitInput, QubitInput] | None) – A dictionary of qubit mappings to apply to the control. Key is the qubit in this
controland the value is what the key is changed to. Default =None.control (QubitSetInput | None) – Control qubits for the new instruction. Default is None.
control_state (BasisStateInput | None) – Quantum state on which to control the operation. Must be a binary sequence of same length as number of qubits in
control. Will be ignored ifcontrolis not present. May be represented as a string, list, or int. For example “0101”, [0, 1, 0, 1], 5 all represent controlling on qubits 0 and 2 being in the |0⟩ state and qubits 1 and 3 being in the |1⟩ state. Default “1” * len(control).power (float) – Integer or fractional power to raise the gate to. Negative powers will be split into an inverse, accompanied by the positive power. Default 1.
- Return type:
Instruction
- Returns:
Instruction – A shallow copy of the instruction.
- Raises:
TypeError – If both
target_mappingandtargetare 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))