import pandas as pd from cascade_at.executor.args.arg_utils import ArgumentList from cascade_at.executor.args.args import ModelVersionID, BoolArg, ListArg, StrArg, LogLevel from cascade_at.context.model_context import Context from cascade_at.core.log import get_loggers, LEVELS from cascade_at.dismod.api.dismod_io import DismodIO LOG = get_loggers(__name__) ARG_LIST = ArgumentList([ ModelVersionID(), ListArg('--locations', help='The locations to pull mulcov statistics from', type=int, required=True), ListArg('--sexes', help='The sexes to pull mulcov statistics from', type=int, required=True), StrArg('--outfile-name', help='Filepath where mulcov statistics will be saved', required=False, default='mulcov_stats'), BoolArg('--sample', help='If true, the results will be pulled from the sample table rather' 'than the fit_var table'), BoolArg('--mean', help='Whether or not to compute the mean'), BoolArg('--std', help='Whether or not to compute the standard deviation'), ListArg('--quantile', help='Quantiles to compute', type=float), LogLevel() ]) def common_covariate_names(dbs): return set.intersection( *map(set, [d.covariate.c_covariate_name.tolist() for d in dbs]) )
from cascade_at.dismod.api.dismod_io import DismodIO from cascade_at.dismod.process.process_behavior import check_sample_asymptotic, SampleAsymptoticError from cascade_at.dismod.api.multithreading import _DismodThread, dmdismod_in_parallel from cascade_at.dismod.api.run_dismod import run_dismod_commands from cascade_at.executor import ExecutorError LOG = get_loggers(__name__) ARG_LIST = ArgumentList([ ModelVersionID(), ParentLocationID(), SexID(), NSim(), NPool(), StrArg('--fit-type', help='what type of fit to simulate for, fit fixed or both', default='both'), BoolArg('--asymptotic', help='whether or not to do asymptotic statistics or fit-refit'), LogLevel() ]) class SampleError(ExecutorError): """Raised when there are issues with sample simulate.""" pass def simulate(path: Union[str, Path], n_sim: int): """ Simulate from a database, within a database.
help='whether or not to fill the dismod database with data'), BoolArg( '--prior-samples', help='whether or not the prior came from samples or just a mean fit'), IntArg( '--prior-parent', help='the location ID of the parent database to grab the prior for'), IntArg('--prior-sex', help='the sex ID of the parent database to grab prior for'), IntArg('--prior-mulcov', help='the model version id where mulcov stats is passed in', required=False), BoolArg('--save-fit', help='whether or not to save the fit'), BoolArg('--save-prior', help='whether or not to save the prior'), LogLevel(), StrArg('--test-dir', help='if set, will save files to the directory specified') ]) class DismodDBError(CascadeATError): """Raised when there is an error with running the dismod_db script.""" pass def get_prior(path: Union[str, Path], location_id: int, sex_id: int, rates: List[str], samples: bool = True) -> Dict[str, Dict[str, np.ndarray]]: """ Gets priors from a path to a database for a given location ID and sex ID.
def test_str_arg(): a = StrArg() assert a._parser_kwargs['type'] == str
from cascade_at.executor.args.arg_utils import ArgumentList from cascade_at.core.log import get_loggers, LEVELS from cascade_at.executor.args.args import ModelVersionID, BoolArg, LogLevel, StrArg LOG = get_loggers(__name__) ARG_LIST = ArgumentList([ ModelVersionID(), BoolArg('--make', help='whether or not to make the file structure for the cascade'), BoolArg('--configure', help='whether or not to configure for the IHME cluster'), LogLevel(), StrArg('--json-file', help='for testing, pass a json file directly by filepath' 'instead of referencing a model version ID.'), StrArg('--test-dir', help='if set, will save files to the directory specified.' 'Invalidated if --configure is set.') ]) class CovariateReference: def __init__(self, inputs): self.inputs = inputs self.cov_ids = { c.covariate_id: c.name for c in inputs.covariate_specs.covariate_specs if c.study_country == 'country' }
from cascade_at.jobmon.workflow import jobmon_workflow_from_cascade_command from cascade_at.settings.settings import settings_from_model_version_id from cascade_at.inputs.locations import LocationDAG LOG = get_loggers(__name__) ARG_LIST = ArgumentList([ ModelVersionID(), BoolArg('--jobmon', help='whether or not to use jobmon to run the cascade' 'or just run as a sequence of command line tasks'), BoolArg('--make', help='whether or not to make the file structure for the cascade'), NSim(), StrArg('--addl-workflow-args', help='additional info to append to workflow args, to re-do models', required=False), BoolArg('--skip-configure'), LogLevel() ]) def run(model_version_id: int, jobmon: bool = True, make: bool = True, n_sim: int = 10, addl_workflow_args: Optional[str] = None, skip_configure: bool = False) -> None: """ Runs the whole cascade or drill for a model version (which one is specified in the model version settings).
import logging import sys from typing import List from cascade_at.executor.args.arg_utils import ArgumentList from cascade_at.executor.args.args import StrArg, DmCommands, LogLevel from cascade_at.core.log import get_loggers, LEVELS from cascade_at.dismod.api.run_dismod import run_dismod LOG = get_loggers(__name__) ARG_LIST = ArgumentList([ StrArg('--file', help='Which database file to execute commands on'), DmCommands(), LogLevel() ]) def run_dmdismod(file, dm_commands: List[str]) -> None: """ Runs commands on a dismod file. Parameters ---------- file Filepath to a database dm_commands List of commands that dismod_at understands """ for c in dm_commands: process = run_dismod(dm_file=file, command=c)
from cascade_at.settings.settings import settings_from_model_version_id from cascade_at.settings.settings import load_settings LOG = get_loggers(__name__) ARG_LIST = ArgumentList([ ModelVersionID(), BoolArg('--jobmon', help='whether or not to use jobmon to run the cascade' 'or just run as a sequence of command line tasks'), BoolArg('--make', help='whether or not to make the file structure for the cascade'), NSim(), NPool(), StrArg('--addl-workflow-args', help='additional info to append to workflow args, to re-do models', required=False), BoolArg('--skip-configure', help='Disable building the inputs.p and settings.json files.'), StrArg('--json-file', help='for testing, pass a json file directly by filepath', required=False), StrArg('--test-dir', help='if set, specifies where files directory is.', required=False), LogLevel() ]) def run(model_version_id: int, jobmon: bool = True,