Skip to content

Commit

Permalink
Merge pull request #2 from vm6502q/qunit_update
Browse files Browse the repository at this point in the history
Update for QInterface
  • Loading branch information
bennbollay committed Apr 26, 2018
2 parents 0f9aa20 + 5dbe2ac commit 3641feb
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 167 deletions.
147 changes: 0 additions & 147 deletions docs/api/coherent_unit.rst

This file was deleted.

154 changes: 154 additions & 0 deletions docs/api/qinterface.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
:orphan:

.. Copyright (c) 2018
QInterface
========================

Defined in `qinterface.hpp <https://github.com/vm6502q/qrack/blob/master/include/qinterface.hpp>`_.

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

.. doxygenclass:: Qrack::QInterface
:project: qrack

Creating a QInterface
-----------------------

There's three primary implementations of a ``QInterface``:

.. doxygenenum:: QInterfaceEngine

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

.. doxygenfunction:: Qrack::CreateQuantumInterface

Constructors
------------

.. doxygenfunction:: Qrack::QInterface::QInterface(bitLenInt)

.. doxygenfunction:: Qrack::QInterface::QInterface(bitLenInt, bitCapInt)

.. doxygenfunction:: Qrack::QInterface::QInterface(const QInterface&)

Members
-------

.. doxygenvariable:: stateVec

Configuration Methods
---------------------------------

.. doxygenfunction:: Qrack::QInterface::GetQubitCount

.. doxygenfunction:: Qrack::QInterface::GetMaxQPower

State Manipulation Methods
--------------------------

.. doxygenfunction:: Qrack::QInterface::SetPermutation

.. doxygenfunction:: Qrack::QInterface::SetQuantumState

.. doxygenfunction:: Qrack::QInterface::Cohere(QInterfacePtr)
.. doxygenfunction:: Qrack::QInterface::Cohere(std::vector<QInterfacePtr>)

.. doxygenfunction:: Qrack::QInterface::Decohere

.. doxygenfunction:: Qrack::QInterface::Dispose

.. doxygenfunction:: Qrack::QInterface::Prob

.. doxygenfunction:: Qrack::QInterface::ProbAll

.. doxygenfunction:: Qrack::QInterface::ProbArray

.. doxygenfunction:: Qrack::QInterface::Swap(bitLenInt, bitLenInt)

.. doxygenfunction:: Qrack::QInterface::Swap(bitLenInt, bitLenInt, bitLenInt)

.. doxygenfunction:: Qrack::QInterface::Reverse(bitLenInt, bitLenInt)

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
~~~~~~~~~~~~~~~~~~~~~

.. doxygenfunction:: Qrack::QInterface::AND(bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CLAND(bitLenInt, bool, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::OR(bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CLOR(bitLenInt, bool, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::XOR(bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CLXOR(bitLenInt, bool, bitLenInt)

.. doxygenfunction:: Qrack::QInterface::H(bitLenInt)
.. doxygenfunction:: Qrack::QInterface::M(bitLenInt)
.. doxygenfunction:: Qrack::QInterface::X(bitLenInt)

.. doxygenfunction:: Qrack::QInterface::Y(bitLenInt)
.. doxygenfunction:: Qrack::QInterface::Z(bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CY(bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CZ(bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RT(double, bitLenInt)

.. doxygenfunction:: Qrack::QInterface::RTDyad(int, int, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RX(double, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RXDyad(int, int, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CRX(double, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CRXDyad(int, int, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RY(double, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RYDyad(int, int, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CRY(double, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CRYDyad(int, int, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RZ(double, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RZDyad(int, int, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CRZ(double, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CRZDyad(int, int, bitLenInt, bitLenInt)

Register-wide Gates
~~~~~~~~~~~~~~~~~~~

.. doxygenfunction:: Qrack::QInterface::AND(bitLenInt, bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CLAND(bitLenInt, bitCapInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::OR(bitLenInt, bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CLOR(bitLenInt, bitCapInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::XOR(bitLenInt, bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CLXOR(bitLenInt, bitCapInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CCNOT(bitLenInt, bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::AntiCCNOT(bitLenInt, bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CNOT(bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CNOT(bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::AntiCNOT(bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::H(bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::MReg(bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::X(bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::Y(bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::Z(bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CY(bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CZ(bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RT(double, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RTDyad(int, int, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RX(double, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RXDyad(int, int, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CRX(double, bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CRXDyad(int, int, bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RY(double, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RYDyad(int, int, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CRY(double, bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CRYDyad(int, int, bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RZ(double, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::RZDyad(int, int, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CRZ(double, bitLenInt, bitLenInt, bitLenInt)
.. doxygenfunction:: Qrack::QInterface::CRZDyad(int, int, bitLenInt, bitLenInt, bitLenInt)

Algorithmic Implementations
---------------------------

.. doxygenfunction:: Qrack::QInterface::QFT
.. doxygenfunction:: Qrack::QInterface::SuperposeReg8
.. doxygenfunction:: Qrack::QInterface::AdcSuperposeReg8
.. doxygenfunction:: Qrack::QInterface::SbcSuperposeReg8
6 changes: 3 additions & 3 deletions docs/implementation.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Implementation
==============

CoherentUnit
QInterface
--------------------------------

A `Qrack::CoherentUnit` stores a set of permutation basis complex number coefficients and operates on them with bit gates and register-like methods.
A `Qrack::QInterface` stores a set of permutation basis complex number coefficients and operates on them with bit gates and register-like methods.

The state vector indicates the probability and phase of all possible pure bit permutations, numbered from :math:`0` to :math:`2^N-1`, by simple binary counting. All operations except measurement should be "unitary," except measurement. They should be representable as a unitary matrix acting on the state vector. Measurement, and methods that involve measurement, should be the only operations that break unitarity. As a rule-of-thumb, this means an operation that doesn't rely on measurement should be "reversible." That is, if a unitary operation is applied to the state, their must be a unitary operation to map back from the output to the exact input. In practice, this means that most gate and register operations entail simply direct exchange of state vector coefficients in a one-to-one manner. (Sometimes, operations involve both a one-to-one exchange and a measurement, like the `CoherentUnit::SetBit` method, or the logical comparison methods.)
The state vector indicates the probability and phase of all possible pure bit permutations, numbered from :math:`0` to :math:`2^N-1`, by simple binary counting. All operations except measurement should be "unitary," except measurement. They should be representable as a unitary matrix acting on the state vector. Measurement, and methods that involve measurement, should be the only operations that break unitarity. As a rule-of-thumb, this means an operation that doesn't rely on measurement should be "reversible." That is, if a unitary operation is applied to the state, their must be a unitary operation to map back from the output to the exact input. In practice, this means that most gate and register operations entail simply direct exchange of state vector coefficients in a one-to-one manner. (Sometimes, operations involve both a one-to-one exchange and a measurement, like the `QInterface::SetBit` method, or the logical comparison methods.)

A single bit gate essentially acts as a :math:`2\times2` matrix between the :math:`0` and :math:`1` states of a single bits. This can be acted independently on all pairs of permutation basis state vector components where all bits are held fixed while :math:`0` and :math:`1` states are paired for the bit being acted on. This is "embarassingly parallel."

Expand Down
18 changes: 14 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Build Status
The first section has the most material present, but the second and
third sections are very sparse. I would not, after reading this, be
able to implement a CoherentUnit, or even understand how CoherentUnit
able to implement a QInterface, or even understand how QInterface
simulates a qubit.
It's worth noting that it's not necessary for you to write all of this
Expand All @@ -51,9 +51,9 @@ Build Status
Introduction
------------

Qrack is a C++ quantum bit simulator, with the ability to support arbitrary numbers of entangled qubits - up to system limitations. Suitable for embedding in other projects, the :cpp:class:`Qrack::CoherentUnit` contains a full and performant collection of standard quantum gates, as well as variations suitable for register operations and arbitrary rotations.
Qrack is a C++ quantum bit simulator, with the ability to support arbitrary numbers of entangled qubits - up to system limitations. Suitable for embedding in other projects, the :cpp:class:`Qrack::QInterface` contains a full and performant collection of standard quantum gates, as well as variations suitable for register operations and arbitrary rotations.

As a demonstration of the :cpp:class:`Qrack::CoherentUnit` implementation, a MOS-6502 microprocessor [MOS-6502]_ virtual machine has been modified with a set of new opcodes (:ref:`mos-6502q-opcodes`) supporting quantum operations. The `vm6502q <https://github.com/vm6502q/vm6502q>`_ virtual machine exposes new integrated quantum opcodes such as Hadamard transforms and an X-indexed LDA, with the X register in superposition, across a page of memory. An assembly example of a Grover's search with a simple oracle function is demonstrated in the `examples <https://github.com/vm6502q/examples>`_ repository.
As a demonstration of the :cpp:class:`Qrack::QInterface` implementation, a MOS-6502 microprocessor [MOS-6502]_ virtual machine has been modified with a set of new opcodes (:ref:`mos-6502q-opcodes`) supporting quantum operations. The `vm6502q <https://github.com/vm6502q/vm6502q>`_ virtual machine exposes new integrated quantum opcodes such as Hadamard transforms and an X-indexed LDA, with the X register in superposition, across a page of memory. An assembly example of a Grover's search with a simple oracle function is demonstrated in the `examples <https://github.com/vm6502q/examples>`_ repository.

Finally, a `6502 toolchain <https://github.com/vm6502q/cc65>`_ - based on `CC65 <http://cc65.github.io/doc/>`_ - has been modified and enhanced to support both the new opcodes - for the assembler - as well as :ref:`c-syntax-enhancements-ref`. This is performed primarily as sandbox/exploratory work to help clarify what quantum computational software engineering might look like as the hardware reaches commoditization.

Expand All @@ -73,7 +73,17 @@ Finally, a `6502 toolchain <https://github.com/vm6502q/cc65>`_ - based on `CC65
:caption: API
:maxdepth: 2

api/coherent_unit
api/qinterface
api/6502

.. toctree::
:hidden:
:caption: Doxygen
:maxdepth: 2

QInterface <_static/doxygen/classQrack_1_1QInterface.html#http://>
QUnit <_static/doxygen/classQrack_1_1QUnit.html#http://>
QEngineCPU <_static/doxygen/classQrack_1_1QEngineCPU.html#http://>
QEngineOCL <_static/doxygen/classQrack_1_1QEngineOCL.html#http://>
Complex16Simd <_static/doxygen/structQrack_1_1Complex16Simd.html#http://>

0 comments on commit 3641feb

Please sign in to comment.