Skip to content

Commit

Permalink
Updated tests and fix Avoid copy.deepcopy (restriction in FEniCS) #90
Browse files Browse the repository at this point in the history
  • Loading branch information
danielandresarcones committed Aug 28, 2024
1 parent f267172 commit 18221f9
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 13 deletions.
2 changes: 1 addition & 1 deletion probeye/inference/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(
):

# attributes from arguments
self.problem = problem
self.problem = cp.deepcopy(problem)
self.show_progress = show_progress
self.seed = seed

Expand Down
2 changes: 1 addition & 1 deletion probeye/subroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ def synchronize_objects(
if attr_is_valid:
if hasattr(new_obj, attribute):
try:
setattr(new_obj, attribute, getattr(ref_obj, attribute))
setattr(new_obj, attribute, copy(getattr(ref_obj, attribute)))
except AttributeError: # pragma: no cover
raise AttributeError(
f"can't set attribute '{attribute}'"
Expand Down
8 changes: 1 addition & 7 deletions tests/unit_tests/inference/bias/test_likelihood_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class TestProblem(unittest.TestCase):
def test_embedded_pce_solver(self):
def test_embedded_likelihood_models(self):

# define the forward model
class LinRe(ForwardModelBase):
Expand Down Expand Up @@ -93,8 +93,6 @@ def response(self, inp: dict) -> dict:
n_walkers=n_walkers, n_steps=n_steps, vectorize=False
)

problem.forward_models.pop("LinRe")
problem.add_forward_model(LinRe("LinRe"), experiments="Tests")
problem.likelihood_models.pop("Tests")
dummy_lmodel.gamma = 1.0
likelihood_model = GlobalMomentMatchingModelError(dummy_lmodel)
Expand All @@ -104,8 +102,6 @@ def response(self, inp: dict) -> dict:
n_walkers=n_walkers, n_steps=n_steps, vectorize=False
)

problem.forward_models.pop("LinRe")
problem.add_forward_model(LinRe("LinRe"), experiments="Tests")
problem.likelihood_models.pop("Tests")
likelihood_model = RelativeGlobalMomentMatchingModelError(dummy_lmodel)
problem.add_likelihood_model(likelihood_model)
Expand All @@ -114,8 +110,6 @@ def response(self, inp: dict) -> dict:
n_walkers=n_walkers, n_steps=n_steps, vectorize=False
)

problem.forward_models.pop("LinRe")
problem.add_forward_model(LinRe("LinRe"), experiments="Tests")
problem.likelihood_models.pop("Tests")
dummy_lmodel.tolerance = 1e-6
likelihood_model = GlobalMomentMatchingModelError(dummy_lmodel)
Expand Down
4 changes: 0 additions & 4 deletions tests/unit_tests/inference/bias/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,11 @@ def response(self, inp: dict) -> dict:
n_walkers=n_walkers, n_steps=n_steps, vectorize=False
)

problem.forward_models.pop("LinRe")
problem.add_forward_model(LinRe("LinRe"), experiments="Tests")
solver_2 = EmbeddedPCESolver(problem, seed=42)
inference_data_2 = solver_2.run(
n_walkers=n_walkers, n_steps=n_steps, vectorize=False
)

problem.forward_models.pop("LinRe")
problem.add_forward_model(LinRe("LinRe"), experiments="Tests")
solver_1b = EmbeddedPCESolver(problem, seed=123)
inference_data_1b = solver_1b.run(
n_walkers=n_walkers, n_steps=n_steps, vectorize=False
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/inference/dynesty/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __call__(self, inp):
"dynamic", nlive_init=nlive_init, nlive_batch=nlive_batch, maxbatch=maxbatch
)


dynesty_solver_2 = DynestySolver(problem, seed=42)
inference_data_2 = dynesty_solver_2.run(
"dynamic", nlive_init=nlive_init, nlive_batch=nlive_batch, maxbatch=maxbatch
Expand Down

0 comments on commit 18221f9

Please sign in to comment.