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
@@ -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
File without changes
File without changes
@@ -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
+ ]