QInterface

Defined in qinterface.hpp.

This provides a basic interface with a wide-ranging set of functionality

class Qrack::QInterface

A “Qrack::QInterface” is an abstract interface exposing qubit permutation state vector with methods to operate on it as by gates and register-like instructions.

See README.md for an overview of the algorithms Qrack employs.

Subclassed by Qrack::QEngineCPU, Qrack::QEngineOCLMulti, Qrack::QUnit

Creating a QInterface

There are four primary implementations of a QInterface:

enum Qrack::QInterfaceEngine

Enumerated list of supported engines.

Use QINTERFACE_OPTIMAL for the best supported engine.

Values:

QINTERFACE_CPU = 0

Create a QEngineCPU leveraging only local CPU and memory resources.

QINTERFACE_OPENCL

Create a QEngineOCL, derived from QEngineCPU, leveraging OpenCL hardware to increase the speed of certain calculations.

QINTERFACE_OPENCL_MULTI

Create a QEngineOCLMUlti, composed from multiple QEngineOCLs, using OpenCL in parallel across 2^N devices, for N an integer >= 0.

QINTERFACE_QUNIT

Create a QUnit, which utilizes other QInterface classes to minimize the amount of work that’s needed for any given operation based on the entanglement of the bits involved.

This, combined with QINTERFACE_OPTIMAL, is the recommended object to use as a library consumer.

QINTERFACE_FIRST = QINTERFACE_CPU
QINTERFACE_OPTIMAL = QINTERFACE_CPU
QINTERFACE_MAX

These enums can be passed to an allocator to create a QInterface of that specified implementation type:

template <typename… Ts>
QInterfacePtr Qrack::CreateQuantumInterface(QInterfaceEngine engine, QInterfaceEngine subengine, Ts... args)

Factory method to create specific engine implementations.

Constructors

Qrack::QInterface::QInterface(bitLenInt n, std::shared_ptr<std::default_random_engine> rgp = nullptr)
Qrack::QInterface::QInterface(bitLenInt n, std::shared_ptr<std::default_random_engine> rgp = nullptr)
Qrack::QInterface::QInterface(bitLenInt n, std::shared_ptr<std::default_random_engine> rgp = nullptr)

Members

complex *Qrack::QEngineCPU::stateVec

Configuration Methods

int Qrack::QInterface::GetQubitCount()

Get the count of bits in this register.

int Qrack::QInterface::GetMaxQPower()

Get the maximum number of basis states, namely \( n^2 \) for \( n \) qubits.

State Manipulation Methods

virtual void Qrack::QInterface::SetPermutation(bitCapInt perm) = 0

Set to a specific permutation.

virtual void Qrack::QInterface::SetQuantumState(complex *inputState) = 0

Set an arbitrary pure quantum state.

virtual bitLenInt Qrack::QInterface::Cohere(QInterfacePtr toCopy) = 0

Combine another QInterface with this one, after the last bit index of this one.

“Cohere” combines the quantum description of state of two independent QInterface objects into one object, containing the full permutation basis of the full object. The “inputState” bits are added after the last qubit index of the QInterface to which we “Cohere.” Informally, “Cohere” is equivalent to “just setting another group of qubits down next to the first” without interacting them. Schroedinger’s equation can form a description of state for two independent subsystems at once or “separable quantum subsystems” without interacting them. Once the description of state of the independent systems is combined, we can interact them, and we can describe their entanglements to each other, in which case they are no longer independent. A full entangled description of quantum state is not possible for two independent quantum subsystems until we “Cohere” them.

“Cohere” multiplies the probabilities of the indepedent permutation states of the two subsystems to find the probabilites of the entire set of combined permutations, by simple combinatorial reasoning. If the probablity of the “left-hand” subsystem being in |00> is 1/4, and the probablity of the “right-hand” subsystem being in |101> is 1/8, than the probability of the combined |00101> permutation state is 1/32, and so on for all permutations of the new combined state.

If the programmer doesn’t want to “cheat” quantum mechanically, then the original copy of the state which is duplicated into the larger QInterface should be “thrown away” to satisfy “no clone theorem.” This is not semantically enforced in Qrack, because optimization of an emulator might be acheived by “cloning” “under-the-hood” while only exposing a quantum mechanically consistent API or instruction set.

Returns the quantum bit offset that the QInterface was appended at, such that bit 5 in toCopy is equal to offset+5 in this object.

virtual std::map<QInterfacePtr, bitLenInt> Qrack::QInterface::Cohere(std::vector<QInterfacePtr> toCopy) = 0
virtual void Qrack::QInterface::Decohere(bitLenInt start, bitLenInt length, QInterfacePtr dest) = 0

Minimally decohere a set of contiguous bits from the full coherent unit, into “destination.”.

Minimally decohere a set of contigious bits from the full coherent unit. The length of this coherent unit is reduced by the length of bits decohered, and the bits removed are output in the destination QInterface pointer. The destination object must be initialized to the correct number of bits, in 0 permutation state. For quantum mechanical accuracy, the bit set removed and the bit set left behind should be quantum mechanically “separable.”

Like how “Cohere” is like “just setting another group of qubits down next to the first,” then “Decohere” is like “just moving a few qubits away from the rest.” Schroedinger’s equation does not require bits to be explicitly interacted in order to describe their permutation basis, and the descriptions of state of separable subsystems, those which are not entangled with other subsystems, are just as easily removed from the description of state.

If we have for example 5 qubits, and we wish to separate into “left” and “right” subsystems of 3 and 2 qubits, we sum probabilities of one permutation of the “left” three over ALL permutations of the “right” two, for all permutations, and vice versa, like so:

\( prob(|(left) 1000>) = prob(|1000 00>) + prob(|1000 10>) + prob(|1000 01>) + prob(|1000 11>). \)

If the subsystems are not “separable,” i.e. if they are entangled, this operation is not well-motivated, and its output is not necessarily defined. (The summing of probabilities over permutations of subsytems will be performed as described above, but this is not quantum mechanically meaningful.) To ensure that the subsystem is “separable,” i.e. that it has no entanglements to other subsystems in the QInterface, it can be measured with M(), or else all qubits other than the subsystem can be measured.

virtual void Qrack::QInterface::Dispose(bitLenInt start, bitLenInt length) = 0

Minimally decohere a set of contigious bits from the full coherent unit, throwing these qubits away.

Minimally decohere a set of contigious bits from the full coherent unit, discarding these bits. The length of this coherent unit is reduced by the length of bits decohered. For quantum mechanical accuracy, the bit set removed and the bit set left behind should be quantum mechanically “separable.”

Like how “Cohere” is like “just setting another group of qubits down next to the first,” then “Dispose” is like “just moving a few qubits away from the rest, and throwing them in the trash.” Schroedinger’s equation does not require bits to be explicitly interacted in order to describe their permutation basis, and the descriptions of state of separable subsystems, those which are not entangled with other subsystems, are just as easily removed from the description of state.

If we have for example 5 qubits, and we wish to separate into “left” and “right” subsystems of 3 and 2 qubits, we sum probabilities of one permutation of the “left” three over ALL permutations of the “right” two, for all permutations, and vice versa, like so:

\( prob(|(left) 1000>) = prob(|1000 00>) + prob(|1000 10>) + prob(|1000 01>) + prob(|1000 11>). \)

If the subsystems are not “separable,” i.e. if they are entangled, this operation is not well-motivated, and its output is not necessarily defined. (The summing of probabilities over permutations of subsytems will be performed as described above, but this is not quantum mechanically meaningful.) To ensure that the subsystem is “separable,” i.e. that it has no entanglements to other subsystems in the QInterface, it can be measured with M(), or else all qubits other than the subsystem can be measured.

virtual real1 Qrack::QInterface::Prob(bitLenInt qubitIndex) = 0

Direct measure of bit probability to be in |1> state.

Warning
PSEUDO-QUANTUM

virtual real1 Qrack::QInterface::ProbAll(bitCapInt fullRegister) = 0

Direct measure of full register probability to be in permutation state.

Warning
PSEUDO-QUANTUM

virtual void Qrack::QInterface::Swap(bitLenInt qubitIndex1, bitLenInt qubitIndex2) = 0

Swap values of two bits in register.

void Qrack::QInterface::Swap(bitLenInt start1, bitLenInt start2, bitLenInt length)

Bitwise swap.

virtual void Qrack::QInterface::Reverse(bitLenInt first, bitLenInt last)

Reverse all of the bits in a sequence.

Quantum Gates

Note

Most gates offer both a single-bit version taking just the index to the qubit, as well as a register-spanning variant for convienence and performance that performs the gate across a sequence of bits.

Single Register Gates

void Qrack::QInterface::AND(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)

Quantum analog of classical “AND” gate.

Measures the outputBit, then overwrites it with result.

void Qrack::QInterface::CLAND(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)

Quantum analog of classical “AND” gate.

Takes one qubit input and one classical bit input. Measures the outputBit, then overwrites it with result.

void Qrack::QInterface::OR(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)

Quantum analog of classical “OR” gate.

Measures the outputBit, then overwrites it with result.

void Qrack::QInterface::CLOR(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)

Quantum analog of classical “OR” gate.

Takes one qubit input and one classical bit input. Measures the outputBit, then overwrites it with result.

void Qrack::QInterface::XOR(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt outputBit)

Quantum analog of classical “XOR” gate.

Measures the outputBit, then overwrites it with result.

void Qrack::QInterface::CLXOR(bitLenInt inputQBit, bool inputClassicalBit, bitLenInt outputBit)

Quantum analog of classical “XOR” gate.

Takes one qubit input and one classical bit input. Measures the outputBit, then overwrites it with result.

virtual void Qrack::QInterface::H(bitLenInt qubitIndex) = 0

Hadamard gate.

Applies a Hadamard gate on qubit at “qubitIndex.”

virtual bool Qrack::QInterface::M(bitLenInt qubitIndex) = 0

Measurement gate.

Measures the qubit at “qubitIndex” and returns either “true” or “false.” (This “gate” breaks unitarity.)

All physical evolution of a quantum state should be “unitary,” except measurement. Measurement of a qubit “collapses” the quantum state into either only permutation states consistent with a |0> state for the bit, or else only permutation states consistent with a |1> state for the bit. Measurement also effectively multiplies the overall quantum state vector of the system by a random phase factor, equiprobable over all possible phase angles.

Effectively, when a bit measurement is emulated, Qrack calculates the norm of all permutation state components, to find their respective probabilities. The probabilities of all states in which the measured bit is “0” can be summed to give the probability of the bit being “0,” and separately the probabilities of all states in which the measured bit is “1” can be summed to give the probability of the bit being “1.” To simulate measurement, a random float between 0 and 1 is compared to the sum of the probability of all permutation states in which the bit is equal to “1”. Depending on whether the random float is higher or lower than the probability, the qubit is determined to be either |0> or |1>, (up to phase). If the bit is determined to be |1>, then all permutation eigenstates in which the bit would be equal to |0> have their probability set to zero, and vice versa if the bit is determined to be |0>. Then, all remaining permutation states with nonzero probability are linearly rescaled so that the total probability of all permutation states is again “normalized” to exactly 100% or 1, (within double precision rounding error). Physically, the act of measurement should introduce an overall random phase factor on the state vector, which is emulated by generating another constantly distributed random float to select a phase angle between 0 and 2 * Pi.

Measurement breaks unitary evolution of state. All quantum gates except measurement should generally act as a unitary matrix on a permutation state vector. (Note that Boolean comparison convenience methods in Qrack such as “AND,” “OR,” and “XOR” employ the measurement operation in the act of first clearing output bits before filling them with the result of comparison, and these convenience methods therefore break unitary evolution of state, but in a physically realistic way. Comparable unitary operations would be performed with a combination of X and CCNOT gates, also called “Toffoli” gates, but the output bits would have to be assumed to be in a known fixed state, like all |0>, ahead of time to produce unitary logical comparison operations.)

virtual void Qrack::QInterface::X(bitLenInt qubitIndex) = 0

X gate.

Applies the Pauli “X” operator to the qubit at “qubitIndex.” The Pauli “X” operator is equivalent to a logical “NOT.”

virtual void Qrack::QInterface::Y(bitLenInt qubitIndex) = 0

Y gate.

Applies the Pauli “Y” operator to the qubit at “qubitIndex.” The Pauli “Y” operator is similar to a logical “NOT” with permutation phase effects.

virtual void Qrack::QInterface::Z(bitLenInt qubitIndex) = 0

Z gate.

Applies the Pauli “Z” operator to the qubit at “qubitIndex.” The Pauli “Z” operator reverses the phase of |1> and leaves |0> unchanged.

virtual void Qrack::QInterface::CY(bitLenInt control, bitLenInt target) = 0

Controlled Y gate.

If the “control” bit is set to 1, then the Pauli “Y” operator is applied to “target.”

virtual void Qrack::QInterface::CZ(bitLenInt control, bitLenInt target) = 0

Controlled Z gate.

If the “control” bit is set to 1, then the Pauli “Z” operator is applied to “target.”

virtual void Qrack::QInterface::RT(real1 radians, bitLenInt qubitIndex) = 0

Phase shift gate.

Rotates as \( e^{-i*\theta/2} \) around |1> state

void Qrack::QInterface::RTDyad(int numerator, int denomPower, bitLenInt qubitIndex)

Dyadic fraction phase shift gate.

Dyadic fraction “phase shift gate” - Rotates as e^(i*(M_PI * numerator) / 2^denomPower) around |1> state.

Rotates as \( e^{i*{\pi * numerator} / 2^denomPower} \) around |1> state.

NOTE THAT * DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

virtual void Qrack::QInterface::CRT(real1 radians, bitLenInt control, bitLenInt target) = 0

Controlled “phase shift gate”.

If control bit is set to 1, rotates target bit as \( e^{-i*\theta/2} \) around |1> state.

void Qrack::QInterface::CRTDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target)

Controlled dyadic fraction “phase shift gate”.

Controlled dyadic “phase shift gate” - if control bit is true, rotates target bit as e^(i*(M_PI * numerator) / 2^denomPower) around |1> state.

If control bit is set to 1, rotates target bit as \( e^{i*{\pi * numerator} / 2^denomPower} \) around |1> state.

virtual void Qrack::QInterface::RX(real1 radians, bitLenInt qubitIndex) = 0

X axis rotation gate.

Rotates as \( e^{-i*\theta/2} \) around Pauli X axis

void Qrack::QInterface::RXDyad(int numerator, int denomPower, bitLenInt qubitIndex)

Dyadic fraction X axis rotation gate.

Dyadic fraction x axis rotation gate - Rotates as e^(i*(M_PI * numerator) / 2^denomPower) around Pauli x axis.

Rotates \( e^{i*{\pi * numerator} / 2^denomPower} \) on Pauli x axis.

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

virtual void Qrack::QInterface::CRX(real1 radians, bitLenInt control, bitLenInt target) = 0

Controlled X axis rotation gate.

If “control” is 1, rotates as \( e^{-i*\theta/2} \) on Pauli x axis.

void Qrack::QInterface::CRXDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target)

Controlled dyadic fraction X axis rotation gate.

Controlled dyadic fraction x axis rotation gate - Rotates as e^(i*(M_PI * numerator) / 2^denomPower) around Pauli x axis.

If “control” is 1, rotates as \( e^{i*{\pi * numerator} / 2^denomPower} \) around Pauli x axis.

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS.

virtual void Qrack::QInterface::RY(real1 radians, bitLenInt qubitIndex) = 0

Y axis rotation gate.

Rotates as \( e^{-i*\theta/2} \) around Pauli y axis.

void Qrack::QInterface::RYDyad(int numerator, int denomPower, bitLenInt qubitIndex)

Dyadic fraction Y axis rotation gate.

Dyadic fraction y axis rotation gate - Rotates as e^(i*(M_PI * numerator) / 2^denomPower) around Pauli y axis.

Rotates as \( e^{i*{\pi * numerator} / 2^denomPower} \) around Pauli Y axis.

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

virtual void Qrack::QInterface::CRY(real1 radians, bitLenInt control, bitLenInt target) = 0

Controlled Y axis rotation gate.

If “control” is set to 1, rotates as \( e^{-i*\theta/2} \) around Pauli Y axis.

void Qrack::QInterface::CRYDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target)

Controlled dyadic fraction y axis rotation gate.

Controlled dyadic fraction y axis rotation gate - Rotates as e^(i*(M_PI * numerator) / 2^denomPower) around Pauli y axis.

If “control” is set to 1, rotates as \( e^{i*{\pi * numerator} / 2^denomPower} \) around Pauli Y axis.

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS.

virtual void Qrack::QInterface::RZ(real1 radians, bitLenInt qubitIndex) = 0

Z axis rotation gate.

Rotates as \( e^{-i*\theta/2} \) around Pauli Z axis.

void Qrack::QInterface::RZDyad(int numerator, int denomPower, bitLenInt qubitIndex)

Dyadic fraction Z axis rotation gate.

Dyadic fraction y axis rotation gate - Rotates as e^(i*(M_PI * numerator) / 2^denomPower) around Pauli y axis.

Rotates as \( e^{i*{\pi * numerator} / 2^denomPower} \) around Pauli Z axis.

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

virtual void Qrack::QInterface::CRZ(real1 radians, bitLenInt control, bitLenInt target) = 0

Controlled Z axis rotation gate.

If “control” is set to 1, rotates as \( e^{-i*\theta/2} \) around Pauli Zaxis.

void Qrack::QInterface::CRZDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target)

Controlled dyadic fraction Z axis rotation gate.

Controlled dyadic fraction z axis rotation gate - Rotates as e^(i*(M_PI * numerator) / 2^denomPower) around Pauli z axis.

If “control” is set to 1, rotates as \( e^{i*{\pi * numerator} / 2^denomPower} \) around Pauli Z axis.

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS.

virtual void Qrack::QInterface::Exp(real1 radians, bitLenInt qubitIndex) = 0

(Identity) Exponentiation gate

Applies \( e^{-i*\theta*I} \), exponentiation of the identity operator

void Qrack::QInterface::ExpDyad(int numerator, int denomPower, bitLenInt qubitIndex)

Dyadic fraction (identity) exponentiation gate.

Dyadic fraction (identity) exponentiation gate - Applies \( e^{-i * \pi * numerator * I / 2^denomPower} \), exponentiation of the identity operator.

Applies \( e^{-i * \pi * numerator * I / 2^denomPower} \), exponentiation of the identity operator

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

virtual void Qrack::QInterface::ExpX(real1 radians, bitLenInt qubitIndex) = 0

Pauli X exponentiation gate.

Applies \( e^{-i*\theta*\sigma_x} \), exponentiation of the Pauli X operator

void Qrack::QInterface::ExpXDyad(int numerator, int denomPower, bitLenInt qubitIndex)

Dyadic fraction Pauli X exponentiation gate.

Dyadic fraction Pauli X exponentiation gate - Applies \( e^{-i * \pi * numerator *\sigma_x / 2^denomPower} \), exponentiation of the Pauli X operator.

Applies \( e^{-i * \pi * numerator * \sigma_x / 2^denomPower} \), exponentiation of the Pauli X operator

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

virtual void Qrack::QInterface::ExpY(real1 radians, bitLenInt qubitIndex) = 0

Pauli Y exponentiation gate.

Applies \( e^{-i*\theta*\sigma_y} \), exponentiation of the Pauli Y operator

void Qrack::QInterface::ExpYDyad(int numerator, int denomPower, bitLenInt qubitIndex)

Dyadic fraction Pauli Y exponentiation gate.

Dyadic fraction Pauli Y exponentiation gate - Applies \( e^{-i * \pi * numerator *\sigma_y / 2^denomPower} \), exponentiation of the Pauli Y operator.

Applies \( e^{-i * \pi * numerator * \sigma_y / 2^denomPower} \), exponentiation of the Pauli Y operator

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

virtual void Qrack::QInterface::ExpZ(real1 radians, bitLenInt qubitIndex) = 0

Pauli Z exponentiation gate.

Applies \( e^{-i*\theta*\sigma_z} \), exponentiation of the Pauli Z operator

void Qrack::QInterface::ExpZDyad(int numerator, int denomPower, bitLenInt qubitIndex)

Dyadic fraction Pauli Z exponentiation gate.

Dyadic fraction Pauli Z exponentiation gate - Applies \( e^{-i * \pi * numerator *\sigma_z / 2^denomPower} \), exponentiation of the Pauli Z operator.

Applies \( e^{-i * \pi * numerator * \sigma_z / 2^denomPower} \), exponentiation of the Pauli Z operator

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

Register-wide Gates

void Qrack::QInterface::AND(bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length)

Bitwise “AND”.

“AND” compare two bit ranges in QInterface, and store result in range starting at output

“AND” registers at “inputStart1” and “inputStart2,” of “length” bits, placing the result in “outputStart”.

void Qrack::QInterface::CLAND(bitLenInt qInputStart, bitCapInt classicalInput, bitLenInt outputStart, bitLenInt length)

Classical bitwise “AND”.

“AND” compare a bit range in QInterface with a classical unsigned integer, and store result in range starting at output

“AND” registers at “inputStart1” and the classic bits of “classicalInput,” of “length” bits, placing the result in “outputStart”.

void Qrack::QInterface::OR(bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length)

Bitwise “OR”.

“OR” compare two bit ranges in QInterface, and store result in range starting at output

void Qrack::QInterface::CLOR(bitLenInt qInputStart, bitCapInt classicalInput, bitLenInt outputStart, bitLenInt length)

Classical bitwise “OR”.

“OR” compare a bit range in QInterface with a classical unsigned integer, and store result in range starting at output

void Qrack::QInterface::XOR(bitLenInt inputStart1, bitLenInt inputStart2, bitLenInt outputStart, bitLenInt length)

Bitwise “XOR”.

“XOR” compare two bit ranges in QInterface, and store result in range starting at output

void Qrack::QInterface::CLXOR(bitLenInt qInputStart, bitCapInt classicalInput, bitLenInt outputStart, bitLenInt length)

Classical bitwise “XOR”.

“XOR” compare a bit range in QInterface with a classical unsigned integer, and store result in range starting at output

void Qrack::QInterface::CCNOT(bitLenInt control1, bitLenInt control2, bitLenInt target, bitLenInt length)

Bitwise doubly controlled-not.

void Qrack::QInterface::AntiCCNOT(bitLenInt control1, bitLenInt control2, bitLenInt target, bitLenInt length)

Bitwise doubly “anti-“controlled-not.

void Qrack::QInterface::CNOT(bitLenInt inputBits, bitLenInt targetBits, bitLenInt length)

Bitwise controlled-not.

virtual void Qrack::QInterface::CNOT(bitLenInt control, bitLenInt target) = 0

Controlled NOT gate.

If the control is set to 1, the target bit is NOT-ed or X-ed.

void Qrack::QInterface::AntiCNOT(bitLenInt inputBits, bitLenInt targetBits, bitLenInt length)

Bitwise “anti-“controlled-not.

void Qrack::QInterface::H(bitLenInt start, bitLenInt length)

Bitwise Hadamard.

Apply Hadamard gate to each bit in “length,” starting from bit index “start”.

bitCapInt Qrack::QInterface::MReg(bitLenInt start, bitLenInt length)

Measure permutation state of a register.

void Qrack::QInterface::X(bitLenInt start, bitLenInt length)

Bitwise Pauli X (or logical “NOT”) operator.

void Qrack::QInterface::Y(bitLenInt start, bitLenInt length)

Bitwise Pauli Y operator.

Apply Pauli Y matrix to each bit.

void Qrack::QInterface::Z(bitLenInt start, bitLenInt length)

Bitwise Pauli Z operator.

Apply Pauli Z matrix to each bit.

void Qrack::QInterface::CY(bitLenInt control, bitLenInt target, bitLenInt length)

Bitwise controlled Y gate.

Apply controlled Pauli Y matrix to each bit.

If the “control” bit is set to 1, then the Pauli “Y” operator is applied to “target.”

void Qrack::QInterface::CZ(bitLenInt control, bitLenInt target, bitLenInt length)

Bitwise controlled Z gate.

Apply controlled Pauli Z matrix to each bit.

If the “control” bit is set to 1, then the Pauli “Z” operator is applied to “target.”

void Qrack::QInterface::RT(real1 radians, bitLenInt start, bitLenInt length)

Bitwise phase shift gate.

“Phase shift gate” - Rotates each bit as e^(-i*/2) around |1> state

Rotates as \( e^{-i*\theta/2} \) around |1> state

void Qrack::QInterface::RTDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length)

Bitwise dyadic fraction phase shift gate.

Dyadic fraction “phase shift gate” - Rotates each bit as e^(i*(M_PI * numerator) / denominator) around |1> state.

Rotates as \( e^{i*{\pi * numerator} / 2^denomPower} \) around |1> state.

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

void Qrack::QInterface::RX(real1 radians, bitLenInt start, bitLenInt length)

Bitwise X axis rotation gate.

x axis rotation gate - Rotates each bit as e^(-i*/2) around Pauli x axis

Rotates as \( e^{-i*\theta/2} \) around Pauli X axis

void Qrack::QInterface::RXDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length)

Bitwise dyadic fraction X axis rotation gate.

Dyadic fraction x axis rotation gate - Rotates each bit as e^(i*(M_PI * numerator) / denominator) around Pauli x axis.

Rotates \( e^{i*{\pi * numerator} / 2^denomPower} \) on Pauli x axis.

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

void Qrack::QInterface::CRX(real1 radians, bitLenInt control, bitLenInt target, bitLenInt length)

Bitwise controlled X axis rotation gate.

Controlled x axis rotation.

If “control” is 1, rotates as \( e^{-i*\theta/2} \) on Pauli x axis.

void Qrack::QInterface::CRXDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target, bitLenInt length)

Bitwise controlled dyadic fraction X axis rotation gate.

Controlled dyadic fraction x axis rotation gate - for each bit, if control bit is true, rotates target bit as as e^(i*(M_PI * numerator) / denominator) around Pauli x axis.

If “control” is 1, rotates as \( e^{i*{\pi * numerator} / 2^denomPower} \) around Pauli x axis.

void Qrack::QInterface::RY(real1 radians, bitLenInt start, bitLenInt length)

Bitwise Y axis rotation gate.

y axis rotation gate - Rotates each bit as e^(-i*/2) around Pauli y axis

Rotates as \( e^{-i*\theta/2} \) around Pauli y axis.

void Qrack::QInterface::RYDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length)

Bitwise dyadic fraction Y axis rotation gate.

Dyadic fraction y axis rotation gate - Rotates each bit as e^(i*(M_PI * numerator) / denominator) around Pauli y axis.

Rotates as \( e^{i*{\pi * numerator} / 2^denomPower} \) around Pauli Y axis.

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

void Qrack::QInterface::CRY(real1 radians, bitLenInt control, bitLenInt target, bitLenInt length)

Bitwise controlled Y axis rotation gate.

Controlled y axis rotation.

If “control” is set to 1, rotates as \( e^{-i*\theta/2} \) around Pauli Y axis.

void Qrack::QInterface::CRYDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target, bitLenInt length)

Bitwise controlled dyadic fraction y axis rotation gate.

Controlled dyadic fraction y axis rotation gate - for each bit, if control bit is true, rotates target bit as e^(i*(M_PI * numerator) / denominator) around Pauli y axis.

If “control” is set to 1, rotates as \( e^{i*{\pi * numerator} / 2^denomPower} \) around Pauli Y axis.

void Qrack::QInterface::RZ(real1 radians, bitLenInt start, bitLenInt length)

Bitwise Z axis rotation gate.

z axis rotation gate - Rotates each bit as e^(-i*/2) around Pauli z axis

Rotates as \( e^{-i*\theta/2} \) around Pauli Z axis.

void Qrack::QInterface::RZDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length)

Bitwise dyadic fraction Z axis rotation gate.

Dyadic fraction z axis rotation gate - Rotates each bit as e^(i*(M_PI * numerator) / denominator) around Pauli y axis.

Rotates as \( e^{i*{\pi * numerator} / 2^denomPower} \) around Pauli Z axis.

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

void Qrack::QInterface::CRZ(real1 radians, bitLenInt control, bitLenInt target, bitLenInt length)

Bitwise controlled Z axis rotation gate.

Controlled z axis rotation.

If “control” is set to 1, rotates as \( e^{-i*\theta/2} \) around Pauli Zaxis.

void Qrack::QInterface::CRZDyad(int numerator, int denomPower, bitLenInt control, bitLenInt target, bitLenInt length)

Bitwise controlled dyadic fraction Z axis rotation gate.

Controlled dyadic fraction z axis rotation gate - for each bit, if control bit is true, rotates target bit as e^(i*(M_PI * numerator) / denominator) around Pauli z axis.

If “control” is set to 1, rotates as \( e^{i*{\pi * numerator} / 2^denomPower} \) around Pauli Z axis.

void Qrack::QInterface::Exp(real1 radians, bitLenInt start, bitLenInt length)

Bitwise (identity) exponentiation gate.

Bitwise (identity) exponentiation gate - Applies \( e^{-i*\theta*I} \), exponentiation of the identity operator.

Applies \( e^{-i*\theta*I} \), exponentiation of the identity operator

void Qrack::QInterface::ExpDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length)

Bitwise Dyadic fraction (identity) exponentiation gate.

Dyadic fraction (identity) exponentiation gate - Applies \( e^{-i * \pi * numerator * I / 2^denomPower} \), exponentiation of the identity operator.

Applies \( e^{-i * \pi * numerator * I / 2^denomPower} \), exponentiation of the identity operator

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

void Qrack::QInterface::ExpX(real1 radians, bitLenInt start, bitLenInt length)

Bitwise Pauli X exponentiation gate.

Bitwise Pauli X exponentiation gate - Applies \( e^{-i*\theta*\sigma_x} \), exponentiation of the Pauli X operator.

Applies \( e^{-i*\theta*\sigma_x} \), exponentiation of the Pauli X operator

void Qrack::QInterface::ExpXDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length)

Bitwise Dyadic fraction Pauli X exponentiation gate.

Dyadic fraction Pauli X exponentiation gate - Applies \( e^{-i * \pi * numerator *\sigma_x / 2^denomPower} \), exponentiation of the Pauli X operator.

Applies \( e^{-i * \pi * numerator * \sigma_x / 2^denomPower} \), exponentiation of the Pauli X operator

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

void Qrack::QInterface::ExpY(real1 radians, bitLenInt start, bitLenInt length)

Bitwise Pauli Y exponentiation gate.

Bitwise Pauli Y exponentiation gate - Applies \( e^{-i*\theta*\sigma_y} \), exponentiation of the Pauli Y operator.

Applies \( e^{-i*\theta*\sigma_y} \), exponentiation of the Pauli Y operator

void Qrack::QInterface::ExpYDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length)

Bitwise Dyadic fraction Pauli Y exponentiation gate.

Dyadic fraction Pauli Y exponentiation gate - Applies \( e^{-i * \pi * numerator *\sigma_y / 2^denomPower} \), exponentiation of the Pauli Y operator.

Applies \( e^{-i * \pi * numerator * \sigma_y / 2^denomPower} \), exponentiation of the Pauli Y operator

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

void Qrack::QInterface::ExpZ(real1 radians, bitLenInt start, bitLenInt length)

Bitwise Pauli Z exponentiation gate.

Bitwise Pauli Z exponentiation gate - Applies \( e^{-i*\theta*\sigma_z} \), exponentiation of the Pauli Z operator.

Applies \( e^{-i*\theta*\sigma_z} \), exponentiation of the Pauli Z operator

void Qrack::QInterface::ExpZDyad(int numerator, int denomPower, bitLenInt start, bitLenInt length)

Bitwise Dyadic fraction Pauli Z exponentiation gate.

Dyadic fraction Pauli Z exponentiation gate - Applies \( e^{-i * \pi * numerator *\sigma_z / 2^denomPower} \), exponentiation of the Pauli Z operator.

Applies \( e^{-i * \pi * numerator * \sigma_z / 2^denomPower} \), exponentiation of the Pauli Z operator

NOTE THAT DYADIC OPERATION ANGLE SIGN IS REVERSED FROM RADIAN ROTATION OPERATORS AND LACKS DIVISION BY A FACTOR OF TWO.

Algorithmic Implementations

void Qrack::QInterface::QFT(bitLenInt start, bitLenInt length)

Quantum Fourier Transform - Apply the quantum Fourier transform to the register.

virtual bitCapInt Qrack::QInterface::IndexedLDA(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, unsigned char *values) = 0

Set 8 bit register bits by a superposed index-offset-based read from classical memory.

“inputStart” is the start index of 8 qubits that act as an index into the 256 byte “values” array. The “outputStart” bits are first cleared, then the separable |input, 00000000> permutation state is mapped to |input, values[input]>, with “values[input]” placed in the “outputStart” register.

While a QInterface represents an interacting set of qubit-based registers, or a virtual quantum chip, the registers need to interact in some way with (classical or quantum) RAM. IndexedLDA is a RAM access method similar to the X addressing mode of the MOS 6502 chip, if the X register can be in a state of coherent superposition when it loads from RAM.

The physical motivation for this addressing mode can be explained as follows: say that we have a superconducting quantum interface device (SQUID) based chip. SQUIDs have already been demonstrated passing coherently superposed electrical currents. In a sufficiently quantum-mechanically isolated qubit chip with a classical cache, with both classical RAM and registers likely cryogenically isolated from the environment, SQUIDs could (hopefully) pass coherently superposed electrical currents into the classical RAM cache to load values into a qubit register. The state loaded would be a superposition of the values of all RAM to which coherently superposed electrical currents were passed.

In qubit system similar to the MOS 6502, say we have qubit-based “accumulator” and “X index” registers, and say that we start with a superposed X index register. In (classical) X addressing mode, the X index register value acts an offset into RAM from a specified starting address. The X addressing mode of a LoaD Accumulator (LDA) instruction, by the physical mechanism described above, should load the accumulator in quantum parallel with the values of every different address of RAM pointed to in superposition by the X index register. The superposed values in the accumulator are entangled with those in the X index register, by way of whatever values the classical RAM pointed to by X held at the time of the load. (If the RAM at index “36” held an unsigned char value of “27,” then the value “36” in the X index register becomes entangled with the value “27” in the accumulator, and so on in quantum parallel for all superposed values of the X index register, at once.) If the X index register or accumulator are then measured, the two registers will both always collapse into a random but valid key-value pair of X index offset and value at that classical RAM address.

Note that a “superposed store operation in classical RAM” is not possible by analagous reasoning. Classical RAM would become entangled with both the accumulator and the X register. When the state of the registers was collapsed, we would find that only one “store” operation to a single memory address had actually been carried out, consistent with the address offset in the collapsed X register and the byte value in the collapsed accumulator. It would not be possible by this model to write in quantum parallel to more than one address of classical memory at a time.

virtual bitCapInt Qrack::QInterface::IndexedADC(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, bitLenInt carryIndex, unsigned char *values) = 0

Add to entangled 8 bit register state with a superposed index-offset-based read from classical memory.

inputStart” is the start index of 8 qubits that act as an index into the 256 byte “values” array. The “outputStart” bits would usually already be entangled with the “inputStart” bits via a IndexedLDA() operation. With the “inputStart” bits being a “key” and the “outputStart” bits being a value, the permutation state |key, value> is mapped to |key, value + values[key]>. This is similar to classical parallel addition of two arrays. However, when either of the registers are measured, both registers will collapse into one random VALID key-value pair, with any addition or subtraction done to the “value.” See IndexedLDA() for context.

While a QInterface represents an interacting set of qubit-based registers, or a virtual quantum chip, the registers need to interact in some way with (classical or quantum) RAM. IndexedLDA is a RAM access method similar to the X addressing mode of the MOS 6502 chip, if the X register can be in a state of coherent superposition when it loads from RAM. “IndexedADC” and “IndexedSBC” perform add and subtract (with carry) operations on a state usually initially prepared with IndexedLDA().

virtual bitCapInt Qrack::QInterface::IndexedSBC(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, bitLenInt carryIndex, unsigned char *values) = 0

Subtract from an entangled 8 bit register state with a superposed index-offset-based read from classical memory.

“inputStart” is the start index of 8 qubits that act as an index into the 256 byte “values” array. The “outputStart” bits would usually already be entangled with the “inputStart” bits via a IndexedLDA() operation. With the “inputStart” bits being a “key” and the “outputStart” bits being a value, the permutation state |key, value> is mapped to |key, value - values[key]>. This is similar to classical parallel addition of two arrays. However, when either of the registers are measured, both registers will collapse into one random VALID key-value pair, with any addition or subtraction done to the “value.” See QInterface::IndexedLDA for context.

While a QInterface represents an interacting set of qubit-based registers, or a virtual quantum chip, the registers need to interact in some way with (classical or quantum) RAM. IndexedLDA is a RAM access method similar to the X addressing mode of the MOS 6502 chip, if the X register can be in a state of coherent superposition when it loads from RAM. “IndexedADC” and “IndexedSBC” perform add and subtract (with carry) operations on a state usually initially prepared with IndexedLDA().