Quantar 0.1.0__tar.gz → 1.0.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.
Files changed (43) hide show
  1. {quantar-0.1.0 → quantar-1.0.0}/.gitignore +2 -3
  2. {quantar-0.1.0 → quantar-1.0.0}/PKG-INFO +36 -14
  3. {quantar-0.1.0 → quantar-1.0.0}/README.md +35 -13
  4. {quantar-0.1.0 → quantar-1.0.0}/pyproject.toml +2 -1
  5. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/__init__.py +1 -1
  6. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/ast_builder.py +2 -1
  7. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/lsp/server.py +6 -17
  8. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/quantar.py +23 -4
  9. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/quantar_parser.py +11 -11
  10. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/runner.py +1 -3
  11. quantar-1.0.0/src/quantar/__init__.py +52 -0
  12. {quantar-0.1.0 → quantar-1.0.0}/Grammar/python.gram +0 -0
  13. {quantar-0.1.0 → quantar-1.0.0}/Grammar/python_clean.gram +0 -0
  14. {quantar-0.1.0 → quantar-1.0.0}/LICENSE +0 -0
  15. {quantar-0.1.0 → quantar-1.0.0}/hatch_build.py +0 -0
  16. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/lsp/__init__.py +0 -0
  17. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/lsp/__main__.py +0 -0
  18. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/operators.py +0 -0
  19. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/pegen_gram_gen.py +0 -0
  20. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/quantar.gram +0 -0
  21. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/quantar_tokens.py +0 -0
  22. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/runtime.py +0 -0
  23. {quantar-0.1.0 → quantar-1.0.0}/src/lang_systems/visitors.py +0 -0
  24. {quantar-0.1.0 → quantar-1.0.0}/src/quantum/__init__.py +0 -0
  25. {quantar-0.1.0 → quantar-1.0.0}/src/quantum/basic_funcs.py +0 -0
  26. {quantar-0.1.0 → quantar-1.0.0}/src/quantum/composites.py +0 -0
  27. {quantar-0.1.0 → quantar-1.0.0}/src/quantum/gate_abs.py +0 -0
  28. {quantar-0.1.0 → quantar-1.0.0}/src/quantum/gate_matrix.py +0 -0
  29. {quantar-0.1.0 → quantar-1.0.0}/src/quantum/kernels.py +0 -0
  30. {quantar-0.1.0 → quantar-1.0.0}/src/quantum/parse_qasm.py +0 -0
  31. {quantar-0.1.0 → quantar-1.0.0}/src/quantum/qasm.py +0 -0
  32. {quantar-0.1.0 → quantar-1.0.0}/src/quantum/qubit_abs.py +0 -0
  33. {quantar-0.1.0 → quantar-1.0.0}/src/stl/__init__.py +0 -0
  34. {quantar-0.1.0 → quantar-1.0.0}/src/stl/physics_algs/__init__.py +0 -0
  35. {quantar-0.1.0 → quantar-1.0.0}/src/stl/physics_algs/duals_and_coords.py +0 -0
  36. {quantar-0.1.0 → quantar-1.0.0}/src/stl/physics_algs/units.py +0 -0
  37. {quantar-0.1.0 → quantar-1.0.0}/src/stl/physics_algs/vector_fields.py +0 -0
  38. {quantar-0.1.0 → quantar-1.0.0}/src/stl/quantum_algs/__init__.py +0 -0
  39. {quantar-0.1.0 → quantar-1.0.0}/src/stl/quantum_algs/fast_factor.py +0 -0
  40. {quantar-0.1.0 → quantar-1.0.0}/src/stl/quantum_algs/grovers_alg.py +0 -0
  41. {quantar-0.1.0 → quantar-1.0.0}/src/stl/quantum_algs/quantum_optim.py +0 -0
  42. {quantar-0.1.0 → quantar-1.0.0}/src/stl/quantum_algs/quantum_optim_hl.py +0 -0
  43. {quantar-0.1.0 → quantar-1.0.0}/src/stl/quantum_algs/shors_alg.py +0 -0
@@ -207,9 +207,8 @@ cython_debug/
207
207
  tempCodeRunnerFile.py
208
208
 
209
209
  # VS Code extension build output
210
- editors/vscode/node_modules/
211
- editors/vscode/out/
212
- editors/vscode/*.vsix
210
+ extension/node_modules/
211
+ extension/*.vsix
213
212
 
214
213
  # Ruff stuff:
215
214
  .ruff_cache/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: Quantar
3
- Version: 0.1.0
3
+ Version: 1.0.0
4
4
  Summary: A Python superset for easy quantum computing, operator creation and physics simulations.
5
5
  License: Apache License
6
6
  Version 2.0, January 2004
@@ -255,6 +255,10 @@ pip install quantar[optimization]
255
255
  pip install quantar[lsp]
256
256
  ```
257
257
 
258
+ also install the VS code extension [here](https://marketplace.visualstudio.com/items?itemName=Gauthamrgb.quantar-lang) for better coloring and errors or just use the `ext` command as follows:
259
+ ```bash
260
+ ext install Gauthamrgb.quantar-lang
261
+ ```
258
262
  ## Running Quantar
259
263
 
260
264
  ```bash
@@ -280,20 +284,22 @@ disable Numba entirely.
280
284
 
281
285
  ## VS Code extension
282
286
 
283
- The extension lives in `editors/vscode`. It provides `.qtr` syntax highlighting,
284
- parser diagnostics, and registry-driven operator highlighting through a
285
- `pygls` language server.
287
+ The extension lives in `extension/`. It provides Python-based syntax
288
+ highlighting for `.qtr` and `.quantar` files, parser diagnostics, and semantic
289
+ highlighting for registered Quantar operators. Operators use one consistent
290
+ cyan accent; the rest of the syntax follows the active VS Code theme.
286
291
 
287
292
  ```bash
288
- pip install -e ".[lsp]"
289
- cd editors/vscode
293
+ python -m pip install -e ".[lsp]"
294
+ cd extension
290
295
  npm install
291
- npm run compile
292
296
  ```
293
297
 
294
- Open `editors/vscode` in VS Code and run the `Run Quantar Extension` launch
295
- configuration. The extension also adds `Quantar: Run File` and
296
- `Quantar: Compile File to Python` commands.
298
+ Open the project root in VS Code and press F5 to launch the `Run Quantar
299
+ Extension` development configuration. The extension uses the Python
300
+ interpreter selected by the VS Code Python extension. Install the LSP extra in
301
+ that interpreter; for a local checkout, run the install command above from the
302
+ project root.
297
303
 
298
304
  ## Parsing Quantar
299
305
 
@@ -343,7 +349,22 @@ tree = parse("a >< b\n")
343
349
 
344
350
  ## Quantar as a library
345
351
 
346
- The quantum and physics packages can be imported directly from Python:
352
+ `quantar` is the umbrella package. It loads the language, quantum, and physics
353
+ packages lazily, so importing it stays lightweight:
354
+
355
+ ```python
356
+ import quantar
357
+
358
+ q = quantar.QuantumComputer(2)
359
+ tree = quantar.parse_ast("a <-> b\n")
360
+ print(quantar.__version__)
361
+
362
+ quantar.lang_systems
363
+ quantar.quantum
364
+ quantar.stl
365
+ ```
366
+
367
+ The underlying packages can still be imported directly:
347
368
 
348
369
  ```python
349
370
  import quantum
@@ -382,9 +403,10 @@ CPython's `Grammar/python.gram` plus the operator overlay in
382
403
 
383
404
  ## Status
384
405
 
385
- Quantar currently provides the parser, AST, quantum library, physics library,
386
- a CLI runner/compiler, and a VS Code extension scaffold. A bytecode interpreter
387
- and debugger are not implemented yet.
406
+ Quantar currently provides the parser, AST, quantum library, physics library, a
407
+ CLI runner/compiler, and a VS Code extension with syntax highlighting,
408
+ operator highlighting, and parser diagnostics. A bytecode interpreter and
409
+ debugger are not implemented yet.
388
410
 
389
411
  ## Feedback
390
412
 
@@ -32,6 +32,10 @@ pip install quantar[optimization]
32
32
  pip install quantar[lsp]
33
33
  ```
34
34
 
35
+ also install the VS code extension [here](https://marketplace.visualstudio.com/items?itemName=Gauthamrgb.quantar-lang) for better coloring and errors or just use the `ext` command as follows:
36
+ ```bash
37
+ ext install Gauthamrgb.quantar-lang
38
+ ```
35
39
  ## Running Quantar
36
40
 
37
41
  ```bash
@@ -57,20 +61,22 @@ disable Numba entirely.
57
61
 
58
62
  ## VS Code extension
59
63
 
60
- The extension lives in `editors/vscode`. It provides `.qtr` syntax highlighting,
61
- parser diagnostics, and registry-driven operator highlighting through a
62
- `pygls` language server.
64
+ The extension lives in `extension/`. It provides Python-based syntax
65
+ highlighting for `.qtr` and `.quantar` files, parser diagnostics, and semantic
66
+ highlighting for registered Quantar operators. Operators use one consistent
67
+ cyan accent; the rest of the syntax follows the active VS Code theme.
63
68
 
64
69
  ```bash
65
- pip install -e ".[lsp]"
66
- cd editors/vscode
70
+ python -m pip install -e ".[lsp]"
71
+ cd extension
67
72
  npm install
68
- npm run compile
69
73
  ```
70
74
 
71
- Open `editors/vscode` in VS Code and run the `Run Quantar Extension` launch
72
- configuration. The extension also adds `Quantar: Run File` and
73
- `Quantar: Compile File to Python` commands.
75
+ Open the project root in VS Code and press F5 to launch the `Run Quantar
76
+ Extension` development configuration. The extension uses the Python
77
+ interpreter selected by the VS Code Python extension. Install the LSP extra in
78
+ that interpreter; for a local checkout, run the install command above from the
79
+ project root.
74
80
 
75
81
  ## Parsing Quantar
76
82
 
@@ -120,7 +126,22 @@ tree = parse("a >< b\n")
120
126
 
121
127
  ## Quantar as a library
122
128
 
123
- The quantum and physics packages can be imported directly from Python:
129
+ `quantar` is the umbrella package. It loads the language, quantum, and physics
130
+ packages lazily, so importing it stays lightweight:
131
+
132
+ ```python
133
+ import quantar
134
+
135
+ q = quantar.QuantumComputer(2)
136
+ tree = quantar.parse_ast("a <-> b\n")
137
+ print(quantar.__version__)
138
+
139
+ quantar.lang_systems
140
+ quantar.quantum
141
+ quantar.stl
142
+ ```
143
+
144
+ The underlying packages can still be imported directly:
124
145
 
125
146
  ```python
126
147
  import quantum
@@ -159,9 +180,10 @@ CPython's `Grammar/python.gram` plus the operator overlay in
159
180
 
160
181
  ## Status
161
182
 
162
- Quantar currently provides the parser, AST, quantum library, physics library,
163
- a CLI runner/compiler, and a VS Code extension scaffold. A bytecode interpreter
164
- and debugger are not implemented yet.
183
+ Quantar currently provides the parser, AST, quantum library, physics library, a
184
+ CLI runner/compiler, and a VS Code extension with syntax highlighting,
185
+ operator highlighting, and parser diagnostics. A bytecode interpreter and
186
+ debugger are not implemented yet.
165
187
 
166
188
  ## Feedback
167
189
 
@@ -33,7 +33,7 @@ path = "src/lang_systems/__init__.py"
33
33
  path = "hatch_build.py"
34
34
 
35
35
  [tool.hatch.build.targets.wheel]
36
- packages = ["src/quantum", "src/stl", "src/lang_systems"]
36
+ packages = ["src/quantar", "src/quantum", "src/stl", "src/lang_systems"]
37
37
 
38
38
  [tool.hatch.build.targets.sdist]
39
39
  include = [
@@ -41,6 +41,7 @@ include = [
41
41
  "/LICENSE",
42
42
  "/pyproject.toml",
43
43
  "/hatch_build.py",
44
+ "/src/quantar",
44
45
  "/src/quantum",
45
46
  "/src/stl",
46
47
  "/src/lang_systems",
@@ -8,7 +8,7 @@ lazily so that importing this package does not require the generated parser
8
8
 
9
9
  import importlib
10
10
 
11
- __version__ = "0.1.0"
11
+ __version__ = "1.0.0"
12
12
 
13
13
  _EXPORTS = {
14
14
  "parse": ("lang_systems.quantar", "parse"),
@@ -19,6 +19,7 @@ import token
19
19
  import tokenize
20
20
  from dataclasses import dataclass
21
21
  from types import CodeType
22
+ from uuid import uuid4
22
23
 
23
24
  from lang_systems.operators import get_known_operator_kind
24
25
  from lang_systems.quantar import parse
@@ -161,7 +162,7 @@ def _render(node, source: _Source, rewrites: list[_Rewrite]) -> str:
161
162
  if first is None or last is None:
162
163
  return _node_text(node, source)
163
164
 
164
- name = f"{_SENTINEL_PREFIX}{len(rewrites)}{_SENTINEL_SUFFIX}"
165
+ name = f"{_SENTINEL_PREFIX}{uuid4().hex}{_SENTINEL_SUFFIX}"
165
166
  kind = get_known_operator_kind(operator.string) or "binary"
166
167
  rewrites.append(_Rewrite(name, operator.string, kind, first.start, last.end))
167
168
 
@@ -16,30 +16,20 @@ import tokenize
16
16
  from lsprotocol import types
17
17
  from pygls.lsp.server import LanguageServer
18
18
 
19
+ from lang_systems import __version__
19
20
  from lang_systems.ast_builder import parse_ast
20
21
  from lang_systems.operators import list_known_operators, load_operators
21
22
  from lang_systems.quantar_tokens import tokenize_source
22
23
 
23
24
  TOKEN_TYPES = ("quantarOperator",)
24
- TOKEN_MODIFIERS = (
25
- "nullary",
26
- "unary",
27
- "binary",
28
- "ternary",
29
- "callable",
30
- "matrix",
31
- )
32
- MODIFIER_BITS = {
33
- name: 1 << index for index, name in enumerate(TOKEN_MODIFIERS)
34
- }
35
25
  LEGEND = types.SemanticTokensLegend(
36
26
  token_types=list(TOKEN_TYPES),
37
- token_modifiers=list(TOKEN_MODIFIERS),
27
+ token_modifiers=[],
38
28
  )
39
29
 
40
30
  logger = logging.getLogger(__name__)
41
31
 
42
- server = LanguageServer("quantar-lsp", "0.1.0")
32
+ server = LanguageServer("quantar-lsp", __version__)
43
33
 
44
34
 
45
35
  def _load_default_operators() -> None:
@@ -126,7 +116,8 @@ def _token_error_range(document, error: tokenize.TokenError) -> types.Range:
126
116
  def _publish_diagnostics(ls: LanguageServer, document) -> None:
127
117
  diagnostics: list[types.Diagnostic] = []
128
118
  try:
129
- parse_ast(document.source, document.path or document.uri)
119
+ filename = document.path or document.uri
120
+ parse_ast(document.source, filename)
130
121
  except SyntaxError as error:
131
122
  diagnostics.append(
132
123
  types.Diagnostic(
@@ -217,15 +208,13 @@ def semantic_tokens_full(
217
208
  if delta_line == 0
218
209
  else start.character
219
210
  )
220
- modifier = MODIFIER_BITS.get(operators[current.string], 0)
221
-
222
211
  data.extend(
223
212
  [
224
213
  delta_line,
225
214
  delta_start,
226
215
  end.character - start.character,
227
216
  0,
228
- modifier,
217
+ 0,
229
218
  ]
230
219
  )
231
220
  previous_line = start.line
@@ -22,17 +22,17 @@ from lang_systems.operators import is_known_operator
22
22
  _RECURSION_LIMIT = 200_000
23
23
 
24
24
 
25
- class QuantarParser(GeneratedParser):
25
+ class QuantarParser(GeneratedParser): # type: ignore[misc]
26
26
  """The generated Python parser plus Quantar's custom-operator matchers."""
27
27
 
28
- def QUANTUM_OP(self):
28
+ def QUANTUM_OP(self): # type: ignore[override]
29
29
  """Match a symbolic operator (e.g. ``<->``) known to the language."""
30
30
  peeked = self._tokenizer.peek()
31
31
  if peeked.type == token.OP and is_known_operator(peeked.string):
32
32
  return self._tokenizer.getnext()
33
33
  return None
34
34
 
35
- def QUANTUM_NAME(self):
35
+ def QUANTUM_NAME(self): # type: ignore[override]
36
36
  """Match an identifier operator (e.g. ``CNOT``) known to the language."""
37
37
  peeked = self._tokenizer.peek()
38
38
  if (
@@ -56,8 +56,27 @@ def parse(source: str):
56
56
  tree = parser.file()
57
57
  if tree is None:
58
58
  bad = parser._tokenizer.peek()
59
+ # Try to find a better error location by scanning tokens
60
+ try:
61
+ tokens = list(tokenize_source(source))
62
+ # Find the last token that's not NEWLINE/INDENT/DEDENT/ENDMARKER
63
+ import token as token_module
64
+ for t in reversed(tokens):
65
+ if t.type not in (token_module.NEWLINE, token_module.INDENT, token_module.DEDENT, token_module.NL, token_module.ENDMARKER, token_module.COMMENT):
66
+ bad = t
67
+ break
68
+ except Exception:
69
+ pass
70
+ line_text = bad.line if bad.line is not None else ""
71
+ if not line_text and bad.start:
72
+ try:
73
+ lines = source.splitlines()
74
+ if 0 < bad.start[0] <= len(lines):
75
+ line_text = lines[bad.start[0] - 1]
76
+ except Exception:
77
+ pass
59
78
  raise SyntaxError(
60
79
  f"invalid Quantar syntax near {bad.string!r}",
61
- ("<quantar>", bad.start[0], bad.start[1] + 1, bad.line),
80
+ ("<quantar>", bad.start[0], bad.start[1] + 1, line_text),
62
81
  )
63
82
  return tree
@@ -7216,17 +7216,6 @@ class GeneratedParser(Parser):
7216
7216
  self._reset(mark)
7217
7217
  return None;
7218
7218
 
7219
- @memoize
7220
- def string_rule(self) -> Optional[Any]:
7221
- # string_rule: STRING
7222
- mark = self._mark()
7223
- if (
7224
- (s := self.string())
7225
- ):
7226
- return s;
7227
- self._reset(mark)
7228
- return None;
7229
-
7230
7219
  @memoize
7231
7220
  def fstring_middle_rule(self) -> Optional[Any]:
7232
7221
  # fstring_middle_rule: fstring_replacement_field | FSTRING_MIDDLE
@@ -7243,6 +7232,17 @@ class GeneratedParser(Parser):
7243
7232
  self._reset(mark)
7244
7233
  return None;
7245
7234
 
7235
+ @memoize
7236
+ def string_rule(self) -> Optional[Any]:
7237
+ # string_rule: STRING
7238
+ mark = self._mark()
7239
+ if (
7240
+ (s := self.string())
7241
+ ):
7242
+ return s;
7243
+ self._reset(mark)
7244
+ return None;
7245
+
7246
7246
  @memoize
7247
7247
  def _loop0_1(self) -> Optional[Any]:
7248
7248
  # _loop0_1: NEWLINE
@@ -50,6 +50,4 @@ def main():
50
50
 
51
51
  if __name__ == "__main__":
52
52
  if len(sys.argv) > 1:
53
- main()
54
- else:
55
- qtr_runner("C:\\Users\\kaart\\programming_stuff\\Quantar\\test\\test1.qtr")
53
+ main()
@@ -0,0 +1,52 @@
1
+ """Quantar umbrella package.
2
+
3
+ The implementation lives in the ``lang_systems``, ``quantum``, and ``stl``
4
+ packages. Importing ``quantar`` stays lightweight; subpackages and common
5
+ objects are loaded on first use.
6
+ """
7
+
8
+ from importlib import import_module
9
+
10
+ from lang_systems import __version__
11
+
12
+ _SUBPACKAGES = ("lang_systems", "quantum", "stl")
13
+
14
+ _EXPORTS = {
15
+ "parse": ("lang_systems", "parse"),
16
+ "parse_ast": ("lang_systems", "parse_ast"),
17
+ "build_ast": ("lang_systems", "build_ast"),
18
+ "lower_ast": ("lang_systems", "lower_ast"),
19
+ "compile_ast": ("lang_systems", "compile_ast"),
20
+ "QuantumOp": ("lang_systems", "QuantumOp"),
21
+ "load_operators": ("lang_systems", "load_operators"),
22
+ "list_known_operators": ("lang_systems", "list_known_operators"),
23
+ "QuantumComputer": ("quantum", "QuantumComputer"),
24
+ "Qubit": ("quantum", "Qubit"),
25
+ "Gate": ("quantum", "Gate"),
26
+ "CompositeGate": ("quantum", "CompositeGate"),
27
+ "CircuitGate": ("quantum", "CircuitGate"),
28
+ "named_gate": ("quantum", "named_gate"),
29
+ "to_openqasm3": ("quantum", "to_openqasm3"),
30
+ "crk": ("quantum", "crk"),
31
+ }
32
+
33
+
34
+ def __getattr__(name: str):
35
+ if name in _SUBPACKAGES:
36
+ value = import_module(name)
37
+ else:
38
+ target = _EXPORTS.get(name)
39
+ if target is None:
40
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
41
+ module_name, attribute = target
42
+ value = getattr(import_module(module_name), attribute)
43
+
44
+ globals()[name] = value
45
+ return value
46
+
47
+
48
+ def __dir__() -> list[str]:
49
+ return sorted(set(globals()) | set(__all__))
50
+
51
+
52
+ __all__ = ["__version__", *_SUBPACKAGES, *_EXPORTS]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes