Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
Change-Id: Id996801b6aa80b5563ab58e13ea65c21f547b0e6
  • Loading branch information
Jaquier Aurélien Tristan committed Nov 6, 2024
1 parent 39c4237 commit ebcc9f7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
48 changes: 25 additions & 23 deletions bluepyemodel/emodel_pipeline/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1893,34 +1893,36 @@ def plot_models(
access_point.pipeline_settings.currentscape_config["current"]["names"],
use_fixed_dt_recordings=False,
)

if plot_optimisation_progress or plot_parameter_evolution:
checkpoint_paths = existing_checkpoint_paths(access_point.emodel_metadata)

if plot_optimisation_progress:
if optimiser is None:
logger.warning("Will not plot optimisation progress because optimiser was not given.")
else:
for chkp_path in checkpoint_paths:
stem = str(Path(chkp_path).stem)
seed = int(stem.rsplit("seed=", maxsplit=1)[-1])

optimisation(
optimiser=optimiser,
emodel=access_point.emodel_metadata.emodel,
iteration=access_point.emodel_metadata.iteration,
seed=seed,
checkpoint_path=chkp_path,
figures_dir=figures_dir / "optimisation",
if plot_optimisation_progress:
if optimiser is None:
logger.warning(
"Will not plot optimisation progress because optimiser was not given."
)
else:
for chkp_path in checkpoint_paths:
stem = str(Path(chkp_path).stem)
seed = int(stem.rsplit("seed=", maxsplit=1)[-1])

optimisation(
optimiser=optimiser,
emodel=access_point.emodel_metadata.emodel,
iteration=access_point.emodel_metadata.iteration,
seed=seed,
checkpoint_path=chkp_path,
figures_dir=figures_dir / "optimisation",
)

if plot_parameter_evolution:
evolution_parameters_density(
evaluator=cell_evaluator,
checkpoint_paths=checkpoint_paths,
metadata=access_point.emodel_metadata,
figures_dir=figures_dir / "parameter_evolution",
)
if plot_parameter_evolution:
evolution_parameters_density(
evaluator=cell_evaluator,
checkpoint_paths=checkpoint_paths,
metadata=access_point.emodel_metadata,
figures_dir=figures_dir / "parameter_evolution",
)

if any(
(
Expand Down
8 changes: 5 additions & 3 deletions bluepyemodel/tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

def existing_checkpoint_paths(emodel_metadata, checkpoint_paths=None):
"""Returns a list of existing checkpoint paths conforming to metadata.
Args:
emodel_metadata (EModelMetadata): contains emodel and iteration
that should be present in each returned checkpoint path
Expand All @@ -42,15 +42,17 @@ def existing_checkpoint_paths(emodel_metadata, checkpoint_paths=None):
checkpoint_paths = glob.glob("./checkpoints/**/*.pkl", recursive=True)
if not checkpoint_paths:
raise ValueError("The checkpoints directory is empty, or there are no .pkl files.")

if not emodel_metadata.iteration:
return [chkp for chkp in checkpoint_paths if emodel_metadata.emodel in chkp.split("/")]
return [
chkp for chkp in checkpoint_paths
chkp
for chkp in checkpoint_paths
if emodel_metadata.emodel in chkp.split("/")
and emodel_metadata.iteration in chkp.split("/")
]


def checkpoint_path_exists(checkpoint_path):
"""Returns True if checkpoint path exists, False if not.
Expand Down

0 comments on commit ebcc9f7

Please sign in to comment.