Skip to content

Commit

Permalink
More refined fixes thanks to Jim Schaff
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeByDrescher committed Oct 4, 2024
1 parent 99db768 commit 878c748
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
13 changes: 6 additions & 7 deletions biosimulators_copasi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def exec_sed_task(task: Task, variables: List[Variable], preprocessed_task: Opti
preprocessed_task.basico_data_model.removeInterface(dh)

# Process output 'data'
actual_output_length, _ = data.shape
copasi_output_length, _ = data.shape
variable_results = VariableResults()
offset = preprocessed_task.init_time_offset

Expand All @@ -220,8 +220,7 @@ def exec_sed_task(task: Task, variables: List[Variable], preprocessed_task: Opti
try:
series = data.loc[:, data_target]
except KeyError as e:
msg = "Unable to find output. Most likely a bug regarding BASICO and DisplayNames with nested braces."
raise RuntimeError(msg, e)
raise RuntimeError("Unable to find output", e)
# Check for duplicates (yes, that can happen)
if isinstance(series, pandas.DataFrame):
_, num_cols = series.shape
Expand All @@ -232,13 +231,13 @@ def exec_sed_task(task: Task, variables: List[Variable], preprocessed_task: Opti
series: pandas.Series = first_sub_series

if basico_task_settings["problem"]["Duration"] > 0.0:
variable_results[variable.id] = numpy.full(actual_output_length, numpy.nan)
variable_results[variable.id] = numpy.full(copasi_output_length, numpy.nan)
for index, value in enumerate(series):
variable_results[variable.id][index] = value if data_target != "Time" else value + offset
adjusted_value = value if data_target != "Time" else value + offset
variable_results[variable.id][index] = adjusted_value
else:
value = series.get(0) if data_target != "Time" else series.get(0) + offset
sedml_utc_sim: Simulation = task.simulation
variable_results[variable.id] = numpy.full(sedml_utc_sim.number_of_steps + 1, value)
variable_results[variable.id] = numpy.full(copasi_output_length, value)
except Exception as e:
raise e

Expand Down
9 changes: 4 additions & 5 deletions biosimulators_copasi/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,14 +985,14 @@ def configure_simulation_settings(self, sim: Union[UniformTimeCourseSimulation,
self.init_time_offset: float = self.sim.initial_time
self._duration_arg: float = self.sim.output_end_time - self.init_time_offset # COPASI is kept in the dark
self._step_size: float = BasicoInitialization._calc_simulation_step_size(self.sim)
self.number_of_steps = self._duration_arg / self._step_size
if int(self.number_of_steps) != self.number_of_steps:
self.number_of_steps = sim.number_of_steps
if int(round(self.number_of_steps)) != self.number_of_steps:
difference = self.number_of_steps - int(round(self.number_of_steps))
decimal_off = difference / int(round(self.number_of_steps))
if abs(decimal_off) > pow(10, -6):
raise NotImplementedError("Number of steps must be an integer number of time points, "
f"not '{self.number_of_steps}'")
self.number_of_steps = int(self.number_of_steps)
self.number_of_steps = int(round(self.number_of_steps))
self._length_of_output: int = (
int((self.sim.output_end_time - self.sim.output_start_time) / self._step_size))
self._length_of_output += 1
Expand All @@ -1004,7 +1004,6 @@ def get_simulation_configuration(self) -> dict:
problem = {
"AutomaticStepSize": False,
"StepNumber": self.number_of_steps,
"StepSize": self._step_size,
"Duration": self._duration_arg,
"OutputStartTime": self.sim.output_start_time - self.init_time_offset
}
Expand Down Expand Up @@ -1048,7 +1047,7 @@ def _calc_simulation_step_size(sim: UniformTimeCourseSimulation) -> int:
time_diff = sim.output_end_time - sim.output_start_time
if time_diff == 0:
raise ZeroDivisionError # We want to have exactly 1 step, and that's what our except block does
step_size_arg = time_diff / sim.number_of_steps
step_size_arg = (sim.output_end_time - sim.initial_time) / sim.number_of_steps
except ZeroDivisionError: # sim.output_end_time == sim.output_start_time
step_size_arg = sim.number_of_points

Expand Down

0 comments on commit 878c748

Please sign in to comment.