diff --git a/HISTORY.rst b/HISTORY.rst index 57549182..991c201d 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,8 @@ History Next Release ------------ +* Set the solver backend earlier in the process, before a COBRApy model is created. + 0.16.0 (2023-11-19) ------------------- * Allow the hybrid interface as a solver. diff --git a/src/memote/suite/cli/reports.py b/src/memote/suite/cli/reports.py index 84143323..4d014b1f 100644 --- a/src/memote/suite/cli/reports.py +++ b/src/memote/suite/cli/reports.py @@ -27,6 +27,7 @@ from multiprocessing import Pool, cpu_count import click +import cobra import git from libsbml import SBMLError from sqlalchemy.exc import ArgumentError @@ -143,6 +144,10 @@ def snapshot( MODEL: Path to model file. Can also be supplied via the environment variable MEMOTE_MODEL or configured in 'setup.cfg' or 'memote.ini'. """ + # Configure the chosen solver before attempting to load the model. + config = cobra.Configuration() + config.solver = solver + model_obj, sbml_ver, notifications = api.validate_model(model) if model_obj is None: LOGGER.critical( @@ -159,7 +164,6 @@ def snapshot( # Update the default test configuration with custom ones (if any). for custom in custom_config: config.merge(ReportConfiguration.load(custom)) - model_obj.solver = solver _, results = api.test_model( model_obj, sbml_version=sbml_ver, @@ -363,6 +367,10 @@ def diff( MODELS: List of paths to two or more model files. """ + # Configure the chosen solver before attempting to load the model. + config = cobra.Configuration() + config.solver = solver + if not any(a.startswith("--tb") for a in pytest_args): pytest_args = ["--tb", "no"] + pytest_args # Add further directories to search for tests. @@ -390,7 +398,6 @@ def diff( "reported in {}.".format(model_filename, report_path) ) continue - model.solver = solver model_and_model_ver_tuple.append((model, model_ver)) except (IOError, SBMLError): LOGGER.debug(exc_info=True) diff --git a/src/memote/suite/cli/runner.py b/src/memote/suite/cli/runner.py index f01b283e..74a66ff2 100644 --- a/src/memote/suite/cli/runner.py +++ b/src/memote/suite/cli/runner.py @@ -31,6 +31,7 @@ import click import click_log +import cobra import git from cookiecutter.main import cookiecutter, get_user_config from github import Github @@ -231,6 +232,11 @@ def is_verbose(arg): sys.exit(0) # Add further directories to search for tests. pytest_args.extend(custom_tests) + + # Configure the chosen solver before attempting to load the model. + config = cobra.Configuration() + config.solver = solver + # Check if the model can be loaded at all. model, sbml_ver, notifications = api.validate_model(model) if model is None: @@ -239,7 +245,7 @@ def is_verbose(arg): ) stdout_notifications(notifications) sys.exit(1) - model.solver = solver + code, result = api.test_model( model=model, sbml_version=sbml_ver, @@ -339,7 +345,6 @@ def _model_from_stream(stream, filename): def _test_history( model, sbml_ver, - solver, solver_timeout, manager, commit, @@ -348,7 +353,6 @@ def _test_history( exclusive, experimental, ): - model.solver = solver # Load the experimental configuration using model information. if experimental is not None: experimental.load(model) @@ -480,6 +484,9 @@ def history( previous = repo.active_branch LOGGER.info("Checking out deployment branch {}.".format(deployment)) repo.git.checkout(deployment) + # Configure the chosen solver before attempting to load the model. + config = cobra.Configuration() + config.solver = solver # Temporarily move the results to a new location so that they are # available while checking out the various commits. engine = None @@ -545,7 +552,6 @@ def history( args=( model_obj, sbml_ver, - solver, solver_timeout, manager, commit,