Skip to content

Commit

Permalink
Fix label indexes.
Browse files Browse the repository at this point in the history
Seemingly, when we added the rules and converted things through sets, the indexes of the labels can change from the indexes of the results that PySCeS exports.  Happily, the results come with labels already, so this switches things up to just use those labels.
  • Loading branch information
luciansmith committed Oct 18, 2024
1 parent 3598c44 commit 051cf94
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions biosimulators_pysces/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,18 @@ def exec_sed_task(task, variables, preprocessed_task=None, log=None, config=None
model.Simulate()

# extract results
results = model.data_sim.getAllSimData(lbls=False)
results, labels = model.data_sim.getAllSimData(lbls=True)
variable_results = VariableResults()
variable_results_model_attr_map = preprocessed_task['model']['variable_results_model_attr_map']
for variable in variables:
i_results, model_attr_name = variable_results_model_attr_map[(variable.target, variable.symbol)]
if i_results is not None:
variable_results[variable.id] = results[:, i_results][-(sim.number_of_points + 1):]
label = variable_results_model_attr_map[(variable.target, variable.symbol)]
index = labels.index(label)

if index is not None:
variable_results[variable.id] = results[:, index][-(sim.number_of_points + 1):]
else:
variable_results[variable.id] = numpy.full((sim.number_of_points + 1,), getattr(model, model_attr_name))
raise ValueError("No variable " + variable.id + " found in simulation output.")
#variable_results[variable.id] = numpy.full((sim.number_of_points + 1,), getattr(model, model_attr_name))

# log action
if config.LOG:
Expand Down Expand Up @@ -339,18 +342,18 @@ def preprocess_sed_task(task, variables, config=None):
for variable in variables:
if variable.symbol:
if variable.symbol == Symbol.time.value:
variable_results_model_attr_map[(variable.target, variable.symbol)] = (0, None)
variable_results_model_attr_map[(variable.target, variable.symbol)] = "Time"
else:
unpredicted_symbols.append(variable.symbol)

else:
sbml_id = variable_target_sbml_id_map[variable.target]
try:
i_dynamic = dynamic_ids.index(sbml_id)
variable_results_model_attr_map[(variable.target, variable.symbol)] = (i_dynamic, None)
variable_results_model_attr_map[(variable.target, variable.symbol)] = sbml_id
except ValueError:
if sbml_id in fixed_ids:
variable_results_model_attr_map[(variable.target, variable.symbol)] = (None, sbml_id)
variable_results_model_attr_map[(variable.target, variable.symbol)] = sbml_id
else:
unpredicted_targets.append(variable.target)

Expand Down

0 comments on commit 051cf94

Please sign in to comment.