Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gempyor API docstring refurbishment #468

Merged
merged 18 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 55 additions & 12 deletions flepimop/gempyor_pkg/src/gempyor/calibrate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
"""
calibrate.py
emprzy marked this conversation as resolved.
Show resolved Hide resolved

Facilitates the calibration of the model using the `emcee` MCMC sampler.
Provides CLI options for users to specify simulation paramters.
emprzy marked this conversation as resolved.
Show resolved Hide resolved

Functions:
calibrate: Reads a configuration file for simulation settings.

Options:
--config, -c Path to the configuration file.
--project_path, -p Path to the flepiMoP project directory.
--nwalkers, -n Number of walkers (MCMC chains) to use. Overrides value in config.
--niterations Number of MCMC iterations. Overrides value in config.
--nsamples Number of samples to retain. OVerrides value in config.
--nthin Number of samples to thin. Overrides value in config.
--j, --jobs Number of CPU cores to use for prallelization.
--id Unique ID for the run.
--prefix Prefix for output files.
--resume Flag determining whether or not to resume the current calibration.
--resume_location, -r Path to the location to resume the run from.
emprzy marked this conversation as resolved.
Show resolved Hide resolved

"""

#!/usr/bin/env python
import click
from gempyor import model_info, file_paths, config, inference_parameter
Expand Down Expand Up @@ -113,18 +137,37 @@
# @profile_options
# @profile()
def calibrate(
config_filepath,
project_path,
nwalkers,
niter,
nsamples,
nthin,
ncpu,
input_run_id,
prefix,
resume,
resume_location,
):
config_filepath: str,
emprzy marked this conversation as resolved.
Show resolved Hide resolved
project_path: str,
nwalkers: int,
niter: int,
nsamples: int,
nthin: int,
ncpu: int,
input_run_id: int,
prefix: str,
resume: bool,
resume_location: str,
emprzy marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
"""
Calibrate using an `emcee` sampler to initialize a model based on a config.

Args:
config_filepath: Path to the configuration file.
project_path: Path to the project directory.
nwalkers: Number of walkers (MCMC chains) to run.
niter: Number of MCMC iterations to perform.
nsamples: Number of samples to select from final MCMC chain.
nthin (optional): How often to save samples.
ncpu: Number of CPU cores to use for parallelization.
input_run_id (optional): Run ID. Will be auto-generated if not provdied.
prefix (optional): A prefix for output files.
resume: Whether or not to resume a previous calibration run.
resume_location (optional): Path to the location of the saved state to resume from.

Returns:
None
"""
emprzy marked this conversation as resolved.
Show resolved Hide resolved
# Choose a run_id
if input_run_id is None:
base_run_id = pathlib.Path(config_filepath).stem.replace("config_", "")
Expand Down
3 changes: 1 addition & 2 deletions flepimop/gempyor_pkg/src/gempyor/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
)
@click.pass_context
def patch(ctx: click.Context = mock_context, **kwargs) -> None:
"""Merge configuration files

"""
emprzy marked this conversation as resolved.
Show resolved Hide resolved
This command will merge multiple config files together by overriding the top level
keys in config files. The order of the config files is important, as the last file
has the highest priority and the first has the lowest.
Expand Down
Loading
Loading