Пример #1
0
def run(model_specification, results_directory, verbose, with_debugger):
    """Run a simulation from the command line.

    The simulation itself is defined by the given MODEL_SPECIFICATION yaml file.

    Within the results directory, which defaults to ~/vivarium_results if none
    is provided, a subdirectory will be created with the same name as the
    MODEL_SPECIFICATION if one does not exist. Results will be written to a
    further subdirectory named after the start time of the simulation run."""
    configure_logging_to_terminal(verbose)

    start = time()
    results_root = get_output_root(results_directory, model_specification)
    results_root.mkdir(parents=True, exist_ok=False)

    configure_logging_to_file(results_root)
    shutil.copy(model_specification, results_root / 'model_specification.yaml')

    main = handle_exceptions(run_simulation, logger, with_debugger)
    override_configuration = {'output_data': {'results_directory': str(results_root)}}
    finished_sim = main(model_specification, configuration=override_configuration)

    idx = pd.Index([finished_sim.configuration.randomness.random_seed], name='random_seed')
    metrics = pd.DataFrame(finished_sim.report(), index=idx)
    metrics['simulation_run_time'] = time() - start
    metrics.to_hdf(results_root / 'output.hdf', key='data')
Пример #2
0
def make_artifacts(location: str, output_dir: str, append: bool, verbose: int,
                   with_debugger: bool) -> None:
    configure_logging_to_terminal(verbose)
    main = handle_exceptions(build_artifacts,
                             logger,
                             with_debugger=with_debugger)
    main(location, output_dir, append, verbose)
Пример #3
0
def test_handle_exceptions(test_input):
    def raise_me(ex):
        raise ex

    with pytest.raises(test_input):
        func = handle_exceptions(raise_me(test_input), None, False)
        func()
Пример #4
0
def make_joint_pafs(location: str, draws: str, verbose: int,
                    with_debugger: bool, queue: str) -> None:
    configure_logging_to_terminal(verbose)
    main = handle_exceptions(build_joint_pafs,
                             logger,
                             with_debugger=with_debugger)
    main(location, draws, verbose, queue)
Пример #5
0
def restart(results_root, **options):
    """Restart a parallel simulation from a previous run at RESULTS_ROOT.

    Restarting will not erase existing results, but will start workers to
    perform the remaining simulations.  RESULTS_ROOT is expected to be an
    output directory from a previous ``psimulate run`` invocation.

    """
    logs.configure_main_process_logging_to_terminal(options["verbose"])
    main = handle_exceptions(runner.main, logger, options["with_debugger"])

    main(
        command=COMMANDS.restart,
        input_paths=paths.InputPaths.from_entry_point_args(
            result_directory=results_root, ),
        native_specification=cluster.NativeSpecification(
            job_name=results_root.parent.name,
            project=options["project"],
            queue=options["queue"],
            peak_memory=options["peak_memory"],
            max_runtime=options["max_runtime"],
        ),
        redis_processes=options["redis"],
        no_batch=options["no_batch"],
        extra_args={},
    )
Пример #6
0
def expand(results_root, **options):
    """Expand a previous run at RESULTS_ROOT by adding input draws and/or
    random seeds.

    Expanding will not erase existing results, but will start workers to perform
    the additional simulations determined by the added draws/seeds.
    RESULTS_ROOT is expected to be an output directory from a previous
    ``psimulate run`` invocation.

    """
    logs.configure_main_process_logging_to_terminal(options["verbose"])
    main = handle_exceptions(runner.main, logger, options["with_debugger"])

    main(
        command=COMMANDS.expand,
        input_paths=paths.InputPaths.from_entry_point_args(
            result_directory=results_root, ),
        native_specification=cluster.NativeSpecification(
            job_name=results_root.parent.name,
            project=options["project"],
            queue=options["queue"],
            peak_memory=options["peak_memory"],
            max_runtime=options["max_runtime"],
        ),
        redis_processes=options["redis"],
        no_batch=options["no_batch"],
        extra_args={
            "num_draws": options["add_draws"],
            "num_seeds": options["add_seeds"],
        },
    )
Пример #7
0
def make_specs(template: str, location: str, output_dir: str, verbose: int,
               with_debugger: bool) -> None:
    """
    Make model specifications

    click application that takes a template model specification file
    and locations for which to create model specs and uses jinja2 to
    render model specs with the correct location parameters plugged in.

    It will look for the model spec template in "model_spec.in" in the directory
    ``src/vivarium_csu_zenon/model_specifications``.
    Add location strings to the ``src/globals.py`` file. By default, specifications
    for all locations will be built. You can choose to make a model specification
    for a single location by specifying that location. However, the location
    string must exist in the list in ``src/globals.py``.

    The application will look for the model spec based on the python environment
    that is active and these files don't need to be specified if the
    default names and location are used.
    """
    configure_logging_to_terminal(verbose)
    main = handle_exceptions(build_model_specifications,
                             logger,
                             with_debugger=with_debugger)
    main(template, location, output_dir)
Пример #8
0
def make_sample_histories(location: str, scenarios: str, verbose: int,
                          with_debugger: bool, queue: str) -> None:
    configure_logging_to_terminal(verbose)
    main = handle_exceptions(build_sample_histories,
                             logger,
                             with_debugger=with_debugger)
    main(location, scenarios, verbose, queue)
Пример #9
0
def run(model_specification, branch_configuration, result_directory, **options):
    """Run a parallel simulation.

    The simulation itself is defined by a MODEL_SPECIFICATION yaml file
    and the parameter changes across runs are defined by a BRANCH_CONFIGURATION
    yaml file.

    If a results directory is provided, a subdirectory will be created with the
    same name as the MODEL_SPECIFICATION if one does not exist. Results will be
    written to a further subdirectory named after the start time of the
    simulation run.

    If a results directory is not provided the base results_directory is taken
    to be /share/costeffectiveness/results.

    """
    utilities.configure_master_process_logging_to_terminal(options['verbose'])
    main = handle_exceptions(runner.main, logger, options['with_debugger'])

    main(model_specification, branch_configuration, result_directory,
         {'project': options['project'],
          'queue': options['queue'],
          'peak_memory': options['peak_memory'],
          'max_runtime': options['max_runtime']},
         redis_processes=options['redis'], no_batch=options['no_batch'])
Пример #10
0
def make_ldl_exposure_thresholds(location: str, draws: str, concat_only: bool,
                                 verbose: int, with_debugger: bool) -> None:
    configure_logging_to_terminal(verbose)
    main = handle_exceptions(build_ldl_thresholds,
                             logger,
                             with_debugger=with_debugger)
    main(location, draws, concat_only, verbose)
Пример #11
0
def test():
    """Run a test simulation using the ``disease_model.yaml`` model specification
    provided in the examples directory.
    """
    configure_logging_to_terminal(verbose=True)
    model_specification = disease_model.get_model_specification_path()

    main = handle_exceptions(run_simulation, logger, with_debugger=False)

    main(model_specification)
    click.echo()
    click.secho("Installation test successful!", fg='green')
Пример #12
0
def make_specs(template: str, location: str, output_dir: str, verbose: int,
               with_debugger: bool) -> None:
    """Generate model specifications based on a template.

    The default template lives here:

    ``src/vivarium_conic_vitamin_a_supp/model_specification/model_spec.in``
    """
    configure_logging_to_terminal(verbose)
    main = handle_exceptions(build_model_specifications,
                             logger,
                             with_debugger=with_debugger)
    main(template, location, output_dir)
Пример #13
0
def run(
    model_specification: Path,
    branch_configuration: Path,
    artifact_path: Optional[Path],
    result_directory: Optional[Path],
    **options,
) -> None:
    """Run a parallel simulation.

    The simulation itself is defined by a MODEL_SPECIFICATION yaml file
    and the parameter changes across runs are defined by a BRANCH_CONFIGURATION
    yaml file.

    The path to the data artifact can be provided as an argument here, in the
    branch configuration, or in the model specification file. Values provided as
    a command line argument or in the branch specification file will override a
    value specified in the model specifications file. If an artifact path is
    provided both as a command line argument and to the branch configuration file
    a ConfigurationError will be thrown.

    Within the provided or default results directory, a subdirectory will be
    created with the same name as the MODEL_SPECIFICATION if one does not exist.
    Results will be written to a further subdirectory named after the start time
    of the simulation run.

    """
    logs.configure_main_process_logging_to_terminal(options["verbose"])
    main = handle_exceptions(runner.main, logger, options["with_debugger"])

    main(
        command=COMMANDS.run,
        input_paths=paths.InputPaths.from_entry_point_args(
            input_model_specification_path=model_specification,
            input_branch_configuration_path=branch_configuration,
            input_artifact_path=artifact_path,
            result_directory=result_directory,
        ),
        native_specification=cluster.NativeSpecification(
            job_name=model_specification.stem,
            project=options["project"],
            queue=options["queue"],
            peak_memory=options["peak_memory"],
            max_runtime=options["max_runtime"],
        ),
        redis_processes=options["redis"],
        no_batch=options["no_batch"],
        extra_args={},
    )
Пример #14
0
def restart(results_root, **options):
    """Restart a parallel simulation from a previous run at RESULTS_ROOT.

    Restarting will not erase existing results, but will start workers to
    perform the remaining simulations.  RESULTS_ROOT is expected to be an
    output directory from a previous ``psimulate run`` invocation.

    """
    utilities.configure_master_process_logging_to_terminal(options['verbose'])
    main = handle_exceptions(runner.main, logger, options['with_debugger'])

    main(None, None, results_root,
         {'project': options['project'],
          'queue': options['queue'],
          'peak_memory': options['peak_memory'],
          'max_runtime': options['max_runtime']},
         redis_processes=options['redis'], restart=True, no_batch=options['no_batch'])
Пример #15
0
def test(test_type, num_workers, result_directory, **options):
    logs.configure_main_process_logging_to_terminal(options["verbose"])
    main = handle_exceptions(runner.main, logger, options["with_debugger"])
    main(
        command=COMMANDS.load_test,
        input_paths=paths.InputPaths.from_entry_point_args(
            result_directory=result_directory, ),
        native_specification=cluster.NativeSpecification(
            job_name=f"load_test_{test_type}",
            project=options["project"],
            queue=options["queue"],
            peak_memory=options["peak_memory"],
            max_runtime=options["max_runtime"],
        ),
        redis_processes=options["redis"],
        no_batch=options["no_batch"],
        extra_args={
            "test_type": test_type,
            "num_workers": num_workers,
        },
    )
Пример #16
0
def make_specs(template: str, location: str, output_dir: str, verbose: int,
               with_debugger: bool) -> None:
    """Generate model specifications based on a template.

    The default template lives here:

    ``vivarium_gates_shigella_vaccine/src/vivarium_gates_shigella_vaccine/model_specification/model_spec.in``

    Supply the locations for which you want a model spec generated by filling
    in the empty 'locations.txt' file. A template for this file can be found at

    ``vivarium_gates_shigella_vaccine/src/vivarium_gates_shigella_vaccine/model_specification/locations.txt``

    with instructions for it's use.

    """
    configure_logging_to_terminal(verbose)
    main = handle_exceptions(build_model_specifications,
                             logger,
                             with_debugger=with_debugger)
    main(template, location, output_dir)
Пример #17
0
def expand(results_root, **options):
    """Expand a previous run at RESULTS_ROOT by adding input draws and/or
    random seeds.

    Expanding will not erase existing results, but will start workers to perform
    the additional simulations determined by the added draws/seeds.
    RESULTS_ROOT is expected to be an output directory from a previous
    ``psimulate run`` invocation.

    """
    utilities.configure_master_process_logging_to_terminal(options['verbose'])
    main = handle_exceptions(runner.main, logger, options['with_debugger'])

    main(None, None, results_root,
         {'project': options['project'],
          'queue': options['queue'],
          'peak_memory': options['peak_memory'],
          'max_runtime': options['max_runtime']},
         redis_processes=options['redis'],
         restart=True,
         expand={'num_draws': options['add_draws'],
                 'num_seeds': options['add_seeds']},
         no_batch=options['no_batch'])
Пример #18
0
def make_results(output_file: str, verbose: int, with_debugger: bool, single_run: bool) -> None:
    configure_logging_to_terminal(verbose)
    main = handle_exceptions(build_results, logger, with_debugger=with_debugger)
    main(output_file, single_run)
Пример #19
0
def parse_logs(worker_log_directory, output_file, verbose, with_debugger):
    configure_logging_to_terminal(verbose)
    main = handle_exceptions(build_results_from_logs,
                             logger,
                             with_debugger=with_debugger)
    main(worker_log_directory, output_file)
Пример #20
0
def build_htn_artifact(location):
    from vivarium_csu_hypertension_sdc.components import builder
    output_root = Path(f'/share/costeffectiveness/artifacts/{PROJECT_NAME}/')
    main = handle_exceptions(builder.build_artifact, logger, with_debugger=True)
    main(output_root, location)