Skip to content

Commit eda4d5e

Browse files
committed
Merge branch 'main' of github.com:cram2/semantic_world into object_knowledge
2 parents a09d63d + 8b16c36 commit eda4d5e

25 files changed

Lines changed: 1407 additions & 2867 deletions

src/semantic_digital_twin/adapters/multi_sim.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
from ..world_description.world_modification import (
4949
AddKinematicStructureEntityModification,
5050
)
51-
from ..spatial_types.symbol_manager import symbol_manager
5251

5352

5453
def cas_pose_to_list(pose: TransformationMatrix) -> List[float]:
@@ -60,8 +59,8 @@ def cas_pose_to_list(pose: TransformationMatrix) -> List[float]:
6059
"""
6160
pos = pose.to_position()
6261
quat = pose.to_quaternion()
63-
px, py, pz, _ = symbol_manager.evaluate_expr(pos).tolist()
64-
qx, qy, qz, qw = symbol_manager.evaluate_expr(quat).tolist()
62+
px, py, pz, _ = pos.evaluate().tolist()
63+
qx, qy, qz, qw = quat.evaluate().tolist()
6564
return [px, py, pz, qw, qx, qy, qz]
6665

6766

src/semantic_digital_twin/adapters/world_entity_kwargs_tracker.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ def add_kinematic_structure_entity(
9393
)
9494

9595
def has_kinematic_structure_entity(self, name: PrefixedName) -> bool:
96-
return name in self._kinematic_structure_entities
96+
try:
97+
self.get_kinematic_structure_entity(name)
98+
return True
99+
except KinematicStructureEntityNotInKwargs:
100+
return False
97101

98102
def get_kinematic_structure_entity(
99103
self, name: PrefixedName

src/semantic_digital_twin/datastructures/prefixed_name.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def __hash__(self):
1515
return hash((self.prefix, self.name))
1616

1717
def __str__(self):
18+
if self.prefix is None:
19+
return self.name
1820
return f"{self.prefix}/{self.name}"
1921

2022
def __eq__(self, other):

src/semantic_digital_twin/exceptions.py

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
WorldEntity,
2323
KinematicStructureEntity,
2424
)
25-
from .spatial_types.spatial_types import Symbol, SymbolicType
25+
from .spatial_types.spatial_types import FloatVariable, SymbolicType
2626

2727

2828
class LogicalError(Exception):
@@ -73,33 +73,6 @@ def __post_init__(self):
7373
super().__init__(msg)
7474

7575

76-
class SymbolManagerException(Exception):
77-
"""
78-
Exceptions related to the symbol manager for special types.
79-
"""
80-
81-
82-
@dataclass
83-
class SymbolResolutionError(SymbolManagerException):
84-
"""
85-
Represents an error that occurs when a symbol in a symbolic expression cannot be resolved.
86-
87-
This exception is raised when the resolution of a symbol fails due to
88-
underlying exceptions or unresolved states. It provides details about
89-
the symbol that caused the error and the original exception responsible
90-
for the failure.
91-
"""
92-
93-
symbol: Symbol
94-
original_exception: Exception
95-
96-
def __post_init__(self):
97-
super().__init__(
98-
f'Symbol "{self.symbol.name}" could not be resolved. '
99-
f"({self.original_exception.__class__.__name__}: {str(self.original_exception)})"
100-
)
101-
102-
10376
class SpatialTypesError(UsageError):
10477
pass
10578

@@ -134,28 +107,41 @@ def __post_init__(self):
134107

135108

136109
@dataclass
137-
class HasFreeSymbolsError(SpatialTypesError):
110+
class HasFreeVariablesError(SpatialTypesError):
138111
"""
139-
Raised when an operation can't be performed on an expression with free symbols.
112+
Raised when an operation can't be performed on an expression with free variables.
140113
"""
141114

142-
symbols: List[Symbol]
115+
variables: List[FloatVariable]
116+
117+
def __post_init__(self):
118+
msg = f"Operation can't be performed on expression with free variables: {self.variables}."
119+
super().__init__(msg)
120+
121+
122+
class ExpressionEvaluationError(SpatialTypesError): ...
123+
124+
125+
@dataclass
126+
class WrongNumberOfArgsError(ExpressionEvaluationError):
127+
expected_number_of_args: int
128+
actual_number_of_args: int
143129

144130
def __post_init__(self):
145-
msg = f"Operation can't be performed on expression with free symbols: {self.symbols}."
131+
msg = f"Expected {self.expected_number_of_args} arguments, but got {self.actual_number_of_args}."
146132
super().__init__(msg)
147133

148134

149135
@dataclass
150-
class DuplicateSymbolsError(SpatialTypesError):
136+
class DuplicateVariablesError(SpatialTypesError):
151137
"""
152-
Raised when duplicate symbols are found in an operation that requires unique symbols.
138+
Raised when duplicate variables are found in an operation that requires unique variables.
153139
"""
154140

155-
symbols: List[Symbol]
141+
variables: List[FloatVariable]
156142

157143
def __post_init__(self):
158-
msg = f"Operation failed due to duplicate symbols: {self.symbols}. All symbols must be unique."
144+
msg = f"Operation failed due to duplicate variables: {self.variables}. All variables must be unique."
159145
super().__init__(msg)
160146

161147

@@ -206,7 +192,7 @@ class SpatialTypeNotJsonSerializable(NotJsonSerializable):
206192
def __post_init__(self):
207193
super().__init__(
208194
f"Object of type '{self.spatial_object.__class__.__name__}' is not JSON serializable, because it has "
209-
f"free variables: {self.spatial_object.free_symbols()}"
195+
f"free variables: {self.spatial_object.free_variables()}"
210196
)
211197

212198

src/semantic_digital_twin/orm/model.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from ..spatial_types import RotationMatrix, Vector3, Point3, TransformationMatrix
1414
from ..spatial_types.derivatives import DerivativeMap
1515
from ..spatial_types.spatial_types import Quaternion
16-
from ..spatial_types.symbol_manager import symbol_manager
1716
from ..world import World
1817
from ..world_description.connections import Connection
1918
from ..world_description.degree_of_freedom import DegreeOfFreedom
@@ -99,7 +98,7 @@ class Vector3Mapping(AlternativeMapping[Vector3]):
9998

10099
@classmethod
101100
def create_instance(cls, obj: Vector3):
102-
x, y, z, _ = symbol_manager.evaluate_expr(obj).tolist()
101+
x, y, z, _ = obj.to_np().tolist()
103102
result = cls(x=x, y=y, z=z)
104103
result.reference_frame = obj.reference_frame
105104
return result
@@ -122,7 +121,7 @@ class Point3Mapping(AlternativeMapping[Point3]):
122121

123122
@classmethod
124123
def create_instance(cls, obj: Point3):
125-
x, y, z, _ = symbol_manager.evaluate_expr(obj).tolist()
124+
x, y, z, _ = obj.to_np().tolist()
126125
result = cls(x=x, y=y, z=z)
127126
result.reference_frame = obj.reference_frame
128127
return result
@@ -144,7 +143,7 @@ class QuaternionMapping(AlternativeMapping[Quaternion]):
144143

145144
@classmethod
146145
def create_instance(cls, obj: Quaternion):
147-
x, y, z, w = symbol_manager.evaluate_expr(obj).tolist()
146+
x, y, z, w = obj.to_np().tolist()
148147
result = cls(x=x, y=y, z=z, w=w)
149148
result.reference_frame = obj.reference_frame
150149
return result

0 commit comments

Comments
 (0)