A CLI tool for simulating Q# quantum programs and visualizing measurement results with histograms.
- π Execute Q# code from files, strings, or stdin
- π Generate histograms of measurement results
- π― Customizable number of shots and output formats
- π§ Flexible entry point configuration
- π JSON output support for programmatic use
git clone <repository-url>
cd collapse
pip install -e .
Run a Q# file:
collapse -f your_quantum_program.qs
Run Q# code from a string:
collapse -s "operation Main() : Result { use q = Qubit(); H(q); MResetZ(q) }"
Read Q# code from stdin:
echo "operation Main() : Result { use q = Qubit(); H(q); MResetZ(q) }" | collapse --stdin
Control how many times to run the quantum program:
collapse -f program.qs -n 2048
Specify a different entry point (default is Main()
):
collapse -f program.qs -e "TestBellState((false, false), (PauliZ, PauliZ))"
Get results as JSON:
collapse -f program.qs --output json
collapse -f entanglement.qs -e "TestBellState((false, false), (PauliZ, PauliZ))" -n 1024 --verbose
Measurement Results Histogram:
----------------------------------------
Result | Count | % | Distribution
----------------------------------------
|00β© | 512 | 50.0% | ββββββββββββββββββββββββββββββββββββββββ
|11β© | 512 | 50.0% | ββββββββββββββββββββββββββββββββββββββββ
----------------------------------------
Total shots: 1024
Option | Short | Description | Default |
---|---|---|---|
--file |
-f |
Path to Q# file to execute | - |
--source |
-s |
Q# source code as string | - |
--stdin |
- | Read Q# code from stdin | false |
--entrypoint |
-e |
Entry point expression | Main() |
--shots |
-n |
Number of shots to run | 1024 |
--width |
- | Maximum histogram width | 80 |
--output |
- | Output format (text/json) | text |
--verbose |
- | Show detailed execution info | false |
--no-color |
- | Disable colorized output | false |
--max-bar |
- | Maximum bar length in chars | 50 |
python -m pytest tests/
This project is licensed under the MIT License. See the LICENSE file for details.