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

#[cfg(not(target_arch = "wasm32"))]
#[cfg_attr(not(target_arch = "wasm32"), macro_use)]
pub mod error;

#[cfg(not(target_arch = "wasm32"))]
pub mod grammar;

#[cfg(not(target_arch = "wasm32"))]
mod linker;

#[cfg(not(target_arch = "wasm32"))]
pub mod statevector;

#[cfg(not(target_arch = "wasm32"))]
pub use crate::{
    arch::native::{
        get_gate_info, parse_and_link, run, simulate, simulate_with_shots, Execution,
        ExecutionTimes,
    },
    error::QasmSimError,
    interpreter::{Computation, Histogram},
    semantics::QasmType,
};

#[cfg(target_arch = "wasm32")]
#[cfg_attr(target_arch = "wasm32", macro_use)]
mod error;

#[cfg(target_arch = "wasm32")]
mod grammar;

#[cfg(target_arch = "wasm32")]
mod linker;

#[cfg(target_arch = "wasm32")]
mod statevector;

#[cfg(target_arch = "wasm32")]
pub use crate::arch::wasm::run;

mod api;
mod arch;
mod complex;
mod interpreter;
mod qe;
mod random;
mod semantics;