Arcelyth/mqc/circuit does not have a README file

    ControlledKernel

    Apply a local kernel on one control block and identity on the others.

    DenseKernel

    Kernel that applies a general dense unitary matrix. Stores the matrix in row-major order.

    LinearKernel

    A linear map from a local complex vector to one of the same size.

    MonomialKernel

    A matrix with exactly one nonzero entry in each row and column. For Pauli Y, the column indices are 1 and 0, in row order.

    ScaledKernel

    Apply the inner linear kernel and multiply each output by a real scalar.

    UnitaryKernel

    A linear kernel that preserves inner products.

    Condition

    pub(open) trait Condition {
    fn evaluate(Self, &MeasurementRecord) -> Bool raise
    QError

    fn name(Self) -> String = _
    }

    A predicate over the current shot. Implement this trait to compare digits across keys or to supply a different rule for selecting a branch.

    Effect

    pub(open) trait Effect {
    fn measurement_key(Self) -> String? = _
    fn name(Self) -> String
    fn dim(Self) -> Array[UInt]
    fn arity(Self) -> Int = _
    fn try_conditional(Self) -> ConditionalEffect? = _
    fn try_unitary(Self) -> Gate? = _
    fn try_channel(Self) -> Channel? = _
    fn try_decompose(Self) -> Program? raise
    QError
    = _
    fn try_adjoint(Self) -> &Effect? raise
    QError
    = _
    fn parameters(Self) -> Array[String] = _
    }

    A quantum action on an ordered local wire shape such as Gate, Channel, and Program.

    An effect describes an operation independently of the physical wires it is applied to. Its local wire indices are mapped onto the enclosing operation's target wires when it is added to a program or circuit.

    MeasurementRecord

    pub(open) trait MeasurementRecord {
    fn latest(Self, String) -> ArrayView[Int] raise
    QError

    }

    Measurement results available to a condition during one shot. Digits are returned in target order. Reading a key before its measurement raises InvalidCondition.

    NoiseModel

    pub(open) trait NoiseModel {
    fn after_gate(Self, Gate, ArrayView[Int]) -> Array[(Channel, Array[Int])] raise
    QError

    }

    Qid

    pub(open) trait Qid : Eq + Hash {
    fn dim(Self) -> UInt
    }

    Identifies a quantum object. Equal IDs must have the same, fixed dimension. Dimensions must be at least two.

    ChainedCondition

    pub(all) struct ChainedCondition(Array[&Condition])

    Chained when calls are unwrapped outermost first. Evaluate them in the original order, including later predicates when an earlier one is false.

    Channel

    type Channel

    A quantum channel defined by Kraus operators.

    The channel transforms a density matrix as follows.

    impl Effect for Channel

    Channel::amplitude_damp

    fn Channel::amplitude_damp(probability : Double) -> Channel raise
    QError

    Create a single-qubit amplitude damping channel.

    probability is the chance that a qubit in the excited state decays to the ground state. A qubit already in the ground state stays there. The probability must be between 0 and 1, inclusive.

    The Kraus matrices below use p for the decay probability.

    Channel::arity

    fn Channel::arity(self : Channel) -> Int

    Channel::dim

    fn Channel::dim(self : Channel) -> Array[UInt]

    Channel::kernels

    Iterate over the linear kernels for the Kraus operators.

    Channel::kraus

    fn Channel::kraus(name : String, dimensions : Array[UInt], operators : Array[Array[
    Complex
    ]]) -> Channel raise
    QError

    Create a channel from a nonempty array of Kraus matrices.

    Each wire dimension must be at least 2. The first wire varies slowest in the basis. For example, dimensions = [2U, 3U] requires 6-by-6 matrices. Pass each matrix as a flat array in row-major order.

    Matrix entries must be finite. The Kraus matrices must satisfy

    Invalid dimensions or matrices raise QError.

    Channel::kraus_operators

    Iterate over the Kraus matrices. Each view contains one matrix in row-major order.

    Channel::measurement_key

    fn Channel::measurement_key(_self : Channel) -> String?

    Channel::mixture

    fn Channel::mixture(terms : Array[(Double, Gate)], name? : String, tolerance? : Double) -> Channel raise
    QError

    Choose one of the supplied gates with its stated probability. All gates must act on the same ordered wire dimensions. Probabilities must be finite, nonnegative, and sum to one within 1e-10.

    Channel::mixture_terms

    fn Channel::mixture_terms(self : Channel) -> ArrayView[(Double, Gate)]?

    Read the fixed probabilities and gates of a mixed-unitary channel. General Kraus channels have state-dependent outcome probabilities.

    Channel::name

    fn Channel::name(self : Channel) -> String

    Channel::parameters

    fn Channel::parameters(_self : Channel) -> Array[String]

    Channel::reset

    fn Channel::reset(d : UInt) -> Channel raise
    QError

    Prepare one wire of dimension d in the ground state. For each input basis digit, one Kraus operator maps that digit to zero:

    Resetting one wire of an entangled state preserves the reduced state of the other wires. The channel produces no measurement record.

    Channel::shape

    Channel::size

    fn Channel::size(self : Channel) -> Int

    Return the number of rows in each Kraus matrix.

    Channel::try_adjoint

    fn Channel::try_adjoint(_self : Channel) -> &Effect? raise
    QError

    Channel::try_channel

    fn Channel::try_channel(self : Channel) -> Channel?

    Channel::try_conditional

    fn Channel::try_conditional(_ : Channel) -> ConditionalEffect?

    Channel::try_decompose

    fn Channel::try_decompose(_self : Channel) -> Program? raise
    QError

    Channel::try_unitary

    fn Channel::try_unitary(_self : Channel) -> Gate?

    Circuit

    type Circuit[Q]

    Represent a quantum circuit which shares the operation sequence.
    impl Show for Circuit[Q]

    Circuit::adjoint

    fn[Q : Qid + Eq + Hash] Circuit::adjoint(self : Circuit[Q]) -> Circuit[Q] raise
    QError

    Reverse the operation order and replace each effect with its adjoint. Reject effects without an adjoint.

    Circuit::append

    fn[Q : Qid + Eq + Hash] Circuit::append(self : Circuit[Q], operation : Operation[Q]) -> Unit raise
    QError

    Append an operation in place.

    Circuit::compile

    fn[Q : Qid + Eq + Hash] Circuit::compile(self : Circuit[Q], name? : String) -> Program

    Compile circuit to program.

    Circuit::concat

    fn[Q : Qid + Eq + Hash] Circuit::concat(self : Circuit[Q], other : Circuit[Q]) -> Circuit[Q] raise
    QError

    Return a new circuit executing self followed by other. Append new wires in order.

    Circuit::copy

    fn[Q] Circuit::copy(self : Circuit[Q]) -> Circuit[Q]

    Copy this circuit.

    Circuit::dim

    fn[Q] Circuit::dim(self : Circuit[Q]) -> Array[UInt]

    Return a copy of the ordered wire dimensions.

    Circuit::extend_ops

    fn[Q : Qid + Eq + Hash] Circuit::extend_ops(self : Circuit[Q], operations : Array[Operation[Q]]) -> Unit raise
    QError

    Append a list of operations in place, in the supplied order.

    Circuit::for_loop

    fn[Q : Qid + Eq + Hash] Circuit::for_loop(self : Circuit[Q], count : Int, body : Circuit[Q]) -> Unit raise
    QError

    Append a loop that executes the body exactly count times on the same state. Each measurement appends its digits in iteration order. A count of zero skips the body. A negative count raises InvalidState.

    Circuit::from_op

    fn[Q : Qid + Eq + Hash] Circuit::from_op(operations : Array[Operation[Q]]) -> Circuit[Q] raise
    QError

    Build a circuit from bound operations in execution order.

    Circuit::if_else

    fn[Q : Qid + Eq + Hash] Circuit::if_else(self : Circuit[Q], condition : &Condition, on_true : Circuit[Q], on_false : Circuit[Q]) -> Unit raise
    QError

    Append a branch to this circuit. Evaluate the condition once on entry, execute the selected circuit, then continue after the branch. Either body can be empty. Measurements in the selected body update the shot's record.

    Circuit::index_of

    fn[Q : Qid + Eq + Hash] Circuit::index_of(self : Circuit[Q], qid : Q) -> Int?

    Find a logical ID's position. Return None if absent.

    Circuit::instructions

    fn[Q] Circuit::instructions(self : Circuit[Q]) -> Iter[Instruction[Q]]

    Iterate over the full sequence, including circuit-level branches.

    Circuit::length

    fn[Q] Circuit::length(self : Circuit[Q]) -> Int

    Count top-level instructions. Each branch occupies one position.

    Circuit::new

    fn[Q : Qid + Eq + Hash] Circuit::new(qids : Array[Q]) -> Circuit[Q] raise
    QError

    Create an empty circuit over an ordered list of distinct logical IDs.

    Circuit::operations

    fn[Q] Circuit::operations(self : Circuit[Q]) -> Iter[Operation[Q]]

    Iterate over top-level quantum operations. Use instructions() to visit control flow as well.

    Circuit::output

    fn[Q : Qid + Show + Eq + Hash] Circuit::output(self : Circuit[Q], logger : &Logger) -> Unit

    Draw one row per wire. Numbered markers show the remaining targets of a gate. Inspired by Cirq.

    For the Bell circuit, println(circuit) prints this diagram.

    0: ───H───CNOT───M("bell")─── 1: ───────#2─────M───────────

    Circuit::qids

    fn[Q] Circuit::qids(self : Circuit[Q]) -> Array[Q]

    Return a copy of the logical IDs in order.

    Circuit::remap

    fn[Q : Qid + Eq + Hash, R : Qid + Eq + Hash] Circuit::remap(self : Circuit[Q], map : (Q) -> R) -> Circuit[R] raise
    QError

    Map each logical wire once, preserving wire and target order.

    Circuit::to_string

    fn[Q : Qid + Show + Eq + Hash] Circuit::to_string(self : Circuit[Q]) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    Circuit::while_loop

    fn[Q : Qid + Eq + Hash] Circuit::while_loop(self : Circuit[Q], condition : &Condition, body : Circuit[Q], max_iterations~ : Int) -> Unit raise
    QError

    Test the condition before each iteration. Body measurements are available to the next test. If the condition still holds after max_iterations, execution raises IterationLimit. Unused record columns contain -1.

    Circuit::with_noise

    fn[Q : Qid + Eq + Hash] Circuit::with_noise(self : Circuit[Q], model : &NoiseModel) -> Circuit[Q] raise
    QError

    Return a circuit with the model's noise inserted after each unitary gate. The model visits each original gate once, including gates inside branches and loop bodies. A guarded gate and its noise share one branch decision.

    ConditionalEffect

    pub struct ConditionalEffect {
    inner : &Effect
    condition : &Condition
    }

    Execute the inner effect only when the measurement satisfies the condition.

    ConditionalEffect::arity

    fn ConditionalEffect::arity(self : ConditionalEffect) -> Int

    ConditionalEffect::dim

    fn ConditionalEffect::dim(self : ConditionalEffect) -> Array[UInt]

    ConditionalEffect::measurement_key

    fn ConditionalEffect::measurement_key(_self : ConditionalEffect) -> String?

    ConditionalEffect::name

    fn ConditionalEffect::name(self : ConditionalEffect) -> String

    ConditionalEffect::parameters

    fn ConditionalEffect::parameters(self : ConditionalEffect) -> Array[String]

    ConditionalEffect::try_adjoint

    ConditionalEffect::try_channel

    fn ConditionalEffect::try_channel(_self : ConditionalEffect) -> Channel?

    ConditionalEffect::try_conditional

    fn ConditionalEffect::try_conditional(self : ConditionalEffect) -> ConditionalEffect?

    ConditionalEffect::try_decompose

    ConditionalEffect::try_unitary

    fn ConditionalEffect::try_unitary(_self : ConditionalEffect) -> Gate?

    ForLoop

    type ForLoop[Q]

    A counted loop captures its body at construction.

    ForLoop::body

    fn[Q] ForLoop::body(self : ForLoop[Q]) -> Iter[Instruction[Q]]

    Iterate over the instructions of one iteration.

    ForLoop::count

    fn[Q] ForLoop::count(self : ForLoop[Q]) -> Int

    Gate

    type Gate

    An immutable unitary effect.
    impl Effect for Gate

    Gate::adjoint

    fn Gate::adjoint(self : Gate) -> Gate

    Return the inverse unitary using the kernel's adjoint.

    Gate::arity

    fn Gate::arity(self : Gate) -> Int

    Gate::controlled

    fn Gate::controlled(self : Gate, control_dimensions? : Array[UInt], control_values? : Array[UInt]) -> Gate raise
    QError

    Create a controlled version of this gate by prepending control wires. Apply this gate only when all control wires match their specified control values.

    control_dimensions specifies the dimension of each control wire. control_values specifies the required basis-state value of each control wire to activate the gate. For example, control values [1, 2] activate the gate when the first two control wires have basis digits 1 and 2, respectively. The default for each control is its highest basis digit.

    Gate::diagonal

    fn Gate::diagonal(name : String, dimensions : Array[UInt], phases : Array[
    Complex
    ]) -> Gate raise
    QError

    Create a diagonal unitary from one phase per basis state.

    Gate::dim

    fn Gate::dim(self : Gate) -> Array[UInt]

    Gate::from_kernel

    fn Gate::from_kernel(name : String, dimensions : Array[UInt], kernel : &
    UnitaryKernel
    ) -> Gate raise
    QError

    Bind a custom unitary kernel to a shape.

    Gate::kernel

    Return the immutable unitary kernel for this gate.

    Gate::measurement_key

    fn Gate::measurement_key(_self : Gate) -> String?

    Gate::monomial

    fn Gate::monomial(name : String, dimensions : Array[UInt], columns : Array[Int], phases : Array[
    Complex
    ]) -> Gate raise
    QError

    Constructs a monomial unitary gate from a column permutation and phase factors.

    Gate::name

    fn Gate::name(self : Gate) -> String

    Gate::parameters

    fn Gate::parameters(_self : Gate) -> Array[String]

    Gate::shape

    Gate::size

    fn Gate::size(self : Gate) -> Int

    Gate::to_repr

    Gate::try_adjoint

    fn Gate::try_adjoint(_self : Gate) -> &Effect? raise
    QError

    Gate::try_channel

    fn Gate::try_channel(_self : Gate) -> Channel?

    Gate::try_conditional

    fn Gate::try_conditional(_ : Gate) -> ConditionalEffect?

    Gate::try_decompose

    fn Gate::try_decompose(_self : Gate) -> Program? raise
    QError

    Gate::try_unitary

    fn Gate::try_unitary(self : Gate) -> Gate?

    Gate::unitary

    fn Gate::unitary(name : String, dimensions : Array[UInt], matrix : Array[
    Complex
    ], tolerance? : Double) -> Gate raise
    QError

    Check the shape, finite entries, and unitarity before accepting a matrix. For a matrix of dimension d, the entries use row-major order.

    The tolerance must be finite, positive, and at most 0.000001. It bounds absolute errors in column inner products. Accepted entries are kept without normalization.

    IfElse

    type IfElse[Q]

    A classical condition and the two instruction sequences it selects between. The branch bodies capture the circuits as they were when if_else was called.

    IfElse::condition

    fn[Q] IfElse::condition(self : IfElse[Q]) -> &Condition

    IfElse::on_false

    fn[Q] IfElse::on_false(self : IfElse[Q]) -> Iter[Instruction[Q]]

    IfElse::on_true

    fn[Q] IfElse::on_true(self : IfElse[Q]) -> Iter[Instruction[Q]]

    IfElse::select

    fn[Q] IfElse::select(self : IfElse[Q], record : &MeasurementRecord) -> Iter[Instruction[Q]] raise
    QError

    Evaluate the condition once and iterate the selected arm in circuit order.

    Instruction

    pub enum Instruction[Q] {
    Operation(Operation[Q])
    IfElse(IfElse[Q])
    ForLoop(ForLoop[Q])
    WhileLoop(WhileLoop[Q])
    }

    A circuit instruction uses logical wire IDs before compilation and integer wire indices afterwards. Only a quantum operation has target wires.

    Instruction::parameters

    fn[Q] Instruction::parameters(self : Instruction[Q]) -> Array[String]

    Instruction::record_width

    fn[Q] Instruction::record_width(self : Instruction[Q]) -> Int

    Number of columns this instruction occupies in a shot. Both arms of a branch start at the same column and reserve space for the wider arm.

    MeasurementCondition

    pub(all) enum MeasurementCondition {
    Nonzero(String)
    And(&Condition, &Condition)
    Or(&Condition, &Condition)
    Not(&Condition)
    }

    Combine named measurement tests with Boolean operators.

    MeasurementCondition::evaluate

    MeasurementCondition::name

    fn MeasurementCondition::name(self : MeasurementCondition) -> String

    Operation

    type Operation[Q]

    A circuit operation bound to distinct, ordered quantum IDs.

    Operation::effect

    fn[Q] Operation::effect(self : Operation[Q]) -> &Effect

    Operation::gate

    fn[Q] Operation::gate(self : Operation[Q]) -> Gate?

    Return the effect's direct unitary capability, if present.

    Operation::new

    fn[Q : Qid + Eq + Hash] Operation::new(effect : &Effect, targets : Array[Q]) -> Operation[Q] raise
    QError

    Operation::targets

    fn[Q] Operation::targets(self : Operation[Q]) -> Array[Q]

    Return a copy of the logical targets in effect wire order.

    Operation::when

    fn[Q] Operation::when(self : Operation[Q], conditions : &Condition) -> Operation[Q] raise
    QError

    Applies a classical condition to this operation. The operation executes only when the condition evaluates to true.

    Program

    type Program

    Program::dim

    fn Program::dim(self : Program) -> Array[UInt]

    Program::instructions

    fn Program::instructions(self : Program, expand_loops? : Bool) -> Iter[Instruction[Int]]

    Iterate over top-level instructions. With expand_loops=true, yield each iteration in execution order. Conditional branches and while loops remain single instructions.

    Program::length

    fn Program::length(self : Program) -> Int

    Program::name

    fn Program::name(self : Program) -> String

    Program::shape

    QubitId

    pub(all) struct QubitId(UInt64) derive(Compare, Eq, Hash,
    Debug
    )

    A logical qubit ID with no device position.
    impl Qid for QubitId
    impl Show for QubitId

    QubitId::compare

    fn QubitId::compare(QubitId, QubitId) -> Int
    automatically derived

    QubitId::dim

    fn QubitId::dim(_self : QubitId) -> UInt

    QubitId::equal

    fn QubitId::equal(QubitId, QubitId) -> Bool
    automatically derived

    QubitId::hash

    fn QubitId::hash(self : QubitId) -> Int
    automatically derived

    QubitId::hash_combine

    fn QubitId::hash_combine(QubitId, Hasher) -> Unit
    automatically derived

    QubitId::not_equal

    fn QubitId::not_equal(x : QubitId, y : QubitId) -> Bool
    automatically derived

    QubitId::op_ge

    fn QubitId::op_ge(x : QubitId, y : QubitId) -> Bool
    automatically derived

    QubitId::op_gt

    fn QubitId::op_gt(x : QubitId, y : QubitId) -> Bool
    automatically derived

    QubitId::op_le

    fn QubitId::op_le(x : QubitId, y : QubitId) -> Bool
    automatically derived

    QubitId::op_lt

    fn QubitId::op_lt(x : QubitId, y : QubitId) -> Bool
    automatically derived

    QubitId::output

    fn QubitId::output(self : QubitId, logger : &Logger) -> Unit

    QubitId::to_repr

    automatically derived

    QubitId::to_string

    fn QubitId::to_string(self : QubitId) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    QuditId

    Identifies a qudit, a quantum system with a finite-dimensional state space. The levels field specifies the dimension of its local Hilbert space.
    impl Qid for QuditId
    impl Show for QuditId

    QuditId::dim

    fn QuditId::dim(self : QuditId) -> UInt

    QuditId::equal

    fn QuditId::equal(QuditId, QuditId) -> Bool
    automatically derived

    QuditId::hash

    fn QuditId::hash(self : QuditId) -> Int
    automatically derived

    QuditId::hash_combine

    fn QuditId::hash_combine(QuditId, Hasher) -> Unit
    automatically derived

    QuditId::new

    fn QuditId::new(id : UInt64, dimension : UInt) -> QuditId raise
    QError

    QuditId::not_equal

    fn QuditId::not_equal(x : QuditId, y : QuditId) -> Bool
    automatically derived

    QuditId::output

    fn QuditId::output(self : QuditId, logger : &Logger) -> Unit

    QuditId::to_repr

    automatically derived

    QuditId::to_string

    fn QuditId::to_string(self : QuditId) -> String

    Default implementation for Show::to_string, uses a StringBuilder

    QuditId::value

    fn QuditId::value(self : QuditId) -> UInt64

    WhileLoop

    type WhileLoop[Q]

    A measurement-controlled loop captures its body once. The iteration bound determines how many measurement columns the loop reserves in each shot.

    WhileLoop::body

    fn[Q] WhileLoop::body(self : WhileLoop[Q]) -> Iter[Instruction[Q]]

    Iterate over one copy of the body in execution order.

    WhileLoop::condition

    fn[Q] WhileLoop::condition(self : WhileLoop[Q]) -> &Condition

    WhileLoop::max_iterations

    fn[Q] WhileLoop::max_iterations(self : WhileLoop[Q]) -> Int

    measure

    fn[Q : Qid + Eq + Hash] measure(targets : Array[Q], key? : String) -> Operation[Q] raise
    QError