usel 1.0.4__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 (58) hide show
  1. usel-1.0.4/LICENSE +21 -0
  2. usel-1.0.4/PKG-INFO +157 -0
  3. usel-1.0.4/README.md +127 -0
  4. usel-1.0.4/pyproject.toml +94 -0
  5. usel-1.0.4/setup.cfg +4 -0
  6. usel-1.0.4/src/usel/__init__.py +22 -0
  7. usel-1.0.4/src/usel/cli/__init__.py +7 -0
  8. usel-1.0.4/src/usel/cli/main.py +151 -0
  9. usel-1.0.4/src/usel/config/__init__.py +7 -0
  10. usel-1.0.4/src/usel/config/loader.py +70 -0
  11. usel-1.0.4/src/usel/exceptions/__init__.py +45 -0
  12. usel-1.0.4/src/usel/io/__init__.py +17 -0
  13. usel-1.0.4/src/usel/io/readers.py +55 -0
  14. usel-1.0.4/src/usel/io/writers.py +47 -0
  15. usel-1.0.4/src/usel/linalg/__init__.py +14 -0
  16. usel-1.0.4/src/usel/linalg/decompositions.py +42 -0
  17. usel-1.0.4/src/usel/logging/__init__.py +12 -0
  18. usel-1.0.4/src/usel/logging/logger.py +74 -0
  19. usel-1.0.4/src/usel/math/__init__.py +8 -0
  20. usel-1.0.4/src/usel/math/matrix.py +212 -0
  21. usel-1.0.4/src/usel/math/transforms.py +48 -0
  22. usel-1.0.4/src/usel/random/__init__.py +19 -0
  23. usel-1.0.4/src/usel/random/generators.py +44 -0
  24. usel-1.0.4/src/usel/schrodinger/__init__.py +60 -0
  25. usel-1.0.4/src/usel/schrodinger/boundary_conditions.py +75 -0
  26. usel-1.0.4/src/usel/schrodinger/evolution.py +61 -0
  27. usel-1.0.4/src/usel/schrodinger/grids.py +85 -0
  28. usel-1.0.4/src/usel/schrodinger/hamiltonian.py +74 -0
  29. usel-1.0.4/src/usel/schrodinger/normalization.py +65 -0
  30. usel-1.0.4/src/usel/schrodinger/observables.py +86 -0
  31. usel-1.0.4/src/usel/schrodinger/operators.py +111 -0
  32. usel-1.0.4/src/usel/schrodinger/potentials.py +67 -0
  33. usel-1.0.4/src/usel/schrodinger/propagators.py +25 -0
  34. usel-1.0.4/src/usel/schrodinger/results.py +67 -0
  35. usel-1.0.4/src/usel/schrodinger/solver.py +325 -0
  36. usel-1.0.4/src/usel/schrodinger/validation.py +33 -0
  37. usel-1.0.4/src/usel/schrodinger/visualization.py +54 -0
  38. usel-1.0.4/src/usel/schrodinger/wavefunctions.py +96 -0
  39. usel-1.0.4/src/usel/solvers/__init__.py +22 -0
  40. usel-1.0.4/src/usel/solvers/crank_nicolson.py +33 -0
  41. usel-1.0.4/src/usel/solvers/finite_difference.py +29 -0
  42. usel-1.0.4/src/usel/solvers/imaginary_time.py +24 -0
  43. usel-1.0.4/src/usel/solvers/integration.py +64 -0
  44. usel-1.0.4/src/usel/solvers/ode.py +84 -0
  45. usel-1.0.4/src/usel/solvers/rk4.py +31 -0
  46. usel-1.0.4/src/usel/solvers/root_finding.py +132 -0
  47. usel-1.0.4/src/usel/solvers/split_operator.py +39 -0
  48. usel-1.0.4/src/usel/utils/__init__.py +26 -0
  49. usel-1.0.4/src/usel/utils/precision.py +24 -0
  50. usel-1.0.4/src/usel/utils/profiling.py +56 -0
  51. usel-1.0.4/src/usel/utils/timing.py +68 -0
  52. usel-1.0.4/src/usel/utils/validation.py +31 -0
  53. usel-1.0.4/src/usel.egg-info/PKG-INFO +157 -0
  54. usel-1.0.4/src/usel.egg-info/SOURCES.txt +56 -0
  55. usel-1.0.4/src/usel.egg-info/dependency_links.txt +1 -0
  56. usel-1.0.4/src/usel.egg-info/entry_points.txt +2 -0
  57. usel-1.0.4/src/usel.egg-info/requires.txt +6 -0
  58. usel-1.0.4/src/usel.egg-info/top_level.txt +1 -0
usel-1.0.4/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Goutam Parashuram Gotur
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
usel-1.0.4/PKG-INFO ADDED
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.4
2
+ Name: usel
3
+ Version: 1.0.4
4
+ Summary: An open-source, CPU-only scientific computing framework focused on quantum physics simulations and numerical methods.
5
+ Author: Goutam Parashuram Gotur, K R Raaghavindhra
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/goutam-tech/usel
8
+ Project-URL: Repository, https://github.com/goutam-tech/usel
9
+ Project-URL: Documentation, https://goutam-tech.github.io/usel
10
+ Keywords: scientific-computing,numerical-methods,physics,linear-algebra,computational-physics,dirac-equation,mathematics,open-source,quantum-mechanics
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Physics
18
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
19
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: numpy>=1.26
24
+ Requires-Dist: scipy>=1.11
25
+ Requires-Dist: sympy>=1.12
26
+ Requires-Dist: pyyaml>=6.0
27
+ Requires-Dist: toml>=0.10.2
28
+ Requires-Dist: matplotlib>=3.8
29
+ Dynamic: license-file
30
+
31
+ # USEL
32
+
33
+ USEL () is an open-source, CPU-only scientific computing framework focused on
34
+ quantum physics simulations and numerical methods.
35
+
36
+ Version 1.0 establishes the mathematical and computational foundation —
37
+ matrix and linear algebra utilities, numerical solvers, FFT-based frequency
38
+ analysis, random number generation, configuration/IO/logging utilities, and a
39
+ CLI — for future quantum mechanics, computational physics, and quantum
40
+ information modules.
41
+
42
+ ## Features
43
+
44
+ - Runs efficiently on standard consumer hardware, no GPU required
45
+ - Operates within 8 GB RAM
46
+ - Cross-platform (Windows, Linux, macOS)
47
+ - Modular, extensible architecture
48
+ - Fully typed, PEP 8 compliant codebase
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ uv sync
54
+ uv run usel version
55
+ ```
56
+
57
+ Or, for local development:
58
+
59
+ ```bash
60
+ git clone https://github.com/usel/usel.git
61
+ cd usel
62
+ uv sync --group dev
63
+ ```
64
+
65
+ See the [examples](examples/) directory for more, including eigenvalue
66
+ solving, ODE integration, FFT analysis, and numerical integration.
67
+
68
+ ## Command Line Interface
69
+
70
+ ```bash
71
+ uv run usel version
72
+ uv run usel doctor
73
+ uv run usel benchmark --size 200
74
+ uv run usel info
75
+ uv run usel config path/to/config.yaml
76
+ uv run usel test
77
+ ```
78
+
79
+ ## Modules
80
+
81
+ | Module | Description |
82
+ | -------------- | ------------------------------------------------ |
83
+ | `usel.math` | Matrix creation, algebra, norms, FFT transforms |
84
+ | `usel.linalg` | Eigenvalues/vectors, SVD, QR, LU, Cholesky |
85
+ | `usel.solvers` | Root finding, ODE solvers, numerical integration |
86
+ | `usel.random` | Random matrices, vectors, and distributions |
87
+ | `usel.utils` | Timing, profiling, validation, precision control |
88
+ | `usel.logging` | Console/file loggers, performance logger |
89
+ | `usel.config` | YAML/JSON/TOML configuration loading |
90
+ | `usel.io` | CSV/JSON/NumPy binary/text file I/O |
91
+ | `usel.cli` | Command line interface |
92
+
93
+ ## Non-Goals (v1.0)
94
+
95
+ This release intentionally excludes the Schrödinger equation, quantum
96
+ circuits/gates/qubits, machine learning, chemistry simulation, GPU/cloud
97
+ computing, and AI integration. These are planned for future releases (see
98
+ [CHANGELOG.md](CHANGELOG.md) and the roadmap below).
99
+
100
+ ## Roadmap
101
+
102
+ - v1.0 — Scientific Computing Foundation
103
+ - Core numerical engine
104
+ - Linear algebra utilities
105
+ - Matrix operations
106
+ - Numerical solvers
107
+ - FFT and mathematical utilities
108
+ - Configuration, logging, and CLI support
109
+
110
+ - v2.0 — Quantum Physics Engine
111
+ - Schrödinger equation module
112
+ - Quantum wavefunction utilities
113
+ - Potential models
114
+ - Hamiltonian construction
115
+ - Time evolution and visualization
116
+
117
+ - v3.0 — Relativistic & Computational Physics
118
+ - Dirac equation module
119
+ - Spinor algebra
120
+ - Gamma matrix operations
121
+ - Relativistic particle simulations
122
+ - Maxwell equation module
123
+ - Electromagnetic field simulations
124
+
125
+ Still more planning is going on this.
126
+
127
+ ## Development
128
+
129
+ ```bash
130
+ uv sync --group dev
131
+ uv run pytest
132
+ uv run ruff check .
133
+ uv run black --check .
134
+ uv run mypy src
135
+ ```
136
+
137
+ ## Documentation
138
+
139
+ Full documentation is built with MkDocs:
140
+
141
+ ```bash
142
+ uv run mkdocs serve
143
+ ```
144
+
145
+ ## Contributing
146
+
147
+ Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for
148
+ guidelines.
149
+
150
+ ## Security
151
+
152
+ usel performs no telemetry, no network communication, and no data
153
+ collection. It is fully offline capable.
154
+
155
+ ## License
156
+
157
+ MIT — see [LICENSE](LICENSE).
usel-1.0.4/README.md ADDED
@@ -0,0 +1,127 @@
1
+ # USEL
2
+
3
+ USEL () is an open-source, CPU-only scientific computing framework focused on
4
+ quantum physics simulations and numerical methods.
5
+
6
+ Version 1.0 establishes the mathematical and computational foundation —
7
+ matrix and linear algebra utilities, numerical solvers, FFT-based frequency
8
+ analysis, random number generation, configuration/IO/logging utilities, and a
9
+ CLI — for future quantum mechanics, computational physics, and quantum
10
+ information modules.
11
+
12
+ ## Features
13
+
14
+ - Runs efficiently on standard consumer hardware, no GPU required
15
+ - Operates within 8 GB RAM
16
+ - Cross-platform (Windows, Linux, macOS)
17
+ - Modular, extensible architecture
18
+ - Fully typed, PEP 8 compliant codebase
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ uv sync
24
+ uv run usel version
25
+ ```
26
+
27
+ Or, for local development:
28
+
29
+ ```bash
30
+ git clone https://github.com/usel/usel.git
31
+ cd usel
32
+ uv sync --group dev
33
+ ```
34
+
35
+ See the [examples](examples/) directory for more, including eigenvalue
36
+ solving, ODE integration, FFT analysis, and numerical integration.
37
+
38
+ ## Command Line Interface
39
+
40
+ ```bash
41
+ uv run usel version
42
+ uv run usel doctor
43
+ uv run usel benchmark --size 200
44
+ uv run usel info
45
+ uv run usel config path/to/config.yaml
46
+ uv run usel test
47
+ ```
48
+
49
+ ## Modules
50
+
51
+ | Module | Description |
52
+ | -------------- | ------------------------------------------------ |
53
+ | `usel.math` | Matrix creation, algebra, norms, FFT transforms |
54
+ | `usel.linalg` | Eigenvalues/vectors, SVD, QR, LU, Cholesky |
55
+ | `usel.solvers` | Root finding, ODE solvers, numerical integration |
56
+ | `usel.random` | Random matrices, vectors, and distributions |
57
+ | `usel.utils` | Timing, profiling, validation, precision control |
58
+ | `usel.logging` | Console/file loggers, performance logger |
59
+ | `usel.config` | YAML/JSON/TOML configuration loading |
60
+ | `usel.io` | CSV/JSON/NumPy binary/text file I/O |
61
+ | `usel.cli` | Command line interface |
62
+
63
+ ## Non-Goals (v1.0)
64
+
65
+ This release intentionally excludes the Schrödinger equation, quantum
66
+ circuits/gates/qubits, machine learning, chemistry simulation, GPU/cloud
67
+ computing, and AI integration. These are planned for future releases (see
68
+ [CHANGELOG.md](CHANGELOG.md) and the roadmap below).
69
+
70
+ ## Roadmap
71
+
72
+ - v1.0 — Scientific Computing Foundation
73
+ - Core numerical engine
74
+ - Linear algebra utilities
75
+ - Matrix operations
76
+ - Numerical solvers
77
+ - FFT and mathematical utilities
78
+ - Configuration, logging, and CLI support
79
+
80
+ - v2.0 — Quantum Physics Engine
81
+ - Schrödinger equation module
82
+ - Quantum wavefunction utilities
83
+ - Potential models
84
+ - Hamiltonian construction
85
+ - Time evolution and visualization
86
+
87
+ - v3.0 — Relativistic & Computational Physics
88
+ - Dirac equation module
89
+ - Spinor algebra
90
+ - Gamma matrix operations
91
+ - Relativistic particle simulations
92
+ - Maxwell equation module
93
+ - Electromagnetic field simulations
94
+
95
+ Still more planning is going on this.
96
+
97
+ ## Development
98
+
99
+ ```bash
100
+ uv sync --group dev
101
+ uv run pytest
102
+ uv run ruff check .
103
+ uv run black --check .
104
+ uv run mypy src
105
+ ```
106
+
107
+ ## Documentation
108
+
109
+ Full documentation is built with MkDocs:
110
+
111
+ ```bash
112
+ uv run mkdocs serve
113
+ ```
114
+
115
+ ## Contributing
116
+
117
+ Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for
118
+ guidelines.
119
+
120
+ ## Security
121
+
122
+ usel performs no telemetry, no network communication, and no data
123
+ collection. It is fully offline capable.
124
+
125
+ ## License
126
+
127
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,94 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "usel"
7
+ version = "1.0.4"
8
+ description = "An open-source, CPU-only scientific computing framework focused on quantum physics simulations and numerical methods."
9
+
10
+ authors = [
11
+ { name = "Goutam Parashuram Gotur" },
12
+ { name = "K R Raaghavindhra" }
13
+ ]
14
+
15
+ license = { text = "MIT" }
16
+ readme = "README.md"
17
+
18
+ keywords = [
19
+ "scientific-computing",
20
+ "numerical-methods",
21
+ "physics",
22
+ "linear-algebra",
23
+ "computational-physics",
24
+ "dirac-equation",
25
+ "mathematics",
26
+ "open-source",
27
+ "quantum-mechanics"
28
+ ]
29
+
30
+ classifiers = [
31
+ "Development Status :: 4 - Beta",
32
+ "Intended Audience :: Science/Research",
33
+ "License :: OSI Approved :: MIT License",
34
+ "Programming Language :: Python :: 3",
35
+ "Programming Language :: Python :: 3.11",
36
+ "Programming Language :: Python :: 3.12",
37
+ "Topic :: Scientific/Engineering :: Physics",
38
+ "Topic :: Scientific/Engineering :: Mathematics",
39
+ "Topic :: Scientific/Engineering :: Chemistry"
40
+ ]
41
+
42
+ requires-python = ">=3.11"
43
+
44
+ dependencies = [
45
+ "numpy>=1.26",
46
+ "scipy>=1.11",
47
+ "sympy>=1.12",
48
+ "pyyaml>=6.0",
49
+ "toml>=0.10.2",
50
+ "matplotlib>=3.8"
51
+ ]
52
+
53
+ [project.urls]
54
+ Homepage = "https://github.com/goutam-tech/usel"
55
+ Repository = "https://github.com/goutam-tech/usel"
56
+ Documentation = "https://goutam-tech.github.io/usel"
57
+
58
+ [project.scripts]
59
+ usel = "usel.cli.main:main"
60
+
61
+ [dependency-groups]
62
+ dev = [
63
+ "ruff>=0.4.0",
64
+ "black>=24.3.0",
65
+ "mypy>=1.9.0",
66
+ "pytest>=8.1.0",
67
+ "pytest-cov>=5.0.0"
68
+ ]
69
+
70
+ [tool.setuptools]
71
+ package-dir = { "" = "src" }
72
+
73
+ [tool.setuptools.packages.find]
74
+ where = ["src"]
75
+
76
+ [tool.ruff]
77
+ line-length = 100
78
+ target-version = "py311"
79
+
80
+ [tool.ruff.lint]
81
+ select = ["E", "F", "I", "UP", "B", "SIM"]
82
+
83
+ [tool.black]
84
+ line-length = 100
85
+ target-version = ["py311", "py312"]
86
+
87
+ [tool.mypy]
88
+ python_version = "3.11"
89
+ strict = true
90
+ ignore_missing_imports = true
91
+
92
+ [tool.pytest.ini_options]
93
+ testpaths = ["tests"]
94
+ addopts = "--cov=usel --cov-report=term-missing"
usel-1.0.4/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,22 @@
1
+ """usel: an open-source, CPU-only scientific computing framework.
2
+
3
+ This package provides the mathematical and computational foundation for
4
+ quantum mechanics, relativistic quantum mechanics, and computational
5
+ electromagnetics:
6
+
7
+ - Reusable matrix and linear algebra utilities
8
+ - Numerical solvers (root finding, ODEs, integration)
9
+ - FFT based frequency analysis
10
+ - Schrödinger equation solvers (bound states, wave-packet propagation)
11
+ - Dirac equation solvers (relativistic spinors, Pauli/Dirac matrices)
12
+ - Maxwell equation solvers (2D FDTD, electrostatics)
13
+ - Random number and matrix generation
14
+ - Configuration, IO, logging, and validation utilities
15
+ - A command line interface (``usel``)
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ __version__ = "1.1.0"
21
+ __license__ = "MIT"
22
+ __all__ = ["__version__", "__license__"]
@@ -0,0 +1,7 @@
1
+ """Command line interface for usel."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from usel.cli.main import main
6
+
7
+ __all__ = ["main"]
@@ -0,0 +1,151 @@
1
+ """usel command line interface.
2
+
3
+ Commands
4
+ --------
5
+ usel version Print the installed usel version.
6
+ usel doctor Check environment health (Python version, dependencies).
7
+ usel benchmark Run a quick matrix-multiplication benchmark.
8
+ usel info Print platform and package information.
9
+ usel config Show or validate a configuration file.
10
+ usel test Run the test suite via pytest.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import argparse
16
+ import importlib
17
+ import platform
18
+ import subprocess
19
+ import sys
20
+ import time
21
+ from collections.abc import Sequence
22
+
23
+ import usel
24
+ from usel.math.matrix import Matrix
25
+
26
+ _REQUIRED_PACKAGES = ("numpy", "scipy", "sympy")
27
+
28
+
29
+ def _cmd_version(_: argparse.Namespace) -> int:
30
+ print(f"usel version {usel.__version__}")
31
+ return 0
32
+
33
+
34
+ def _cmd_info(_: argparse.Namespace) -> int:
35
+ print("usel Info")
36
+ print("-" * 40)
37
+ print(f"Version: {usel.__version__}")
38
+ print(f"License: {usel.__license__}")
39
+ print(f"Python: {platform.python_version()}")
40
+ print(f"Platform: {platform.platform()}")
41
+ print(f"Processor: {platform.processor() or 'unknown'}")
42
+ return 0
43
+
44
+
45
+ def _cmd_doctor(_: argparse.Namespace) -> int:
46
+ print("Running usel environment check...")
47
+ ok = True
48
+
49
+ major, minor = sys.version_info[:2]
50
+ if (major, minor) >= (3, 11):
51
+ print(f"[OK] Python version {major}.{minor} >= 3.11")
52
+ else:
53
+ print(f"[FAIL] Python version {major}.{minor} < 3.11")
54
+ ok = False
55
+
56
+ for package in _REQUIRED_PACKAGES:
57
+ try:
58
+ importlib.import_module(package)
59
+ print(f"[OK] Dependency '{package}' is importable")
60
+ except ImportError:
61
+ print(f"[FAIL] Dependency '{package}' is missing")
62
+ ok = False
63
+
64
+ if ok:
65
+ print("\nAll checks passed. usel is ready to use.")
66
+ else:
67
+ print("\nSome checks failed. Please review the output above.")
68
+ return 0 if ok else 1
69
+
70
+
71
+ def _cmd_benchmark(args: argparse.Namespace) -> int:
72
+ size = args.size
73
+ print(f"Benchmarking {size}x{size} matrix multiplication...")
74
+ a = Matrix.random(size, size, seed=42)
75
+ b = Matrix.random(size, size, seed=43)
76
+
77
+ start = time.perf_counter()
78
+ _ = a @ b
79
+ elapsed = time.perf_counter() - start
80
+
81
+ print(f"Completed in {elapsed:.6f} seconds")
82
+ return 0
83
+
84
+
85
+ def _cmd_config(args: argparse.Namespace) -> int:
86
+ from usel.config.loader import load_config
87
+
88
+ try:
89
+ data = load_config(args.path)
90
+ except Exception as exc: # noqa: BLE001
91
+ print(f"[FAIL] Could not load configuration: {exc}")
92
+ return 1
93
+
94
+ print(f"[OK] Configuration file '{args.path}' loaded successfully")
95
+ print(f"Keys: {sorted(data.keys())}")
96
+ return 0
97
+
98
+
99
+ def _cmd_test(args: argparse.Namespace) -> int:
100
+ cmd = [sys.executable, "-m", "pytest"]
101
+ if args.path:
102
+ cmd.append(args.path)
103
+ result = subprocess.run(cmd, check=False) # noqa: S603
104
+ return result.returncode
105
+
106
+
107
+ def build_parser() -> argparse.ArgumentParser:
108
+ """Build and return the usel argument parser."""
109
+ parser = argparse.ArgumentParser(
110
+ prog="usel", description="usel: CPU-only scientific computing framework"
111
+ )
112
+ subparsers = parser.add_subparsers(dest="command", required=True)
113
+
114
+ subparsers.add_parser("version", help="Print the installed usel version").set_defaults(
115
+ func=_cmd_version
116
+ )
117
+ subparsers.add_parser("info", help="Print platform and package information").set_defaults(
118
+ func=_cmd_info
119
+ )
120
+ subparsers.add_parser(
121
+ "doctor", help="Check environment health (Python version, dependencies)"
122
+ ).set_defaults(func=_cmd_doctor)
123
+
124
+ benchmark_parser = subparsers.add_parser(
125
+ "benchmark", help="Run a quick matrix-multiplication benchmark"
126
+ )
127
+ benchmark_parser.add_argument(
128
+ "--size", type=int, default=200, help="Matrix dimension for the benchmark (default: 200)"
129
+ )
130
+ benchmark_parser.set_defaults(func=_cmd_benchmark)
131
+
132
+ config_parser = subparsers.add_parser("config", help="Load and validate a configuration file")
133
+ config_parser.add_argument("path", help="Path to a .yaml, .json, or .toml configuration file")
134
+ config_parser.set_defaults(func=_cmd_config)
135
+
136
+ test_parser = subparsers.add_parser("test", help="Run the test suite via pytest")
137
+ test_parser.add_argument("path", nargs="?", default=None, help="Optional test path filter")
138
+ test_parser.set_defaults(func=_cmd_test)
139
+
140
+ return parser
141
+
142
+
143
+ def main(argv: Sequence[str] | None = None) -> int:
144
+ """usel CLI entry point."""
145
+ parser = build_parser()
146
+ args = parser.parse_args(argv)
147
+ return int(args.func(args))
148
+
149
+
150
+ if __name__ == "__main__":
151
+ raise SystemExit(main())
@@ -0,0 +1,7 @@
1
+ """Configuration loading and saving for YAML, JSON, and TOML formats."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from usel.config.loader import load_config, save_config
6
+
7
+ __all__ = ["load_config", "save_config"]
@@ -0,0 +1,70 @@
1
+ """Load and save configuration files in YAML, JSON, or TOML format.
2
+
3
+ The format is inferred from the file extension: ``.yaml``/``.yml``,
4
+ ``.json``, or ``.toml``.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ from pathlib import Path
11
+ from typing import Any
12
+
13
+ from usel.exceptions import ConfigError
14
+
15
+ _SUPPORTED_SUFFIXES = {".yaml", ".yml", ".json", ".toml"}
16
+
17
+
18
+ def load_config(filepath: str | Path) -> dict[str, Any]:
19
+ """Load a configuration file, inferring the format from its extension."""
20
+ path = Path(filepath)
21
+ if not path.exists():
22
+ raise ConfigError(f"Configuration file not found: {path}")
23
+ if path.suffix not in _SUPPORTED_SUFFIXES:
24
+ raise ConfigError(
25
+ f"Unsupported configuration format '{path.suffix}'. "
26
+ f"Supported formats: {sorted(_SUPPORTED_SUFFIXES)}"
27
+ )
28
+
29
+ try:
30
+ text = path.read_text(encoding="utf-8")
31
+ if path.suffix in (".yaml", ".yml"):
32
+ import yaml
33
+
34
+ data = yaml.safe_load(text) or {}
35
+ elif path.suffix == ".json":
36
+ data = json.loads(text) if text.strip() else {}
37
+ else: # .toml
38
+ import toml
39
+
40
+ data = toml.loads(text)
41
+ except Exception as exc: # noqa: BLE001 - re-raised as ConfigError
42
+ raise ConfigError(f"Failed to parse configuration file {path}: {exc}") from exc
43
+
44
+ if not isinstance(data, dict):
45
+ raise ConfigError(f"Configuration root must be a mapping/object, got {type(data).__name__}")
46
+ return data
47
+
48
+
49
+ def save_config(data: dict[str, Any], filepath: str | Path) -> None:
50
+ """Save a configuration dictionary, inferring the format from its extension."""
51
+ path = Path(filepath)
52
+ if path.suffix not in _SUPPORTED_SUFFIXES:
53
+ raise ConfigError(
54
+ f"Unsupported configuration format '{path.suffix}'. "
55
+ f"Supported formats: {sorted(_SUPPORTED_SUFFIXES)}"
56
+ )
57
+
58
+ try:
59
+ if path.suffix in (".yaml", ".yml"):
60
+ import yaml
61
+
62
+ path.write_text(yaml.safe_dump(data, sort_keys=False), encoding="utf-8")
63
+ elif path.suffix == ".json":
64
+ path.write_text(json.dumps(data, indent=2), encoding="utf-8")
65
+ else: # .toml
66
+ import toml
67
+
68
+ path.write_text(toml.dumps(data), encoding="utf-8")
69
+ except Exception as exc: # noqa: BLE001 - re-raised as ConfigError
70
+ raise ConfigError(f"Failed to write configuration file {path}: {exc}") from exc