libqasm Python Package
Project description
libQASM
libQASM is a library to parse cQASM programs, developed by QuTech. At the moment, libQASM only supports cQASM v3.0 programs (see cQASM-spec for the language specification).
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 from:
- 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 "libqasm/v3x/cqasm-python.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.8-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18f5a4a84a95b7b49f4400302fb0bbaca6cc315dbdb11045adc8d13127ac7dc9 |
|
MD5 | 0ac11ce272f41eeeb465c764df19814c |
|
BLAKE2b-256 | e8ee3bb70742c44f5e12100b9e5c3fa119b2d77b6f88d0993cc642129d36c829 |
Hashes for libqasm-0.6.8-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4734c4945d04f9affa15fd7cd183cbb10ec817ee4eb95668836ae76736a7f3f5 |
|
MD5 | 497c0fd9658f851044fe2bb66b0f5268 |
|
BLAKE2b-256 | 18b72a62f4d2a0e45a7bbb2189b3be4c90dd46a4c9c443de09e4bc6a369993b8 |
Hashes for libqasm-0.6.8-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f5a6b3b80382009c0bb9b64d7cca6cdc09411695349ff2a1986306f873af732 |
|
MD5 | ec029fe5c838c2a14a10a127850b0469 |
|
BLAKE2b-256 | 0d6d8722f877845830c1a55c171e6885b1ce2dd6c2ce8bb258952fd89dd4093c |
Hashes for libqasm-0.6.8-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7f3e1668071a31092cdc56dad5860c44682da620e3e80dabeeebb0d29ff0eaa |
|
MD5 | 62043b7d6264c2872c467e46bfd97990 |
|
BLAKE2b-256 | 3900a4169770309af453928aae2950cbd84bfbb0739b65da94eb7babe804b8b6 |
Hashes for libqasm-0.6.8-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a327ed0a54fcc107ba087f5939980cbc4d9babea11ac093b67252809af44569c |
|
MD5 | 1c00d498f8b3da89c44a8c021d204a1b |
|
BLAKE2b-256 | 0560a9b5c54d56fa2d4b90ecd7cfe392d2afce50db449dc7363124a1a62d957e |
Hashes for libqasm-0.6.8-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab440b44ffb3827bbe79f88e4a05be46862d9719ef16ab356e23465f12dd7eac |
|
MD5 | b318a68d97dfe42fafed7126f91a676d |
|
BLAKE2b-256 | 267661bf100b9f7c404e139ab803e4212206b739d297da95ec143ee1862dd509 |
Hashes for libqasm-0.6.8-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b1865314660d3fd22efc58a7dc467c34bb089347907c2ae0034db9d67edd5e5 |
|
MD5 | 9c38ff3da767d5dbdfc8dc5e3e7f5b9c |
|
BLAKE2b-256 | bc9c5c0ba34a1c5db18e3bac25cbdd792f3b8ef4537c7abe51402aa6f8edb307 |
Hashes for libqasm-0.6.8-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c4d4c4defbd971db614d984a64770b7ef57dc5291d82ace27d3674eabd9bcab |
|
MD5 | bb8faa84e750bde10d47c5f509c7a6ce |
|
BLAKE2b-256 | 8302b27259d30d4705c491338613ef93644ba250ded2acb99072b16aa25ccb49 |
Hashes for libqasm-0.6.8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71e66a61b2fbdba83be1a41e9532a58eade47dc3361814e50dedc1363b007363 |
|
MD5 | 512bd69234c06346344f967200a5a67e |
|
BLAKE2b-256 | 6f32dfbda623a5493d013c16c3ae741be379ebb95250861a2c4f3bea73a89201 |
Hashes for libqasm-0.6.8-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1ffb0b83aa99b4b3a64009b1e886e840bef09202c4fea511b2a768af1d61549 |
|
MD5 | 882c52ea30e8290480dca1122e4154fa |
|
BLAKE2b-256 | 8e947cc2aa0050faac93c0c9f2f8dc72851c575205ffb237a39c945bf205f748 |
Hashes for libqasm-0.6.8-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3f6f05995f57604a81e7dbf807c9200916b1c1028d70b02462b31d7add4f54f |
|
MD5 | f97a97de67086f9279f9627ebfeeaae2 |
|
BLAKE2b-256 | d9eb8d1777e3be872e1ace92d0542798e935db4a72ee51bdac5a1c93221a2903 |
Hashes for libqasm-0.6.8-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee1d91b5ebedc0f485492162350f90f9ac8713e6065a6e27958f9271ea69e844 |
|
MD5 | 5374790ed8dc3d59febc4b71cecfcfd4 |
|
BLAKE2b-256 | 67fedfe4da6cb599cac19418319e9e815ef2d600383c0cedfffc3e061410be31 |
Hashes for libqasm-0.6.8-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30b7caf93475ca5c9be907bcab33f0e22a25d80404cecb36e73ed40aff37efa1 |
|
MD5 | 7ddd5c185e4c88abc84238fd97ea7aff |
|
BLAKE2b-256 | a2c3c933f3b46242d00e1a399003d154b48a2086359b169c88a0c2dc168072cd |
Hashes for libqasm-0.6.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32293630e5e799967f89b61020097206878c8556ce8410ffa742ff83afe9427f |
|
MD5 | 64cbbebf7e4f9a3ad0a4160ee712dcc6 |
|
BLAKE2b-256 | ff0c94801301218a26c09a52cb7923df87fd305ca1f97df87a3d18cea565410a |
Hashes for libqasm-0.6.8-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cc4640f9967bc419f4a686153416258f9ce24d8e453991de6346bc0a330a51b |
|
MD5 | a5169a587eea4572bbeb42f9b7ead396 |
|
BLAKE2b-256 | ce57f15a7203b247513206bd290f6d38af3ee605254c75c7635b740815a144dc |
Hashes for libqasm-0.6.8-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 805de2cb6fc643fac33cfcda9fabdda5f730b05270168a656e9a787b997f1a14 |
|
MD5 | 7d9240028f273ea816f33e87e793eaf7 |
|
BLAKE2b-256 | 7bbcfc9de12088f5bf5b0111766013035929e64efa0599a47213e539951f4a89 |
Hashes for libqasm-0.6.8-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85e7ba1e47ee2d4da385d695f0bb3bff6ae7e1658f45400eb7ef6e3700c1264d |
|
MD5 | f489748dba49186fed226fce2fff04b4 |
|
BLAKE2b-256 | c424f303ddb6e3cad3103840371134cd49343e5b8e4b173e32932c285524aac3 |
Hashes for libqasm-0.6.8-cp39-cp39-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92e81ad1095ef45ba21730f78675a940c08b823a272fd4ca1503c4e283c08d34 |
|
MD5 | 30a0cbc022bc39bcc3ae659dcc4f1b28 |
|
BLAKE2b-256 | 54c7e4212e496a0eb06abd55bdc3e3244beadcb54ffc7712f1bd260a9c33d8c1 |
Hashes for libqasm-0.6.8-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8288054ab5485c883a14e6b76abc58201e080ddeae4270730c0fc947892aeb07 |
|
MD5 | d52c9f7f743b99eee900e55e46a48232 |
|
BLAKE2b-256 | 6d4ad4b1f4d9cefbcfc492d254c0fb77c5e9cb4517f7887e87754db40b99788e |
Hashes for libqasm-0.6.8-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bffef6deb600c4cd6e038fe3226f7f9b830599830bcda8b4423f82a80c4a8d35 |
|
MD5 | e1b8a2cf396b7a21b15b6d7d3a9a00cf |
|
BLAKE2b-256 | 5a8b7b664117a25df03830398958a390318ef3930d5a5fc199ad8b4b4fca4f3d |