qnty 0.0.8__py3-none-any.whl → 0.1.0__py3-none-any.whl

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 (74) hide show
  1. qnty/__init__.py +140 -59
  2. qnty/constants/__init__.py +10 -0
  3. qnty/constants/numerical.py +18 -0
  4. qnty/constants/solvers.py +6 -0
  5. qnty/constants/tests.py +6 -0
  6. qnty/dimensions/__init__.py +23 -0
  7. qnty/dimensions/base.py +97 -0
  8. qnty/dimensions/field_dims.py +126 -0
  9. qnty/dimensions/field_dims.pyi +128 -0
  10. qnty/dimensions/signature.py +111 -0
  11. qnty/equations/__init__.py +4 -0
  12. qnty/equations/equation.py +220 -0
  13. qnty/equations/system.py +130 -0
  14. qnty/expressions/__init__.py +40 -0
  15. qnty/expressions/formatter.py +188 -0
  16. qnty/expressions/functions.py +74 -0
  17. qnty/expressions/nodes.py +701 -0
  18. qnty/expressions/types.py +70 -0
  19. qnty/extensions/plotting/__init__.py +0 -0
  20. qnty/extensions/reporting/__init__.py +0 -0
  21. qnty/problems/__init__.py +145 -0
  22. qnty/problems/composition.py +1031 -0
  23. qnty/problems/problem.py +695 -0
  24. qnty/problems/rules.py +145 -0
  25. qnty/problems/solving.py +1216 -0
  26. qnty/problems/validation.py +127 -0
  27. qnty/quantities/__init__.py +29 -0
  28. qnty/quantities/base_qnty.py +677 -0
  29. qnty/quantities/field_converters.py +24004 -0
  30. qnty/quantities/field_qnty.py +1012 -0
  31. qnty/quantities/field_setter.py +12320 -0
  32. qnty/quantities/field_vars.py +6325 -0
  33. qnty/quantities/field_vars.pyi +4191 -0
  34. qnty/solving/__init__.py +0 -0
  35. qnty/solving/manager.py +96 -0
  36. qnty/solving/order.py +403 -0
  37. qnty/solving/solvers/__init__.py +13 -0
  38. qnty/solving/solvers/base.py +82 -0
  39. qnty/solving/solvers/iterative.py +165 -0
  40. qnty/solving/solvers/simultaneous.py +475 -0
  41. qnty/units/__init__.py +1 -0
  42. qnty/units/field_units.py +10507 -0
  43. qnty/units/field_units.pyi +2461 -0
  44. qnty/units/prefixes.py +203 -0
  45. qnty/{unit.py → units/registry.py} +89 -61
  46. qnty/utils/__init__.py +16 -0
  47. qnty/utils/caching/__init__.py +23 -0
  48. qnty/utils/caching/manager.py +401 -0
  49. qnty/utils/error_handling/__init__.py +66 -0
  50. qnty/utils/error_handling/context.py +39 -0
  51. qnty/utils/error_handling/exceptions.py +96 -0
  52. qnty/utils/error_handling/handlers.py +171 -0
  53. qnty/utils/logging.py +40 -0
  54. qnty/utils/protocols.py +164 -0
  55. qnty/utils/scope_discovery.py +420 -0
  56. qnty-0.1.0.dist-info/METADATA +199 -0
  57. qnty-0.1.0.dist-info/RECORD +60 -0
  58. qnty/dimension.py +0 -186
  59. qnty/equation.py +0 -297
  60. qnty/expression.py +0 -553
  61. qnty/prefixes.py +0 -229
  62. qnty/unit_types/base.py +0 -47
  63. qnty/units.py +0 -8113
  64. qnty/variable.py +0 -300
  65. qnty/variable_types/base.py +0 -58
  66. qnty/variable_types/expression_variable.py +0 -106
  67. qnty/variable_types/typed_variable.py +0 -87
  68. qnty/variables.py +0 -2298
  69. qnty/variables.pyi +0 -6148
  70. qnty-0.0.8.dist-info/METADATA +0 -355
  71. qnty-0.0.8.dist-info/RECORD +0 -19
  72. /qnty/{unit_types → extensions}/__init__.py +0 -0
  73. /qnty/{variable_types → extensions/integration}/__init__.py +0 -0
  74. {qnty-0.0.8.dist-info → qnty-0.1.0.dist-info}/WHEEL +0 -0
@@ -1,355 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: qnty
3
- Version: 0.0.8
4
- Summary: High-performance unit system library for Python with dimensional safety and fast unit conversions
5
- License: Apache-2.0
6
- Keywords: units,dimensional analysis,engineering,physics,quantities,measurements
7
- Author: tn3wman
8
- Requires-Python: >=3.11, <3.14
9
- Classifier: Development Status :: 4 - Beta
10
- Classifier: Intended Audience :: Developers
11
- Classifier: Intended Audience :: Science/Research
12
- Classifier: License :: OSI Approved :: Apache Software License
13
- Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.11
15
- Classifier: Programming Language :: Python :: 3.12
16
- Classifier: Programming Language :: Python :: 3.13
17
- Classifier: Topic :: Scientific/Engineering
18
- Classifier: Topic :: Scientific/Engineering :: Physics
19
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
- Provides-Extra: benchmark
21
- Provides-Extra: dev
22
- Requires-Dist: Pint (>=0.24.4) ; extra == "benchmark"
23
- Requires-Dist: numpy (>=2.3.2)
24
- Requires-Dist: pytest (>=8.4.1) ; extra == "dev"
25
- Requires-Dist: ruff (>=0.1.0) ; extra == "dev"
26
- Project-URL: Bug Tracker, https://github.com/tn3wman/qnty/issues
27
- Project-URL: Documentation, https://github.com/tn3wman/qnty#readme
28
- Project-URL: Homepage, https://github.com/tn3wman/qnty
29
- Project-URL: Repository, https://github.com/tn3wman/qnty
30
- Description-Content-Type: text/markdown
31
-
32
- # Qnty
33
-
34
- **High-performance unit system library for Python with dimensional safety and fast unit conversions for engineering calculations.**
35
-
36
- [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
37
- [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
38
- [![Development Status](https://img.shields.io/badge/status-beta-orange.svg)](https://pypi.org/project/qnty/)
39
-
40
- ## ⚠️ Important Disclaimer
41
-
42
- **🚧 Work in Progress**: Qnty is currently in active development and has not been thoroughly vetted for production engineering calculations. While we strive for accuracy, this library should not be used for critical engineering applications without independent verification.
43
-
44
- **📐 Accuracy Notice**: The authors are not responsible or liable for incorrect results, calculation errors, or any consequences arising from the use of this library. Always validate calculations independently using established engineering tools and practices.
45
-
46
- **🚀 Learn from History**: Remember, even NASA's Mars Climate Orbiter had a $327 million oops moment due to unit conversion errors between metric and imperial systems. Don't let your project become the next cautionary tale - double-check everything!
47
-
48
- *Use Qnty to help prevent unit errors, but always verify critical calculations through multiple methods.*
49
-
50
- ---
51
-
52
- Qnty is designed around **type safety** and **performance optimization** using compile-time dimensional analysis. It provides ultra-fast unit conversions and dimensional checking for engineering applications where performance matters.
53
-
54
- ## ✨ Key Features
55
-
56
- - **🚀 Ultra-Fast Performance**: Prime number encoding and pre-computed conversion tables
57
- - **🛡️ Type Safety**: Compile-time dimensional analysis prevents unit errors
58
- - **⚡ Zero-Cost Abstractions**: Optimized operations with `__slots__` and caching
59
- - **🔗 Fluent API**: Intuitive method chaining for readable code
60
- - **🧮 Engineering-Focused**: Built for real-world engineering calculations
61
- - **🧬 Mathematical System**: Built-in equation solving and expression trees
62
- - **📊 Comprehensive Testing**: 457 tests with performance benchmarks
63
- - **🏗️ Clean Architecture**: Circular import-free design with strict dependency hierarchy
64
-
65
- ## 🚀 Quick Start
66
-
67
- ### Installation
68
-
69
- ```bash
70
- pip install qnty
71
- # or with Poetry
72
- poetry add qnty
73
- ```
74
-
75
- ### Basic Usage
76
-
77
- ```python
78
- from qnty import Length, Pressure, Dimensionless
79
- from qnty.variable import FastQuantity
80
- from qnty.units import LengthUnits, PressureUnits
81
-
82
- # Type-safe variables with fluent API
83
- beam_length = Length("beam_length")
84
- beam_length.set(100.0).millimeters
85
- print(beam_length) # beam_length: 100.0 mm
86
-
87
- # Convert units effortlessly
88
- length_in_meters = beam_length.quantity.to(LengthUnits.meter)
89
- print(length_in_meters) # 0.1 m
90
-
91
- # High-performance calculations
92
- pressure = FastQuantity(150.0, PressureUnits.psi)
93
- area = FastQuantity(0.5, LengthUnits.meter) * FastQuantity(2.0, LengthUnits.meter)
94
- force = pressure * area # Automatic dimensional analysis
95
- ```
96
-
97
- ### Engineering Example
98
-
99
- ```python
100
- from qnty import Length, Pressure
101
-
102
- # ASME pressure vessel calculation with mixed units
103
- pressure = Pressure("internal_pressure")
104
- diameter = Length("outer_diameter")
105
- stress = Pressure("allowable_stress")
106
-
107
- # Set values with different units - no manual conversion needed!
108
- pressure.set(2900.75).psi # Imperial
109
- diameter.set(168.275).millimeters # Metric
110
- stress.set(137.895).MPa # SI
111
-
112
- # Qnty handles all unit conversions automatically
113
- thickness = (pressure.quantity * diameter.quantity) / (2 * stress.quantity)
114
- print(f"Required thickness: {thickness}") # Automatically in correct units
115
- ```
116
-
117
- ### Mathematical Equations & Solving
118
-
119
- ```python
120
- from qnty import Length, Pressure, Dimensionless
121
-
122
- # Define engineering variables
123
- T = Length("Wall Thickness", is_known=False) # Unknown to solve for
124
- T_bar = Length(0.147, "inches", "Nominal Wall Thickness")
125
- U_m = Dimensionless(0.125, "Mill Undertolerance")
126
-
127
- # Create equation using fluent API: T = T_bar * (1 - U_m)
128
- equation = T.equals(T_bar * (1 - U_m))
129
-
130
- # Solve automatically
131
- known_vars = {"T_bar": T_bar, "U_m": U_m}
132
- result = equation.solve_for("T", known_vars)
133
- print(f"Solved thickness: {result.quantity}") # 0.128625 inches
134
-
135
- # Verify equation is satisfied
136
- assert equation.check_residual(known_vars) is True
137
- ```
138
-
139
- ## 🏗️ Architecture
140
-
141
- ### Clean Dependency Design
142
-
143
- Qnty features a carefully designed architecture that eliminates circular imports through a strict dependency hierarchy:
144
-
145
- ```python
146
- variable → variables → expression → equation
147
- ```
148
-
149
- This ensures clean type checking, maintainable code, and optimal performance throughout the system.
150
-
151
- ### Core Components
152
-
153
- ### 🔢 Dimensional System
154
-
155
- - Prime number encoding for ultra-fast dimensional compatibility checks
156
- - Zero-cost dimensional analysis at compile time
157
- - Immutable dimension signatures for thread safety
158
-
159
- ### ⚙️ High-Performance Quantities
160
-
161
- - `FastQuantity`: Optimized for engineering calculations with `__slots__`
162
- - Cached SI factors and dimension signatures
163
- - Fast-path optimizations for same-unit operations
164
-
165
- ### 🎯 Type-Safe Variables
166
-
167
- - `Length`, `Pressure`, `Dimensionless`: Domain-specific variables with compile-time safety
168
- - Fluent API with specialized setters
169
- - Prevents dimensional errors at the type level
170
-
171
- ### 🔄 Smart Unit System
172
-
173
- - Pre-computed conversion tables
174
- - Automatic unit resolution for calculations
175
- - Support for mixed-unit operations
176
-
177
- ### 🧬 Mathematical System
178
-
179
- - Built-in equation solving with symbolic manipulation
180
- - Expression trees for complex mathematical operations
181
- - Automatic residual checking and validation
182
- - Engineering equation support (ASME, pressure vessels, etc.)
183
-
184
- ## 📊 Performance
185
-
186
- Qnty significantly outperforms other unit libraries with **18.9x average speedup** over Pint:
187
-
188
- ### Real Benchmark Results (μs per operation)
189
-
190
- | Operation | Qnty | Pint | **Speedup** |
191
- |-----------|------|------|-------------|
192
- | Unit Conversion (m → mm) | 0.50 | 9.72 | **19.5x** |
193
- | Mixed Unit Addition (mm + in) | 0.76 | 17.52 | **23.1x** |
194
- | Multiplication (m × m) | 0.82 | 10.64 | **12.9x** |
195
- | Division (psi ÷ mm) | 0.87 | 11.23 | **12.9x** |
196
- | Complex ASME Equation | 4.07 | 106.17 | **26.1x** 🚀 |
197
- | Type-Safe Variables | 0.98 | 9.65 | **9.8x** |
198
- | Chained Operations | 1.83 | 42.22 | **23.1x** |
199
- | Loop (10 additions) | 5.32 | 79.48 | **14.9x** |
200
- | **AVERAGE** | **1.89** | **35.83** | **18.9x** 🏆 |
201
-
202
- *Benchmarks performed on typical engineering calculations. Run `pytest tests/test_benchmark.py -v -s` to verify on your system.*
203
-
204
- ## 🧪 Advanced Features
205
-
206
- ### Fluent API Design
207
-
208
- ```python
209
- # Method chaining for readable code
210
- pipe_system = {
211
- 'inlet': Pressure("inlet").set(150.0).psi,
212
- 'outlet': Pressure("outlet").set(120.0).psi,
213
- 'diameter': Length("diameter").set(6.0).inches,
214
- 'length': Length("length").set(100.0).feet
215
- }
216
-
217
- pressure_drop = pipe_system['inlet'].quantity - pipe_system['outlet'].quantity
218
- ```
219
-
220
- ### Dimensional Safety
221
-
222
- ```python
223
- # This will raise a TypeError at assignment time
224
- length = Length("distance")
225
- try:
226
- length.set(100.0).psi # Wrong! Pressure unit for length variable
227
- except TypeError as e:
228
- print(f"Caught error: {e}") # Unit psi incompatible with expected dimension
229
-
230
- # Type checker catches this at development time
231
- ```
232
-
233
- ### Mixed Unit Calculations
234
-
235
- ```python
236
- # Automatically handles unit conversions in calculations
237
- width = Length("width").set(100.0).millimeters
238
- height = Length("height").set(4.0).inches # Different unit!
239
-
240
- # Qnty automatically converts to compatible units
241
- area = width.quantity * height.quantity
242
- perimeter = 2 * (width.quantity + height.quantity)
243
- ```
244
-
245
- ### Equation Solving System
246
-
247
- ```python
248
- from qnty import Length, Pressure, Dimensionless
249
-
250
- # Multi-variable engineering equations
251
- P = Pressure(90, "psi", "P") # Known
252
- D = Length(0.84, "inches", "D") # Known
253
- t = Length("t", is_known=False) # Unknown - solve for this
254
- S = Pressure(20000, "psi", "S") # Known
255
-
256
- # ASME pressure vessel equation: P = (S * t) / ((D/2) + 0.6*t)
257
- # Rearranged to solve for t
258
- equation = t.equals((P * D) / (2 * S - 1.2 * P))
259
-
260
- # Solve automatically
261
- known_variables = {"P": P, "D": D, "S": S}
262
- thickness_result = equation.solve_for("t", known_variables)
263
- print(f"Required thickness: {thickness_result.quantity}")
264
-
265
- # Verify solution
266
- assert equation.check_residual(known_variables) is True
267
- ```
268
-
269
- ### Import Strategy
270
-
271
- Qnty provides a clean, minimal public API:
272
-
273
- ```python
274
- # Preferred import style - clean public API
275
- from qnty import Length, Pressure, Dimensionless
276
-
277
- # Internal imports when needed for advanced usage
278
- from qnty.variable import FastQuantity, TypeSafeVariable
279
- from qnty.expression import Expression
280
- from qnty.equation import Equation, EquationSystem
281
- ```
282
-
283
- ## 🔧 Development
284
-
285
- ### Setup Development Environment
286
-
287
- ```bash
288
- git clone https://github.com/your-username/qnty.git
289
- cd qnty
290
- pip install -r requirements.txt
291
-
292
- # Run all tests
293
- pytest
294
-
295
- # Run specific test file
296
- pytest tests/test_dimension.py -v
297
-
298
- # Run benchmarks
299
- python tests/test_benchmark.py
300
- ```
301
-
302
- ### Code Quality
303
-
304
- ```bash
305
- # Linting with ruff (200 character line length)
306
- ruff check src/ tests/
307
- ruff format src/ tests/
308
-
309
- # Type checking
310
- mypy src/qnty/
311
- ```
312
-
313
- ## 📚 Documentation
314
-
315
- ### Core Classes
316
-
317
- - **`FastQuantity`**: High-performance quantity with value and unit
318
- - **`TypeSafeVariable`**: Base class for dimension-specific variables
319
- - **`Length`**, **`Pressure`**, **`Dimensionless`**: Specialized variables with fluent setters
320
- - **`Equation`**: Mathematical equations with solving capabilities
321
- - **`Expression`**: Abstract base for mathematical expression trees
322
- - **`DimensionSignature`**: Immutable dimension encoding system
323
- - **`UnitConstant`**: Type-safe unit definitions
324
-
325
- ### Unit Categories
326
-
327
- - **Length**: meter, millimeter, inch, foot, etc.
328
- - **Pressure**: pascal, psi, bar, kilopascal, megapascal, etc.
329
- - **Dimensionless**: ratios, efficiency factors, etc.
330
- - *More dimensions coming soon*
331
-
332
- ## 🤝 Contributing
333
-
334
- We welcome contributions! Please see our contributing guidelines and:
335
-
336
- 1. Fork the repository
337
- 2. Create a feature branch
338
- 3. Add tests for new functionality
339
- 4. Ensure all tests pass: `pytest`
340
- 5. Submit a pull request
341
-
342
- ## 📄 License
343
-
344
- This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
345
-
346
- ## 🙏 Acknowledgments
347
-
348
- - Inspired by the [Pint](https://pint.readthedocs.io/) library
349
- - Built for the engineering community
350
- - Designed with performance-critical applications in mind
351
-
352
- ---
353
-
354
- **Ready to supercharge your engineering calculations?** Install Qnty today and experience the power of type-safe, high-performance unit handling! 🚀
355
-
@@ -1,19 +0,0 @@
1
- qnty/__init__.py,sha256=o9rtuo8QAdC3ppaD7ev1jqjrWbCvpdFbi_yZwUBuc6Q,5551
2
- qnty/dimension.py,sha256=yc4zSJ5KCzgihya2MZX4lfP3E4YNg97mP8Sw_ajO2Pg,11117
3
- qnty/equation.py,sha256=RRe3pJBn3ZrM3LtSnioG_i7gKmBnNVsIxc9KXf5UrTg,12278
4
- qnty/expression.py,sha256=pbQ8fB2xc7VVi4LTqw8PbJFqG7XW4U36wI2pe6P4yto,24609
5
- qnty/prefixes.py,sha256=bRwcNbE_nX9gXI_WnJZLL-i7kQncIOZivCCSN8dur2g,6000
6
- qnty/unit.py,sha256=V3rQY-fYAnYC8Ed2r9FlCCkMOZ4zQQvGaVPS4VH-K9c,5585
7
- qnty/unit_types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- qnty/unit_types/base.py,sha256=Gk2Ab4TE-SfGBn-ko_p0vDI178PG9SyZOJ0cBOYEpdg,1620
9
- qnty/units.py,sha256=8swGhiJQfrA_-gas2e2cbwKTXf4g0xmBbeVibYsqCHk,302897
10
- qnty/variable.py,sha256=y2rQnGKeErC7_NKz9Z3WLV_cEn2Ya3ZvBEEPwioHrSo,13091
11
- qnty/variable_types/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- qnty/variable_types/base.py,sha256=Otm7FOvuvi1gdlZm-djlTwqhlsSdzPIL46AXnB2cd18,1735
13
- qnty/variable_types/expression_variable.py,sha256=xTHTSqITZt9h5vas3M_pZsQeE8Bm5cJxZBr7Q1EdhUs,4838
14
- qnty/variable_types/typed_variable.py,sha256=kjw8VOShMaE7iorc3mqCIApYaFgOfvv-jSu_tmT1DgM,4227
15
- qnty/variables.py,sha256=boClctOkzemu18yMv2rzuVq96MNCVFR-MOVVO1InBQc,142715
16
- qnty/variables.pyi,sha256=KYPDJ-Qh_LPP4vHsafzrV6ZAUeepErY-RwRpOTieuhk,219690
17
- qnty-0.0.8.dist-info/METADATA,sha256=uo_wncOYHiRWJYeie3RWMWMOeAVbWBnQMquWnYLPGAs,12113
18
- qnty-0.0.8.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
19
- qnty-0.0.8.dist-info/RECORD,,
File without changes
File without changes