Operator

Trait Operator 

Source
pub trait Operator:
    Send
    + Sync
    + Debug
    + DynClone
    + Display {
    // Required methods
    fn apply(
        &self,
        state: &State,
        target_qubits: &[usize],
        control_qubits: &[usize],
    ) -> Result<State, Error>;
    fn base_qubits(&self) -> usize;

    // Provided method
    fn to_compilable(&self) -> Option<&dyn Compilable> { ... }
}
Expand description

A trait defining the interface for all operators.

Required Methods§

Source

fn apply( &self, state: &State, target_qubits: &[usize], control_qubits: &[usize], ) -> Result<State, Error>

Applies the operator to the given state’s target qubits, using the control qubits if required.

§Arguments:
  • state - The state to apply the operator to.

  • target_qubits - The target qubits to apply the operator to. If no target qubits are specified, the operator will be applied to all qubits in the state.

  • control_qubits - The control qubits to apply the operator to.

§Returns:
  • The new state after applying the operator.
Source

fn base_qubits(&self) -> usize

Returns the number of qubits that the operator acts on.

§Returns:
  • The number of qubits that the operator acts on.

Provided Methods§

Source

fn to_compilable(&self) -> Option<&dyn Compilable>

Optionally returns an intermediate representation of the operator for compilation to OpenQASM.

If you are not planning to compile the operator to an IR, you can ignore this method. If you want to compile the operator to QASM, you should implement this method.

§Returns:
  • An optional vector of InstructionIR representing the operator in an intermediate representation.

Implementors§