Usage

qecsim provides access to all features via a command-line interface. It can also be used as a library via the fully-documented API. It includes many common codes, error models and decoders and can be extended with additional components.

Command-line

qecsim can be accessed via the command line in two ways:

$ qecsim                    # console script
$ python3 -O -m qecsim      # module script with Python options e.g -O for optimize

The default command provides version and general help options:

$ qecsim --help
Usage: qecsim [OPTIONS] COMMAND [ARGS]...

  qecsim - quantum error correction simulator using stabilizer codes.

  See qecsim COMMAND --help for command-specific help.

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  merge    Merge simulation data files.
  run      Simulate quantum error correction.
  run-ftp  Simulate fault-tolerant (time-periodic) quantum error correction.

The merge command merges simulation data according to qecsim.app.merge():

$ qecsim merge --help
Usage: qecsim merge [OPTIONS] DATA_FILE...

  Merge simulation data files.

  Arguments:

   DATA_FILE...          One or more data files

  Examples:

   qecsim merge "data1.json" "data2.json" "data3.json"

   qecsim merge -o"merged.json" data*.json

Options:
  -o, --output FILENAME  Output file. (Writes to log if file exists).
  --help                 Show this message and exit.

The run command runs simulations according to qecsim.app.run():

$ qecsim run --help
Usage: qecsim run [OPTIONS] CODE ERROR_MODEL DECODER ERROR_PROBABILITY...

  Simulate quantum error correction.

  Arguments:

   CODE                  Stabilizer code in format name(<args>)
    color666        Color 6.6.6 (size INT odd >=3)
    five_qubit      5-qubit
    planar          Planar (rows INT >= 2, cols INT >= 2)
    rotated_planar  Rotated planar (rows INT >= 3, cols INT >= 3)
    rotated_toric   Rotated toric (rows INT even >= 2, cols INT even >= 2)
    steane          Steane
    toric           Toric (rows INT >= 2, cols INT >= 2)

   ERROR_MODEL           Error model in format name(<args>)
    generic.biased_depolarizing  Biased (bias FLOAT > 0, [axis] CHAR)
    generic.biased_y_x           Biased Y v. X (bias FLOAT >= 0)
    generic.bit_flip             Pr I,X,Y,Z is 1-p,p,0,0
    generic.bit_phase_flip       Pr I,X,Y,Z is 1-p,0,p,0
    generic.center_slice         Slice (lim 3-tuple of FLOAT, pos FLOAT)
    generic.depolarizing         Pr I,X,Y,Z is 1-p,p/3,p/3,p/3
    generic.file                 File (filename STR, [start] INT >= 0)
    generic.phase_flip           Pr I,X,Y,Z is 1-p,0,0,p

   DECODER               Decoder in format name(<args>)
    color666.mps          MPS ([chi] INT, ...)
    generic.naive         Naive ([max_qubits] INT)
    planar.cmwpm          Converging MWPM ([factor] FLOAT >=0, ...)
    planar.mps            MPS ([chi] INT >=0, [mode] CHAR, ...)
    planar.mwpm           MWPM
    planar.rmps           Rotated MPS ([chi] INT >=0, [mode] CHAR, ...)
    planar.y              Y-noise
    rotated_planar.mps    MPS ([chi] INT >=0, [mode] CHAR, ...)
    rotated_planar.rmps   Rotated MPS ([chi] INT >=0, [mode] CHAR, ...)
    rotated_planar.smwpm  Symmetry MWPM ([eta] FLOAT >=0)
    rotated_toric.smwpm   Symmetry MWPM ([itp] BOOL, [eta] FLOAT >=0)
    toric.mwpm            MWPM

   ERROR_PROBABILITY...  One or more probabilities as FLOAT in [0.0, 1.0]

  Examples:

   qecsim run -r10 "five_qubit" "generic.depolarizing" "generic.naive" 0.1

   qecsim run -f5 -r50 -s13 "steane" "generic.phase_flip" "generic.naive"
   0.1

   qecsim run -r20 "planar(7,7)" "generic.bit_flip" "planar.mps(6)" 0.101
   0.102 0.103

   qecsim run -r10 "color666(7)" "generic.bit_flip" "color666.mps(16)" 0.09
   0.10

   qecsim run -o"data.json" -f9 "toric(3,3)" "generic.bit_flip" "toric.mwpm"
   0.1

Options:
  -f, --max-failures INT  Maximum number of failures for each probability.
  -r, --max-runs INT      Maximum number of runs for each probability.
                          [default: 1 if max-failures unspecified]

  -o, --output FILENAME   Output file. (Writes to log if file exists).
  -s, --random-seed INT   Random seed for qubit error generation. (Re-applied
                          for each probability).

  --help                  Show this message and exit.

The run-ftp command runs fault-tolerant simulations according to qecsim.app.run_ftp():

$ qecsim run-ftp --help
Usage: qecsim run-ftp [OPTIONS] CODE TIME_STEPS ERROR_MODEL DECODER
                      ERROR_PROBABILITY...

  Simulate fault-tolerant (time-periodic) quantum error correction.

  Arguments:

   CODE                  Stabilizer code in format name(<args>)
    rotated_planar  Rotated planar (rows INT >= 3, cols INT >= 3)
    rotated_toric   Rotated toric (rows INT even >= 2, cols INT even >= 2)

   TIME_STEPS            Number of time steps as INT >= 1

   ERROR_MODEL           Error model in format name(<args>)
    generic.biased_depolarizing  Biased (bias FLOAT > 0, [axis] CHAR)
    generic.biased_y_x           Biased Y v. X (bias FLOAT >= 0)
    generic.bit_flip             Pr I,X,Y,Z is 1-p,p,0,0
    generic.bit_phase_flip       Pr I,X,Y,Z is 1-p,0,p,0
    generic.center_slice         Slice (lim 3-tuple of FLOAT, pos FLOAT)
    generic.depolarizing         Pr I,X,Y,Z is 1-p,p/3,p/3,p/3
    generic.phase_flip           Pr I,X,Y,Z is 1-p,0,0,p

   DECODER               Decoder in format name(<args>)
    rotated_planar.smwpm  Symmetry MWPM ([eta] FLOAT >=0)
    rotated_toric.smwpm   Symmetry MWPM ([itp] BOOL, [eta] FLOAT >=0)

   ERROR_PROBABILITY...  One or more probabilities as FLOAT in [0.0, 1.0]

  Examples:

   qecsim run-ftp -r5 "rotated_planar(13,13)" 13 "generic.bit_phase_flip"
   "rotated_planar.smwpm" 0.1 0.2

   qecsim run-ftp -r5 -m0.05 "rotated_toric(6,6)" 4 "generic.bit_phase_flip"
   "rotated_toric.smwpm" 0.1

   qecsim run-ftp -r5 -o"data.json" "rotated_planar(7,7)" 7
   "generic.depolarizing" "rotated_planar.smwpm" 0.1

Options:
  -f, --max-failures INT          Maximum number of failures for each
                                  probability.

  -r, --max-runs INT              Maximum number of runs for each probability.
                                  [default: 1 if max_failures unspecified]

  -m, --measurement-error-probability FLOAT
                                  Measurement error probability [default: 0.0
                                  if TIME_STEPS == 1 else ERROR_PROBABILITY].

  -o, --output FILENAME           Output file. (Writes to log if file exists).
  -s, --random-seed INT           Random seed for qubit error generation. (Re-
                                  applied for each probability).

  --help                          Show this message and exit.

Library

qecsim can be accessed as a library:

>>> import qecsim
>>> qecsim.__version__
'1.0b9'

Extension

qecsim can be extended with additional codes, error models and decoders that integrate into the command-line interface. See https://github.com/qecsim/qecsimext for a basic example.