Skip to content

Delete old solver on multiple calls to loadJson #368

@K20shores

Description

@K20shores

When we load a mechanism with loadJson

self.solver = musica.MICM(config_path=camp_path, solver_type=musica.SolverType.rosenbrock_standard_order)
elif "mechanism" in data and data["mechanism"]:
# V1 mechanism configuration (in the same file)
mechanism_json = data['mechanism']
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as tmp_mech_file:
tmp_mech_file.write(json.dumps(mechanism_json))
tmp_mech_file.flush()
tmp_mech_file_path = tmp_mech_file.name
# Save mechanism
parser = mc.Parser()
self.__mechanism = parser.parse(tmp_mech_file_path)
# Initalize the musica solver
self.solver = musica.MICM(config_path=tmp_mech_file_path, solver_type=musica.SolverType.rosenbrock_standard_order)

We directly assign to self.solver. If a solver already exists there, we may be leaking memory. Make sure that somehow those old solvers and their data get deleted

Acceptance criteria

  • Make sure the __del__ option gets called on the solver

Ideas

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions