libQasm Python Package
Project description
libQASM: Library to parse cQASM v1.0 files
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.
- git
- MSVC 2015 with update 3 or above
- Python 3.5+ (make sure to get a 64-bit version!)
- cmake 3.15.3
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for libqasm-0.3.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88bfc6851e0b5faad1849a21f33f2497d6239ab8cf2e7495d2f9d334c1465fc8 |
|
MD5 | b7090decb2bbf7ec32761a5cbc1c16ed |
|
BLAKE2b-256 | 7298464341d66c2cf5b8c50283e3fdd3088b8a2a7657233a81014458baacf190 |
Hashes for libqasm-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c1ff620147d9e797a46d9697ddaf3515311ba3c576b2e13dd0a9c70d6dd0681 |
|
MD5 | 087a9878512c814b6ae2581e6f9574d4 |
|
BLAKE2b-256 | f3443bd90b9ebeaa936027a42f6ec4fd35b5e43fcf8da8fae26528b04aaa6670 |
Hashes for libqasm-0.3.0-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98b500e6011a4840189b71ade960c765f64f616edf657326f37d34d667c8c2c2 |
|
MD5 | ed555f88e1068a4c618594e0380fe249 |
|
BLAKE2b-256 | f1d0531dca5e6f3bcf7cb8895462db3518f123dbaf0375393626653fc04c2268 |
Hashes for libqasm-0.3.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 447a19b7f6d7cd1acc2e31eec87dca50f791a067206d19ecc6bfe20605300d26 |
|
MD5 | 00d9b876ee1b898e87dc8eb224cc42da |
|
BLAKE2b-256 | ed70f16727e57c40ef52ff33215945fcf024ad649c9e030ca7f0529c6d274253 |
Hashes for libqasm-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 945a03d3f1f020e86c8f0957ff2a978f0e6f1db8c90e83ceb278cdfc90b3a06f |
|
MD5 | 0b668b6a68c527db82f9e73d3a8f5e23 |
|
BLAKE2b-256 | 28bc7aeea6cadaf07a5e630a7f9de53223899a30a02e45a04c649e12c4f45fef |
Hashes for libqasm-0.3.0-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b5aee92683c9fbe70a830fcb080680dd87a6808fa56a8741bd9239cbb6ed5a1 |
|
MD5 | cd002a03a9e8ae95ba029fe6fc6c310c |
|
BLAKE2b-256 | b2344ee037251febfbdbee537e0364cdc113098744903941919e7f36e41a4d83 |
Hashes for libqasm-0.3.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0dd87c519f7ff13f628985c16f7385a921af06ca94c46098bdd34b1631159dd7 |
|
MD5 | 2475f350ec5a299874ab69f4911a20be |
|
BLAKE2b-256 | 4f4364ef6286da066611c323c119650e556d53f7dc06d09cfda72e9813791408 |
Hashes for libqasm-0.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 700344a63a1cc560bb8cf8819b9fee33f32559409cb5aeac51943ae6f948a213 |
|
MD5 | 42472a13915f2d4ac658ee5e8240a797 |
|
BLAKE2b-256 | d78141062468a7d8c8c7748c8a1fd15fc33fd465fbe1c43ab22fe93adef4f3b4 |
Hashes for libqasm-0.3.0-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d98f10cb1163e3aba3dc2717cce54a0868f96a220e9ff5afce31977370181f9 |
|
MD5 | 8ed908cf44e8acc20edb026ad5880fea |
|
BLAKE2b-256 | ef40fba29482b5fbd4bbce14efdd1ed1dad8e3cbccc5338135bfa3caaf20b7bb |
Hashes for libqasm-0.3.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c173c22d927db66abce50097f26617aee030d81f35b4764c121f424c596afd8d |
|
MD5 | b348d6db9eabe23a68c5aaaa36d6cf1e |
|
BLAKE2b-256 | 338d1a5fa41da5f7e6ba44783bdebb250ff10eeacae65e3571213f03575939f6 |
Hashes for libqasm-0.3.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95f0b3d5828002466b929846dba35008a4764189a51e0088a74e6a98e6398f25 |
|
MD5 | 7c1273c04fab11fc0bcfb5690eef9fa0 |
|
BLAKE2b-256 | a15a0c6a1c26a37faa611ccdf749f8c1ea1314331a1ae1984c76cc7bf86b1f06 |
Hashes for libqasm-0.3.0-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fc1871f3b73b019cb812ca5e377beb3e11ef37124911a5fdc736e0ee789302b |
|
MD5 | 649f24a39bc04b69da262d882bbd403b |
|
BLAKE2b-256 | 9b9323084ebda09dfc20dc32ba4f58863f1c901e07e5de9fb154b0191987f6d3 |