Context#

class pharmpy.workflows.Context(name, ref=None)[source]#

Bases: ABC

Context for runs

A database of results, metadata and run files for one tool run

Parameters:
  • name (str) – Name of the context

  • ref (str) – A reference (path) to the context

Attributes Summary

broadcaster

context_path

dispatcher

model_database

ModelDatabase to store results of models run in context

name

ref

seed

Methods Summary

abort_workflow(message)

Ask the dispatcher to abort the currently running workflow directly

call_workflow(workflow, unique_name)

Ask the dispatcher to call a subworkflow

create_rng(index)

Create a random number generator

create_subcontext(name)

Create a new subcontext of this context

exists(name[, ref])

finalize()

Called after a tool has finished its run in a context can be implemented to do cleanup of the context

get_model_context_path(model)

get_ncores_for_execution()

Get number of cores for execution (using available cores among allocation)

get_parent_context()

Get the parent context of this context

get_subcontext(name)

Get one of the subcontexts of this context

get_top_level_context()

Get the top level context of this context

has_completed()

Check if the tool running in the context has completed

has_started()

Check if the tool running in the context has started

list_all_names()

Retrieve a list of all model names in the context

list_all_subcontexts()

Retrieve a list of the names of all subcontexts in the context

log_error(message[, model])

Add an error message to the log

log_info(message[, model])

Add an info message to the log

log_message(severity, message[, model])

Add a message to the log

log_warning(message[, model])

Add a warning message to the log

retrieve_annotation(name)

Retrieve an annotation for a model

retrieve_common_options()

retrieve_dispatching_options()

retrieve_final_model_entry()

Retrieve the ModelEntry of the model marked as final

retrieve_input_model_entry()

Retrieve the ModelEntry of the model marked as input

retrieve_key(name)

Retrive the key corresponding to a model name

retrieve_log([level])

Retrieve the entire log all - the entire log current - only the current Context level lower - current and sub levels

retrieve_metadata()

Read tool metadata

retrieve_model_entry(name)

retrieve_results()

Retrieve tool results

spawn_seed(rng[, n])

Spawn a new seed using a random number generator

store_annotation(name, annotation)

Store an annotation string (description) for a model

store_final_model_entry(me)

store_input_model_entry(me)

store_key(name, key)

Associate a key with a model name

store_message(severity, ctxpath, date, message)

store_metadata(metadata)

Store tool metadata

store_model_entry(me)

store_results(res)

Store tool results

Attributes Documentation

broadcaster#
context_path#
dispatcher#
model_database#

ModelDatabase to store results of models run in context

name#
ref#
seed#

Methods Documentation

abort_workflow(message)[source]#

Ask the dispatcher to abort the currently running workflow directly

call_workflow(workflow, unique_name)[source]#

Ask the dispatcher to call a subworkflow

create_rng(index)[source]#

Create a random number generator

Creating the generator will be using the seed common option, the index and the context path to get a unique sequence.

abstractmethod create_subcontext(name)[source]#

Create a new subcontext of this context

abstractmethod static exists(name, ref=None)[source]#
abstractmethod finalize()[source]#

Called after a tool has finished its run in a context can be implemented to do cleanup of the context

get_model_context_path(model)[source]#
get_ncores_for_execution()[source]#

Get number of cores for execution (using available cores among allocation)

abstractmethod get_parent_context()[source]#

Get the parent context of this context

abstractmethod get_subcontext(name)[source]#

Get one of the subcontexts of this context

abstractmethod get_top_level_context()[source]#

Get the top level context of this context

has_completed()[source]#

Check if the tool running in the context has completed

has_started()[source]#

Check if the tool running in the context has started

abstractmethod list_all_names()[source]#

Retrieve a list of all model names in the context

abstractmethod list_all_subcontexts()[source]#

Retrieve a list of the names of all subcontexts in the context

log_error(message, model=None)[source]#

Add an error message to the log

log_info(message, model=None)[source]#

Add an info message to the log

Currently with echo to stdout. In the future this could be changed or be configurable.

log_message(severity, message, model=None)[source]#

Add a message to the log

log_warning(message, model=None)[source]#

Add a warning message to the log

abstractmethod retrieve_annotation(name)[source]#

Retrieve an annotation for a model

abstractmethod retrieve_common_options()[source]#
abstractmethod retrieve_dispatching_options()[source]#
retrieve_final_model_entry()[source]#

Retrieve the ModelEntry of the model marked as final

retrieve_input_model_entry()[source]#

Retrieve the ModelEntry of the model marked as input

abstractmethod retrieve_key(name)[source]#

Retrive the key corresponding to a model name

This key can be used to lookup the model in the model database

abstractmethod retrieve_log(level='all')[source]#

Retrieve the entire log all - the entire log current - only the current Context level lower - current and sub levels

abstractmethod retrieve_metadata()[source]#

Read tool metadata

retrieve_model_entry(name)[source]#
abstractmethod retrieve_results()[source]#

Retrieve tool results

Returns:

Results – Tool results object

spawn_seed(rng, n=128)[source]#

Spawn a new seed using a random number generator

Parameters:
  • rng (Random number generator) – Random number generator

  • n (int) – Size of seed to generate in number of bits

Returns:

int – New random seed

abstractmethod store_annotation(name, annotation)[source]#

Store an annotation string (description) for a model

store_final_model_entry(me)[source]#
store_input_model_entry(me)[source]#
abstractmethod store_key(name, key)[source]#

Associate a key with a model name

abstractmethod store_message(severity, ctxpath, date, message)[source]#
abstractmethod store_metadata(metadata)[source]#

Store tool metadata

Parameters:

metadata (dict) – Tool metadata dictionary

store_model_entry(me)[source]#
abstractmethod store_results(res)[source]#

Store tool results

Parameters:

res (Results) – Tool results object