From 25c65202f48778ce0ad8d144bbdf45e11c314ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez=20Duque?= Date: Fri, 26 Sep 2025 18:36:20 +0200 Subject: [PATCH 1/2] Adds a helpful error when conda env creation fails --- examples/minimal_isolation_example.py | 14 ++++++++++++++ src/poli/core/util/isolation/instancing.py | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 examples/minimal_isolation_example.py diff --git a/examples/minimal_isolation_example.py b/examples/minimal_isolation_example.py new file mode 100644 index 00000000..b50ccd23 --- /dev/null +++ b/examples/minimal_isolation_example.py @@ -0,0 +1,14 @@ +import numpy as np + +from poli.repository import EhrlichHoloBlackBox + +f = EhrlichHoloBlackBox( + sequence_length=10, + motif_length=3, + n_motifs=2, +) + +print(f.alphabet) +print(f) +print(f(np.array(["ACGTACGTAA", "ACGTACGTAC"]))) +print(f) diff --git a/src/poli/core/util/isolation/instancing.py b/src/poli/core/util/isolation/instancing.py index 300dc640..4a141a16 100644 --- a/src/poli/core/util/isolation/instancing.py +++ b/src/poli/core/util/isolation/instancing.py @@ -72,7 +72,11 @@ def __create_conda_env(environment_file: Path, quiet: bool = False): if not quiet: print(f"poli 🧪: {env_name} already exists.") else: - raise e + raise RuntimeError( + "Failed to create the underlying conda environment." + " Try to create the environment manually by running:\n" + f"conda env create -f {environment_file}\n" + ) from e def __register_isolated_function_from_repository( From e3e18ee5c23b216ebca417765b2206f5d3af2587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez=20Duque?= Date: Fri, 26 Sep 2025 18:54:57 +0200 Subject: [PATCH 2/2] Runs registration always, mitigating stale config.rc file issues --- src/poli/core/util/isolation/instancing.py | 39 ++++++---------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/src/poli/core/util/isolation/instancing.py b/src/poli/core/util/isolation/instancing.py index 4a141a16..b061cfdc 100644 --- a/src/poli/core/util/isolation/instancing.py +++ b/src/poli/core/util/isolation/instancing.py @@ -216,31 +216,15 @@ def register_isolated_function(name: str, quiet: bool = False): If True, we squelch the messages giving feedback about the creation process. By default, it is False. """ - config = load_config() - if name not in config: - # Register problem - - # Two cases: - # (i) some of the isolated functions are not alongside - # their black boxes and problem factories, but are rather inside - # the core of poli. For now, the only case is tdc, but more may - # come in the future. - # - # (ii) the isolated function is in the repository, living alongside - # the black box and the problem factory. - if name == "tdc__isolated": - logging.debug( - "poli 🧪: Registered the isolated function from the repository." - ) - __register_isolated_function_from_core(name, quiet=quiet) - config = load_config() - else: - logging.debug( - "poli 🧪: Registered the isolated function from the repository." - ) - __register_isolated_function_from_repository(name, quiet=quiet) - # Refresh the config - config = load_config() + if name == "tdc__isolated": + logging.debug("poli 🧪: Registered the isolated function from core.") + __register_isolated_function_from_core(name, quiet=quiet) + _ = load_config() + else: + logging.debug("poli 🧪: Registered the isolated function from the repository.") + __register_isolated_function_from_repository(name, quiet=quiet) + # Refresh the config + _ = load_config() def __create_function_as_isolated_process( @@ -266,6 +250,8 @@ def __create_function_as_isolated_process( **kwargs_for_factory : dict, optional Additional keyword arguments for the factory. """ + register_isolated_function(name=name, quiet=quiet) + config = load_config() if name not in config: raise ValueError( @@ -323,9 +309,6 @@ def instance_function_as_isolated_process( "https://machinelearninglifescience.github.io/poli-docs/." ) - # Register the problem if it hasn't been registered. - register_isolated_function(name=name, quiet=quiet) - f = __create_function_as_isolated_process( name=name, quiet=quiet,