Skip to content

Commit

Permalink
⚡ perf(Optimization): Avoid superfluous DB calls (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
glatterf42 authored Jan 16, 2025
1 parent 0deac5b commit c243743
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions ixmp4/core/optimization/equation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ def add(self, data: dict[str, Any] | pd.DataFrame) -> None:
self.backend.optimization.equations.add_data(
equation_id=self._model.id, data=data
)
self._model.data = self.backend.optimization.equations.get(
self._model = self.backend.optimization.equations.get(
run_id=self._model.run__id, name=self._model.name
).data
)

def remove_data(self) -> None:
"""Removes data from an existing Equation."""
self.backend.optimization.equations.remove_data(equation_id=self._model.id)
self._model.data = self.backend.optimization.equations.get(
self._model = self.backend.optimization.equations.get(
run_id=self._model.run__id, name=self._model.name
).data
)

@property
def levels(self) -> list[float]:
Expand Down
4 changes: 2 additions & 2 deletions ixmp4/core/optimization/indexset.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def add(
self.backend.optimization.indexsets.add_data(
indexset_id=self._model.id, data=data
)
self._model.data = self.backend.optimization.indexsets.get(
self._model = self.backend.optimization.indexsets.get(
run_id=self._model.run__id, name=self._model.name
).data
)

@property
def run_id(self) -> int:
Expand Down
4 changes: 2 additions & 2 deletions ixmp4/core/optimization/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def add(self, data: dict[str, Any] | pd.DataFrame) -> None:
self.backend.optimization.parameters.add_data(
parameter_id=self._model.id, data=data
)
self._model.data = self.backend.optimization.parameters.get(
self._model = self.backend.optimization.parameters.get(
run_id=self._model.run__id, name=self._model.name
).data
)

@property
def values(self) -> list[float]:
Expand Down
4 changes: 2 additions & 2 deletions ixmp4/core/optimization/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def data(self) -> dict[str, Any]:
def add(self, data: dict[str, Any] | pd.DataFrame) -> None:
"""Adds data to an existing Table."""
self.backend.optimization.tables.add_data(table_id=self._model.id, data=data)
self._model.data = self.backend.optimization.tables.get(
self._model = self.backend.optimization.tables.get(
run_id=self._model.run__id, name=self._model.name
).data
)

@property
def constrained_to_indexsets(self) -> list[str]:
Expand Down
8 changes: 4 additions & 4 deletions ixmp4/core/optimization/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ def add(self, data: dict[str, Any] | pd.DataFrame) -> None:
self.backend.optimization.variables.add_data(
variable_id=self._model.id, data=data
)
self._model.data = self.backend.optimization.variables.get(
self._model = self.backend.optimization.variables.get(
run_id=self._model.run__id, name=self._model.name
).data
)

def remove_data(self) -> None:
"""Removes data from an existing Variable."""
self.backend.optimization.variables.remove_data(variable_id=self._model.id)
self._model.data = self.backend.optimization.variables.get(
self._model = self.backend.optimization.variables.get(
run_id=self._model.run__id, name=self._model.name
).data
)

@property
def levels(self) -> list[float]:
Expand Down

0 comments on commit c243743

Please sign in to comment.