Browse Source

Working on benchmarking and documentation

Adam Kelly 5 years ago
parent
commit
88331d7d8e
11 changed files with 184 additions and 126 deletions
  1. 10 10
      benchmarking.py
  2. 2 1
      docs/conf.py
  3. 37 9
      docs/index.rst
  4. 46 0
      docs/install.rst
  5. 0 52
      docs/installing.rst
  6. 38 0
      docs/quickstart.rst
  7. 27 51
      notebooks/Benchmarking.ipynb
  8. 2 1
      qcgpu/gate.py
  9. 9 1
      qcgpu/state.py
  10. 1 1
      requirements.txt
  11. 12 0
      working.py

+ 10 - 10
benchmarking.py

@@ -23,6 +23,7 @@ def bench_qcgpu(n, depth):
 
             if q != 0:
                 state.apply_controlled_gate(x, q, 0)
+
     return time.time() - start
 
 # Qiskit Implementation
@@ -34,6 +35,8 @@ def bench_qiskit(n, depth):
     c = ClassicalRegister(n)
     qc = QuantumCircuit(q, c)
     
+    start = time.time()
+
     for level in range(depth):
         for i in range(n):
             qc.h(q[i])
@@ -41,11 +44,10 @@ def bench_qiskit(n, depth):
 
             if i != 0:
                 qc.cx(q[i], q[0])
-    qc.measure(q, c)
 
-    start = time.time()
-    
     job_sim = execute(qc, "local_statevector_simulator")
+
+    job_sim.result()
     
     return time.time() - start
 
@@ -68,28 +70,26 @@ def bench_projectq(n, depth):
             if q != qbits[0]:
                 ops.CNOT | (q, qbits[0])
 
-    runtime = time.time() - start
-
     for q in qbits:
         ops.Measure | q
-    eng.flush()
-    return runtime
+    return time.time() - start
 
 # Reporting
 
-functions = bench_qcgpu, bench_qiskit, bench_projectq
+functions = bench_qcgpu, bench_qiskit#, bench_projectq
+# functions = bench_qiskit,
 
 times = {f.__name__: [] for f in functions}
 
 names = []
 means = []
 
-samples = 10
+samples = 100
 for i in range(samples):  # adjust accordingly so whole thing takes a few sec
     progress = i / samples
     print("\rProgress: [{0:50s}] {1:.1f}%".format('#' * int(progress * 50), progress*100), end="", flush=True)
     func = random.choice(functions)
-    t = func(5,1)
+    t = func(20,10)
     times[func.__name__].append(t)
 
 print('')

+ 2 - 1
docs/conf.py

@@ -44,6 +44,7 @@ extensions = [
     'sphinx.ext.mathjax',
     'sphinx.ext.ifconfig',
     'sphinx.ext.githubpages',
+    'sphinx.ext.napoleon'
 ]
 
 # Add any paths that contain templates here, relative to this directory.
@@ -79,7 +80,7 @@ pygments_style = None
 # The theme to use for HTML and HTML Help pages.  See the documentation for
 # a list of builtin themes.
 #
-html_theme = 'sphinx_rtd_theme'
+html_theme = 'press'
 
 # Theme options are theme-specific and customize the look and feel of a theme
 # further.  For a list of options available for each theme, see the

+ 37 - 9
docs/index.rst

@@ -1,14 +1,42 @@
-.. include:: ../README.rst
+QCGPU
+=====
+
+.. image:: https://img.shields.io/travis/QCGPU/qcgpu.svg?style=for-the-badge   
+   :alt: Travis (.org)   
+   :target: https://travis-ci.org/QCGPU/qcgpu
+.. image:: https://img.shields.io/pypi/v/qcgpu.svg?style=for-the-badge
+   :target: https://pypi.python.org/pypi/qcgpu
+   :alt: PyPi Version
+.. image:: https://img.shields.io/pypi/l/qcgpu.svg?style=for-the-badge
+   :target: https://pypi.python.org/pypi/qcgpu/
+   :alt: License
+.. image:: https://img.shields.io/github/stars/qcgpu/qcgpu.svg?style=for-the-badge&label=Stars
+   :alt: GitHub stars
+   :target: https://github.com/QCGPU/qcgpu
+
+QCGPU is an open source, high performance library for simulating
+quantum circuits. 
+It takes advantage of hardware acceleration with
+OpenCL.
+Read the `research paper`_.
+
+.. _`research paper`: https://arxiv.org/abs/1805.00988
+
+
+
+Table of Contents
+==================
 
 .. toctree::
    :maxdepth: 2
-   :caption: Contents:
    
-   installing
-
-Indices and tables
-==================
+   install
+   Getting started <quickstart>
+   Software reference <_autodoc/qcgpu>
 
-* :ref:`genindex`
-* :ref:`modindex`
-* :ref:`search`
+.. Python Modules
+    ==============
+    .. autosummary::
+        :nosignatures:
+        qcgpu
+    :ref:`modindex`

+ 46 - 0
docs/install.rst

@@ -0,0 +1,46 @@
+============
+Installation
+============
+
+Prerequisites
+-------------
+
+To use QCGPU you will need to be using `Python 2.7 or later <https://www.python.org/downloads/>`_.
+You will also need to ensure that you have an `OpenCL <https://www.khronos.org/opencl/>`_ implementation installed. 
+This is done by default on MacOS, but you shuld check that ``clinfo`` or some other diagnostic command will run.
+
+You can also use `Anaconda 3 <https://www.continuum.io/downloads>`_, which will have many of the required dependencies already installed.
+
+Installing from PyPI
+--------------------
+
+This library is distributed on `PyPI <https://pypi.python.org/pypi/qcgpu>`_ and can be installed using pip:
+
+.. code:: sh
+
+   $ pip install qcgpu
+
+If you run into any issues, you should try installing from source.
+
+Installing from Source
+----------------------
+
+You can install QCGPU from the source. First, clone the repository off
+GitHub:
+
+.. code:: sh
+
+   $ git clone https://github.com/qcgpu/qcgpu
+
+Then you will need to ``cd`` into the directory, and install the
+requirements.
+
+.. code:: sh
+
+   $ pip install -r requirements.txt
+
+And finally you can install:
+
+.. code:: sh
+
+   $ python setup.py install

+ 0 - 52
docs/installing.rst

@@ -1,52 +0,0 @@
-.. _installing:
-
-Installing
-==========
-
-There are a few things you have to do to install QCGPU.
-
-Prerequisites
--------------
-
--  `OpenCL`_ (Ensure that an OpenCL implementation is installed for your
-   platform and that ``clinfo`` or some other diagnostic command will
-   run).
--  `Python`_ (Version 2.7 or later).
-
-Installing from PyPI
---------------------
-
-This library is distributed on `PyPI`_ and can be installed using pip:
-
-.. code:: bash
-
-   $ pip install qcgpu
-
-If you run into any issues, you should try installing from source.
-
-Installing from Source
-----------------------
-
-You can install QCGPU from the source. First, clone the repository off
-GitHub:
-
-.. code:: bash
-
-   $ git clone https://github.com/qcgpu/qcgpu
-
-Then you will need to ``cd`` into the directory, and install the
-requirements.
-
-.. code:: bash
-
-   $ pip install -r requirements.txt
-
-And finally you can install:
-
-.. code:: bash
-
-   $ python setup.py install
-
-.. _OpenCL: https://www.khronos.org/opencl/
-.. _Python: https://www.python.org/
-.. _PyPI: https://pypi.python.org/pypi/qcgpu

+ 38 - 0
docs/quickstart.rst

@@ -0,0 +1,38 @@
+Getting Started
+===============
+
+When using this library, you will most likely be using the :class:`~qiskit.State` class.
+This class represents the state of a quantum register. 
+Using this class you can apply gates to the register, measure, get the state vector and things like that.
+
+To run a simple quantum circuit, you can use something like this,
+
+.. code-block:: python
+
+    # Import QCGPU
+    import qcgpu
+
+    # Create a new quantum register with 2 qubits
+    register = qcgpu.State(2)
+
+    # Apply a hadamard (H) gate to the first qubit.
+    # You should note that the qubits are zero indexed
+    register.h(0)
+
+    # Add a controlled not (CNOT/CX) gate, with the control as
+    # the first qubit and target as the second.
+    # The register will now be in the bell state.
+    register.cx(0, 1)
+
+    # Perform a measurement with 1000 samples
+    results = register.measure(samples=1000)
+
+    # Show the results
+    print(results)
+
+The output of a measurement gives a dictionary of measurement outcomes,
+along with how often they occurred.
+
+.. code-block:: python
+
+    {'00': 486, '11': 514}

File diff suppressed because it is too large
+ 27 - 51
notebooks/Benchmarking.ipynb


+ 2 - 1
qcgpu/gate.py

@@ -42,4 +42,5 @@ def t():
     return Gate(np.array([[1, 0], [0, np.exp(np.pi * 1j / 4)]]))
 
 def sqrt_x():
-    return Gate(0.5 * np.array([[1+1j, 1-1j], [1-1j, 1+1j]]))
+    return Gate(0.5 * np.array([[1+1j, 1-1j], [1-1j, 1+1j]]))
+

+ 9 - 1
qcgpu/state.py

@@ -3,8 +3,16 @@ import pyopencl as cl
 import numpy as np
 
 class State:
-    """Represents the state of a quantum register"""
+    """  Creates a new quantum register.
+
+    Args:
+        num_qubits (int): The number of qubits to create in the register
+
+    Returns:
+        State: A representation of the quantum register
+    """
     def __init__(self, num_qubits):
+        
         if not isinstance(num_qubits, int):
             raise ValueError("num_qubits must be an int")
         if num_qubits <= 0:

+ 1 - 1
requirements.txt

@@ -4,4 +4,4 @@ pybind11==2.2.4
 pyopencl==2018.2
 scipy==1.1.0
 Sphinx==1.8.1
-sphinx_rtd_theme 
+sphinx-press-theme

+ 12 - 0
working.py

@@ -0,0 +1,12 @@
+import qcgpu
+import time
+
+s = qcgpu.State(28)
+h = qcgpu.gate.h()
+
+s.apply_all(h)
+
+
+
+print(s.measure(1000))
+# print(s.backend.measure(samples=10000))