openscvx 0.3.2.dev170__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.
Potentially problematic release.
This version of openscvx might be problematic. Click here for more details.
- openscvx/__init__.py +123 -0
- openscvx/_version.py +34 -0
- openscvx/algorithms/__init__.py +92 -0
- openscvx/algorithms/autotuning.py +24 -0
- openscvx/algorithms/base.py +351 -0
- openscvx/algorithms/optimization_results.py +215 -0
- openscvx/algorithms/penalized_trust_region.py +384 -0
- openscvx/config.py +437 -0
- openscvx/discretization/__init__.py +47 -0
- openscvx/discretization/discretization.py +236 -0
- openscvx/expert/__init__.py +23 -0
- openscvx/expert/byof.py +326 -0
- openscvx/expert/lowering.py +419 -0
- openscvx/expert/validation.py +357 -0
- openscvx/integrators/__init__.py +48 -0
- openscvx/integrators/runge_kutta.py +281 -0
- openscvx/lowered/__init__.py +30 -0
- openscvx/lowered/cvxpy_constraints.py +23 -0
- openscvx/lowered/cvxpy_variables.py +124 -0
- openscvx/lowered/dynamics.py +34 -0
- openscvx/lowered/jax_constraints.py +133 -0
- openscvx/lowered/parameters.py +54 -0
- openscvx/lowered/problem.py +70 -0
- openscvx/lowered/unified.py +718 -0
- openscvx/plotting/__init__.py +63 -0
- openscvx/plotting/plotting.py +756 -0
- openscvx/plotting/scp_iteration.py +299 -0
- openscvx/plotting/viser/__init__.py +126 -0
- openscvx/plotting/viser/animated.py +605 -0
- openscvx/plotting/viser/plotly_integration.py +333 -0
- openscvx/plotting/viser/primitives.py +355 -0
- openscvx/plotting/viser/scp.py +459 -0
- openscvx/plotting/viser/server.py +112 -0
- openscvx/problem.py +734 -0
- openscvx/propagation/__init__.py +60 -0
- openscvx/propagation/post_processing.py +104 -0
- openscvx/propagation/propagation.py +248 -0
- openscvx/solvers/__init__.py +51 -0
- openscvx/solvers/cvxpy.py +226 -0
- openscvx/symbolic/__init__.py +9 -0
- openscvx/symbolic/augmentation.py +630 -0
- openscvx/symbolic/builder.py +492 -0
- openscvx/symbolic/constraint_set.py +92 -0
- openscvx/symbolic/expr/__init__.py +222 -0
- openscvx/symbolic/expr/arithmetic.py +517 -0
- openscvx/symbolic/expr/array.py +632 -0
- openscvx/symbolic/expr/constraint.py +796 -0
- openscvx/symbolic/expr/control.py +135 -0
- openscvx/symbolic/expr/expr.py +720 -0
- openscvx/symbolic/expr/lie/__init__.py +87 -0
- openscvx/symbolic/expr/lie/adjoint.py +357 -0
- openscvx/symbolic/expr/lie/se3.py +172 -0
- openscvx/symbolic/expr/lie/so3.py +138 -0
- openscvx/symbolic/expr/linalg.py +279 -0
- openscvx/symbolic/expr/math.py +699 -0
- openscvx/symbolic/expr/spatial.py +209 -0
- openscvx/symbolic/expr/state.py +607 -0
- openscvx/symbolic/expr/stl.py +136 -0
- openscvx/symbolic/expr/variable.py +321 -0
- openscvx/symbolic/hashing.py +112 -0
- openscvx/symbolic/lower.py +760 -0
- openscvx/symbolic/lowerers/__init__.py +106 -0
- openscvx/symbolic/lowerers/cvxpy.py +1302 -0
- openscvx/symbolic/lowerers/jax.py +1382 -0
- openscvx/symbolic/preprocessing.py +757 -0
- openscvx/symbolic/problem.py +110 -0
- openscvx/symbolic/time.py +116 -0
- openscvx/symbolic/unified.py +420 -0
- openscvx/utils/__init__.py +20 -0
- openscvx/utils/cache.py +131 -0
- openscvx/utils/caching.py +210 -0
- openscvx/utils/printing.py +301 -0
- openscvx/utils/profiling.py +37 -0
- openscvx/utils/utils.py +100 -0
- openscvx-0.3.2.dev170.dist-info/METADATA +350 -0
- openscvx-0.3.2.dev170.dist-info/RECORD +79 -0
- openscvx-0.3.2.dev170.dist-info/WHEEL +5 -0
- openscvx-0.3.2.dev170.dist-info/licenses/LICENSE +201 -0
- openscvx-0.3.2.dev170.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Lowering backends for converting symbolic expressions to executable code.
|
|
2
|
+
|
|
3
|
+
This package contains backend implementations that translate openscvx's symbolic
|
|
4
|
+
expression AST into executable code for different computational frameworks. The
|
|
5
|
+
lowering process is a compilation step that happens after symbolic problem
|
|
6
|
+
construction but before numerical optimization.
|
|
7
|
+
|
|
8
|
+
Architecture:
|
|
9
|
+
All lowerers in this package follow a common visitor pattern:
|
|
10
|
+
|
|
11
|
+
1. **Visitor Pattern**: Each backend defines visitor methods for each expression
|
|
12
|
+
type, registered via the @visitor decorator
|
|
13
|
+
2. **Recursive Lowering**: Visitors recursively lower child expressions and
|
|
14
|
+
compose backend-specific operations
|
|
15
|
+
3. **Centralized Dispatch**: The dispatch() function routes expressions to
|
|
16
|
+
their registered visitor methods
|
|
17
|
+
4. **Type Safety**: Each visitor is strongly typed to its backend's output format
|
|
18
|
+
|
|
19
|
+
Available Backends:
|
|
20
|
+
- **jax**: Lowers to JAX functions with automatic differentiation support
|
|
21
|
+
- **cvxpy**: Lowers to CVXPy expressions for disciplined convex programming
|
|
22
|
+
|
|
23
|
+
See individual backend modules for detailed documentation and usage examples.
|
|
24
|
+
|
|
25
|
+
For Contributors:
|
|
26
|
+
**Adding a New Backend**
|
|
27
|
+
|
|
28
|
+
To add a new lowering backend:
|
|
29
|
+
|
|
30
|
+
1. **Create a new module** in this package (e.g., `mybackend.py`)
|
|
31
|
+
|
|
32
|
+
2. **Implement the visitor pattern**::
|
|
33
|
+
|
|
34
|
+
from typing import Dict, Type, Callable, Any
|
|
35
|
+
from openscvx.symbolic.expr import Expr
|
|
36
|
+
|
|
37
|
+
_MYBACKEND_VISITORS: Dict[Type[Expr], Callable] = {}
|
|
38
|
+
|
|
39
|
+
def visitor(expr_cls: Type[Expr]):
|
|
40
|
+
'''Decorator to register visitor methods.'''
|
|
41
|
+
def register(fn: Callable):
|
|
42
|
+
_MYBACKEND_VISITORS[expr_cls] = fn
|
|
43
|
+
return fn
|
|
44
|
+
return register
|
|
45
|
+
|
|
46
|
+
def dispatch(lowerer: Any, expr: Expr):
|
|
47
|
+
'''Dispatch expression to registered visitor.'''
|
|
48
|
+
fn = _MYBACKEND_VISITORS.get(type(expr))
|
|
49
|
+
if fn is None:
|
|
50
|
+
raise NotImplementedError(
|
|
51
|
+
f"{lowerer.__class__.__name__} has no visitor for {type(expr).__name__}"
|
|
52
|
+
)
|
|
53
|
+
return fn(lowerer, expr)
|
|
54
|
+
|
|
55
|
+
3. **Create the lowerer class**::
|
|
56
|
+
|
|
57
|
+
class MyBackendLowerer:
|
|
58
|
+
'''Lower symbolic expressions to MyBackend format.'''
|
|
59
|
+
|
|
60
|
+
def lower(self, expr: Expr):
|
|
61
|
+
'''Main entry point for lowering.'''
|
|
62
|
+
return dispatch(self, expr)
|
|
63
|
+
|
|
64
|
+
@visitor(Constant)
|
|
65
|
+
def _visit_constant(self, node: Constant):
|
|
66
|
+
# Convert to backend representation
|
|
67
|
+
return mybackend.constant(node.value)
|
|
68
|
+
|
|
69
|
+
@visitor(Add)
|
|
70
|
+
def _visit_add(self, node: Add):
|
|
71
|
+
# Recursively lower and combine
|
|
72
|
+
terms = [self.lower(t) for t in node.terms]
|
|
73
|
+
return mybackend.add(*terms)
|
|
74
|
+
|
|
75
|
+
# Implement visitors for all expression types...
|
|
76
|
+
|
|
77
|
+
4. **Add convenience wrapper**::
|
|
78
|
+
|
|
79
|
+
def lower_to_mybackend(expr: Expr, **kwargs):
|
|
80
|
+
'''Convenience function for lowering to MyBackend.'''
|
|
81
|
+
lowerer = MyBackendLowerer(**kwargs)
|
|
82
|
+
return lowerer.lower(expr)
|
|
83
|
+
|
|
84
|
+
5. **Document thoroughly** - Follow the documentation patterns in jax.py
|
|
85
|
+
and cvxpy.py, including module docstring, class docstring, and method
|
|
86
|
+
docstrings for all visitor methods.
|
|
87
|
+
|
|
88
|
+
**Key Design Patterns**
|
|
89
|
+
|
|
90
|
+
- Use private method names for visitors: `_visit_*` (not part of public API)
|
|
91
|
+
- Recursively lower child expressions using `self.lower()`
|
|
92
|
+
- Keep visitor methods stateless when possible
|
|
93
|
+
- Handle edge cases (scalars, empty arrays, etc.)
|
|
94
|
+
- Document mathematical properties and backend-specific constraints
|
|
95
|
+
|
|
96
|
+
**Adding Support for New Expression Types**
|
|
97
|
+
|
|
98
|
+
See the "For Contributors" sections in the existing backend modules for
|
|
99
|
+
detailed guidance on adding visitor methods for new expression types.
|
|
100
|
+
|
|
101
|
+
See Also:
|
|
102
|
+
- openscvx.symbolic.lower: Main lowering orchestration functions
|
|
103
|
+
- openscvx.symbolic.expr: Symbolic expression AST definitions
|
|
104
|
+
- openscvx.symbolic.lowerers.jax: JAX backend documentation and implementation
|
|
105
|
+
- openscvx.symbolic.lowerers.cvxpy: CVXPy backend documentation and implementation
|
|
106
|
+
"""
|