Skip to content

Commit

Permalink
isort and black formating
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaskoenig committed Nov 5, 2020
1 parent 00d61b2 commit 02498e6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

from sbmlsim.data import Data
from sbmlsim.experiment import SimulationExperiment, ExperimentRunner
from sbmlsim.experiment import ExperimentRunner, SimulationExperiment
from sbmlsim.model import AbstractModel, RoadrunnerSBMLModel
from sbmlsim.plot import Axis, Figure
from sbmlsim.simulation import (
Expand All @@ -21,6 +21,7 @@
from sbmlsim.simulator.simulation_ray import SimulatorParallel, SimulatorSerial
from sbmlsim.task import Task


base_path = Path(__file__).parent


Expand All @@ -30,20 +31,15 @@ class AssignmentExperiment(SimulationExperiment):
def models(self) -> Dict[str, AbstractModel]:
return {
"model": RoadrunnerSBMLModel(
source=base_path / "initial_assignment.xml",
ureg=self.ureg
source=base_path / "initial_assignment.xml", ureg=self.ureg
),
"model_changes": RoadrunnerSBMLModel(
source=base_path / "initial_assignment.xml",
ureg=self.ureg,
changes={
"D": self.Q_(2.0, "mmole")
}
)
changes={"D": self.Q_(2.0, "mmole")},
),
}



def tasks(self) -> Dict[str, Task]:
tasks = {}
for model_key in self._models.keys():
Expand All @@ -54,30 +50,25 @@ def tasks(self) -> Dict[str, Task]:
return tasks

def datagenerators(self) -> None:
self.add_selections(selections=[
"time", "A1", "[A1]", "D"
])
self.add_selections(selections=["time", "A1", "[A1]", "D"])

def simulations(self) -> Dict[str, AbstractSim]:
Q_ = self.Q_
tcs = {}
tcs["sim1"] = TimecourseSim(
[
Timecourse(
start=0, end=20, steps=200, changes={}
)
]
[Timecourse(start=0, end=20, steps=200, changes={})]
)
tcs["sim2"] = TimecourseSim(
[
Timecourse(start=0, end=10, steps=200, changes={}),
Timecourse(
start=0, end=10, steps=200, changes={}
),
Timecourse(
start=0, end=10, steps=200, changes={
start=0,
end=10,
steps=200,
changes={
"D": Q_(10.0, "mmole"),
}
)
},
),
]
)

Expand Down Expand Up @@ -107,12 +98,27 @@ def figures(self) -> Dict[str, Figure]:
"color": colors[ks],
"linestyle": "-" if model_key == "model" else "--",
}
plots[0].add_data(task=task_key, xid="time", yid="A1",
label=f"{model_key} {sim_key}", **kwargs)
plots[1].add_data(task=task_key, xid="time", yid="[A1]",
label=f"{model_key} {sim_key}", **kwargs)
plots[2].add_data(task=task_key, xid="time", yid="D",
label=f"{model_key} {sim_key}", **kwargs)
plots[0].add_data(
task=task_key,
xid="time",
yid="A1",
label=f"{model_key} {sim_key}",
**kwargs,
)
plots[1].add_data(
task=task_key,
xid="time",
yid="[A1]",
label=f"{model_key} {sim_key}",
**kwargs,
)
plots[2].add_data(
task=task_key,
xid="time",
yid="D",
label=f"{model_key} {sim_key}",
**kwargs,
)
return {
fig1.sid: fig1,
}
Expand All @@ -126,11 +132,9 @@ def run(output_path):
AssignmentExperiment,
simulator=SimulatorParallel(),
base_path=base_path,
data_path=base_path
)
runner.run_experiments(
output_path=output_path / "results", show_figures=True
data_path=base_path,
)
runner.run_experiments(output_path=output_path / "results", show_figures=True)


if __name__ == "__main__":
Expand Down
8 changes: 6 additions & 2 deletions src/sbmlsim/simulation/timecourse.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def remove_model_change(self, sid: str):

def normalize(self, udict, ureg):
""" Normalize values to model units for all changes."""
self.model_changes = Units.normalize_changes(self.model_changes, udict=udict, ureg=ureg)
self.model_changes = Units.normalize_changes(
self.model_changes, udict=udict, ureg=ureg
)
self.changes = Units.normalize_changes(self.changes, udict=udict, ureg=ureg)

def strip_units(self):
Expand Down Expand Up @@ -134,7 +136,9 @@ def __init__(
else:
for k, tc in enumerate(self.timecourses):
if k > 0 and tc.model_changes:
logger.error(f"'model_changes' only allowed on first timecourse: {tc}")
logger.error(
f"'model_changes' only allowed on first timecourse: {tc}"
)

self.selections = deepcopy(selections)
self.reset = reset
Expand Down
3 changes: 1 addition & 2 deletions src/sbmlsim/simulator/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import logging

import pandas as pd
from roadrunner import RoadRunner, SelectionRecord

from sbmlsim.model import ModelChange
from sbmlsim.result import XResult
from sbmlsim.simulation import ScanSim, Timecourse, TimecourseSim

from roadrunner import RoadRunner

from roadrunner import SelectionRecord
logger = logging.getLogger(__name__)


Expand Down

0 comments on commit 02498e6

Please sign in to comment.