qubasic 0.1.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qubasic-0.3.0/CHANGELOG.md +21 -0
- qubasic-0.3.0/MANIFEST.in +4 -0
- {qubasic-0.1.0 → qubasic-0.3.0}/PKG-INFO +24 -16
- {qubasic-0.1.0 → qubasic-0.3.0}/README.md +18 -12
- qubasic-0.3.0/examples/bell.qb +6 -0
- qubasic-0.3.0/examples/grover3.qb +27 -0
- qubasic-0.3.0/examples/locc_teleport.qb +19 -0
- qubasic-0.3.0/examples/sweep_rx.qb +7 -0
- {qubasic-0.1.0 → qubasic-0.3.0}/pyproject.toml +14 -8
- {qubasic-0.1.0 → qubasic-0.3.0}/qubasic.egg-info/PKG-INFO +24 -16
- qubasic-0.3.0/qubasic.egg-info/SOURCES.txt +56 -0
- qubasic-0.3.0/qubasic.egg-info/entry_points.txt +2 -0
- {qubasic-0.1.0 → qubasic-0.3.0}/qubasic.egg-info/requires.txt +5 -0
- qubasic-0.3.0/qubasic.egg-info/top_level.txt +2 -0
- qubasic-0.1.0/qbasic.py → qubasic-0.3.0/qubasic.py +12 -12
- qubasic-0.3.0/qubasic_core/__init__.py +80 -0
- qubasic-0.3.0/qubasic_core/__main__.py +6 -0
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/analysis.py +9 -5
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/backend.py +1 -1
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/classic.py +2 -2
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/control_flow.py +4 -4
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/debug.py +2 -2
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/demos.py +1 -1
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/display.py +3 -3
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/engine.py +4 -4
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/engine_state.py +4 -4
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/errors.py +2 -2
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/exec_context.py +1 -1
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/executor.py +51 -16
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/expression.py +8 -1
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/file_io.py +41 -10
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/help_text.py +31 -14
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/io_protocol.py +1 -1
- qubasic-0.3.0/qubasic_core/locc.py +10 -0
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/locc_commands.py +2 -2
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/locc_display.py +1 -1
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/locc_engine.py +4 -3
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/locc_execution.py +19 -16
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/memory.py +2 -2
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/mock_backend.py +6 -6
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/noise_mixin.py +1 -1
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/parser.py +15 -4
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/patterns.py +4 -2
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/profiler.py +8 -4
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/program_mgmt.py +3 -3
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/protocol.py +1 -1
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/scope.py +1 -1
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/screen.py +4 -4
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/state_display.py +2 -2
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/statements.py +1 -1
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/strings.py +1 -1
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/subs.py +12 -5
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/sweep.py +1 -1
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/terminal.py +194 -67
- qubasic-0.1.0/qbasic_core/__init__.py +0 -80
- qubasic-0.1.0/qbasic_core/__main__.py +0 -6
- qubasic-0.1.0/qbasic_core/locc.py +0 -10
- qubasic-0.1.0/qbasic_core/py.typed +0 -0
- qubasic-0.1.0/qubasic.egg-info/SOURCES.txt +0 -51
- qubasic-0.1.0/qubasic.egg-info/entry_points.txt +0 -2
- qubasic-0.1.0/qubasic.egg-info/top_level.txt +0 -2
- {qubasic-0.1.0 → qubasic-0.3.0}/LICENSE +0 -0
- {qubasic-0.1.0 → qubasic-0.3.0}/qubasic.egg-info/dependency_links.txt +0 -0
- {qubasic-0.1.0/qbasic_core → qubasic-0.3.0/qubasic_core}/gates.py +0 -0
- {qubasic-0.1.0 → qubasic-0.3.0}/setup.cfg +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2026-03-28)
|
|
4
|
+
|
|
5
|
+
Initial PyPI release.
|
|
6
|
+
|
|
7
|
+
- BASIC REPL with line-numbered program editing
|
|
8
|
+
- 30+ quantum gates (H, X, Y, Z, CX, CCX, RX, RY, RZ, CP, SWAP, etc.)
|
|
9
|
+
- LOCC mode: 2-26 party distributed quantum simulation (SPLIT and JOINT)
|
|
10
|
+
- Full BASIC language: FOR/NEXT, WHILE/WEND, DO/LOOP, SELECT CASE, SUB/FUNCTION, IF/THEN/ELSE
|
|
11
|
+
- AST-based expression evaluator (no eval)
|
|
12
|
+
- Noise models: depolarizing, amplitude damping, phase flip, thermal, readout, combined, Pauli, reset
|
|
13
|
+
- Debugging: STEP, TRON/TROFF, breakpoints, watch, time-travel (REWIND/FORWARD), PROFILE
|
|
14
|
+
- Memory map: PEEK/POKE/SYS/DUMP/MAP/MONITOR
|
|
15
|
+
- Analysis: EXPECT, ENTROPY, DENSITY, SWEEP, BENCH, RAM
|
|
16
|
+
- File I/O: SAVE/LOAD/INCLUDE/IMPORT, OPEN/CLOSE/PRINT#/INPUT#, CSV, OpenQASM 3.0 export
|
|
17
|
+
- 12 built-in demos: Bell, GHZ, Grover, QFT, Deutsch-Jozsa, Bernstein-Vazirani, Superdense, Teleport, LOCC
|
|
18
|
+
- JSON output mode for agent/pipeline integration
|
|
19
|
+
- String variable resolution in PRINT (LEFT$, RIGHT$, CHR$, concatenation)
|
|
20
|
+
- DEF FN and parameterized DEF subroutine invocation
|
|
21
|
+
- Trusted publisher CI/CD to PyPI
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: qubasic
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Quantum BASIC Interactive Terminal
|
|
5
5
|
Author-email: "Charles C. Norton" <machineelv@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/CharlesCNorton/
|
|
8
|
-
Project-URL: Repository, https://github.com/CharlesCNorton/
|
|
9
|
-
Project-URL: Issues, https://github.com/CharlesCNorton/
|
|
7
|
+
Project-URL: Homepage, https://github.com/CharlesCNorton/qubasic
|
|
8
|
+
Project-URL: Repository, https://github.com/CharlesCNorton/qubasic
|
|
9
|
+
Project-URL: Issues, https://github.com/CharlesCNorton/qubasic/issues
|
|
10
10
|
Keywords: quantum,computing,qiskit,basic,repl,simulator
|
|
11
11
|
Classifier: Development Status :: 3 - Alpha
|
|
12
12
|
Classifier: Intended Audience :: Education
|
|
@@ -27,9 +27,11 @@ Requires-Dist: psutil>=5.9
|
|
|
27
27
|
Requires-Dist: rich>=13.0
|
|
28
28
|
Provides-Extra: charts
|
|
29
29
|
Requires-Dist: plotille>=5.0; extra == "charts"
|
|
30
|
+
Provides-Extra: readline
|
|
31
|
+
Requires-Dist: pyreadline3>=3.4; sys_platform == "win32" and extra == "readline"
|
|
30
32
|
Dynamic: license-file
|
|
31
33
|
|
|
32
|
-
#
|
|
34
|
+
# QUBASIC
|
|
33
35
|
|
|
34
36
|
Quantum computing in a BASIC REPL.
|
|
35
37
|
|
|
@@ -46,7 +48,7 @@ RAN 3 lines, 4 qubits, 1024 shots in 0.12s [depth=2, gates=2]
|
|
|
46
48
|
|11> 506 49.4% █████████████████
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
QUBASIC is a quantum computing environment built on Qiskit Aer that uses BASIC syntax for circuit construction, execution, and analysis. It runs as an interactive REPL, as a script interpreter, or as a headless Python engine.
|
|
50
52
|
|
|
51
53
|
**For agents**: minimal syntax, maximum context-window efficiency. `10 H 0 / 20 CX 0,1 / 30 MEASURE / RUN` replaces 8 lines of Qiskit Python. JSON output mode (`--json`) for pipeline integration. `Engine` class for direct API use without subprocess overhead.
|
|
52
54
|
|
|
@@ -56,6 +58,12 @@ QBASIC is a quantum computing environment built on Qiskit Aer that uses BASIC sy
|
|
|
56
58
|
|
|
57
59
|
## Install
|
|
58
60
|
|
|
61
|
+
```
|
|
62
|
+
pip install qubasic
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Development install:
|
|
66
|
+
|
|
59
67
|
```
|
|
60
68
|
pip install -e ".[charts]"
|
|
61
69
|
```
|
|
@@ -65,18 +73,18 @@ Requires Python >= 3.10, Qiskit >= 1.0, qiskit-aer >= 0.13.
|
|
|
65
73
|
## Usage
|
|
66
74
|
|
|
67
75
|
```
|
|
68
|
-
python
|
|
69
|
-
python
|
|
70
|
-
python
|
|
71
|
-
python
|
|
72
|
-
python
|
|
76
|
+
python qubasic.py Interactive REPL
|
|
77
|
+
python qubasic.py script.qb Run a script file
|
|
78
|
+
python qubasic.py --quiet script Suppress banner, output results only
|
|
79
|
+
python qubasic.py --json script Machine-readable JSON output
|
|
80
|
+
python qubasic.py --help Show CLI help
|
|
73
81
|
```
|
|
74
82
|
|
|
75
83
|
Headless (no REPL):
|
|
76
84
|
|
|
77
85
|
```python
|
|
78
|
-
from
|
|
79
|
-
from
|
|
86
|
+
from qubasic_core.engine_state import Engine
|
|
87
|
+
from qubasic_core.terminal import QBasicTerminal
|
|
80
88
|
|
|
81
89
|
t = QBasicTerminal()
|
|
82
90
|
t.num_qubits = 2
|
|
@@ -683,7 +691,7 @@ Programs with SEND use prefix/suffix splitting: the deterministic prefix (before
|
|
|
683
691
|
## JSON output
|
|
684
692
|
|
|
685
693
|
```
|
|
686
|
-
python
|
|
694
|
+
python qubasic.py --json examples/bell.qb
|
|
687
695
|
```
|
|
688
696
|
|
|
689
697
|
```json
|
|
@@ -697,8 +705,8 @@ python qbasic.py --json examples/bell.qb
|
|
|
697
705
|
## Architecture
|
|
698
706
|
|
|
699
707
|
```
|
|
700
|
-
|
|
701
|
-
|
|
708
|
+
qubasic.py CLI entry point
|
|
709
|
+
qubasic_core/
|
|
702
710
|
engine_state.py Engine: standalone state container
|
|
703
711
|
terminal.py QBasicTerminal: REPL + command dispatch
|
|
704
712
|
engine.py Constants, gate tables, numpy simulation, LOCCEngine
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# QUBASIC
|
|
2
2
|
|
|
3
3
|
Quantum computing in a BASIC REPL.
|
|
4
4
|
|
|
@@ -15,7 +15,7 @@ RAN 3 lines, 4 qubits, 1024 shots in 0.12s [depth=2, gates=2]
|
|
|
15
15
|
|11> 506 49.4% █████████████████
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
QUBASIC is a quantum computing environment built on Qiskit Aer that uses BASIC syntax for circuit construction, execution, and analysis. It runs as an interactive REPL, as a script interpreter, or as a headless Python engine.
|
|
19
19
|
|
|
20
20
|
**For agents**: minimal syntax, maximum context-window efficiency. `10 H 0 / 20 CX 0,1 / 30 MEASURE / RUN` replaces 8 lines of Qiskit Python. JSON output mode (`--json`) for pipeline integration. `Engine` class for direct API use without subprocess overhead.
|
|
21
21
|
|
|
@@ -25,6 +25,12 @@ QBASIC is a quantum computing environment built on Qiskit Aer that uses BASIC sy
|
|
|
25
25
|
|
|
26
26
|
## Install
|
|
27
27
|
|
|
28
|
+
```
|
|
29
|
+
pip install qubasic
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Development install:
|
|
33
|
+
|
|
28
34
|
```
|
|
29
35
|
pip install -e ".[charts]"
|
|
30
36
|
```
|
|
@@ -34,18 +40,18 @@ Requires Python >= 3.10, Qiskit >= 1.0, qiskit-aer >= 0.13.
|
|
|
34
40
|
## Usage
|
|
35
41
|
|
|
36
42
|
```
|
|
37
|
-
python
|
|
38
|
-
python
|
|
39
|
-
python
|
|
40
|
-
python
|
|
41
|
-
python
|
|
43
|
+
python qubasic.py Interactive REPL
|
|
44
|
+
python qubasic.py script.qb Run a script file
|
|
45
|
+
python qubasic.py --quiet script Suppress banner, output results only
|
|
46
|
+
python qubasic.py --json script Machine-readable JSON output
|
|
47
|
+
python qubasic.py --help Show CLI help
|
|
42
48
|
```
|
|
43
49
|
|
|
44
50
|
Headless (no REPL):
|
|
45
51
|
|
|
46
52
|
```python
|
|
47
|
-
from
|
|
48
|
-
from
|
|
53
|
+
from qubasic_core.engine_state import Engine
|
|
54
|
+
from qubasic_core.terminal import QBasicTerminal
|
|
49
55
|
|
|
50
56
|
t = QBasicTerminal()
|
|
51
57
|
t.num_qubits = 2
|
|
@@ -652,7 +658,7 @@ Programs with SEND use prefix/suffix splitting: the deterministic prefix (before
|
|
|
652
658
|
## JSON output
|
|
653
659
|
|
|
654
660
|
```
|
|
655
|
-
python
|
|
661
|
+
python qubasic.py --json examples/bell.qb
|
|
656
662
|
```
|
|
657
663
|
|
|
658
664
|
```json
|
|
@@ -666,8 +672,8 @@ python qbasic.py --json examples/bell.qb
|
|
|
666
672
|
## Architecture
|
|
667
673
|
|
|
668
674
|
```
|
|
669
|
-
|
|
670
|
-
|
|
675
|
+
qubasic.py CLI entry point
|
|
676
|
+
qubasic_core/
|
|
671
677
|
engine_state.py Engine: standalone state container
|
|
672
678
|
terminal.py QBasicTerminal: REPL + command dispatch
|
|
673
679
|
engine.py Constants, gate tables, numpy simulation, LOCCEngine
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Grover's Search — find |101> among 8 states
|
|
2
|
+
# Classically ~4 queries; quantum: 2 iterations, ~95% success.
|
|
3
|
+
QUBITS 3
|
|
4
|
+
SHOTS 1024
|
|
5
|
+
10 REM Superposition
|
|
6
|
+
20 H 0 : H 1 : H 2
|
|
7
|
+
30 REM === Grover iteration 1 ===
|
|
8
|
+
40 REM Oracle: flip phase of |101>
|
|
9
|
+
50 X 1
|
|
10
|
+
60 H 2 : CCX 0,1,2 : H 2
|
|
11
|
+
70 X 1
|
|
12
|
+
80 REM Diffusion
|
|
13
|
+
90 H 0 : H 1 : H 2
|
|
14
|
+
100 X 0 : X 1 : X 2
|
|
15
|
+
110 H 2 : CCX 0,1,2 : H 2
|
|
16
|
+
120 X 0 : X 1 : X 2
|
|
17
|
+
130 H 0 : H 1 : H 2
|
|
18
|
+
140 REM === Grover iteration 2 ===
|
|
19
|
+
150 X 1
|
|
20
|
+
160 H 2 : CCX 0,1,2 : H 2
|
|
21
|
+
170 X 1
|
|
22
|
+
180 H 0 : H 1 : H 2
|
|
23
|
+
190 X 0 : X 1 : X 2
|
|
24
|
+
200 H 2 : CCX 0,1,2 : H 2
|
|
25
|
+
210 X 0 : X 1 : X 2
|
|
26
|
+
220 H 0 : H 1 : H 2
|
|
27
|
+
230 MEASURE
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# LOCC Teleportation — full protocol with classical correction
|
|
2
|
+
# Alice teleports |+> to Bob using a pre-shared Bell pair.
|
|
3
|
+
LOCC JOINT 3 3
|
|
4
|
+
SHOTS 1024
|
|
5
|
+
10 REM Prepare state to teleport: |+> on A[0]
|
|
6
|
+
20 @A H 0
|
|
7
|
+
30 REM Create shared entanglement: A[2] <-> B[0]
|
|
8
|
+
40 SHARE A 2, B 0
|
|
9
|
+
50 REM Alice entangles her data qubit with her half of the pair
|
|
10
|
+
60 @A CX 0, 2
|
|
11
|
+
70 @A H 0
|
|
12
|
+
80 REM Alice measures and sends classical bits to Bob
|
|
13
|
+
90 SEND A 0 -> m0
|
|
14
|
+
100 SEND A 2 -> m1
|
|
15
|
+
110 REM Bob applies corrections
|
|
16
|
+
120 IF m1 THEN @B X 0
|
|
17
|
+
130 IF m0 THEN @B Z 0
|
|
18
|
+
140 REM Bob's qubit 0 now holds Alice's original |+> state
|
|
19
|
+
150 MEASURE
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "qubasic"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
description = "Quantum BASIC Interactive Terminal"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -33,22 +33,28 @@ dependencies = [
|
|
|
33
33
|
]
|
|
34
34
|
|
|
35
35
|
[project.urls]
|
|
36
|
-
Homepage = "https://github.com/CharlesCNorton/
|
|
37
|
-
Repository = "https://github.com/CharlesCNorton/
|
|
38
|
-
Issues = "https://github.com/CharlesCNorton/
|
|
36
|
+
Homepage = "https://github.com/CharlesCNorton/qubasic"
|
|
37
|
+
Repository = "https://github.com/CharlesCNorton/qubasic"
|
|
38
|
+
Issues = "https://github.com/CharlesCNorton/qubasic/issues"
|
|
39
39
|
|
|
40
40
|
[project.optional-dependencies]
|
|
41
41
|
charts = ["plotille>=5.0"]
|
|
42
|
+
readline = ["pyreadline3>=3.4; sys_platform == 'win32'"]
|
|
42
43
|
|
|
43
44
|
[project.scripts]
|
|
44
|
-
|
|
45
|
+
qubasic = "qubasic:main"
|
|
45
46
|
|
|
46
47
|
[tool.setuptools]
|
|
47
|
-
py-modules = ["
|
|
48
|
-
packages = ["
|
|
48
|
+
py-modules = ["qubasic"]
|
|
49
|
+
packages = ["qubasic_core"]
|
|
50
|
+
|
|
51
|
+
[tool.setuptools.package-data]
|
|
52
|
+
|
|
53
|
+
[tool.setuptools.data-files]
|
|
54
|
+
"share/qubasic/examples" = ["examples/*.qb"]
|
|
49
55
|
|
|
50
56
|
[tool.coverage.run]
|
|
51
|
-
source = ["
|
|
57
|
+
source = ["qubasic_core"]
|
|
52
58
|
omit = ["*/test_*"]
|
|
53
59
|
|
|
54
60
|
[tool.coverage.report]
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: qubasic
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Quantum BASIC Interactive Terminal
|
|
5
5
|
Author-email: "Charles C. Norton" <machineelv@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
7
|
-
Project-URL: Homepage, https://github.com/CharlesCNorton/
|
|
8
|
-
Project-URL: Repository, https://github.com/CharlesCNorton/
|
|
9
|
-
Project-URL: Issues, https://github.com/CharlesCNorton/
|
|
7
|
+
Project-URL: Homepage, https://github.com/CharlesCNorton/qubasic
|
|
8
|
+
Project-URL: Repository, https://github.com/CharlesCNorton/qubasic
|
|
9
|
+
Project-URL: Issues, https://github.com/CharlesCNorton/qubasic/issues
|
|
10
10
|
Keywords: quantum,computing,qiskit,basic,repl,simulator
|
|
11
11
|
Classifier: Development Status :: 3 - Alpha
|
|
12
12
|
Classifier: Intended Audience :: Education
|
|
@@ -27,9 +27,11 @@ Requires-Dist: psutil>=5.9
|
|
|
27
27
|
Requires-Dist: rich>=13.0
|
|
28
28
|
Provides-Extra: charts
|
|
29
29
|
Requires-Dist: plotille>=5.0; extra == "charts"
|
|
30
|
+
Provides-Extra: readline
|
|
31
|
+
Requires-Dist: pyreadline3>=3.4; sys_platform == "win32" and extra == "readline"
|
|
30
32
|
Dynamic: license-file
|
|
31
33
|
|
|
32
|
-
#
|
|
34
|
+
# QUBASIC
|
|
33
35
|
|
|
34
36
|
Quantum computing in a BASIC REPL.
|
|
35
37
|
|
|
@@ -46,7 +48,7 @@ RAN 3 lines, 4 qubits, 1024 shots in 0.12s [depth=2, gates=2]
|
|
|
46
48
|
|11> 506 49.4% █████████████████
|
|
47
49
|
```
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
QUBASIC is a quantum computing environment built on Qiskit Aer that uses BASIC syntax for circuit construction, execution, and analysis. It runs as an interactive REPL, as a script interpreter, or as a headless Python engine.
|
|
50
52
|
|
|
51
53
|
**For agents**: minimal syntax, maximum context-window efficiency. `10 H 0 / 20 CX 0,1 / 30 MEASURE / RUN` replaces 8 lines of Qiskit Python. JSON output mode (`--json`) for pipeline integration. `Engine` class for direct API use without subprocess overhead.
|
|
52
54
|
|
|
@@ -56,6 +58,12 @@ QBASIC is a quantum computing environment built on Qiskit Aer that uses BASIC sy
|
|
|
56
58
|
|
|
57
59
|
## Install
|
|
58
60
|
|
|
61
|
+
```
|
|
62
|
+
pip install qubasic
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Development install:
|
|
66
|
+
|
|
59
67
|
```
|
|
60
68
|
pip install -e ".[charts]"
|
|
61
69
|
```
|
|
@@ -65,18 +73,18 @@ Requires Python >= 3.10, Qiskit >= 1.0, qiskit-aer >= 0.13.
|
|
|
65
73
|
## Usage
|
|
66
74
|
|
|
67
75
|
```
|
|
68
|
-
python
|
|
69
|
-
python
|
|
70
|
-
python
|
|
71
|
-
python
|
|
72
|
-
python
|
|
76
|
+
python qubasic.py Interactive REPL
|
|
77
|
+
python qubasic.py script.qb Run a script file
|
|
78
|
+
python qubasic.py --quiet script Suppress banner, output results only
|
|
79
|
+
python qubasic.py --json script Machine-readable JSON output
|
|
80
|
+
python qubasic.py --help Show CLI help
|
|
73
81
|
```
|
|
74
82
|
|
|
75
83
|
Headless (no REPL):
|
|
76
84
|
|
|
77
85
|
```python
|
|
78
|
-
from
|
|
79
|
-
from
|
|
86
|
+
from qubasic_core.engine_state import Engine
|
|
87
|
+
from qubasic_core.terminal import QBasicTerminal
|
|
80
88
|
|
|
81
89
|
t = QBasicTerminal()
|
|
82
90
|
t.num_qubits = 2
|
|
@@ -683,7 +691,7 @@ Programs with SEND use prefix/suffix splitting: the deterministic prefix (before
|
|
|
683
691
|
## JSON output
|
|
684
692
|
|
|
685
693
|
```
|
|
686
|
-
python
|
|
694
|
+
python qubasic.py --json examples/bell.qb
|
|
687
695
|
```
|
|
688
696
|
|
|
689
697
|
```json
|
|
@@ -697,8 +705,8 @@ python qbasic.py --json examples/bell.qb
|
|
|
697
705
|
## Architecture
|
|
698
706
|
|
|
699
707
|
```
|
|
700
|
-
|
|
701
|
-
|
|
708
|
+
qubasic.py CLI entry point
|
|
709
|
+
qubasic_core/
|
|
702
710
|
engine_state.py Engine: standalone state container
|
|
703
711
|
terminal.py QBasicTerminal: REPL + command dispatch
|
|
704
712
|
engine.py Constants, gate tables, numpy simulation, LOCCEngine
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
CHANGELOG.md
|
|
2
|
+
LICENSE
|
|
3
|
+
MANIFEST.in
|
|
4
|
+
README.md
|
|
5
|
+
pyproject.toml
|
|
6
|
+
qubasic.py
|
|
7
|
+
examples/bell.qb
|
|
8
|
+
examples/grover3.qb
|
|
9
|
+
examples/locc_teleport.qb
|
|
10
|
+
examples/sweep_rx.qb
|
|
11
|
+
qubasic.egg-info/PKG-INFO
|
|
12
|
+
qubasic.egg-info/SOURCES.txt
|
|
13
|
+
qubasic.egg-info/dependency_links.txt
|
|
14
|
+
qubasic.egg-info/entry_points.txt
|
|
15
|
+
qubasic.egg-info/requires.txt
|
|
16
|
+
qubasic.egg-info/top_level.txt
|
|
17
|
+
qubasic_core/__init__.py
|
|
18
|
+
qubasic_core/__main__.py
|
|
19
|
+
qubasic_core/analysis.py
|
|
20
|
+
qubasic_core/backend.py
|
|
21
|
+
qubasic_core/classic.py
|
|
22
|
+
qubasic_core/control_flow.py
|
|
23
|
+
qubasic_core/debug.py
|
|
24
|
+
qubasic_core/demos.py
|
|
25
|
+
qubasic_core/display.py
|
|
26
|
+
qubasic_core/engine.py
|
|
27
|
+
qubasic_core/engine_state.py
|
|
28
|
+
qubasic_core/errors.py
|
|
29
|
+
qubasic_core/exec_context.py
|
|
30
|
+
qubasic_core/executor.py
|
|
31
|
+
qubasic_core/expression.py
|
|
32
|
+
qubasic_core/file_io.py
|
|
33
|
+
qubasic_core/gates.py
|
|
34
|
+
qubasic_core/help_text.py
|
|
35
|
+
qubasic_core/io_protocol.py
|
|
36
|
+
qubasic_core/locc.py
|
|
37
|
+
qubasic_core/locc_commands.py
|
|
38
|
+
qubasic_core/locc_display.py
|
|
39
|
+
qubasic_core/locc_engine.py
|
|
40
|
+
qubasic_core/locc_execution.py
|
|
41
|
+
qubasic_core/memory.py
|
|
42
|
+
qubasic_core/mock_backend.py
|
|
43
|
+
qubasic_core/noise_mixin.py
|
|
44
|
+
qubasic_core/parser.py
|
|
45
|
+
qubasic_core/patterns.py
|
|
46
|
+
qubasic_core/profiler.py
|
|
47
|
+
qubasic_core/program_mgmt.py
|
|
48
|
+
qubasic_core/protocol.py
|
|
49
|
+
qubasic_core/scope.py
|
|
50
|
+
qubasic_core/screen.py
|
|
51
|
+
qubasic_core/state_display.py
|
|
52
|
+
qubasic_core/statements.py
|
|
53
|
+
qubasic_core/strings.py
|
|
54
|
+
qubasic_core/subs.py
|
|
55
|
+
qubasic_core/sweep.py
|
|
56
|
+
qubasic_core/terminal.py
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env python3
|
|
2
2
|
"""
|
|
3
|
-
|
|
3
|
+
QUBASIC — Quantum BASIC Interactive Terminal
|
|
4
4
|
|
|
5
5
|
Usage:
|
|
6
|
-
python
|
|
7
|
-
python
|
|
6
|
+
python qubasic.py Interactive REPL
|
|
7
|
+
python qubasic.py script.qb Run a script file
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
import sys
|
|
@@ -22,8 +22,8 @@ if sys.stderr and hasattr(sys.stderr, 'reconfigure'):
|
|
|
22
22
|
except Exception:
|
|
23
23
|
pass
|
|
24
24
|
|
|
25
|
-
from
|
|
26
|
-
from
|
|
25
|
+
from qubasic_core.terminal import QBasicTerminal
|
|
26
|
+
from qubasic_core.program_mgmt import ProgramMgmtMixin
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
def run_script(path: str, terminal: 'QBasicTerminal') -> None:
|
|
@@ -59,15 +59,15 @@ def main():
|
|
|
59
59
|
args = [a for a in args if a != '--json']
|
|
60
60
|
|
|
61
61
|
if any(a in ('-h', '--help') for a in args):
|
|
62
|
-
from
|
|
63
|
-
print(f"
|
|
62
|
+
from qubasic_core import __version__
|
|
63
|
+
print(f"QUBASIC {__version__} — Quantum BASIC Interactive Terminal")
|
|
64
64
|
print()
|
|
65
65
|
print("Usage:")
|
|
66
|
-
print("
|
|
67
|
-
print("
|
|
68
|
-
print("
|
|
69
|
-
print("
|
|
70
|
-
print("
|
|
66
|
+
print(" qubasic Interactive REPL")
|
|
67
|
+
print(" qubasic script.qb Run a script file")
|
|
68
|
+
print(" qubasic --quiet script Suppress banner and progress")
|
|
69
|
+
print(" qubasic --json script Output results as JSON")
|
|
70
|
+
print(" qubasic --help Show this help")
|
|
71
71
|
print()
|
|
72
72
|
print("Type HELP inside the REPL for full command reference.")
|
|
73
73
|
sys.exit(0)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""QUBASIC — Quantum BASIC Interactive Terminal (package)."""
|
|
2
|
+
|
|
3
|
+
# Lightweight imports that don't pull in Qiskit/numpy
|
|
4
|
+
from qubasic_core.statements import Stmt, GateStmt, RawStmt
|
|
5
|
+
from qubasic_core.errors import (
|
|
6
|
+
QBasicError, QBasicSyntaxError, QBasicRuntimeError,
|
|
7
|
+
QBasicBuildError, QBasicRangeError, QBasicIOError, QBasicUndefinedError,
|
|
8
|
+
)
|
|
9
|
+
from qubasic_core.io_protocol import IOPort, StdIOPort
|
|
10
|
+
from qubasic_core.exec_context import ExecContext
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
'QBasicTerminal', 'LOCCEngine', 'ExecResult', 'ExecOutcome',
|
|
14
|
+
'ExpressionMixin', 'DisplayMixin', 'DemoMixin', 'ControlFlowMixin',
|
|
15
|
+
'LOCCMixin', 'LOCCCommandsMixin', 'LOCCDisplayMixin', 'LOCCExecutionMixin',
|
|
16
|
+
'NoiseMixin', 'StateDisplayMixin', 'HELP_TEXT', 'BANNER_ART',
|
|
17
|
+
'FileIOMixin', 'AnalysisMixin', 'SweepMixin',
|
|
18
|
+
'MemoryMixin', 'StringMixin', 'ScreenMixin', 'ClassicMixin',
|
|
19
|
+
'SubroutineMixin', 'DebugMixin', 'ProgramMgmtMixin', 'ProfilerMixin',
|
|
20
|
+
'TerminalProtocol',
|
|
21
|
+
'Engine', 'ExecutorMixin',
|
|
22
|
+
'QBasicError', 'QBasicSyntaxError', 'QBasicRuntimeError',
|
|
23
|
+
'QBasicBuildError', 'QBasicRangeError', 'QBasicIOError', 'QBasicUndefinedError',
|
|
24
|
+
'IOPort', 'StdIOPort',
|
|
25
|
+
'Stmt', 'GateStmt', 'RawStmt', 'parse_stmt',
|
|
26
|
+
'ExecContext', 'Scope',
|
|
27
|
+
'QuantumBackend', 'QiskitBackend', 'LOCCRegBackend',
|
|
28
|
+
'GATE_TABLE', 'GATE_ALIASES',
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
__version__ = '0.3.0'
|
|
32
|
+
|
|
33
|
+
def __getattr__(name):
|
|
34
|
+
"""Lazy import heavy modules on first access."""
|
|
35
|
+
_lazy_imports = {
|
|
36
|
+
'GATE_TABLE': 'qubasic_core.engine',
|
|
37
|
+
'GATE_ALIASES': 'qubasic_core.engine',
|
|
38
|
+
'LOCCEngine': 'qubasic_core.engine',
|
|
39
|
+
'ExecResult': 'qubasic_core.engine',
|
|
40
|
+
'ExecOutcome': 'qubasic_core.engine',
|
|
41
|
+
'QBasicTerminal': 'qubasic_core.terminal',
|
|
42
|
+
'Engine': 'qubasic_core.engine_state',
|
|
43
|
+
'ExecutorMixin': 'qubasic_core.executor',
|
|
44
|
+
'ExpressionMixin': 'qubasic_core.expression',
|
|
45
|
+
'DisplayMixin': 'qubasic_core.display',
|
|
46
|
+
'LOCCMixin': 'qubasic_core.locc',
|
|
47
|
+
'LOCCCommandsMixin': 'qubasic_core.locc_commands',
|
|
48
|
+
'LOCCDisplayMixin': 'qubasic_core.locc_display',
|
|
49
|
+
'LOCCExecutionMixin': 'qubasic_core.locc_execution',
|
|
50
|
+
'ControlFlowMixin': 'qubasic_core.control_flow',
|
|
51
|
+
'DemoMixin': 'qubasic_core.demos',
|
|
52
|
+
'FileIOMixin': 'qubasic_core.file_io',
|
|
53
|
+
'AnalysisMixin': 'qubasic_core.analysis',
|
|
54
|
+
'SweepMixin': 'qubasic_core.sweep',
|
|
55
|
+
'MemoryMixin': 'qubasic_core.memory',
|
|
56
|
+
'StringMixin': 'qubasic_core.strings',
|
|
57
|
+
'ScreenMixin': 'qubasic_core.screen',
|
|
58
|
+
'ClassicMixin': 'qubasic_core.classic',
|
|
59
|
+
'SubroutineMixin': 'qubasic_core.subs',
|
|
60
|
+
'DebugMixin': 'qubasic_core.debug',
|
|
61
|
+
'ProgramMgmtMixin': 'qubasic_core.program_mgmt',
|
|
62
|
+
'ProfilerMixin': 'qubasic_core.profiler',
|
|
63
|
+
'NoiseMixin': 'qubasic_core.noise_mixin',
|
|
64
|
+
'StateDisplayMixin': 'qubasic_core.state_display',
|
|
65
|
+
'TerminalProtocol': 'qubasic_core.protocol',
|
|
66
|
+
'HELP_TEXT': 'qubasic_core.help_text',
|
|
67
|
+
'BANNER_ART': 'qubasic_core.help_text',
|
|
68
|
+
'QuantumBackend': 'qubasic_core.backend',
|
|
69
|
+
'QiskitBackend': 'qubasic_core.backend',
|
|
70
|
+
'LOCCRegBackend': 'qubasic_core.backend',
|
|
71
|
+
'Scope': 'qubasic_core.scope',
|
|
72
|
+
'parse_stmt': 'qubasic_core.parser',
|
|
73
|
+
}
|
|
74
|
+
if name in _lazy_imports:
|
|
75
|
+
import importlib
|
|
76
|
+
module = importlib.import_module(_lazy_imports[name])
|
|
77
|
+
val = getattr(module, name)
|
|
78
|
+
globals()[name] = val # cache for next access
|
|
79
|
+
return val
|
|
80
|
+
raise AttributeError(f"module 'qubasic_core' has no attribute {name}")
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""QUBASIC analysis mixin — EXPECT, ENTROPY, DENSITY, BENCH, RAM."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -8,7 +8,7 @@ from qiskit import QuantumCircuit, transpile
|
|
|
8
8
|
from qiskit_aer import AerSimulator
|
|
9
9
|
import numpy as np
|
|
10
10
|
|
|
11
|
-
from
|
|
11
|
+
from qubasic_core.engine import (
|
|
12
12
|
_estimate_gb, _get_ram_gb,
|
|
13
13
|
OVERHEAD_FACTOR, RAM_BUDGET_FRACTION,
|
|
14
14
|
)
|
|
@@ -107,8 +107,12 @@ class AnalysisMixin:
|
|
|
107
107
|
self.io.writeln(f"\n Purity: {np.real(np.trace(rho @ rho)):.6f}")
|
|
108
108
|
self.io.writeln('')
|
|
109
109
|
|
|
110
|
-
def cmd_bench(self) -> None:
|
|
111
|
-
"""BENCH — benchmark simulation at various qubit counts."""
|
|
110
|
+
def cmd_bench(self, rest: str = '') -> None:
|
|
111
|
+
"""BENCH [n1 n2 ...] — benchmark simulation at various qubit counts."""
|
|
112
|
+
if rest.strip():
|
|
113
|
+
qubit_counts = [int(x) for x in rest.replace(',', ' ').split() if x.strip()]
|
|
114
|
+
else:
|
|
115
|
+
qubit_counts = [4, 8, 12, 16, 20, 24, 28]
|
|
112
116
|
self.io.writeln("\n Benchmark (H + CX chain + measure):")
|
|
113
117
|
try:
|
|
114
118
|
import psutil
|
|
@@ -117,7 +121,7 @@ class AnalysisMixin:
|
|
|
117
121
|
has_psutil = False
|
|
118
122
|
header_mem = ' mem_gb' if has_psutil else ''
|
|
119
123
|
self.io.writeln(f" {'qubits':>8} {'method':>20} {'time':>8}{header_mem}")
|
|
120
|
-
for n in
|
|
124
|
+
for n in qubit_counts:
|
|
121
125
|
qc = QuantumCircuit(n)
|
|
122
126
|
for i in range(n):
|
|
123
127
|
qc.h(i)
|