qnty 0.0.9__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 (92) hide show
  1. qnty/__init__.py +2 -3
  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 +1 -1
  12. qnty/equations/equation.py +118 -155
  13. qnty/equations/system.py +68 -65
  14. qnty/expressions/__init__.py +25 -46
  15. qnty/expressions/formatter.py +188 -0
  16. qnty/expressions/functions.py +46 -68
  17. qnty/expressions/nodes.py +539 -384
  18. qnty/expressions/types.py +70 -0
  19. qnty/problems/__init__.py +145 -0
  20. qnty/problems/composition.py +1031 -0
  21. qnty/problems/problem.py +695 -0
  22. qnty/problems/rules.py +145 -0
  23. qnty/problems/solving.py +1216 -0
  24. qnty/problems/validation.py +127 -0
  25. qnty/quantities/__init__.py +28 -5
  26. qnty/quantities/base_qnty.py +677 -0
  27. qnty/quantities/field_converters.py +24004 -0
  28. qnty/quantities/field_qnty.py +1012 -0
  29. qnty/{generated/setters.py → quantities/field_setter.py} +3071 -2961
  30. qnty/{generated/quantities.py → quantities/field_vars.py} +754 -432
  31. qnty/{generated/quantities.pyi → quantities/field_vars.pyi} +1289 -1290
  32. qnty/solving/manager.py +50 -44
  33. qnty/solving/order.py +181 -133
  34. qnty/solving/solvers/__init__.py +2 -9
  35. qnty/solving/solvers/base.py +27 -37
  36. qnty/solving/solvers/iterative.py +115 -135
  37. qnty/solving/solvers/simultaneous.py +93 -165
  38. qnty/units/__init__.py +1 -0
  39. qnty/{generated/units.py → units/field_units.py} +1700 -991
  40. qnty/units/field_units.pyi +2461 -0
  41. qnty/units/prefixes.py +58 -105
  42. qnty/units/registry.py +76 -89
  43. qnty/utils/__init__.py +16 -0
  44. qnty/utils/caching/__init__.py +23 -0
  45. qnty/utils/caching/manager.py +401 -0
  46. qnty/utils/error_handling/__init__.py +66 -0
  47. qnty/utils/error_handling/context.py +39 -0
  48. qnty/utils/error_handling/exceptions.py +96 -0
  49. qnty/utils/error_handling/handlers.py +171 -0
  50. qnty/utils/logging.py +4 -4
  51. qnty/utils/protocols.py +164 -0
  52. qnty/utils/scope_discovery.py +420 -0
  53. {qnty-0.0.9.dist-info → qnty-0.1.0.dist-info}/METADATA +1 -1
  54. qnty-0.1.0.dist-info/RECORD +60 -0
  55. qnty/_backup/problem_original.py +0 -1251
  56. qnty/_backup/quantity.py +0 -63
  57. qnty/codegen/cli.py +0 -125
  58. qnty/codegen/generators/data/unit_data.json +0 -8807
  59. qnty/codegen/generators/data_processor.py +0 -345
  60. qnty/codegen/generators/dimensions_gen.py +0 -434
  61. qnty/codegen/generators/doc_generator.py +0 -141
  62. qnty/codegen/generators/out/dimension_mapping.json +0 -974
  63. qnty/codegen/generators/out/dimension_metadata.json +0 -123
  64. qnty/codegen/generators/out/units_metadata.json +0 -223
  65. qnty/codegen/generators/quantities_gen.py +0 -159
  66. qnty/codegen/generators/setters_gen.py +0 -178
  67. qnty/codegen/generators/stubs_gen.py +0 -167
  68. qnty/codegen/generators/units_gen.py +0 -295
  69. qnty/expressions/cache.py +0 -94
  70. qnty/generated/dimensions.py +0 -514
  71. qnty/problem/__init__.py +0 -91
  72. qnty/problem/base.py +0 -142
  73. qnty/problem/composition.py +0 -385
  74. qnty/problem/composition_mixin.py +0 -382
  75. qnty/problem/equations.py +0 -413
  76. qnty/problem/metaclass.py +0 -302
  77. qnty/problem/reconstruction.py +0 -1016
  78. qnty/problem/solving.py +0 -180
  79. qnty/problem/validation.py +0 -64
  80. qnty/problem/variables.py +0 -239
  81. qnty/quantities/expression_quantity.py +0 -314
  82. qnty/quantities/quantity.py +0 -428
  83. qnty/quantities/typed_quantity.py +0 -215
  84. qnty/validation/__init__.py +0 -0
  85. qnty/validation/registry.py +0 -0
  86. qnty/validation/rules.py +0 -167
  87. qnty-0.0.9.dist-info/RECORD +0 -63
  88. /qnty/{codegen → extensions}/__init__.py +0 -0
  89. /qnty/{codegen/generators → extensions/integration}/__init__.py +0 -0
  90. /qnty/{codegen/generators/utils → extensions/plotting}/__init__.py +0 -0
  91. /qnty/{generated → extensions/reporting}/__init__.py +0 -0
  92. {qnty-0.0.9.dist-info → qnty-0.1.0.dist-info}/WHEEL +0 -0
qnty/validation/rules.py DELETED
@@ -1,167 +0,0 @@
1
- """
2
- Engineering problem checks and validation system.
3
-
4
- This module provides a clean API for defining engineering code compliance checks,
5
- warnings, and validation rules at the problem level rather than variable level.
6
- """
7
-
8
- from __future__ import annotations
9
-
10
- from dataclasses import dataclass
11
- from typing import Any, Literal
12
-
13
- from qnty.expressions import Expression as QntyExpression
14
-
15
-
16
- @dataclass
17
- class Rules:
18
- """
19
- Represents an engineering problem check (code compliance, validation, etc.).
20
-
21
- Checks are defined at the EngineeringProblem class level and evaluated after solving.
22
- They can represent code compliance rules, engineering judgment warnings, or
23
- validation conditions.
24
- """
25
- condition: QntyExpression
26
- message: str
27
- warning_type: str = "VALIDATION"
28
- severity: Literal["INFO", "WARNING", "ERROR"] = "WARNING"
29
- name: str | None = None
30
-
31
- def __post_init__(self):
32
- """Generate a name if not provided."""
33
- if self.name is None:
34
- self.name = f"{self.warning_type}_{self.severity}"
35
-
36
- def evaluate(self, variables: dict[str, Any]) -> dict[str, Any] | None:
37
- """
38
- Evaluate the check condition and return a warning dict if condition is True.
39
-
40
- Args:
41
- variables: Dictionary of variable name -> variable object mappings
42
-
43
- Returns:
44
- Warning dictionary if condition is met, None otherwise
45
- """
46
- try:
47
- # Evaluate the condition expression using qnty's evaluation system
48
- result = self._evaluate_expression(self.condition, variables)
49
-
50
- if result:
51
- return {
52
- "type": self.warning_type,
53
- "severity": self.severity,
54
- "message": self.message,
55
- "check_name": self.name,
56
- "condition": str(self.condition)
57
- }
58
-
59
- except Exception as e:
60
- # If evaluation fails, return an error warning
61
- import traceback
62
- return {
63
- "type": "EVALUATION_ERROR",
64
- "severity": "ERROR",
65
- "message": f"Failed to evaluate check '{self.name}': {str(e)}",
66
- "check_name": self.name,
67
- "condition": str(self.condition),
68
- "debug_info": f"Expression type: {type(self.condition)}, Variables: {list(variables.keys())}",
69
- "traceback": traceback.format_exc()
70
- }
71
-
72
- return None
73
-
74
- def _evaluate_expression(self, expr: QntyExpression, variables: dict[str, Any]) -> bool:
75
- """
76
- Evaluate a qnty expression with current variable values.
77
-
78
- For qnty expressions, we can evaluate them directly since they have
79
- references to the variable values.
80
- """
81
- try:
82
- # qnty expressions have an evaluate() method that needs variable values
83
- if hasattr(expr, 'evaluate'):
84
- # Create a variable_values dict with the variable objects, not their quantities
85
- var_values = {}
86
- for var_name, var_obj in variables.items():
87
- var_values[var_name] = var_obj
88
-
89
- result = expr.evaluate(var_values)
90
- # For boolean comparisons, result should be 1.0 (True) or 0.0 (False)
91
- # Handle FastQuantity type
92
- if hasattr(result, 'value'): # FastQuantity
93
- return bool(result.value > 0.5)
94
- elif hasattr(result, '__float__'):
95
- # Use type: ignore to handle FastQuantity/Expression types that don't have __float__
96
- return bool(float(result) > 0.5) # type: ignore[arg-type]
97
- else:
98
- # Last resort - try str conversion then float
99
- result_str = str(result)
100
- # Handle cases like "0.0 " (with units)
101
- try:
102
- return bool(float(result_str.split()[0]) > 0.5)
103
- except (ValueError, IndexError):
104
- return False
105
- else:
106
- # Try direct conversion as fallback
107
- if hasattr(expr, '__float__'):
108
- # Use type: ignore to handle Expression types that don't have __float__
109
- return bool(float(expr) > 0.5) # type: ignore[arg-type]
110
- else:
111
- return bool(float(str(expr)) > 0.5)
112
- except Exception as e:
113
- # If evaluation fails, assume the condition is not met
114
- # Re-raise to get better debugging info
115
- raise e
116
-
117
-
118
- def add_rule(
119
- condition: QntyExpression,
120
- message: str,
121
- warning_type: str = "VALIDATION",
122
- severity: Literal["INFO", "WARNING", "ERROR"] = "WARNING",
123
- name: str | None = None
124
- ) -> Rules:
125
- """
126
- Create a new engineering problem check.
127
-
128
- This function is intended to be called at the class level when defining
129
- EngineeringProblem subclasses. It creates Check objects that will be
130
- automatically collected by the metaclass.
131
-
132
- Args:
133
- condition: A qnty Expression that evaluates to True when the check should trigger
134
- message: Descriptive message explaining what the check means
135
- warning_type: Category of check (e.g., "CODE_COMPLIANCE", "VALIDATION")
136
- severity: Severity level of the check
137
- name: Optional name for the check
138
-
139
- Returns:
140
- Check object that can be assigned to a class attribute
141
-
142
- Example:
143
- class MyProblem(EngineeringProblem):
144
- # Variables...
145
- P = Pressure(90, "psi")
146
- t = Length(0.1, "inch")
147
- D = Length(1.0, "inch")
148
-
149
- # Checks defined at class level
150
- thick_wall_check = add_check(
151
- t.geq(D / 6),
152
- "Thick wall condition detected - requires special consideration",
153
- warning_type="CODE_COMPLIANCE",
154
- severity="WARNING"
155
- )
156
- """
157
- return Rules(
158
- condition=condition,
159
- message=message,
160
- warning_type=warning_type,
161
- severity=severity,
162
- name=name
163
- )
164
-
165
- __all__ = [
166
- "add_rule"
167
- ]
@@ -1,63 +0,0 @@
1
- qnty/__init__.py,sha256=nixvrkyF4sIwtLCPVIfADSEKkQoKlFZs_7TbpuBFWXE,5563
2
- qnty/_backup/problem_original.py,sha256=M58iUTiWBO1sS3rM3aQSlpIwxbSRiW2LICYK-Lnoz90,56698
3
- qnty/_backup/quantity.py,sha256=oD-TNDkxK1Tfa6S_sxNnDWyv1_SuW0TrNKz01e45fxg,1509
4
- qnty/codegen/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- qnty/codegen/cli.py,sha256=C66IQ-je69UP0llVy7kgSrfUYM3PHuantcefYvFBDHw,4092
6
- qnty/codegen/generators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- qnty/codegen/generators/data/unit_data.json,sha256=KbJHRv5U2bF_uS_Az9G-uFSjwvxCcvmn1ZCxR5H0uGI,253446
8
- qnty/codegen/generators/data_processor.py,sha256=3Cibqkegi48KuaD9I9i1QinP2h7Fi76EOJ2hwmZq6ug,13741
9
- qnty/codegen/generators/dimensions_gen.py,sha256=03Ryq8CPIU3gMSOZNnOjc2JMR3Vi-lgVmBYFnOliL8w,16379
10
- qnty/codegen/generators/doc_generator.py,sha256=zmhDWwxODII5d-_FlKskhMTHHBmS8NRZOzOyPzPMyTs,6184
11
- qnty/codegen/generators/out/dimension_mapping.json,sha256=_YRPCzMvT9RW_YhURbuHH8gKhYtdu8gaYSqJ-bZxSAE,23864
12
- qnty/codegen/generators/out/dimension_metadata.json,sha256=-2uXcB8grYMZew9A6mDSajrJ9yCoegrTx23g70QTK_Y,2929
13
- qnty/codegen/generators/out/units_metadata.json,sha256=5MMDsT6Y99tthus8YT5Xu6iaG4cn99sP-JomKYZ084k,5890
14
- qnty/codegen/generators/quantities_gen.py,sha256=9Nf_3PUpTf0A1yLe8L4CodrpsD4Oz7DTXX3E-sssj3I,6271
15
- qnty/codegen/generators/setters_gen.py,sha256=u76OwdH7Sl6XsIDGZn6ID8Xp0VEptBXO1QJ4h6sne1c,7145
16
- qnty/codegen/generators/stubs_gen.py,sha256=F6ZEk48W9C8nRKP6_pKoGPO3gnDtGfvn-42XgrhA4uk,6659
17
- qnty/codegen/generators/units_gen.py,sha256=iESIFLCVNWi_4Ftss2_s2QTGTOTutInAeltLQdMjrI8,10592
18
- qnty/codegen/generators/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
- qnty/equations/__init__.py,sha256=ngficq_uwosz7O2BaqDH-G6dqp1burjfkcwE4MnGyIo,108
20
- qnty/equations/equation.py,sha256=dv527D-fE_0jLmK6BJI5SNCjIgzql1JpBcxZkej06-A,10848
21
- qnty/equations/system.py,sha256=mgslAh_YgEU1V_y48Yy1_eHIFO37vDsSG4Gb3zeuPxc,5115
22
- qnty/expressions/__init__.py,sha256=qo5I-Z3O1hP9Kk1Jgf5r7x4tAzMLS-a96rY5cqRNVKc,917
23
- qnty/expressions/cache.py,sha256=ahJ-AyxJJQyGAVQWSEcQAng1TdQ2qysBPiujk9hhink,3413
24
- qnty/expressions/functions.py,sha256=X7Cfchmc4qY3JE3NnacI5DomYE0jPbAAQHOsrxG3vqk,3618
25
- qnty/expressions/nodes.py,sha256=bTmpJ36sjnlxgKb2npJfh56K1arN-FOxoiI30Gx31-g,23394
26
- qnty/generated/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
- qnty/generated/dimensions.py,sha256=WHVr28Ou2DB2QuZCDcxLY2AcauqdE4QGrNFNUJ2EDXY,20661
28
- qnty/generated/quantities.py,sha256=1FC1P_hIcXotUgDiJXy28P9OCq2jdWEmO5aVZJepNpY,245345
29
- qnty/generated/quantities.pyi,sha256=URYr8K2JVeXlwbSnUvOLoLYS9beVhGrL33A7Y1hs1Hs,151386
30
- qnty/generated/setters.py,sha256=Go62i_TlfcBztI8rI7h2FMWGmtoVPGc3JTx6ZmJMrWI,446272
31
- qnty/generated/units.py,sha256=WXkSL_G4hKzbTiGmN3jreWCuUyutyGb50tRwfT0Xje4,285245
32
- qnty/problem/__init__.py,sha256=9bML5bjM-uPAHet8n98_OwQLivEs2mzaHjZhENbA7sE,3140
33
- qnty/problem/base.py,sha256=jepN3vmMyh9eXptJrAQfPICHbDPLQsD2g9k4EY7IqrA,5680
34
- qnty/problem/composition.py,sha256=DUdJ7oMl1d4ETqgR4rDflqfBOdE2ykr-f6qONOErfZQ,13894
35
- qnty/problem/composition_mixin.py,sha256=hH9bEZyWc5vz5LfLb7GM2K6WDP7SUgHWUu_Vx4BtEM0,17603
36
- qnty/problem/equations.py,sha256=QefhpWBQt9OD0vUeYRZs54iv7kQ9xkO0XBtYBtOjfPE,19334
37
- qnty/problem/metaclass.py,sha256=00T4fg3ACeTo7w1njRgZyOGP2jZm2P2_yxO0rZlnwhE,11944
38
- qnty/problem/reconstruction.py,sha256=hE7L5Eh2OH3nR_3PFKsSiNRHDSbgSumrhXxPRESmJXI,40042
39
- qnty/problem/solving.py,sha256=DJ_Dj63vn2ykdFUp77QNxEGOWmPrAzpLe7A_mnCkMzs,6657
40
- qnty/problem/validation.py,sha256=1Kbebn4JvYO0qw2VOhfeyzzkuSmnTpOANpvVmsXcNuU,2157
41
- qnty/problem/variables.py,sha256=Fmhc-GmW-tHMQk1YVtHgOQlfvRJxH1le94Nc0HmeyBY,9911
42
- qnty/quantities/__init__.py,sha256=C8Z032FGpMVt9-PvtIQLNZkxmXjbHUm2OHoytebUL1g,107
43
- qnty/quantities/expression_quantity.py,sha256=khJ5izSaj497-rd6Ci1p8XyBidwAoXFlqpBiOqVbi3A,13278
44
- qnty/quantities/quantity.py,sha256=PK1vGMZv55fy87ysvakVipO0lWK_XySKZCobJfKMjTQ,18855
45
- qnty/quantities/typed_quantity.py,sha256=-PL_6qhJvOLdGXoxJjCHiCx3ZB5Oao9l-e2zrON3cug,9681
46
- qnty/solving/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
- qnty/solving/manager.py,sha256=FfG3DOrwAKeR0vHll46RtkLB9ZuWN43mthYHnr5AW98,3594
48
- qnty/solving/order.py,sha256=Z7I_7QonCaGC47DthC2O0m77On34GcaD7nn2oLIFmqs,14411
49
- qnty/solving/solvers/__init__.py,sha256=CBI2PGLhnQ3AVsfJPfBB7b0ff_BlPCRamGUIHjEMStM,501
50
- qnty/solving/solvers/base.py,sha256=KYACgawfo8GoRaXEduZRQjJeo948QNFU76N2VrCwcA4,3041
51
- qnty/solving/solvers/iterative.py,sha256=5SxIGMdP1HkAKsT6cXZR7Lxv3LIgM7dXY3PsTn0w_d4,8139
52
- qnty/solving/solvers/simultaneous.py,sha256=pqYUwh067z26kP49Nxq8HcCxsxB0dirPaVHMWG4QMTE,23225
53
- qnty/units/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
- qnty/units/prefixes.py,sha256=U-dGj5ZdseErwFIzvz_RC3fID0D-DazE6ozD6vn4DSs,7442
55
- qnty/units/registry.py,sha256=rnKnEaG8rZg56ejK1nGl9xpe9hm1WmWAtD8tJ0A0MvA,7524
56
- qnty/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
- qnty/utils/logging.py,sha256=QSYgZg6w1n9L-lIj5c3Ufee84E8VvRZOUgoW84vTUbA,1159
58
- qnty/validation/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
59
- qnty/validation/registry.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
- qnty/validation/rules.py,sha256=4X3pR6bl9YA5skT2vRmJFB78FR588Rz_cSTTJXD0BDI,6285
61
- qnty-0.0.9.dist-info/METADATA,sha256=AKPCK06zvVod4ss5nmYHmCgActFnehcUGRF8b7cIfLo,6761
62
- qnty-0.0.9.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
63
- qnty-0.0.9.dist-info/RECORD,,
File without changes
File without changes
File without changes