Crate qasmsim

source ·
Expand description

The qasmsim library includes a OPENQASM 2.0 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:

// 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;
$ qasmsim --shots 1024 test.qasm
+------+-----------+-------+
| Name | Int value | Count |
+------+-----------+-------+
|    c |         0 |   503 |
|      |         3 |   521 |
+------+-----------+-------+

Check the full options with:

$ 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

Re-exports

Modules

  • Contain the error types ragarding the different tasks that QasmSim can perform.
  • Contain the machinery for parsing and processing OPENQASM programs. This module is unstable.
  • Contain utilities for representing the internal state of a quantum system.

Structs

  • Represent the result of a simulation.
  • Represent a complete execution of a program, from parsing to simulating.
  • Register the milliseconds spent in parsing the program and simulating.

Enums

  • The different types for OPENQASM values.

Functions

  • Return the signature and documentation of the gate gate_name if it is defined in the source code input.
  • Return the AST of input and link external sources with linker.
  • Parse and simulate the input OPENQASM program with optional shots.
  • Perform a simulation of the parsed program.
  • Perform shots number of simulations of the parsed proram program.

Type Aliases

  • Map classical registers with values and number of outcomes.