Skip to content

Emulation class

The Emulation class is alsways created using the EmulationFactory class. The Emulation class is the main class for the emulation. It is used to create and run the emulation.

A top level class to store all information about an emulation run.

Note that since the ideal parameter is useful when comparing the emulator results with the simulator for all points. Providing such results may not be always possible. Therefore, the ideal parameter is optional.

Parameters:

Name Type Description Default
configs Configs

The configuration yml file

required
solver Solver

The solver

required
simulator Simulator

The simulator containing experimental data

required
emulator Emulator

The emulator

required
ideal Optional[Simulator]

The simulator containing ideal data (for all emulated points)

field(default=None)
Source code in emulode/emulation.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@dataclass
class Emulation:
    """
    A top level class to store all information about an emulation run.

    Note that since the `ideal` parameter is useful when comparing the
    emulator results with the simulator for all points. Providing such
    results may not be always possible. Therefore, the `ideal` parameter
    is optional.

    Args:
        configs: The configuration yml file
        solver: The solver
        simulator: The simulator containing experimental data
        emulator: The emulator
        ideal: The simulator containing ideal data (for all emulated points)

    """

    configs: Configs
    ode: ODE
    solver: Solver
    simulator: Simulator
    emulator: Emulator
    ideal: Optional[Simulator] = field(default=None)

    def plot(self) -> None:
        """
        Create a combined plot containing the `simulator`, `emulator` and
        `ideal` data (if provided) and saves it to the file specified in the
        `configs` parameter.
        """

        Plotter.create_combined_plot(
            self.configs, self.emulator, self.simulator, self.ideal, save=True
        )

plot()

Create a combined plot containing the simulator, emulator and ideal data (if provided) and saves it to the file specified in the configs parameter.

Source code in emulode/emulation.py
42
43
44
45
46
47
48
49
50
51
def plot(self) -> None:
    """
    Create a combined plot containing the `simulator`, `emulator` and
    `ideal` data (if provided) and saves it to the file specified in the
    `configs` parameter.
    """

    Plotter.create_combined_plot(
        self.configs, self.emulator, self.simulator, self.ideal, save=True
    )

EmulationFactory class

The EmulationFactory class is used to create an Emulation object. This object is used to create and run the emulation.

Factory class for the creating the Emulator object.

Currrntly, only yml configuration files are supported. Future versions may support JSON and other configuration files.

Source code in emulode/emulation.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
class EmulationFactory:
    """
    Factory class for the creating the Emulator object.

    Currrntly, only yml configuration files are supported. Future versions
    may support JSON and other configuration files.
    """

    @staticmethod
    def create_from_yml_file(config_file: os.PathLike, ideal_run: bool) -> Emulation:
        """
        Create an `Emulation` object from a yml configuration file.

        Args:
            config_file: The configuration yml file
            ideal_run: Whether to include ideal results

        """

        configs = Configs(config_file)

        ode = ODEFactory.create_from_config(configs)
        solver = SolverFactory.create_from_config(ode, configs)
        simulator = SimulatorFactory.create_from_config(solver, configs)
        emulator = EmulatorFactory.create_from_config(simulator, configs)

        if ideal_run:
            ideal = SimulatorFactory.create_from_config(solver, configs, ideal=True)
            return Emulation(configs, ode, solver, simulator, emulator, ideal)

        return Emulation(configs, ode, solver, simulator, emulator)

    @staticmethod
    def create_from_json_file(config_file: os.PathLike) -> Emulation:
        """
        Create an `Emulation` object from a json configuration file
        (in future).
        """

        raise NotImplementedError("JSON configuration files not supported yet")

create_from_json_file(config_file) staticmethod

Create an Emulation object from a json configuration file (in future).

Source code in emulode/emulation.py
86
87
88
89
90
91
92
93
@staticmethod
def create_from_json_file(config_file: os.PathLike) -> Emulation:
    """
    Create an `Emulation` object from a json configuration file
    (in future).
    """

    raise NotImplementedError("JSON configuration files not supported yet")

create_from_yml_file(config_file, ideal_run) staticmethod

Create an Emulation object from a yml configuration file.

Parameters:

Name Type Description Default
config_file PathLike

The configuration yml file

required
ideal_run bool

Whether to include ideal results

required
Source code in emulode/emulation.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
@staticmethod
def create_from_yml_file(config_file: os.PathLike, ideal_run: bool) -> Emulation:
    """
    Create an `Emulation` object from a yml configuration file.

    Args:
        config_file: The configuration yml file
        ideal_run: Whether to include ideal results

    """

    configs = Configs(config_file)

    ode = ODEFactory.create_from_config(configs)
    solver = SolverFactory.create_from_config(ode, configs)
    simulator = SimulatorFactory.create_from_config(solver, configs)
    emulator = EmulatorFactory.create_from_config(simulator, configs)

    if ideal_run:
        ideal = SimulatorFactory.create_from_config(solver, configs, ideal=True)
        return Emulation(configs, ode, solver, simulator, emulator, ideal)

    return Emulation(configs, ode, solver, simulator, emulator)