Skip to main content

libQasm Python Package

Project description

libQASM: Library to parse cQASM v1.0 files

CI PyPI Anaconda API docs

Dependencies

  • Flex (>= 2.6.1)
  • Bison (>= 3.0)
  • cmake (>= 3.12)
  • gcc and g++ capable of C++11 standard
  • MinGW (For Windows builds)
  • doctest (As a git submodule)
  • Python3 (Tested on Python v3.6)
  • Swig
    • Linux: 3.0.12
    • Windows: 4.0.0

Windows environment using MSVC (Visual C++)

libqasm should work with the environment described for building OpenQL from sources on Windows. In case that link breaks, here's a summary.

Download and install the following tools. When prompted whether you want to add them to your PATH, do so.

Download an extract the following tools, and then add the directories containing the executables to your PATH manually:

You should also find out where and how Python installed, and link its include directory and the pythonXX.dll file using the PYTHON_INCLUDE and PYTHON_LIB environment variables. For me, these are:

  • PYTHON_INCLUDE -> C:\Users\IEUser\AppData\Local\Programs\Python\Python38\include
  • PYTHON_LIB -> C:\Users\IEUser\AppData\Local\Programs\Python\Python38\python38.dll

Next, in an elevated Powershell (that is, "run as administrator"), run:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Install-Module -AllowClobber -Name Pscx -RequiredVersion 3.2.2

Finally, whenever you open a Powershell to build, first run ONE of the following, depending on your MSVC version (you may need to modify version numbers as well...):

Invoke-BatchFile "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
Invoke-BatchFile "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" amd64

Organization

  • The original paper and BNF specification for the cQASM v1.0 are located in the ./doc directory. Please note however that the language has changed to some degree since then, and the qasm.bnf has never fully corresponded with the flex/bison grammar. New, up-to-date documentation is a work in progress.
  • There are currently two C++ API versions contained in this repository, a new API still being worked on and the original soon-to-be deprecated API maintained for backward compatibility purposes. The new API is fully self-contained in the ./src/cqasm directory. The older API is where it used to be, with its sources residing in ./src/library and its tests in ./src/tests.

Installing/using the library

From Python

Install from the project root directory as follows:

python -m pip install .

or if you'd rather use conda:

conda build python/conda
conda install libqasm --use-local

You can test if it works using

python -m unittest discover -s src/tests -v

or, with pytest if you prefer,

python -m pytest

Now you should be able to import libQasm to use the bindings for the original API. The new API doesn't have Python bindings yet.

From C++ using CMake, without installation

The easiest way to use libqasm in a CMake project is to clone this repository into your repository as a submodule, and then use

add_subdirectory(libqasm) # or wherever your submodule is
target_link_libraries(<your target> cqasm)

The target_link_libraries() directive should automatically add the public include directories for libqasm's new API to your target's include path. You need to do this for each target.

The original API headers are not included by default. To enable those, add option(LIBQASM_COMPAT "" ON) before the add_subdirectory() directive.

From C++ by manually installing (only tested on Linux)

The CMakeLists.txt file in the root directory includes install targets:

mkdir cbuild
cd cbuild
cmake .. <directives, see below>
make -j <Number of processors>
make install

You may want to add one or more directives to the cmake command:

  • -DLIBQASM_COMPAT=yes: enables installation of the headers for the original API, on top of the ones for the new API.
  • -DBUILD_SHARED_LIBS=yes: builds a shared object library instead of a static library, if applicable.
  • -DCMAKE_INSTALL_PREFIX=<directory>: specifies the directory that the library will be installed into, in case you want to override whatever the default is for your OS.

Testing the library

Linux and MacOS

git submodule update --init --recursive
mkdir cbuild
cd cbuild
cmake .. -DLIBQASM_BUILD_TESTS=yes -DLIBQASM_COMPAT=yes
make -j <Number of processors>
make test

Windows + MinGW

Same as the above, except we'll use the MinGW toolchain. You should first get mingw-w64 and install it.

git submodule update --init --recursive
mkdir cbuild
cd cbuild
cmake -G "MinGW Makefiles" .. -DLIBQASM_BUILD_TESTS=yes -DLIBQASM_COMPAT=yes
mingw32-make.exe
mingw32-make.exe test

This will output _libQasm.pyd, liblexgram.dll and a static library liblexgramstatic.a

Windows + MSVC

Continuing from the Windows environment setup instructions (don't forget to run vcvarsall.bat first):

git submodule update --init --recursive
mkdir cbuild
cd cbuild
cmake .. -DLIBQASM_BUILD_TESTS=yes -DLIBQASM_COMPAT=yes
cmake --build .
cmake --build . --target RUN_TESTS

Docker

This tests the library in a container with the bare minimum requirements for libqasm.

docker build .

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

libqasm-0.3.0-cp39-cp39-win_amd64.whl (687.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

libqasm-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

libqasm-0.3.0-cp39-cp39-macosx_10_14_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 macOS 10.14+ x86-64

libqasm-0.3.0-cp38-cp38-win_amd64.whl (687.4 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

libqasm-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

libqasm-0.3.0-cp38-cp38-macosx_10_14_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 macOS 10.14+ x86-64

libqasm-0.3.0-cp37-cp37m-win_amd64.whl (687.1 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

libqasm-0.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

libqasm-0.3.0-cp37-cp37m-macosx_10_14_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.7m macOS 10.14+ x86-64

libqasm-0.3.0-cp36-cp36m-win_amd64.whl (687.0 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

libqasm-0.3.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.17+ x86-64

libqasm-0.3.0-cp36-cp36m-macosx_10_14_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.6m macOS 10.14+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page