Class Instruction

java.lang.Object
com.quantum4j.core.circuit.Instruction

public final class Instruction extends Object
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.

  • Method Details

    • gate

      public static Instruction gate(Gate gate, int... qubits)
      Create a gate instruction.
      Parameters:
      gate - the gate to apply
      qubits - target qubit indices
      Returns:
      a new gate Instruction
    • measure

      public static Instruction measure(int qubit, int classicalBit)
      Create a measurement instruction.
      Parameters:
      qubit - the qubit to measure
      classicalBit - the classical bit index to store result
      Returns:
      a new measurement Instruction
    • getType

      public Instruction.Type getType()
      Get the type of this instruction.
      Returns:
      GATE or MEASURE
    • getGate

      public Gate 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

      public Instruction 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