Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove configuration twice #243

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/acom_music_box/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,8 @@ def main():
# Create and load a MusicBox object
myBox = MusicBox()
logger.debug(f"Configuration file = {musicBoxConfigFile}")
myBox.readConditionsFromJson(musicBoxConfigFile)

# Create solver and solve
config_path = os.path.join(
os.path.dirname(musicBoxConfigFile),
myBox.config_file)
myBox.create_solver(config_path)
myBox.loadJson(musicBoxConfigFile, myBox)
K20shores marked this conversation as resolved.
Show resolved Hide resolved

result = myBox.solve(musicBoxOutputPath)

if musicBoxOutputPath is None:
Expand Down
36 changes: 14 additions & 22 deletions src/acom_music_box/music_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,6 @@ def add_evolving_condition(self, time_point, conditions):
time=[time_point], conditions=[conditions])
self.evolvingConditions.append(evolving_condition)

def create_solver(
self,
path_to_config,
solver_type=musica.micmsolver.rosenbrock,
number_of_grid_cells=1):
"""
Creates a micm solver object using the CAMP configuration files.

Args:
path_to_config (str): The path to CAMP configuration directory.

Returns:
None
"""
# Create a solver object using the configuration file
self.solver = musica.create_solver(
path_to_config,
solver_type,
number_of_grid_cells)

def solve(self, output_path=None, callback=None):
"""
Solves the box model simulation and optionally writes the output to a file.
Expand Down Expand Up @@ -246,12 +226,13 @@ def solve(self, output_path=None, callback=None):

return df

def readConditionsFromJson(self, path_to_json):
def loadJson(self, path_to_json, box_model):
K20shores marked this conversation as resolved.
Show resolved Hide resolved
"""
Reads and parses a JSON file from the CAMP JSON file to set up the box model simulation.
Reads and parses a JSON file and create a solver

Args:
path_to_json (str): The JSON path to the JSON file.
box_model: Instance of the MusicBox class

Returns:
None
Expand Down Expand Up @@ -279,6 +260,17 @@ def readConditionsFromJson(self, path_to_json):
# Set initial conditions
self.evolving_conditions = EvolvingConditions.from_config_JSON(
path_to_json, data, self.species_list, self.reaction_list)

camp_path = os.path.join(
os.path.dirname(path_to_json),
box_model.config_file)
K20shores marked this conversation as resolved.
Show resolved Hide resolved

# Creates a micm solver object using the CAMP configuration files.
self.solver = musica.create_solver(
camp_path,
musica.micmsolver.rosenbrock,
1)


def speciesOrdering(self):
"""
Expand Down
8 changes: 1 addition & 7 deletions tests/integration/test_analytical.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ class TestAnalytical:
def test_run(self):
box_model = MusicBox()

# configures box model
conditions_path = Examples.Analytical.path
box_model.readConditionsFromJson(conditions_path)

camp_path = os.path.join(
os.path.dirname(conditions_path),
box_model.config_file)

box_model.create_solver(camp_path)
box_model.loadJson(conditions_path, box_model)
K20shores marked this conversation as resolved.
Show resolved Hide resolved

# solves and saves output
df = box_model.solve()
Expand Down
10 changes: 2 additions & 8 deletions tests/integration/test_carbon_bond_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@
class TestCarbonBond5:
def test_run(self):
box_model = MusicBox()

# configures box model

conditions_path = Examples.CarbonBond5.path
box_model.readConditionsFromJson(conditions_path)

camp_path = os.path.join(
os.path.dirname(conditions_path),
box_model.config_file)

box_model.create_solver(camp_path)
box_model.loadJson(conditions_path, box_model)
K20shores marked this conversation as resolved.
Show resolved Hide resolved

# solves and saves output
df = box_model.solve()
Expand Down
10 changes: 2 additions & 8 deletions tests/integration/test_chapman.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ class TestChapman:
def test_run(self):
box_model = MusicBox()

# configures box model
conditions_path = Examples.Chapman.path
box_model.readConditionsFromJson(conditions_path)

camp_path = os.path.join(
os.path.dirname(conditions_path),
box_model.config_file)

box_model.create_solver(camp_path)

box_model.loadJson(conditions_path, box_model)
K20shores marked this conversation as resolved.
Show resolved Hide resolved

# solves and saves output
df = box_model.solve()
Expand Down
10 changes: 2 additions & 8 deletions tests/integration/test_flow_tube.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ class TestWallLoss:
def test_run(self):
box_model = MusicBox()

# configures box model
conditions_path = Examples.FlowTube.path
box_model.readConditionsFromJson(conditions_path)

camp_path = os.path.join(
os.path.dirname(conditions_path),
box_model.config_file)

box_model.create_solver(camp_path)

box_model.loadJson(conditions_path, box_model)
K20shores marked this conversation as resolved.
Show resolved Hide resolved

# solves and saves output
df = box_model.solve()
model_output = [df.columns.values.tolist()] + df.values.tolist()
Expand Down
9 changes: 2 additions & 7 deletions tests/unit/test_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ def test_run(self, mocker):
box_model = MusicBox()

conditions_path = Examples.Analytical.path
box_model.readConditionsFromJson(conditions_path)

camp_path = os.path.join(
os.path.dirname(conditions_path),
box_model.config_file)

box_model.create_solver(camp_path)

box_model.loadJson(conditions_path, box_model)
K20shores marked this conversation as resolved.
Show resolved Hide resolved

# Mock the callback function
callback_mock = mocker.Mock(side_effect=callback)
Expand Down