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.

Inherits from Qrack::ParallelFor

Subclassed by Qrack::QBdt, Qrack::QEngine, Qrack::QPager, Qrack::QStabilizer, Qrack::QStabilizerHybrid, Qrack::QUnit

Creating a QInterface

These are the 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, leveraging OpenCL hardware to increase the speed of certain calculations.

QINTERFACE_HYBRID

Create a QHybrid, switching between QEngineCPU and QEngineOCL as efficient.

QINTERFACE_BDT

Create a QBinaryDecisionTree, (CPU-based).

QINTERFACE_MASK_FUSION

Create a QMaskFusion, coalescing Pauli gates.

QINTERFACE_STABILIZER

Create a QStabilizer, limited to Clifford/Pauli operations, but efficient.

QINTERFACE_STABILIZER_HYBRID

Create a QStabilizerHybrid, switching between a QStabilizer and a QHybrid as efficient.

QINTERFACE_QPAGER

Create a QPager, which breaks up the work of a QEngine into equally sized “pages.”.

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_QUNIT_MULTI

Create a QUnitMulti, which distributes the explicitly separated “shards” of a QUnit across available OpenCL devices.

QINTERFACE_OPTIMAL_SCHROEDINGER = QINTERFACE_CPU
QINTERFACE_OPTIMAL_SINGLE_PAGE = QINTERFACE_MASK_FUSION
QINTERFACE_OPTIMAL_BASE = QINTERFACE_CPU
QINTERFACE_OPTIMAL = QINTERFACE_QUNIT
QINTERFACE_OPTIMAL_MULTI = QINTERFACE_QUNIT_MULTI
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(std::vector<QInterfaceEngine> engines, Ts... args)

Constructors

Qrack::QInterface::QInterface(bitLenInt n, qrack_rand_gen_ptr rgp = nullptr, bool doNorm = false, bool useHardwareRNG = true, bool randomGlobalPhase = true, real1_f norm_thresh = REAL1_EPSILON)
Qrack::QInterface::QInterface()

Default constructor, primarily for protected internal use.

Copying

virtual QInterfacePtr Qrack::QInterface::Clone() = 0

Clone this QInterface.

Members

StateVectorPtr Qrack::QEngineCPU::stateVec

Configuration Methods

virtual bitLenInt Qrack::QInterface::GetQubitCount()

Get the count of bits in this register.

virtual bitCapInt Qrack::QInterface::GetMaxQPower()

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

virtual bool Qrack::QInterface::isBinaryDecisionTree()

Returns “true” if current state representation is definitely a binary decision tree, “false” if it is definitely not, or “true” if it cannot be determined.

virtual bool Qrack::QInterface::isClifford()

Returns “true” if current state is identifiably within the Clifford set, or “false” if it is not or cannot be determined.

virtual bool Qrack::QInterface::isClifford(bitLenInt qubit)

Returns “true” if current qubit state is identifiably within the Clifford set, or “false” if it is not or cannot be determined.

virtual void Qrack::QInterface::SetReactiveSeparate(bool isAggSep)

Set reactive separation option (on by default if available)

If reactive separation is available, as in Qrack::QUnit, then turning this option on attempts to more-aggresively recover separability of subsystems. It can either hurt or help performance, though it commonly helps.

virtual bool Qrack::QInterface::GetReactiveSeparate()

Get reactive separation option.

If reactive separation is available, as in Qrack::QUnit, then turning this option on attempts to more-aggresively recover separability of subsystems. It can either hurt or help performance, though it commonly helps.

virtual void Qrack::QInterface::SetDevice(int dID, bool forceReInit = false)

Set the device index, if more than one device is available.

virtual int64_t Qrack::QInterface::GetDevice()

Get the device index.

(“-1” is default).

bitCapIntOcl Qrack::QInterface::GetMaxSize()

Get maximum number of amplitudes that can be allocated on current device.

State Manipulation Methods

void Qrack::QInterface::SetPermutation(bitCapInt perm, complex phaseFac = CMPLX_DEFAULT_ARG)

Set to a specific permutation of all qubits.

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

Set an arbitrary pure quantum state representation.

Warning
PSEUDO-QUANTUM

virtual bitLenInt Qrack::QInterface::Compose(QInterfacePtr toCopy)

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

“Compose” 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 “Compose.” Informally, “Compose” 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 “Compose” them.

“Compose” 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.

bitLenInt Qrack::QInterface::Compose(QInterfacePtr toCopy, bitLenInt start)

Warning

doxygenfunction: Unable to resolve multiple matches for function “Qrack::QInterface::Decompose” with arguments () in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml. Potential matches:

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

Minimally decompose a set of contiguous bits from the separably composed unit, and discard the separable bits from index “start” for “length.”.

Minimally decompose a set of contigious bits from the separably composed unit. The length of this separable unit is reduced by the length of bits decomposed, 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 “Compose” is like “just setting another group of qubits down next to the first,” then “Decompose” 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. (This is equivalent to a “Schmidt decomposition.”)

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:

\( P(|1000>|xy>) = P(|1000 00>) + P(|1000 10>) + P(|1000 01>) + P(|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, bitCapInt disposedPerm) = 0

Dispose a a contiguous set of qubits that are already in a permutation eigenstate.

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

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

Warning
PSEUDO-QUANTUM

virtual real1_f Qrack::QInterface::ProbAll(bitCapInt fullRegister)

Direct measure of full permutation probability.

Warning
PSEUDO-QUANTUM

real1_f Qrack::QInterface::ProbReg(bitLenInt start, bitLenInt length, bitCapInt permutation)

Direct measure of register permutation probability.

Returns probability of permutation of the register.

Warning
PSEUDO-QUANTUM

real1_f Qrack::QInterface::ProbMask(bitCapInt mask, bitCapInt permutation)

Direct measure of masked permutation probability.

Returns probability of permutation of the mask.

“mask” masks the bits to check the probability of. “permutation” sets the 0 or 1 value for each bit in the mask. Bits which are set in the mask can be set to 0 or 1 in the permutation, while reset bits in the mask should be 0 in the permutation.

Warning
PSEUDO-QUANTUM

void Qrack::QInterface::ProbMaskAll(bitCapInt mask, real1 *probsArray)

Direct measure of masked permutation probability.

“mask” masks the bits to check the probability of. The probabilities of all permutations of the masked bits, from left/low to right/high are returned in the “probsArray” argument.

Warning
PSEUDO-QUANTUM

void Qrack::QInterface::ProbBitsAll(const bitLenInt *bits, bitLenInt length, real1 *probsArray)

Direct measure of listed permutation probability.

The probabilities of all included permutations of bits, with bits valued from low to high as the order of the “bits” array parameter argument, are returned in the “probsArray” parameter.

Warning
PSEUDO-QUANTUM

virtual void Qrack::QInterface::GetProbs(real1 *outputProbs) = 0

Get the pure quantum state representation.

Warning
PSEUDO-QUANTUM

real1_f Qrack::QInterface::ExpectationBitsAll(const bitLenInt *bits, bitLenInt length, bitCapInt offset = 0)

Get permutation expectation value of bits.

The permutation expectation value of all included bits is returned, with bits valued from low to high as the order of the “bits” array parameter argument.

Warning
PSEUDO-QUANTUM

void Qrack::QInterface::Swap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)

Swap values of two bits in register.

void Qrack::QInterface::Swap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)

Swap values of two bits in register.

void Qrack::QInterface::ISwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)

Swap values of two bits in register, and apply phase factor of i if bits are different.

void Qrack::QInterface::ISwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)

Swap values of two bits in register, and apply phase factor of i if bits are different.

void Qrack::QInterface::SqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)

Square root of Swap gate.

void Qrack::QInterface::SqrtSwap(bitLenInt qubitIndex1, bitLenInt qubitIndex2)

Square root of Swap gate.

void Qrack::QInterface::CSwap(const bitLenInt *controls, bitLenInt controlLen, bitLenInt qubit1, bitLenInt qubit2)

Apply a swap with arbitrary control bits.

void Qrack::QInterface::AntiCSwap(const bitLenInt *controls, bitLenInt controlLen, bitLenInt qubit1, bitLenInt qubit2)

Apply a swap with arbitrary (anti) control bits.

void Qrack::QInterface::CSqrtSwap(const bitLenInt *controls, bitLenInt controlLen, bitLenInt qubit1, bitLenInt qubit2)

Apply a square root of swap with arbitrary control bits.

void Qrack::QInterface::AntiCSqrtSwap(const bitLenInt *controls, bitLenInt controlLen, bitLenInt qubit1, bitLenInt qubit2)

Apply a square root of swap with arbitrary (anti) control bits.

virtual void Qrack::QInterface::FSim(real1_f theta, real1_f phi, bitLenInt qubitIndex1, bitLenInt qubitIndex2) = 0

The 2-qubit “fSim” gate, (useful in the simulation of particles with fermionic statistics)

virtual void Qrack::QInterface::FSim(real1_f theta, real1_f phi, bitLenInt qubitIndex1, bitLenInt qubitIndex2) = 0

The 2-qubit “fSim” gate, (useful in the simulation of particles with fermionic statistics)

void Qrack::QInterface::UniformlyControlledRY(const bitLenInt *controls, bitLenInt controlLen, bitLenInt qubitIndex, const real1 *angles)

Apply a “uniformly controlled” rotation of a bit around the Pauli Y axis.

Uniformly controlled y axis rotation gate - Rotates as e^(-i*/2) around Pauli y axis for each permutation “k” of the control bits.

(See https://arxiv.org/abs/quant-ph/0312218)

A different rotation angle is associated with each permutation of the control bits. The first control bit index in the “controls” array is the least significant bit of the permutation, proceeding to the most significant bit. “angles” is an array where each subsequent component is rotation angle associated with the next permutation of the control bits, starting from 0. All combinations of control bits apply one of rotation angles. For k control bits, there are therefore 2^k real components in “angles.”

void Qrack::QInterface::UniformlyControlledRZ(const bitLenInt *controls, bitLenInt controlLen, bitLenInt qubitIndex, const real1 *angles)

Apply a “uniformly controlled” rotation of a bit around the Pauli Z axis.

Uniformly controlled z axis rotation gate - Rotates as e^(-i*/2) around Pauli z axis for each permutation “k” of the control bits.

(See https://arxiv.org/abs/quant-ph/0312218)

A different rotation angle is associated with each permutation of the control bits. The first control bit index in the “controls” array is the least significant bit of the permutation, proceeding to the most significant bit. “angles” is an array where each subsequent component is rotation angle associated with the next permutation of the control bits, starting from 0. All combinations of control bits apply one of rotation angles. For k control bits, there are therefore 2^k real components in “angles.”

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::UniformParityRZ” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::CUniformParityRZ” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

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

Reverse all of the bits in a sequence.

virtual bool Qrack::QInterface::TrySeparate(bitLenInt qubit)

Single-qubit TrySeparate()

virtual bool Qrack::QInterface::TrySeparate(bitLenInt qubit1, bitLenInt qubit2)

Two-qubit TrySeparate()

bool Qrack::QInterface::TryDecompose(bitLenInt start, QInterfacePtr dest, real1_f error_tol = TRYDECOMPOSE_EPSILON)
std::map<bitCapInt, int> Qrack::QInterface::MultiShotMeasureMask(const bitCapInt *qPowers, bitLenInt qPowerCount, unsigned shots)

Statistical measure of masked permutation probability.

“qPowers” contains powers of 2^n, each representing QInterface bit “n.” The order of these values defines a mask for the result bitCapInt, of 2^0 ~ qPowers[0] to 2^(qPowerCount - 1) ~ qPowers[qPowerCount - 1], in contiguous ascending order. “shots” specifies the number of samples to take as if totally re-preparing the pre-measurement state. This method returns a dictionary with keys, which are the (masked-order) measurement results, and values, which are the number of “shots” that produced that particular measurement result. This method does not “collapse” the state of this QInterface. (The idea is to efficiently simulate a potentially statistically random sample of multiple re-preparations of the state right before measurement, and to collect random measurement resutls, without forcing the user to re-prepare or “clone” the state.)

Warning
PSEUDO-QUANTUM

void Qrack::QInterface::MultiShotMeasureMask(const bitCapInt *qPowers, bitLenInt qPowerCount, unsigned shots, unsigned *shotsArray)

Statistical measure of masked permutation probability (returned as array)

Same Qrack::MultiShotMeasureMask(), except the shots are returned as an array.

Warning
PSEUDO-QUANTUM

virtual bool Qrack::QInterface::ApproxCompare(QInterfacePtr toCompare, real1_f error_tol = TRYDECOMPOSE_EPSILON)

Compare state vectors approximately, component by component, to determine whether this state vector is the same as the target.

Warning
PSEUDO-QUANTUM

void Qrack::QInterface::TimeEvolve(Hamiltonian h, real1_f timeDiff)

To define a Hamiltonian, give a vector of controlled single bit gates (“HamiltonianOp” instances) that are applied by left-multiplication in low-to-high vector index order on the state vector.

As a general point of linear algebra, where A and B are linear operators,

\[\begin{equation}e^{i (A + B) t} = e^{i A t} e^{i B t} \end{equation}\]
might NOT hold, if the operators A and B do not commute. As a rule of thumb, A will commute with B at least in the case that A and B act on entirely different sets of qubits. However, for defining the intended Hamiltonian, the programmer can be guaranteed that the exponential factors will be applied right-to-left, by left multiplication, in the order
\[\begin{equation} e^{-i H_{N - 1} t} e^{-i H_{N - 2} t} \ldots e^{-i H_0 t} \left|\psi \rangle\right. .\end{equation}\]
(For example, if A and B are single bit gates acting on the same bit, form their composition into one gate by the intended right-to-left fusion and apply them as a single HamiltonianOp.)
Warning
Hamiltonian components might not commute.

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.

Note

Qrack::QInterface also offers arithmetic logic unit (ALU) gates. See the Doxygen.

Single Gates

virtual void Qrack::QInterface::Mtrx(const complex *mtrx, bitLenInt qubitIndex) = 0

Apply an arbitrary single bit unitary transformation.

virtual void Qrack::QInterface::MCMtrx(const bitLenInt *controls, bitLenInt controlLen, const complex *mtrx, bitLenInt target) = 0

Apply an arbitrary single bit unitary transformation, with arbitrary control bits.

void Qrack::QInterface::MACMtrx(const bitLenInt *controls, bitLenInt controlLen, const complex *mtrx, bitLenInt target)

Apply an arbitrary single bit unitary transformation, with arbitrary (anti-)control bits.

void Qrack::QInterface::Phase(const complex topLeft, const complex bottomRight, bitLenInt qubitIndex)

Apply a single bit transformation that only effects phase.

void Qrack::QInterface::MCPhase(const bitLenInt *controls, bitLenInt controlLen, complex topLeft, complex bottomRight, bitLenInt target)

Apply a single bit transformation that only effects phase, with arbitrary control bits.

void Qrack::QInterface::MACPhase(const bitLenInt *controls, bitLenInt controlLen, complex topLeft, complex bottomRight, bitLenInt target)

Apply a single bit transformation that only effects phase, with arbitrary (anti-)control bits.

void Qrack::QInterface::Invert(const complex topRight, const complex bottomLeft, bitLenInt qubitIndex)

Apply a single bit transformation that reverses bit probability and might effect phase.

void Qrack::QInterface::MCInvert(const bitLenInt *controls, bitLenInt controlLen, complex topRight, complex bottomLeft, bitLenInt target)

Apply a single bit transformation that reverses bit probability and might effect phase, with arbitrary control bits.

void Qrack::QInterface::MACInvert(const bitLenInt *controls, bitLenInt controlLen, complex topRight, complex bottomLeft, bitLenInt target)

Apply a single bit transformation that reverses bit probability and might effect phase, with arbitrary (anti-)control bits.

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

Quantum analog of classical “AND” gate.

(Assumes the outputBit is in the 0 state)

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. (Assumes the outputBit is in the 0 state)

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

Quantum analog of classical “OR” gate.

(Assumes the outputBit is in the 0 state)

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. (Assumes the outputBit is in the 0 state)

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

Quantum analog of classical “XOR” gate.

(Assumes the outputBit is in the 0 state)

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. (Assumes the outputBit is in the 0 state)

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

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 bool Qrack::QInterface::ForceM(bitLenInt qubit, bool result, bool doForce = true, bool doApply = true) = 0

Act as if is a measurement was applied, except force the (usually random) result.

Warning
PSEUDO-QUANTUM

void Qrack::QInterface::U(bitLenInt target, real1_f theta, real1_f phi, real1_f lambda)

General unitary gate.

Applies a gate guaranteed to be unitary, from three angles, as commonly defined, spanning all possible single bit unitary gates, (up to a global phase factor which has no effect on Hermitian operator expectation values).

virtual void Qrack::QInterface::U2(bitLenInt target, real1_f phi, real1_f lambda)

2-parameter unitary gate

Applies a gate guaranteed to be unitary, from two angles, as commonly defined.

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

Hadamard gate.

Applies a Hadamard gate on qubit at “qubitIndex.”

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

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)

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)

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.

void Qrack::QInterface::S(bitLenInt qubitIndex)

S gate.

Apply 1/4 phase rotation.

Applies a 1/4 phase rotation to the qubit at “qubitIndex.”

void Qrack::QInterface::IS(bitLenInt qubitIndex)

Inverse S gate.

Apply inverse 1/4 phase rotation.

Applies an inverse 1/4 phase rotation to the qubit at “qubitIndex.”

virtual void Qrack::QInterface::SH(bitLenInt qubitIndex)

Y-basis transformation gate.

Converts from Pauli Z basis to Y, (via H then S gates).

virtual void Qrack::QInterface::HIS(bitLenInt qubitIndex)

Y-basis (inverse) transformation gate.

Converts from Pauli Y basis to Z, (via IS then H gates).

void Qrack::QInterface::T(bitLenInt qubitIndex)

T gate.

Apply 1/8 phase rotation.

Applies a 1/8 phase rotation to the qubit at “qubitIndex.”

void Qrack::QInterface::IT(bitLenInt qubitIndex)

Inverse T gate.

Apply inverse 1/8 phase rotation.

Applies an inverse 1/8 phase rotation to the qubit at “qubitIndex.”

virtual void Qrack::QInterface::SqrtX(bitLenInt qubitIndex)

Square root of X gate.

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

virtual void Qrack::QInterface::ISqrtX(bitLenInt qubitIndex)

Inverse square root of X gate.

Applies the (by convention) inverse square root of the Pauli “X” operator to the qubit at “qubitIndex.” The Pauli “X” operator is equivalent to a logical “NOT.”

virtual void Qrack::QInterface::SqrtY(bitLenInt qubitIndex)

Square root of Y gate.

Applies the square root of 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::ISqrtY(bitLenInt qubitIndex)

Square root of Y gate.

Applies the (by convention) inverse square root of 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::SqrtH(bitLenInt qubitIndex)

Square root of Hadamard gate.

Applies the square root of the Hadamard gate on qubit at “qubitIndex.”

virtual void Qrack::QInterface::SqrtXConjT(bitLenInt qubitIndex)

Phased square root of X gate.

Applies T.SqrtX.IT to the qubit at “qubitIndex.”

virtual void Qrack::QInterface::ISqrtXConjT(bitLenInt qubitIndex)

Inverse phased square root of X gate.

Applies IT.ISqrtX.T to the qubit at “qubitIndex.”

void Qrack::QInterface::PhaseRootN(bitLenInt n, bitLenInt qubitIndex)

“PhaseRootN” gate

Apply 1/(2^N) phase rotation.

Applies a 1/(2^N) phase rotation to the qubit at “qubitIndex.”

void Qrack::QInterface::IPhaseRootN(bitLenInt n, bitLenInt qubitIndex)

Inverse “PhaseRootN” gate.

Apply inverse 1/(2^N) phase rotation.

Applies an inverse 1/(2^N) phase rotation to the qubit at “qubitIndex.”

void Qrack::QInterface::CPhaseRootN(bitLenInt n, bitLenInt control, bitLenInt target)

Controlled “PhaseRootN” gate.

Apply controlled “PhaseRootN” gate to bit.

If the “control” bit is set to 1, then the “PhaseRootN” gate is applied to “target.”

void Qrack::QInterface::CIPhaseRootN(bitLenInt n, bitLenInt control, bitLenInt target)

Controlled inverse “PhaseRootN” gate.

Apply controlled “IPhaseRootN” gate to bit.

If the “control” bit is set to 1, then the inverse “PhaseRootN” gate is applied to “target.”

void Qrack::QInterface::CNOT(bitLenInt control, bitLenInt target)

Controlled NOT gate.

Controlled not.

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

void Qrack::QInterface::AntiCNOT(bitLenInt control, bitLenInt target)

Anti controlled NOT gate.

“Anti-controlled not” - Apply “not” if control bit is zero, do not apply if control bit is one.

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

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

Doubly-controlled NOT gate.

Doubly-controlled not.

If both controls are set to 1, the target bit is NOT-ed or X-ed.

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

Anti doubly-controlled NOT gate.

“Anti-doubly-controlled not” - Apply “not” if control bits are both zero, do not apply if either control bit is one.

If both controls are set to 0, the target bit is NOT-ed or X-ed.

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

Controlled Y gate.

Apply controlled Pauli Y matrix to 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)

Controlled Z gate.

Apply controlled Pauli Z matrix to bit.

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

void Qrack::QInterface::RT(real1_f radians, bitLenInt qubitIndex)

Phase shift gate.

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

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

void Qrack::QInterface::RX(real1_f radians, bitLenInt qubitIndex)

X axis rotation gate.

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

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

void Qrack::QInterface::RY(real1_f radians, bitLenInt qubitIndex)

Y axis rotation gate.

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

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

void Qrack::QInterface::RZ(real1_f radians, bitLenInt qubitIndex)

Z axis rotation gate.

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

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

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

Controlled Z axis rotation gate.

Controlled z axis rotation - if control bit is true, rotates as e^(-i*) around Pauli z axis.

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

virtual void Qrack::QInterface::UniformlyControlledSingleBit(const bitLenInt *controls, bitLenInt controlLen, bitLenInt qubitIndex, const complex *mtrxs)

Apply a “uniformly controlled” arbitrary single bit unitary transformation.

(See https://arxiv.org/abs/quant-ph/0312218)

A different unitary 2x2 complex matrix is associated with each permutation of the control bits. The first control bit index in the “controls” array is the least significant bit of the permutation, proceeding to the most significant bit. “mtrxs” is a flat (1-dimensional) array where each subsequent set of 4 components is an arbitrary 2x2 single bit gate associated with the next permutation of the control bits, starting from 0. All combinations of control bits apply one of the 4 component (flat 2x2) matrices. For k control bits, there are therefore 4 * 2^k complex components in “mtrxs,” representing 2^k complex matrices of 2x2 components. (The component ordering in each matrix is the same as all other gates with an arbitrary 2x2 applied to a single bit, such as Qrack::ApplySingleBit.)

void Qrack::QInterface::UniformlyControlledRY(const bitLenInt *controls, bitLenInt controlLen, bitLenInt qubitIndex, const real1 *angles)

Apply a “uniformly controlled” rotation of a bit around the Pauli Y axis.

Uniformly controlled y axis rotation gate - Rotates as e^(-i*/2) around Pauli y axis for each permutation “k” of the control bits.

(See https://arxiv.org/abs/quant-ph/0312218)

A different rotation angle is associated with each permutation of the control bits. The first control bit index in the “controls” array is the least significant bit of the permutation, proceeding to the most significant bit. “angles” is an array where each subsequent component is rotation angle associated with the next permutation of the control bits, starting from 0. All combinations of control bits apply one of rotation angles. For k control bits, there are therefore 2^k real components in “angles.”

void Qrack::QInterface::UniformlyControlledRZ(const bitLenInt *controls, bitLenInt controlLen, bitLenInt qubitIndex, const real1 *angles)

Apply a “uniformly controlled” rotation of a bit around the Pauli Z axis.

Uniformly controlled z axis rotation gate - Rotates as e^(-i*/2) around Pauli z axis for each permutation “k” of the control bits.

(See https://arxiv.org/abs/quant-ph/0312218)

A different rotation angle is associated with each permutation of the control bits. The first control bit index in the “controls” array is the least significant bit of the permutation, proceeding to the most significant bit. “angles” is an array where each subsequent component is rotation angle associated with the next permutation of the control bits, starting from 0. All combinations of control bits apply one of rotation angles. For k control bits, there are therefore 2^k real components in “angles.”

Arithmetic

Qrack can build with quantum arithmetic methods, using CMake option ``-DENABLE_ALU=ON`.

void Qrack::QInterface::INC(bitCapInt toAdd, bitLenInt start, bitLenInt length)

Add integer (without sign)

void Qrack::QInterface::DEC(bitCapInt toSub, bitLenInt start, bitLenInt length)

Subtract classical integer (without sign)

Subtract integer (without sign)

void Qrack::QInterface::CINC(bitCapInt toAdd, bitLenInt inOutStart, bitLenInt length, const bitLenInt *controls, bitLenInt controlLen)

Add integer (without sign, with controls)

void Qrack::QInterface::CDEC(bitCapInt toSub, bitLenInt inOutStart, bitLenInt length, const bitLenInt *controls, bitLenInt controlLen)

Subtract classical integer (without sign, with controls)

Subtract integer (without sign, with controls)

void Qrack::QInterface::INCC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)

Add integer (without sign, with carry)

void Qrack::QInterface::INCS(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)

Add a classical integer to the register, with sign and without carry.

void Qrack::QInterface::DECS(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)

Subtract a classical integer from the register, with sign and without carry.

Subtract an integer from the register, with sign and without carry.

Because the register length is an arbitrary number of bits, the sign bit position on the integer to add is variable. Hence, the integer to add is specified as cast to an unsigned format, with the sign bit assumed to be set at the appropriate position before the cast.

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::INCSC” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::INCSC” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::MUL” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::DIV” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::CMUL” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::CDIV” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::MULModNOut” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::IMULModNOut” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::CMULModNOut” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::CIMULModNOut” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::POWModNOut” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::CPOWModNOut” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

void Qrack::QInterface::FullAdd(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)

Quantum analog of classical “Full Adder” gate.

(Assumes the outputBit is in the 0 state)

void Qrack::QInterface::IFullAdd(bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)

Inverse of FullAdd.

(Can be thought of as “subtraction,” but with a register convention that the same inputs invert FullAdd.)

void Qrack::QInterface::CFullAdd(const bitLenInt *controls, bitLenInt controlLen, bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)

Controlled quantum analog of classical “Full Adder” gate.

Quantum analog of classical “Full Adder” gate.

(Assumes the outputBit is in the 0 state)

void Qrack::QInterface::CIFullAdd(const bitLenInt *controls, bitLenInt controlLen, bitLenInt inputBit1, bitLenInt inputBit2, bitLenInt carryInSumOut, bitLenInt carryOut)

Inverse of CFullAdd.

Inverse of FullAdd.

(Can be thought of as “subtraction,” but with a register convention that the same inputs invert CFullAdd.)

void Qrack::QInterface::ADC(bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry)

Add a quantum integer to a quantum integer, with carry.

(Assumes the output register is in the 0 state)

void Qrack::QInterface::IADC(bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry)

Inverse of ADC.

(Can be thought of as “subtraction,” but with a register convention that the same inputs invert ADC.)

void Qrack::QInterface::CADC(const bitLenInt *controls, bitLenInt controlLen, bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry)

Add a quantum integer to a quantum integer, with carry and with controls.

(Assumes the output register is in the 0 state)

void Qrack::QInterface::CIADC(const bitLenInt *controls, bitLenInt controlLen, bitLenInt input1, bitLenInt input2, bitLenInt output, bitLenInt length, bitLenInt carry)

Inverse of CADC.

(Can be thought of as “subtraction,” but with a register convention that the same inputs invert CADC.)

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::IndexedLDA” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::IndexedADC” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::IndexedSBC” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Warning

doxygenfunction: Cannot find function “Qrack::QInterface::Hash” in doxygen xml output for project “qrack” from directory: /tmp/qrack/doc/xml

Algorithmic Implementations

void Qrack::QInterface::QFT(bitLenInt start, bitLenInt length, bool trySeparate = false)

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

Quantum Fourier Transform - Optimized for going from |0>/|1> to |+>/|-> basis.

“trySeparate” is an optional hit-or-miss optimization, specifically for QUnit types. Our suggestion is, turn it on for speed and memory effciency if you expect the result of the QFT to be in a permutation basis eigenstate. Otherwise, turning it on will probably take longer.

void Qrack::QInterface::IQFT(bitLenInt start, bitLenInt length, bool trySeparate = false)

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

Inverse Quantum Fourier Transform - Quantum Fourier transform optimized for going from |+>/|-> to |0>/|1> basis.

“trySeparate” is an optional hit-or-miss optimization, specifically for QUnit types. Our suggestion is, turn it on for speed and memory effciency if you expect the result of the QFT to be in a permutation basis eigenstate. Otherwise, turning it on will probably take longer.

void Qrack::QInterface::QFTR(const bitLenInt *qubits, bitLenInt length, bool trySeparate = false)

Quantum Fourier Transform (random access) - Apply the quantum Fourier transform to the register.

Quantum Fourier Transform - Optimized for going from |0>/|1> to |+>/|-> basis.

“trySeparate” is an optional hit-or-miss optimization, specifically for QUnit types. Our suggestion is, turn it on for speed and memory effciency if you expect the result of the QFT to be in a permutation basis eigenstate. Otherwise, turning it on will probably take longer.

void Qrack::QInterface::IQFTR(const bitLenInt *qubits, bitLenInt length, bool trySeparate = false)

Inverse Quantum Fourier Transform (random access) - Apply the inverse quantum Fourier transform to the register.

Inverse Quantum Fourier Transform - Quantum Fourier transform optimized for going from |+>/|-> to |0>/|1> basis.

“trySeparate” is an optional hit-or-miss optimization, specifically for QUnit types. Our suggestion is, turn it on for speed and memory effciency if you expect the result of the QFT to be in a permutation basis eigenstate. Otherwise, turning it on will probably take longer.