Skip to content

Commit

Permalink
API to obtain version number, closes 153
Browse files Browse the repository at this point in the history
  • Loading branch information
imranashraf committed Sep 12, 2018
1 parent 225bf55 commit ea3f273
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 5 deletions.
61 changes: 59 additions & 2 deletions doc/api/openql.html
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,7 @@ <h1>Index</h1>
<li class="mono"><a href="#openql.openql.QASM_Loader_swigregister">QASM_Loader_swigregister</a></li>
<li class="mono"><a href="#openql.openql.SwigPyIterator_swigregister">SwigPyIterator_swigregister</a></li>
<li class="mono"><a href="#openql.openql.get_option">get_option</a></li>
<li class="mono"><a href="#openql.openql.get_version">get_version</a></li>
<li class="mono"><a href="#openql.openql.print_options">print_options</a></li>
<li class="mono"><a href="#openql.openql.set_option">set_option</a></li>
<li class="mono"><a href="#openql.openql.vectord_swigregister">vectord_swigregister</a></li>
Expand Down Expand Up @@ -1322,7 +1323,7 @@ <h1>Index</h1>

<header id="section-intro">
<h1 class="title"><span class="name">openql.openql</span> module</h1>
<p><code>OpenQL</code> is a C++/Python framework for high-level quantum programming. The framework provides a compiler for compiling and optimizing quantum code. The compiler produces the intermediate quantum assembly language and the compiled eQASM (executable QASM) for various target platforms. While the eQASM is platform-specific, the quantum assembly code (QASM) is hardware-agnostic and can be simulated on the QX simulator.</p>
<p><code>OpenQL</code> is a C++/Python framework for high-level quantum programming. The framework provides a compiler for compiling and optimizing quantum code. The compiler produces the intermediate quantum assembly language in cQASM (Common QASM) and the compiled eQASM (executable QASM) for various target platforms. While the eQASM is platform-specific, the quantum assembly code (QASM) is hardware-agnostic and can be simulated on the QX simulator.</p>

<p class="source_link"><a href="javascript:void(0);" onclick="toggle('source-openql.openql', this);">Show source &equiv;</a></p>
<div id="source-openql.openql" class="source">
Expand All @@ -1332,7 +1333,7 @@ <h1 class="title"><span class="name">openql.openql</span> module</h1>
<span class="c1"># Do not make changes to this file unless you know what you are doing--modify</span>
<span class="c1"># the SWIG interface file instead.</span>

<span class="sd">&quot;&quot;&quot;`OpenQL` is a C++/Python framework for high-level quantum programming. The framework provides a compiler for compiling and optimizing quantum code. The compiler produces the intermediate quantum assembly language and the compiled eQASM (executable QASM) for various target platforms. While the eQASM is platform-specific, the quantum assembly code (QASM) is hardware-agnostic and can be simulated on the QX simulator.&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;`OpenQL` is a C++/Python framework for high-level quantum programming. The framework provides a compiler for compiling and optimizing quantum code. The compiler produces the intermediate quantum assembly language in cQASM (Common QASM) and the compiled eQASM (executable QASM) for various target platforms. While the eQASM is platform-specific, the quantum assembly code (QASM) is hardware-agnostic and can be simulated on the QX simulator.&quot;&quot;&quot;</span>


<span class="kn">from</span> <span class="nn">sys</span> <span class="kn">import</span> <span class="n">version_info</span> <span class="k">as</span> <span class="n">_swig_python_version_info</span>
Expand Down Expand Up @@ -1929,6 +1930,22 @@ <h1 class="title"><span class="name">openql.openql</span> module</h1>
<span class="n">vectord_swigregister</span><span class="p">(</span><span class="n">vectord</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">get_version</span><span class="p">():</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Returns OpenQL version</span>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> None</span>

<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> str</span>
<span class="sd"> version number as a string</span>

<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">_openql</span><span class="o">.</span><span class="n">get_version</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">set_option</span><span class="p">(</span><span class="n">option_name</span><span class="p">,</span> <span class="n">option_value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets any of the following OpenQL options:</span>
Expand Down Expand Up @@ -2875,6 +2892,46 @@ <h2>Returns</h2>
</div>


<div class="item">
<div class="name def" id="openql.openql.get_version">
<p>def <span class="ident">get_version</span>(</p><p>)</p>
</div>




<div class="desc"><p>Returns OpenQL version</p>
<h2>Parameters</h2>
<p>None</p>
<h2>Returns</h2>
<p>str
version number as a string</p></div>
<div class="source_cont">
<p class="source_link"><a href="javascript:void(0);" onclick="toggle('source-openql.openql.get_version', this);">Show source &equiv;</a></p>
<div id="source-openql.openql.get_version" class="source">
<div class="codehilite"><pre><span></span><span class="k">def</span> <span class="nf">get_version</span><span class="p">():</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Returns OpenQL version</span>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> None</span>

<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> str</span>
<span class="sd"> version number as a string</span>

<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">_openql</span><span class="o">.</span><span class="n">get_version</span><span class="p">()</span>
</pre></div>

</div>
</div>

</div>


<div class="item">
<div class="name def" id="openql.openql.print_options">
<p>def <span class="ident">print_options</span>(</p><p>)</p>
Expand Down
Binary file modified doc/api/openql.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions openql/openql.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
#include <cassert>
#include <time.h>

#include <ql/version.h>
#include <ql/openql.h>
#include <ql/classical.h>
#include <ql/qasm_loader.h>

static std::string get_version()
{
return OPENQL_VERSION_STRING;
}

void set_option(std::string option_name, std::string option_value)
{
ql::options::set(option_name, option_value);
Expand Down
16 changes: 15 additions & 1 deletion openql/openql.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @brief swig interface file
*/
%define DOCSTRING
"`OpenQL` is a C++/Python framework for high-level quantum programming. The framework provides a compiler for compiling and optimizing quantum code. The compiler produces the intermediate quantum assembly language and the compiled eQASM (executable QASM) for various target platforms. While the eQASM is platform-specific, the quantum assembly code (QASM) is hardware-agnostic and can be simulated on the QX simulator."
"`OpenQL` is a C++/Python framework for high-level quantum programming. The framework provides a compiler for compiling and optimizing quantum code. The compiler produces the intermediate quantum assembly language in cQASM (Common QASM) and the compiled eQASM (executable QASM) for various target platforms. While the eQASM is platform-specific, the quantum assembly code (QASM) is hardware-agnostic and can be simulated on the QX simulator."
%enddef

%module(docstring=DOCSTRING) openql
Expand Down Expand Up @@ -60,6 +60,20 @@ try



%feature("docstring") get_version
""" Returns OpenQL version
Parameters
----------
None
Returns
-------
str
version number as a string
"""


%feature("docstring") set_option
""" Sets any of the following OpenQL options:
Opt. Name : Default : Possible values
Expand Down
16 changes: 16 additions & 0 deletions ql/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#define OPENQL_MAJOR_VERSION 0

#define OPENQL_MINOR_VERSION 5

#define OPENQL_PATCH_VERSION 0

// Make it easier to check for QISA version dependencies.
// This assumes the PATCH and MINOR version will not exceed 99
#define OPENQL_FULL_VERSION (OPENQL_MAJOR_VERSION * 10000 + OPENQL_MINOR_VERSION * 100 + OPENQL_PATCH_VERSION)

#define OPENQL_VERSION_STRING_S1(arg) #arg
#define OPENQL_VERSION_STRING_S(arg) OPENQL_VERSION_STRING_S1(arg)

#define OPENQL_VERSION_STRING (OPENQL_VERSION_STRING_S(OPENQL_MAJOR_VERSION) "." \
OPENQL_VERSION_STRING_S(OPENQL_MINOR_VERSION) "." \
OPENQL_VERSION_STRING_S(OPENQL_PATCH_VERSION))
46 changes: 44 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
import re
from setuptools import setup
from shutil import copyfile
import subprocess
from sys import platform

rootDir = os.path.dirname(os.path.realpath(__file__))
srcDir = os.path.join(rootDir, "ql")
buildDir = os.path.join(rootDir, "cbuild")
clibDir = os.path.join(buildDir, "openql")

Expand Down Expand Up @@ -54,17 +56,57 @@
os.chdir(rootDir)


def get_version(verbose=0):
""" Extract version information from source code """

matcher = re.compile('[\t ]*#define[\t ]+OPENQL_(MAJOR|MINOR|PATCH)_VERSION[\t ]+(.*)')

openql_major_version = None
openql_minor_version = None
openql_patch_version = None

version = None
try:
with open(os.path.join(srcDir, 'version.h'), 'r') as f:
for ln in f:
m = matcher.match(ln)
if m:
version_val = int(m.group(2))
if m.group(1) == 'MAJOR':
openql_major_version = version_val
elif m.group(1) == 'MINOR':
openql_minor_version = version_val
else:
openql_patch_version = version_val

if ((openql_major_version is not None) and
(openql_minor_version is not None) and
(openql_patch_version is not None)):
version = '{}.{}.{}'.format(openql_major_version,
openql_minor_version,
openql_patch_version)
break;

except Exception as E:
print(E)
version = 'none'

if verbose:
print('get_version: %s' % version)

return version

def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()


setup(name='openql',
version='0.5.0',
version=get_version(),
description='OpenQL Python Package',
long_description=read('README.md'),
author='Nader Khammassi and Imran Ashraf',
author_email='nader.khammassi@gmail.com, iimran.aashraf@gmail.com',
url='https://github.com/QE-Lab/OpenQL',
license=read('license'),
packages=['openql'],
include_package_data=True,
package_data={'openql': [clib]},
Expand Down

0 comments on commit ea3f273

Please sign in to comment.