Package com.quantum4j.core.circuit
Class Instruction
java.lang.Object
com.quantum4j.core.circuit.Instruction
Represents a single instruction in a quantum circuit.
An Instruction can be either a gate operation or a measurement. Gate instructions include the gate and target qubit indices. Measurement instructions include qubit and classical bit indices.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumType of instruction: GATE or MEASURE. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Create a deep copy of this instruction.static InstructionCreate a gate instruction.int[]Get the classical bit indices (only for MEASURE type instructions).getGate()Get the gate (only for GATE type instructions).int[]Get the target qubits.getType()Get the type of this instruction.static Instructionmeasure(int qubit, int classicalBit) Create a measurement instruction.
-
Method Details
-
gate
Create a gate instruction.- Parameters:
gate- the gate to applyqubits- target qubit indices- Returns:
- a new gate Instruction
-
measure
Create a measurement instruction.- Parameters:
qubit- the qubit to measureclassicalBit- the classical bit index to store result- Returns:
- a new measurement Instruction
-
getType
Get the type of this instruction.- Returns:
- GATE or MEASURE
-
getGate
Get the gate (only for GATE type instructions).- Returns:
- the gate, or null if this is a MEASURE
-
getQubits
public int[] getQubits()Get the target qubits.- Returns:
- array of qubit indices
-
getClassicalBits
public int[] getClassicalBits()Get the classical bit indices (only for MEASURE type instructions).- Returns:
- array of classical bit indices
-
copy
Create a deep copy of this instruction. Gate instances are treated as immutable and are shared; qubit/classical index arrays are cloned to avoid aliasing.- Returns:
- a new Instruction with the same contents
-