Assisted specification: Saving the outputs AND the pareto file in another folder

9 views
Skip to first unread message

Antonin Danalet

unread,
Jul 31, 2026, 5:25:24 AM (11 days ago) Jul 31
to Biogeme
Dear Michel,

When using biogeme, I tend to use:

def estimate_in_directory(
biogeme_instance: bio.BIOGEME, directory: Path
) -> bio.res.bioResults:
"""Estimate with biogeme and save results in a directory."""
cwd = os.getcwd()
os.chdir(directory)
# Estimate the parameters
results = biogeme_instance.estimate()
os.chdir(cwd)
return results

Instead of results = biogeme_instance.estimate(), in order to separate code from output.

I've tried to do the same with assisted specification:

def run_assisted_specification_in_directory(
assisted_specification, output_directory: Path
) -> None:
cwd = os.getcwd()
os.chdir(output_directory)
non_dominated_models = assisted_specification.run()

compiled_results, specs = compile_estimation_results(
non_dominated_models, use_short_names=True
)
[...]
os.chdir(cwd)

Unfortunately, biogeme does not find the pareto file (when re-running).

Is there a way to solve this?

I'm using biogeme 3.2.13.

Thanks!

Antonin

Michel Bierlaire

unread,
Jul 31, 2026, 5:31:23 AM (11 days ago) Jul 31
to antonin...@sbb.ch, Michel Bierlaire, Biogeme
Dear Antonin,

The name of the Pareto file is interpreted when the AssistedSpecification object is created. Therefore, if the object is created before changing the working directory, Biogeme will look for the Pareto file relative to the original directory.
The simplest solution is to provide an absolute path when constructing the object:
output_directory = output_directory.resolve()
pareto_file = output_directory / "my_model.pareto"

assisted_specification = AssistedSpecification(
biogeme_object=the_biogeme,
multi_objectives=loglikelihood_dimension,
pareto_file_name=str(pareto_file),
)

You can then run it from any working directory:
non_dominated_models = assisted_specification.run()

Alternatively, change directory before constructing AssistedSpecification, but using an absolute path is safer and avoids global changes to the process working directory.

If you still want to change directory for the other output files, make sure that it is restored even if estimation raises an exception:
from contextlib import contextmanager
from pathlib import Path
import os

@contextmanager
def working_directory(directory: Path):
previous_directory = Path.cwd()
os.chdir(directory)
try:
yield
finally:
os.chdir(previous_directory)


with working_directory(output_directory):
non_dominated_models = assisted_specification.run()

But the Pareto filename should still preferably be absolute.

Best regards,

Michel
> --
> You received this message because you are subscribed to the Google Groups "Biogeme" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to biogeme+u...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/biogeme/a4b8aa63-1eae-48b1-8511-95d0848f3e4cn%40googlegroups.com.

Michel Bierlaire
Transport and Mobility Laboratory
School of Architecture, Civil and Environmental Engineering
EPFL - Ecole Polytechnique Fédérale de Lausanne
http://transp-or.epfl.ch
http://people.epfl.ch/michel.bierlaire

Reply all
Reply to author
Forward
0 new messages