From a16e320b955c1516f64ba4d2c833d2f48ce4a2a4 Mon Sep 17 00:00:00 2001 From: Abel Legese <73869888+Abellegese@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:42:28 +0300 Subject: [PATCH] Creating python API for Nox sessions (#1414) * Update config.yml - fix Circle CI pipeline * Playground Implementation * Playground Implementation * Support CLI batching, and more * Update CLI test * Update CLI test * Update CLI test * CLI test Update * A few fix on the playground test * A few fix on the playground test * A few fix on the playground test * Playground with all command at #1368 * Playground with all command at #1368 * Playground with all command at #1368 * Playground with all command at #1368 * Playground with all command at #1368 * Playground with all command at #1368 * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground * Session Parallelization on CLI test playground with pytest dependency * Rich lib integration pyproject config * Make the serializer use the fields from the header (#1406) * Generalize Standard Run (#1411) * Modify header calculation to choose from predefined example output file or standard example output file * Remove the readiness function from SCRA because it is redundant, since those checks are also performed by the amenable function * Remove unused method * Make csv serialization work for any kind of model api response * Remove the standard flag from the CLI since it is now the default run * Update tests * Creating python for Nox sessions * Creating python for Nox sessions * Generalize Standard Run (#1411) * Modify header calculation to choose from predefined example output file or standard example output file * Remove the readiness function from SCRA because it is redundant, since those checks are also performed by the amenable function * Remove unused method * Make csv serialization work for any kind of model api response * Remove the standard flag from the CLI since it is now the default run * Update tests * Generalize Standard Run (#1411) * Modify header calculation to choose from predefined example output file or standard example output file * Remove the readiness function from SCRA because it is redundant, since those checks are also performed by the amenable function * Remove unused method * Make csv serialization work for any kind of model api response * Remove the standard flag from the CLI since it is now the default run * Update tests * Make the serializer use the fields from the header (#1406) * Merge sample command with the example command (#1422) * Merge sample command with the example command * Fix example command usage * Generalize Standard Run (#1411) * Modify header calculation to choose from predefined example output file or standard example output file * Remove the readiness function from SCRA because it is redundant, since those checks are also performed by the amenable function * Remove unused method * Make csv serialization work for any kind of model api response * Remove the standard flag from the CLI since it is now the default run * Update tests * Conflict resolved with upstream * Conflict resolved with upstream * Generalize Standard Run (#1411) * Modify header calculation to choose from predefined example output file or standard example output file * Remove the readiness function from SCRA because it is redundant, since those checks are also performed by the amenable function * Remove unused method * Make csv serialization work for any kind of model api response * Remove the standard flag from the CLI since it is now the default run * Update tests * Make the serializer use the fields from the header (#1406) * Generalize Standard Run (#1411) * Modify header calculation to choose from predefined example output file or standard example output file * Remove the readiness function from SCRA because it is redundant, since those checks are also performed by the amenable function * Remove unused method * Make csv serialization work for any kind of model api response * Remove the standard flag from the CLI since it is now the default run * Update tests * Conflict resolved with upstream * Conflict resolved with upstream * Unnecessary files removed * Generalize Standard Run (#1411) * Modify header calculation to choose from predefined example output file or standard example output file * Remove the readiness function from SCRA because it is redundant, since those checks are also performed by the amenable function * Remove unused method * Make csv serialization work for any kind of model api response * Remove the standard flag from the CLI since it is now the default run * Update tests * Unnecessary files removed * Generalize Standard Run (#1411) * Modify header calculation to choose from predefined example output file or standard example output file * Remove the readiness function from SCRA because it is redundant, since those checks are also performed by the amenable function * Remove unused method * Make csv serialization work for any kind of model api response * Remove the standard flag from the CLI since it is now the default run * Update tests * Make the serializer use the fields from the header (#1406) * Unnecessary files removed * Unnecessary files removed * Unnecessary files removed * Unnecessary files removed * Fix: Unnecessary files removed --------- Co-authored-by: Dhanshree Arora --- ersilia/cli/commands/example.py | 13 ++++++++++--- ersilia/io/input.py | 2 +- ersilia/utils/exceptions_utils/exceptions.py | 4 +++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ersilia/cli/commands/example.py b/ersilia/cli/commands/example.py index b319fd97..fdc5be99 100644 --- a/ersilia/cli/commands/example.py +++ b/ersilia/cli/commands/example.py @@ -37,7 +37,6 @@ def example_cmd(): def example(): pass - @example.command() @click.argument("model", required=False, default=None, type=click.STRING) @click.option("--n_samples", "-n", default=5, type=click.INT) @@ -50,6 +49,15 @@ def inputs(model, n_samples, file_name, simple, predefined): else: session = Session(config_json=None) model_id = session.current_model_id() + if model_id is None: + click.echo( + click.style( + "Error: No model id given and no model found running in this shell.", + fg="red", + ), + err=True, + ) + return eg = ExampleGenerator(model_id=model_id) if file_name is None: echo( @@ -61,7 +69,6 @@ def inputs(model, n_samples, file_name, simple, predefined): else: eg.example(n_samples, file_name, simple, try_predefined=predefined) - @example.command() @click.option("--n_samples", "-n", default=5, type=click.INT) @click.option("--file_name", "-f", default=None, type=click.STRING) @@ -71,4 +78,4 @@ def models(n_samples, file_name): if file_name is None: echo(json.dumps(sampler.sample(n_samples), indent=4)) else: - sampler.sample(n_samples, file_name) \ No newline at end of file + sampler.sample(n_samples, file_name) diff --git a/ersilia/io/input.py b/ersilia/io/input.py index 53c3a287..59c1b9cf 100644 --- a/ersilia/io/input.py +++ b/ersilia/io/input.py @@ -271,7 +271,7 @@ def example(self, n_samples, file_name, simple, try_predefined): if try_predefined is True and file_name is not None: self.logger.debug("Trying with predefined input") predefined_available = self.predefined_example(file_name) - + if predefined_available: with open(file_name, "r") as f: return f.read() diff --git a/ersilia/utils/exceptions_utils/exceptions.py b/ersilia/utils/exceptions_utils/exceptions.py index d71faaf0..70521455 100644 --- a/ersilia/utils/exceptions_utils/exceptions.py +++ b/ersilia/utils/exceptions_utils/exceptions.py @@ -93,7 +93,9 @@ def run_from_terminal(self): output_file = os.path.join(framework_dir, "example_output.csv") tmp_folder = make_temp_dir(prefix="ersilia-") log_file = os.path.join(tmp_folder, "terminal.log") - run_command("ersilia example inputs {0} -n 3 -f {1}".format(self.model_id, input_file)) + run_command( + "ersilia example inputs {0} -n 3 -f {1}".format(self.model_id, input_file) + ) cmd = "bash {0} {1} {2} {3} 2>&1 | tee -a {4}".format( exec_file, framework_dir, input_file, output_file, log_file )