libqasm Python Package
Project description
libQASM
libQASM is a library to parse programs written in the cQASM quantum programming language, developed by QuTech. At the moment, libQASM only supports cQASM v3.0 programs.
It performs lexical, syntactic, and semantic analysis of an input program received via a file or a string. It produces one of the following results:
- A syntactic or semantic AST (Abstract Syntax Tree) object. Depending on if we are parsing or analysing.
- A list of parsing or analysing errors. In case the input program was malformed.
- A JSON representation of either the AST or the list of errors.
It can be used within:
- C++ projects (as a Conan package).
- Python projects (as a Python package).
- Emscripten projects (via a Typescript frontend).
Check out QX simulator and OpenSquirrel compiler for an example of use in a C++ and a Python project, respectively.
Getting started
Given a cQASM program example.cq
.
version 3.0
qubit[2] q
bit[2] b
H q[0]
CNOT q[0], q[1]
b = measure q
We can parse or analyze this circuit, using libQASM through the following programming language:
C++
#include "v3/cqasm-py.hpp"
int main() {
auto parse_result = V3xAnalyzer::parse_file("example.cq");
auto analyzer = V3xAnalyzer();
auto analysis_result = analyzer.analyze_file("example.cq");
}
Emscripten
The emscripten API only allows to input a cQASM program as a string.
import { default as wrapper } from 'cqasm_emscripten.mjs';
wrapper().then(function(result: any) {
let analyzer = new result["EmscriptenWrapper"]()
let program = `
version 3
qubit[2] q
bit[2] b
H q[0]
CNOT q[0], q[1]
b = measure q
`
let output = analyzer.parse_string_to_json(program)
analyzer.delete()
}).catch((error: any) => {
console.error("unhandledRejection", error, "\n");
});
Python
from libqasm import Analyzer
if __name__ == "__main__":
parse_result = Analyzer.parse_file('example.cq')
analyzer = Analyzer()
analysis_result = analyzer.analyze_file('example.cq')
Documentation
The libQASM documentation is hosted through GitHub Pages.
License
libQASM is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.
Authors
Quantum Inspire: support@quantum-inspire.com
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.6.7-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c74c33d4449355be9f909620e734cce0c7e7026ea56688234968e5ec3a0c12eb |
|
MD5 | 12f1e8c3f4f83c3663cc4b3b43ca4a6f |
|
BLAKE2b-256 | d69cfa0dd673d93c36be3ae260eff256b06006d4192891382e963ca5e395cbfd |
Hashes for libqasm-0.6.7-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b8a15e27d79007c18e812d5ec42c62053131100cb38a36f1295476ba3407361 |
|
MD5 | 88ef0a92d8c2ebbdc5d0c3eb1028a6ce |
|
BLAKE2b-256 | a7a8d495a20a5a28f91cba084b14789c03895028e9784fb32bcad41221f08623 |
Hashes for libqasm-0.6.7-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69c04f44925416f9472af5603cf9b52e1aff4ba2d9509327c8af374c7bc22e27 |
|
MD5 | 4bf5245ccb3c3f117d821097260fbb34 |
|
BLAKE2b-256 | c5153cebea07b3dc8124949c55e08d8e909dda3a58f57d1f3c228da3059b5903 |
Hashes for libqasm-0.6.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed64ba178e33c6a48c04ce50642e751ce289c57703ede0f71304befbbc66fb42 |
|
MD5 | 32bf6bc1bf5f0dee67d67990d94dd271 |
|
BLAKE2b-256 | b7200cfda7813b988e9cc3414a7ef6b65293b7b25246b1762c9a03e9cc09dc8c |
Hashes for libqasm-0.6.7-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a04b16c604d5c7212bcd1d43d8ce6a6ef08057a8a5e4e793499c2988424bde5a |
|
MD5 | 9dbf843290f3819249f31356eeed96f7 |
|
BLAKE2b-256 | 1ca66c001132e7f08e36cf6cd241f7732360457893ec3066156170eaa663b92c |
Hashes for libqasm-0.6.7-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 947863a5715184a59022cbba05b4518c359c49087cbfa0b27eb5eef19ea69559 |
|
MD5 | 30c19a8dad2fd1739513d5d91c582d76 |
|
BLAKE2b-256 | cc733e5d9b785e5d3f792e9c6d349b049b720036553578312e4dc1a42f9cb8f7 |
Hashes for libqasm-0.6.7-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1650be6510a9a6ce002f33aaa66b34ac5d1e269794c8c4683dc77459f3e61b9e |
|
MD5 | e1e3367da08b9b25a105c5bbfd6bc0b8 |
|
BLAKE2b-256 | 17182fa94942e11e9f866b3346c7805e3911da417fadd157baa0d2303c4d2d81 |
Hashes for libqasm-0.6.7-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecd02d4391cc539fd78459496b92580aa171f0a1660d943c61d162ae58be0d81 |
|
MD5 | edda6369ff1ea5655780259b36e7d6c5 |
|
BLAKE2b-256 | d17045a4c967f21609792671f68a3cd35dd03c08f3aae35a3177141df1a68b14 |
Hashes for libqasm-0.6.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a187d7b7121e8b1a51885a7b56470b94be52f9eb201a0d62afb4766f515eda0a |
|
MD5 | d8eb5f911268f1e1148de911d85a5cf9 |
|
BLAKE2b-256 | b7f5344eed36d1bf1e27f0d2fdf1a63793b0d33dab1f0143e323eb0f1d82f3b2 |
Hashes for libqasm-0.6.7-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad6f4fce0cfd8bd276e8b7ce2ed91da6f34d634c3a4322e257f374e7386b6fb3 |
|
MD5 | 572a90e2bad2044374bd8903a0bedc08 |
|
BLAKE2b-256 | 600651c50096fa5d849ad46776d31bb4a841e358e2a6e652a9aef81851d96947 |
Hashes for libqasm-0.6.7-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a39edf23f224912a14925134025209aebc60c56ac0819ed03d032760977e7516 |
|
MD5 | 1170697d563148af95ee55a68f4a0382 |
|
BLAKE2b-256 | dd6d13d4ee0738e2f37c93716b9071064aac0be0dd8ac1081251079dd3dd8496 |
Hashes for libqasm-0.6.7-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7b4e94ca70cc20a0efdc0fd7cf4322948c44c9b5c867174824d625462289a47 |
|
MD5 | 98518cdc5c3eecc465562da249276a1d |
|
BLAKE2b-256 | e49aade9d7b683bb6921216ca5b07132d80d60078a46443aff1b685842c60c09 |
Hashes for libqasm-0.6.7-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc5efadc23d948b2065b405021a85e1aac9186c223bff0e8e96c96815ecf31f4 |
|
MD5 | c3f02a340ff8896988a2c4a654f82505 |
|
BLAKE2b-256 | 3846b9a46b1f4ad5ec06eaf995e10ae31a2e0e1f5518bc5ce0ee8ea0ece07ded |
Hashes for libqasm-0.6.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4369f7e4f036a1dd77bafcda638dfa2e2b66eda3ef3577ce8a0f650b68103c76 |
|
MD5 | a69360b02d7c6fb6a07029098ad4bae7 |
|
BLAKE2b-256 | 588751b5385b1d408a841c09295bce86cefe1ef24331c1c64c9fd019a51f0275 |
Hashes for libqasm-0.6.7-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85012c73625ceb44c112a4cab9bd81664118a2b000dd47a47925d6d5711c31b4 |
|
MD5 | 2eedb1ad1caf2344a3c6a57a4aea466d |
|
BLAKE2b-256 | f286b27fa7484a5178bf6c61ad59ab8ac5f8af0aed277952015756bc2a1924db |
Hashes for libqasm-0.6.7-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e7b5064921d1a7e232f5bbf5151fce532972a69135d359c10e5c12bcf7ce9e5 |
|
MD5 | bff1278902e2e30f4511693f6026d22e |
|
BLAKE2b-256 | e3373e2eab1e5030779bdaca123ef06e8031af58dd6e17ef2d91812d56a92da7 |
Hashes for libqasm-0.6.7-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b201ddd0a608b2256f7a2364d3195012bf2e13dd655abb3f078f682676f94b9 |
|
MD5 | e788b4276ba0120a4e6703a8568fa4b8 |
|
BLAKE2b-256 | cf6859d60106a5c22e44f32c5d2af8d956d13e886d3a557de3ca1bd976508df6 |
Hashes for libqasm-0.6.7-cp39-cp39-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 161e67e58f7b78f9f53d97dc5d15c529a29c06c5dc554c92e76e70f71001aaca |
|
MD5 | 29c44a86bde96f3426ddff2104e562b7 |
|
BLAKE2b-256 | f1c5a8536c4e8eee7cdf3cc76d1bf1325a53dbe3696027245be57c7c3d53fd05 |
Hashes for libqasm-0.6.7-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94228b90493625381fd23a0473c02b135dc6c9727bf26b0c7f7bfec13a822c66 |
|
MD5 | e31bdabb14db90f5d63b453471232f8b |
|
BLAKE2b-256 | 3cf574bb9ba3be949c213473b28fad4b90e82a442905e49b93af4c25005e9c5a |
Hashes for libqasm-0.6.7-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3573a244d5b939b3a51c17557ef56fd7bcafd550ba37a11de8e7f38933629565 |
|
MD5 | d5a65d8eb760315b4a1d18978f5e467b |
|
BLAKE2b-256 | 43d856266c56f203b0823ee80cefd6ad1fb3f1be260490c81595633d3c2447d5 |