Skip to content

Commit

Permalink
Merge pull request #266 from sblauth/db_memory_leak
Browse files Browse the repository at this point in the history
Fix a memory leak regarding the database
  • Loading branch information
sblauth authored Jul 11, 2023
2 parents af66b62 + 8cf39d2 commit 4aabacd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions cashocs/_optimization/line_search/armijo_line_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def search(
if self._check_for_nonconvergence(solver):
return (None, False)

if self.db.parameter_db.problem_type == "shape":
if self.problem_type == "shape":
self.decrease_measure_w_o_step = (
self.optimization_variable_abstractions.compute_decrease_measure(
search_direction
Expand Down Expand Up @@ -151,7 +151,7 @@ def search(
if not has_curvature_info:
self.stepsize *= self.beta_armijo

if self.db.parameter_db.problem_type == "shape":
if self.problem_type == "shape":
return (self.optimization_variable_abstractions.deformation, is_remeshed)
else:
return (None, False)
Expand All @@ -168,11 +168,11 @@ def _compute_decrease_measure(
The computed decrease measure.
"""
if self.db.parameter_db.problem_type in ["control", "topology"]:
if self.problem_type in ["control", "topology"]:
return self.optimization_variable_abstractions.compute_decrease_measure(
search_direction
)
elif self.db.parameter_db.problem_type == "shape":
elif self.problem_type == "shape":
return self.decrease_measure_w_o_step * self.stepsize
else:
return float("inf")
5 changes: 3 additions & 2 deletions cashocs/_optimization/line_search/line_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(
"""
self.db = db
self.problem_type = db.parameter_db.problem_type

self.config = self.db.config
self.form_handler = optimization_problem.form_handler
Expand All @@ -57,7 +58,7 @@ def __init__(
)
self.cost_functional = optimization_problem.reduced_cost_functional

if self.db.parameter_db.problem_type == "shape":
if self.problem_type == "shape":
if "deformation_function" in self.db.parameter_db.temp_dict.keys():
self.deformation_function = self.db.parameter_db.temp_dict[
"deformation_function"
Expand Down Expand Up @@ -215,7 +216,7 @@ def _satisfies_armijo_condition(
A boolean flag which is True in case the condition is satisfied.
"""
if not self.db.parameter_db.problem_type == "topology":
if not self.problem_type == "topology":
val = bool(
objective_step
< current_function_value + self.epsilon_armijo * decrease_measure
Expand Down
8 changes: 4 additions & 4 deletions cashocs/_optimization/line_search/polynomial_line_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def search(
if self._check_for_nonconvergence(solver):
return (None, False)

if self.db.parameter_db.problem_type == "shape":
if self.problem_type == "shape":
self.decrease_measure_w_o_step = (
self.optimization_variable_abstractions.compute_decrease_measure(
search_direction
Expand Down Expand Up @@ -172,7 +172,7 @@ def search(
if not has_curvature_info:
self.stepsize /= self.factor_high

if self.db.parameter_db.problem_type == "shape":
if self.problem_type == "shape":
return (self.optimization_variable_abstractions.deformation, is_remeshed)
else:
return (None, False)
Expand Down Expand Up @@ -301,11 +301,11 @@ def _compute_decrease_measure(
The computed decrease measure.
"""
if self.db.parameter_db.problem_type in ["control", "topology"]:
if self.problem_type in ["control", "topology"]:
return self.optimization_variable_abstractions.compute_decrease_measure(
search_direction
)
elif self.db.parameter_db.problem_type == "shape":
elif self.problem_type == "shape":
return self.decrease_measure_w_o_step * self.stepsize
else:
return float("inf")
3 changes: 2 additions & 1 deletion cashocs/geometry/mesh_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import subprocess # nosec B404
import tempfile
from typing import List, TYPE_CHECKING
import weakref

import fenics
import numpy as np
Expand Down Expand Up @@ -123,7 +124,7 @@ def __init__(
a_posteriori_tester: The tester after mesh modification.
"""
self.db = db
self.db = weakref.proxy(db)
self.form_handler = form_handler
self.a_priori_tester = a_priori_tester
self.a_posteriori_tester = a_posteriori_tester
Expand Down

0 comments on commit 4aabacd

Please sign in to comment.