qasmsim/lib.rs
1#![warn(missing_docs)]
2#![doc(html_root_url = "https://docs.rs/qasmsim/1.3.1")]
3//! The `qasmsim` library includes a
4//! [OPENQASM 2.0](https://github.com/Qiskit/openqasm/blob/master/spec-human/)
5//! parser and interpreter, along with a statevector simulator. Compiled with
6//! default features, the library presents a `qasmsim` CLI for running programs
7//! like the following one:
8//!
9//! ```qasm
10//! // in test.qasm
11//! OPENQASM 2.0;
12//! include "qelib1.inc";
13//! qreg q[2];
14//! creg c[2];
15//! h q[0];
16//! cx q[0], q[1];
17//! measure q -> c;
18//! ```
19//!
20//! ```sh
21//! $ qasmsim --shots 1024 test.qasm
22//! +------+-----------+-------+
23//! | Name | Int value | Count |
24//! +------+-----------+-------+
25//! | c | 0 | 503 |
26//! | | 3 | 521 |
27//! +------+-----------+-------+
28//! ```
29//!
30//! Check the full options with:
31//!
32//! ```sh
33//! $ qasmsim --help
34//! qasmsim 1.2.0
35//! A QASM interpreter and quantum simulator in Rust.
36//!
37//! USAGE:
38//! qasmsim [FLAGS] [OPTIONS] [source]
39//!
40//! FLAGS:
41//! -b, --binary Prints the binary representation of the values
42//! -h, --help Prints help information
43//! -x, --hexadecimal Prints the hexadecimal representation of the values
44//! -i, --integer Prints the interger representation of the values. Default option
45//! --probabilities Prints the probabilities vector of the simulation. Ignored if shots is set
46//! --statevector Prints the state vector of the simulation. Ignored if shots is set
47//! -t, --times Prints times measured for parsing and simulating
48//! -V, --version Prints version information
49//! -v Verbosity of the output
50//!
51//! OPTIONS:
52//! --info <info> Show gate-related information
53//! --out <out> Output files prefix, print in the stdout if not present. The output format of each file is
54//! CSV. At most, three files are created with the names out.memory.csv, out.state.csv and
55//! out.times.csv
56//! --shots <shots> Specify the number of simulations
57//!
58//! ARGS:
59//! <source> QASM program file, read from stdin if not present
60//! ```
61
62#[cfg(not(target_arch = "wasm32"))]
63#[cfg_attr(not(target_arch = "wasm32"), macro_use)]
64pub mod error;
65
66#[cfg(not(target_arch = "wasm32"))]
67pub mod grammar;
68
69#[cfg(not(target_arch = "wasm32"))]
70mod linker;
71
72#[cfg(not(target_arch = "wasm32"))]
73pub mod statevector;
74
75#[cfg(not(target_arch = "wasm32"))]
76pub use crate::{
77 arch::native::{
78 get_gate_info, parse_and_link, run, simulate, simulate_with_shots, Execution,
79 ExecutionTimes,
80 },
81 error::QasmSimError,
82 interpreter::{Computation, Histogram},
83 semantics::QasmType,
84};
85
86#[cfg(target_arch = "wasm32")]
87#[cfg_attr(target_arch = "wasm32", macro_use)]
88mod error;
89
90#[cfg(target_arch = "wasm32")]
91mod grammar;
92
93#[cfg(target_arch = "wasm32")]
94mod linker;
95
96#[cfg(target_arch = "wasm32")]
97mod statevector;
98
99#[cfg(target_arch = "wasm32")]
100pub use crate::arch::wasm::run;
101
102mod api;
103mod arch;
104mod complex;
105mod interpreter;
106mod qe;
107mod random;
108mod semantics;