To provide a more interactive experience for developers, PyQASM offers a
command-line interface (CLI) tool. The CLI tool can be installed as an extra
dependency by running the following command:
pip install 'pyqasm[cli]'
This feature is still in active development and may not be stable for
production use
Users can then verify their installation by running the following command:
pyqasm --help
Usage: pyqasm [OPTIONS] COMMAND [ARGS]...The PyQASM CLI.╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────╮│ --version -v Show the version and exit. ││ --install-completion Install completion for the current shell. ││ --show-completion Show completion for the current shell, to copy it or customize the ││ installation. ││ --help -h Show this message and exit. │╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯╭─ Commands ─────────────────────────────────────────────────────────────────────────────────────────────────────╮│ validate Validate OpenQASM files. || unroll Unroll OpenQASM files. │╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ValidateThe validate functionality can be used to check QASM files. You can provide the path to
the QASM file or a directory as an argument to the validate command. The tool will then check the
semantic validity of the file(s) and return the results.
Validate commands
Validate QASM files
pyqasm validate --help
Usage: pyqasm validate [OPTIONS] SRC_PATHS... Validate OpenQASM files.╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────╮│ * src_paths SRC_PATHS... Source file or directory paths to validate. │╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────╮│ --skip -s TEXT Files to skip during validation. ││ --help -h Show this message and exit. │╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
$ pyqasm validate tests/cli/resources/valid1.qasmSuccess: no issues found in 1 source file
$ pyqasm validate tests/cli/resources/tests/cli/resources/invalid1.qasm: error: Index 2 out of range for register of size 1 in qubit [validation]Found errors in 1 file (checked 3 source files)
UnrollThe unroll functionality is used to expand all macros and modular structures in OpenQASM files into flat, low-level instructions that are directly executable by quantum devices or emulators. You can provide either the path to a specific QASM file or a directory containing multiple QASM files as an argument to the unroll command. By default, the unrolled file is saved with the following naming convention: <original_qasm_filename>_unrolled
Unroll commands
Unrolling QASM files
pyqasm unroll --help
Usage: pyqasm unroll [OPTIONS] SRC_PATHS... Unroll OpenQASM files.╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────╮│ * src_paths SRC_PATHS... Source file or directory paths to unroll. │╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────╮│ --skip -s TEXT Files to skip during unrolling. ││ --overwrite Overwrite original files instead of creating new ones. ││ --output -o TEXT Output file path (can only be used with a single input file). ││ --help -h Show this message and exit. │╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
$ pyqasm unroll tests/cli/resources/Successfully unrolled 2 files----------------------------------------------------------------------------------------------------Failed to unroll: tests/cli/resources/invalid1.qasm[validation-error] -> Index 2 out of range for register of size 1 in qubitError at line 8, column 0 in QASM file >>>>>> h q[2];----------------------------------------------------------------------------------------------------Failed to unroll 1 fileChecked 3 source files