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.
- qnty/__init__.py +2 -3
- qnty/constants/__init__.py +10 -0
- qnty/constants/numerical.py +18 -0
- qnty/constants/solvers.py +6 -0
- qnty/constants/tests.py +6 -0
- qnty/dimensions/__init__.py +23 -0
- qnty/dimensions/base.py +97 -0
- qnty/dimensions/field_dims.py +126 -0
- qnty/dimensions/field_dims.pyi +128 -0
- qnty/dimensions/signature.py +111 -0
- qnty/equations/__init__.py +1 -1
- qnty/equations/equation.py +118 -155
- qnty/equations/system.py +68 -65
- qnty/expressions/__init__.py +25 -46
- qnty/expressions/formatter.py +188 -0
- qnty/expressions/functions.py +46 -68
- qnty/expressions/nodes.py +539 -384
- qnty/expressions/types.py +70 -0
- qnty/problems/__init__.py +145 -0
- qnty/problems/composition.py +1031 -0
- qnty/problems/problem.py +695 -0
- qnty/problems/rules.py +145 -0
- qnty/problems/solving.py +1216 -0
- qnty/problems/validation.py +127 -0
- qnty/quantities/__init__.py +28 -5
- qnty/quantities/base_qnty.py +677 -0
- qnty/quantities/field_converters.py +24004 -0
- qnty/quantities/field_qnty.py +1012 -0
- qnty/{generated/setters.py → quantities/field_setter.py} +3071 -2961
- qnty/{generated/quantities.py → quantities/field_vars.py} +754 -432
- qnty/{generated/quantities.pyi → quantities/field_vars.pyi} +1289 -1290
- qnty/solving/manager.py +50 -44
- qnty/solving/order.py +181 -133
- qnty/solving/solvers/__init__.py +2 -9
- qnty/solving/solvers/base.py +27 -37
- qnty/solving/solvers/iterative.py +115 -135
- qnty/solving/solvers/simultaneous.py +93 -165
- qnty/units/__init__.py +1 -0
- qnty/{generated/units.py → units/field_units.py} +1700 -991
- qnty/units/field_units.pyi +2461 -0
- qnty/units/prefixes.py +58 -105
- qnty/units/registry.py +76 -89
- qnty/utils/__init__.py +16 -0
- qnty/utils/caching/__init__.py +23 -0
- qnty/utils/caching/manager.py +401 -0
- qnty/utils/error_handling/__init__.py +66 -0
- qnty/utils/error_handling/context.py +39 -0
- qnty/utils/error_handling/exceptions.py +96 -0
- qnty/utils/error_handling/handlers.py +171 -0
- qnty/utils/logging.py +4 -4
- qnty/utils/protocols.py +164 -0
- qnty/utils/scope_discovery.py +420 -0
- {qnty-0.0.9.dist-info → qnty-0.1.0.dist-info}/METADATA +1 -1
- qnty-0.1.0.dist-info/RECORD +60 -0
- qnty/_backup/problem_original.py +0 -1251
- qnty/_backup/quantity.py +0 -63
- qnty/codegen/cli.py +0 -125
- qnty/codegen/generators/data/unit_data.json +0 -8807
- qnty/codegen/generators/data_processor.py +0 -345
- qnty/codegen/generators/dimensions_gen.py +0 -434
- qnty/codegen/generators/doc_generator.py +0 -141
- qnty/codegen/generators/out/dimension_mapping.json +0 -974
- qnty/codegen/generators/out/dimension_metadata.json +0 -123
- qnty/codegen/generators/out/units_metadata.json +0 -223
- qnty/codegen/generators/quantities_gen.py +0 -159
- qnty/codegen/generators/setters_gen.py +0 -178
- qnty/codegen/generators/stubs_gen.py +0 -167
- qnty/codegen/generators/units_gen.py +0 -295
- qnty/expressions/cache.py +0 -94
- qnty/generated/dimensions.py +0 -514
- qnty/problem/__init__.py +0 -91
- qnty/problem/base.py +0 -142
- qnty/problem/composition.py +0 -385
- qnty/problem/composition_mixin.py +0 -382
- qnty/problem/equations.py +0 -413
- qnty/problem/metaclass.py +0 -302
- qnty/problem/reconstruction.py +0 -1016
- qnty/problem/solving.py +0 -180
- qnty/problem/validation.py +0 -64
- qnty/problem/variables.py +0 -239
- qnty/quantities/expression_quantity.py +0 -314
- qnty/quantities/quantity.py +0 -428
- qnty/quantities/typed_quantity.py +0 -215
- qnty/validation/__init__.py +0 -0
- qnty/validation/registry.py +0 -0
- qnty/validation/rules.py +0 -167
- qnty-0.0.9.dist-info/RECORD +0 -63
- /qnty/{codegen → extensions}/__init__.py +0 -0
- /qnty/{codegen/generators → extensions/integration}/__init__.py +0 -0
- /qnty/{codegen/generators/utils → extensions/plotting}/__init__.py +0 -0
- /qnty/{generated → extensions/reporting}/__init__.py +0 -0
- {qnty-0.0.9.dist-info → qnty-0.1.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
"""
|
2
|
+
Expression Type Definitions
|
3
|
+
===========================
|
4
|
+
|
5
|
+
Type definitions and protocols to avoid circular imports.
|
6
|
+
"""
|
7
|
+
|
8
|
+
from __future__ import annotations
|
9
|
+
|
10
|
+
from typing import Protocol
|
11
|
+
from ..quantities import FieldQnty, Quantity
|
12
|
+
|
13
|
+
|
14
|
+
class ExpressionProtocol(Protocol):
|
15
|
+
"""Protocol for expression objects."""
|
16
|
+
|
17
|
+
def evaluate(self, variable_values: dict[str, FieldQnty]) -> Quantity:
|
18
|
+
"""Evaluate the expression with given variables."""
|
19
|
+
...
|
20
|
+
|
21
|
+
|
22
|
+
class VariableReferenceProtocol(Protocol):
|
23
|
+
"""Protocol for variable reference objects."""
|
24
|
+
|
25
|
+
name: str
|
26
|
+
|
27
|
+
def evaluate(self, variable_values: dict[str, FieldQnty]) -> Quantity:
|
28
|
+
"""Evaluate the variable reference."""
|
29
|
+
...
|
30
|
+
|
31
|
+
|
32
|
+
class ConstantProtocol(Protocol):
|
33
|
+
"""Protocol for constant objects."""
|
34
|
+
|
35
|
+
value: Quantity
|
36
|
+
|
37
|
+
def evaluate(self, variable_values: dict[str, FieldQnty]) -> Quantity:
|
38
|
+
"""Evaluate the constant."""
|
39
|
+
...
|
40
|
+
|
41
|
+
|
42
|
+
class BinaryOperationProtocol(Protocol):
|
43
|
+
"""Protocol for binary operation objects."""
|
44
|
+
|
45
|
+
left: ExpressionProtocol
|
46
|
+
right: ExpressionProtocol
|
47
|
+
operator: str
|
48
|
+
|
49
|
+
def evaluate(self, variable_values: dict[str, FieldQnty]) -> Quantity:
|
50
|
+
"""Evaluate the binary operation."""
|
51
|
+
...
|
52
|
+
|
53
|
+
def _can_auto_evaluate(self) -> tuple[bool, dict[str, FieldQnty] | None]:
|
54
|
+
"""Check if auto-evaluation is possible."""
|
55
|
+
...
|
56
|
+
|
57
|
+
|
58
|
+
class UnaryFunctionProtocol(Protocol):
|
59
|
+
"""Protocol for unary function objects."""
|
60
|
+
|
61
|
+
function_name: str
|
62
|
+
operand: ExpressionProtocol
|
63
|
+
|
64
|
+
|
65
|
+
class ConditionalExpressionProtocol(Protocol):
|
66
|
+
"""Protocol for conditional expression objects."""
|
67
|
+
|
68
|
+
condition: ExpressionProtocol
|
69
|
+
true_expr: ExpressionProtocol
|
70
|
+
false_expr: ExpressionProtocol
|
@@ -0,0 +1,145 @@
|
|
1
|
+
"""
|
2
|
+
Consolidated Problem system for engineering calculations.
|
3
|
+
|
4
|
+
This module provides a streamlined Problem system with 4 focused files instead of 15+:
|
5
|
+
- problem.py: Main Problem class with variable and equation management
|
6
|
+
- composition.py: Sub-problem composition with metaclass system
|
7
|
+
- solving.py: Problem solving with equation reconstruction
|
8
|
+
- validation.py: Problem validation integration
|
9
|
+
|
10
|
+
The system maintains full backward compatibility with the original Problem API.
|
11
|
+
"""
|
12
|
+
|
13
|
+
from .composition import (
|
14
|
+
CompositionMixin,
|
15
|
+
ConfigurableVariable,
|
16
|
+
DelayedEquation,
|
17
|
+
DelayedExpression,
|
18
|
+
DelayedFunction,
|
19
|
+
DelayedVariableReference,
|
20
|
+
MetaclassError,
|
21
|
+
NamespaceError,
|
22
|
+
ProblemMeta,
|
23
|
+
ProxiedNamespace,
|
24
|
+
SubProblemProxy,
|
25
|
+
SubProblemProxyError,
|
26
|
+
delayed_max_expr,
|
27
|
+
delayed_min_expr,
|
28
|
+
delayed_sin,
|
29
|
+
)
|
30
|
+
from .problem import EquationValidationError, SolverError, ValidationMixin, VariableNotFoundError
|
31
|
+
from .problem import Problem as BaseProblem
|
32
|
+
from .solving import (
|
33
|
+
CompositeExpressionRebuilder,
|
34
|
+
DelayedExpressionResolver,
|
35
|
+
EquationReconstructionError,
|
36
|
+
EquationReconstructor,
|
37
|
+
ExpressionParser,
|
38
|
+
MalformedExpressionError,
|
39
|
+
NamespaceMapper,
|
40
|
+
NamespaceMappingError,
|
41
|
+
PatternReconstructionError,
|
42
|
+
)
|
43
|
+
|
44
|
+
# ValidationMixin is already imported from .problem above
|
45
|
+
|
46
|
+
# ========== INTEGRATED PROBLEM CLASS ==========
|
47
|
+
|
48
|
+
|
49
|
+
class Problem(BaseProblem, CompositionMixin, metaclass=ProblemMeta):
|
50
|
+
"""
|
51
|
+
Main container class for engineering problems with composition support.
|
52
|
+
|
53
|
+
This class integrates all aspects of engineering problem definition, solving, and analysis.
|
54
|
+
It supports both programmatic problem construction and class-level inheritance patterns
|
55
|
+
for defining domain-specific engineering problems with sub-problem composition.
|
56
|
+
|
57
|
+
Key Features:
|
58
|
+
- Automatic dependency graph construction and topological solving order
|
59
|
+
- Dual solving approach: SymPy symbolic solving with numerical fallback
|
60
|
+
- Sub-problem composition with automatic variable namespacing
|
61
|
+
- Comprehensive validation and error handling
|
62
|
+
- Professional report generation capabilities
|
63
|
+
|
64
|
+
Usage Patterns:
|
65
|
+
1. Inheritance Pattern (Recommended for domain problems):
|
66
|
+
class MyProblem(Problem):
|
67
|
+
x = Variable("x", Qty(5.0, length))
|
68
|
+
y = Variable("y", Qty(0.0, length), is_known=False)
|
69
|
+
eq = y.equals(x * 2)
|
70
|
+
|
71
|
+
2. Programmatic Pattern (For dynamic problems):
|
72
|
+
problem = Problem("Dynamic Problem")
|
73
|
+
problem.add_variables(x, y)
|
74
|
+
problem.add_equation(y.equals(x * 2))
|
75
|
+
|
76
|
+
3. Composition Pattern (For reusable sub-problems):
|
77
|
+
class ComposedProblem(Problem):
|
78
|
+
sub1 = create_sub_problem()
|
79
|
+
sub2 = create_sub_problem()
|
80
|
+
# Equations can reference sub1.variable, sub2.variable
|
81
|
+
|
82
|
+
Attributes:
|
83
|
+
name (str): Human-readable name for the problem
|
84
|
+
description (str): Detailed description of the problem
|
85
|
+
variables (dict[str, Variable]): All variables in the problem
|
86
|
+
equations (list[Equation]): All equations in the problem
|
87
|
+
is_solved (bool): Whether the problem has been successfully solved
|
88
|
+
solution (dict[str, Variable]): Solved variable values
|
89
|
+
sub_problems (dict[str, Problem]): Integrated sub-problems
|
90
|
+
"""
|
91
|
+
|
92
|
+
def __init__(self, name: str | None = None, description: str = ""):
|
93
|
+
# Initialize the base Problem class
|
94
|
+
super().__init__(name, description)
|
95
|
+
|
96
|
+
# Auto-populate from class-level variables and equations (subclass pattern)
|
97
|
+
# This is handled by the CompositionMixin via _extract_from_class_variables()
|
98
|
+
self._extract_from_class_variables()
|
99
|
+
|
100
|
+
|
101
|
+
# ========== BACKWARD COMPATIBILITY ALIASES ==========
|
102
|
+
|
103
|
+
# Alias for backward compatibility
|
104
|
+
EngineeringProblem = Problem
|
105
|
+
|
106
|
+
# Export all relevant classes and exceptions for compatibility
|
107
|
+
__all__ = [
|
108
|
+
# Main classes
|
109
|
+
"Problem",
|
110
|
+
"EngineeringProblem",
|
111
|
+
# Mixins
|
112
|
+
"ValidationMixin",
|
113
|
+
"CompositionMixin",
|
114
|
+
# Metaclass system
|
115
|
+
"ProblemMeta",
|
116
|
+
"ProxiedNamespace",
|
117
|
+
# Composition classes
|
118
|
+
"SubProblemProxy",
|
119
|
+
"ConfigurableVariable",
|
120
|
+
"DelayedEquation",
|
121
|
+
"DelayedVariableReference",
|
122
|
+
"DelayedExpression",
|
123
|
+
"DelayedFunction",
|
124
|
+
# Delayed function factories
|
125
|
+
"delayed_sin",
|
126
|
+
"delayed_min_expr",
|
127
|
+
"delayed_max_expr",
|
128
|
+
# Reconstruction system
|
129
|
+
"EquationReconstructor",
|
130
|
+
"ExpressionParser",
|
131
|
+
"NamespaceMapper",
|
132
|
+
"CompositeExpressionRebuilder",
|
133
|
+
"DelayedExpressionResolver",
|
134
|
+
# Exceptions
|
135
|
+
"VariableNotFoundError",
|
136
|
+
"EquationValidationError",
|
137
|
+
"SolverError",
|
138
|
+
"MetaclassError",
|
139
|
+
"SubProblemProxyError",
|
140
|
+
"NamespaceError",
|
141
|
+
"EquationReconstructionError",
|
142
|
+
"MalformedExpressionError",
|
143
|
+
"NamespaceMappingError",
|
144
|
+
"PatternReconstructionError",
|
145
|
+
]
|