Skip to content

Commit 88331d7

Browse files
committed
Working on benchmarking and documentation
1 parent 2f0ee8d commit 88331d7

File tree

11 files changed

+184
-126
lines changed

11 files changed

+184
-126
lines changed

benchmarking.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def bench_qcgpu(n, depth):
2323

2424
if q != 0:
2525
state.apply_controlled_gate(x, q, 0)
26+
2627
return time.time() - start
2728

2829
# Qiskit Implementation
@@ -34,18 +35,19 @@ def bench_qiskit(n, depth):
3435
c = ClassicalRegister(n)
3536
qc = QuantumCircuit(q, c)
3637

38+
start = time.time()
39+
3740
for level in range(depth):
3841
for i in range(n):
3942
qc.h(q[i])
4043
qc.t(q[i])
4144

4245
if i != 0:
4346
qc.cx(q[i], q[0])
44-
qc.measure(q, c)
4547

46-
start = time.time()
47-
4848
job_sim = execute(qc, "local_statevector_simulator")
49+
50+
job_sim.result()
4951

5052
return time.time() - start
5153

@@ -68,28 +70,26 @@ def bench_projectq(n, depth):
6870
if q != qbits[0]:
6971
ops.CNOT | (q, qbits[0])
7072

71-
runtime = time.time() - start
72-
7373
for q in qbits:
7474
ops.Measure | q
75-
eng.flush()
76-
return runtime
75+
return time.time() - start
7776

7877
# Reporting
7978

80-
functions = bench_qcgpu, bench_qiskit, bench_projectq
79+
functions = bench_qcgpu, bench_qiskit#, bench_projectq
80+
# functions = bench_qiskit,
8181

8282
times = {f.__name__: [] for f in functions}
8383

8484
names = []
8585
means = []
8686

87-
samples = 10
87+
samples = 100
8888
for i in range(samples): # adjust accordingly so whole thing takes a few sec
8989
progress = i / samples
9090
print("\rProgress: [{0:50s}] {1:.1f}%".format('#' * int(progress * 50), progress*100), end="", flush=True)
9191
func = random.choice(functions)
92-
t = func(5,1)
92+
t = func(20,10)
9393
times[func.__name__].append(t)
9494

9595
print('')

docs/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
'sphinx.ext.mathjax',
4545
'sphinx.ext.ifconfig',
4646
'sphinx.ext.githubpages',
47+
'sphinx.ext.napoleon'
4748
]
4849

4950
# Add any paths that contain templates here, relative to this directory.
@@ -79,7 +80,7 @@
7980
# The theme to use for HTML and HTML Help pages. See the documentation for
8081
# a list of builtin themes.
8182
#
82-
html_theme = 'sphinx_rtd_theme'
83+
html_theme = 'press'
8384

8485
# Theme options are theme-specific and customize the look and feel of a theme
8586
# further. For a list of options available for each theme, see the

docs/index.rst

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,42 @@
1-
.. include:: ../README.rst
1+
QCGPU
2+
=====
3+
4+
.. image:: https://img.shields.io/travis/QCGPU/qcgpu.svg?style=for-the-badge
5+
:alt: Travis (.org)
6+
:target: https://travis-ci.org/QCGPU/qcgpu
7+
.. image:: https://img.shields.io/pypi/v/qcgpu.svg?style=for-the-badge
8+
:target: https://pypi.python.org/pypi/qcgpu
9+
:alt: PyPi Version
10+
.. image:: https://img.shields.io/pypi/l/qcgpu.svg?style=for-the-badge
11+
:target: https://pypi.python.org/pypi/qcgpu/
12+
:alt: License
13+
.. image:: https://img.shields.io/github/stars/qcgpu/qcgpu.svg?style=for-the-badge&label=Stars
14+
:alt: GitHub stars
15+
:target: https://github.com/QCGPU/qcgpu
16+
17+
QCGPU is an open source, high performance library for simulating
18+
quantum circuits.
19+
It takes advantage of hardware acceleration with
20+
OpenCL.
21+
Read the `research paper`_.
22+
23+
.. _`research paper`: https://arxiv.org/abs/1805.00988
24+
25+
26+
27+
Table of Contents
28+
==================
229

330
.. toctree::
431
:maxdepth: 2
5-
:caption: Contents:
632

7-
installing
8-
9-
Indices and tables
10-
==================
33+
install
34+
Getting started <quickstart>
35+
Software reference <_autodoc/qcgpu>
1136

12-
* :ref:`genindex`
13-
* :ref:`modindex`
14-
* :ref:`search`
37+
.. Python Modules
38+
==============
39+
.. autosummary::
40+
:nosignatures:
41+
qcgpu
42+
:ref:`modindex`

docs/install.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
============
2+
Installation
3+
============
4+
5+
Prerequisites
6+
-------------
7+
8+
To use QCGPU you will need to be using `Python 2.7 or later <https://www.python.org/downloads/>`_.
9+
You will also need to ensure that you have an `OpenCL <https://www.khronos.org/opencl/>`_ implementation installed.
10+
This is done by default on MacOS, but you shuld check that ``clinfo`` or some other diagnostic command will run.
11+
12+
You can also use `Anaconda 3 <https://www.continuum.io/downloads>`_, which will have many of the required dependencies already installed.
13+
14+
Installing from PyPI
15+
--------------------
16+
17+
This library is distributed on `PyPI <https://pypi.python.org/pypi/qcgpu>`_ and can be installed using pip:
18+
19+
.. code:: sh
20+
21+
$ pip install qcgpu
22+
23+
If you run into any issues, you should try installing from source.
24+
25+
Installing from Source
26+
----------------------
27+
28+
You can install QCGPU from the source. First, clone the repository off
29+
GitHub:
30+
31+
.. code:: sh
32+
33+
$ git clone https://github.com/qcgpu/qcgpu
34+
35+
Then you will need to ``cd`` into the directory, and install the
36+
requirements.
37+
38+
.. code:: sh
39+
40+
$ pip install -r requirements.txt
41+
42+
And finally you can install:
43+
44+
.. code:: sh
45+
46+
$ python setup.py install

docs/installing.rst

Lines changed: 0 additions & 52 deletions
This file was deleted.

docs/quickstart.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Getting Started
2+
===============
3+
4+
When using this library, you will most likely be using the :class:`~qiskit.State` class.
5+
This class represents the state of a quantum register.
6+
Using this class you can apply gates to the register, measure, get the state vector and things like that.
7+
8+
To run a simple quantum circuit, you can use something like this,
9+
10+
.. code-block:: python
11+
12+
# Import QCGPU
13+
import qcgpu
14+
15+
# Create a new quantum register with 2 qubits
16+
register = qcgpu.State(2)
17+
18+
# Apply a hadamard (H) gate to the first qubit.
19+
# You should note that the qubits are zero indexed
20+
register.h(0)
21+
22+
# Add a controlled not (CNOT/CX) gate, with the control as
23+
# the first qubit and target as the second.
24+
# The register will now be in the bell state.
25+
register.cx(0, 1)
26+
27+
# Perform a measurement with 1000 samples
28+
results = register.measure(samples=1000)
29+
30+
# Show the results
31+
print(results)
32+
33+
The output of a measurement gives a dictionary of measurement outcomes,
34+
along with how often they occurred.
35+
36+
.. code-block:: python
37+
38+
{'00': 486, '11': 514}

0 commit comments

Comments
 (0)