Skip to content

Commit 9355bad

Browse files
committed
feat(cellml): add flag to skip over non observable variables in cellml files
add a flag to skips over variables in the cellML that have been labeled as `"public_interface"="in"` or `"private_interface"="in"` as these are not exposed by OpenCor after simulation. No information is lost from the reports, as these variables have a connection to another component that contains the same variable, with the public interface set to "out". Accessing the variable through that component works fine.
1 parent a152d78 commit 9355bad

2 files changed

Lines changed: 100 additions & 7 deletions

File tree

biosimulators_utils/model_lang/cellml/utils.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
def get_parameters_variables_outputs_for_simulation(model_filename, model_language, simulation_type, algorithm_kisao_id=None,
26-
change_level=SedDocument, native_ids=False, native_data_types=False,
26+
change_level=SedDocument, native_ids=False, native_data_types=False, observable_only=False,
2727
config=None):
2828
""" Get the possible observables for a simulation of a model
2929
@@ -37,6 +37,7 @@ def get_parameters_variables_outputs_for_simulation(model_filename, model_langua
3737
native_ids (:obj:`bool`, optional): whether to return the raw id and name of each model component rather than the suggested name
3838
for the variable of an associated SED-ML data generator
3939
native_data_types (:obj:`bool`, optional): whether to return new_values in their native data types
40+
observable_only (:obj:`bool`, optional): whether to skip the variables that are not exposed by OpenCor
4041
config (:obj:`Config`, optional): whether to fail on missing includes
4142
4243
Returns:
@@ -66,15 +67,16 @@ def get_parameters_variables_outputs_for_simulation(model_filename, model_langua
6667
or default_ns.startswith('http://www.cellml.org/cellml/1.1')
6768
):
6869
return get_parameters_variables_for_simulation_version_1(model, root, simulation_type, algorithm_kisao_id=algorithm_kisao_id,
69-
native_ids=native_ids, native_data_types=native_data_types)
70+
native_ids=native_ids, native_data_types=native_data_types,
71+
observable_only=observable_only)
7072

7173
else:
7274
return get_parameters_variables_for_simulation_version_2(model, root, simulation_type, algorithm_kisao_id=algorithm_kisao_id,
7375
native_ids=native_ids, native_data_types=native_data_types)
7476

7577

7678
def get_parameters_variables_for_simulation_version_1(model, xml_root, simulation_type,
77-
algorithm_kisao_id=None, native_ids=False, native_data_types=False):
79+
algorithm_kisao_id=None, native_ids=False, native_data_types=False, observable_only=False):
7880
""" Get the possible observables for a simulation of a model
7981
8082
Args:
@@ -86,6 +88,7 @@ def get_parameters_variables_for_simulation_version_1(model, xml_root, simulatio
8688
native_ids (:obj:`bool`, optional): whether to return the raw id and name of each model component rather than the suggested name
8789
for the variable of an associated SED-ML data generator
8890
native_data_types (:obj:`bool`, optional): whether to return new_values in their native data types
91+
observable_only (:obj:`bool`, optional): whether to skip the variables that are not exposed by OpenCor
8992
9093
Returns:
9194
:obj:`list` of :obj:`ModelAttributeChange`: possible attributes of a model that can be changed and their default values
@@ -124,6 +127,12 @@ def get_parameters_variables_for_simulation_version_1(model, xml_root, simulatio
124127
component_name = component.attrib['name']
125128
for variable in component.xpath('cellml:variable', namespaces=namespaces):
126129
variable_name = variable.attrib['name']
130+
public_interface_in = variable.attrib.get('public_interface', None) == 'in'
131+
private_interface_in = variable.attrib.get('private_interface', None) == 'in'
132+
variable_is_hidden = private_interface_in or public_interface_in
133+
134+
if(variable_is_hidden and observable_only):
135+
continue
127136
initial_value = variable.attrib.get('initial_value', None)
128137
if initial_value is not None:
129138
params.append(ModelAttributeChange(

tests/model_lang/cellml/test_cellml_utils.py

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,53 @@ def test_get_parameters_variables_for_simulation_version_1(self):
6565
target_namespaces=namespaces,
6666
)))
6767

68+
def test_get_parameters_variables_for_simulation_version_1_observable_only(self):
69+
params, sims, vars, plots = get_parameters_variables_outputs_for_simulation(
70+
self.V1_FIXTURE_FILENAME, None, OneStepSimulation, None, observable_only=True)
71+
params, sims, vars, plots = get_parameters_variables_outputs_for_simulation(
72+
self.V1_FIXTURE_FILENAME, None, UniformTimeCourseSimulation, None, observable_only=True)
73+
74+
self.assertEqual(len(params), 13)
75+
self.assertEqual(len(vars), 30)
76+
77+
namespaces = {
78+
'cellml': 'http://www.cellml.org/cellml/1.0#',
79+
}
80+
81+
self.assertTrue(params[0].is_equal(ModelAttributeChange(
82+
id='initial_value_component_total_cytoplasmic_Ca_flux_variable_F',
83+
name='Initial value of variable "F" of component "total_cytoplasmic_Ca_flux"',
84+
target=(
85+
"/cellml:model"
86+
"/cellml:component[@name='total_cytoplasmic_Ca_flux']"
87+
"/cellml:variable[@name='F']"
88+
"/@initial_value"
89+
),
90+
target_namespaces=namespaces,
91+
new_value='96.5',
92+
)))
93+
94+
self.assertEqual(len(sims), 1)
95+
96+
sim = sims[0]
97+
self.assertIsInstance(sim, UniformTimeCourseSimulation)
98+
99+
self.assertTrue(vars[0].is_equal(Variable(
100+
id='value_component_environment_variable_time',
101+
name='Value of variable "time" of component "environment"',
102+
target=(
103+
"/cellml:model"
104+
"/cellml:component[@name='environment']"
105+
"/cellml:variable[@name='time']"
106+
),
107+
target_namespaces=namespaces,
108+
)))
109+
68110
def test_get_parameters_variables_for_simulation_version_1_native_ids_data_types(self):
69111
params, sims, vars, plots = get_parameters_variables_outputs_for_simulation(self.V1_FIXTURE_FILENAME, None, OneStepSimulation, None,
70-
native_ids=True, native_data_types=True)
112+
native_ids=True, native_data_types=True)
71113
params, sims, vars, plots = get_parameters_variables_outputs_for_simulation(self.V1_FIXTURE_FILENAME, None, UniformTimeCourseSimulation, None,
72-
native_ids=True, native_data_types=True)
114+
native_ids=True, native_data_types=True)
73115

74116
self.assertEqual(len(params), 13)
75117
self.assertEqual(len(vars), 54)
@@ -107,6 +149,48 @@ def test_get_parameters_variables_for_simulation_version_1_native_ids_data_types
107149
target_namespaces=namespaces,
108150
)))
109151

152+
def test_get_parameters_variables_for_simulation_version_1_native_ids_data_types_observable_only(self):
153+
params, sims, vars, plots = get_parameters_variables_outputs_for_simulation(self.V1_FIXTURE_FILENAME, None, OneStepSimulation, None,
154+
native_ids=True, native_data_types=True, observable_only=True)
155+
params, sims, vars, plots = get_parameters_variables_outputs_for_simulation(self.V1_FIXTURE_FILENAME, None, UniformTimeCourseSimulation, None,
156+
native_ids=True, native_data_types=True, observable_only=True)
157+
158+
self.assertEqual(len(params), 13)
159+
self.assertEqual(len(vars), 30)
160+
161+
namespaces = {
162+
'cellml': 'http://www.cellml.org/cellml/1.0#',
163+
}
164+
165+
self.assertTrue(params[0].is_equal(ModelAttributeChange(
166+
id='total_cytoplasmic_Ca_flux.F',
167+
name=None,
168+
target=(
169+
"/cellml:model"
170+
"/cellml:component[@name='total_cytoplasmic_Ca_flux']"
171+
"/cellml:variable[@name='F']"
172+
"/@initial_value"
173+
),
174+
target_namespaces=namespaces,
175+
new_value=96.5,
176+
)))
177+
178+
self.assertEqual(len(sims), 1)
179+
180+
sim = sims[0]
181+
self.assertIsInstance(sim, UniformTimeCourseSimulation)
182+
183+
self.assertTrue(vars[0].is_equal(Variable(
184+
id='environment.time',
185+
name=None,
186+
target=(
187+
"/cellml:model"
188+
"/cellml:component[@name='environment']"
189+
"/cellml:variable[@name='time']"
190+
),
191+
target_namespaces=namespaces,
192+
)))
193+
110194
def test_get_parameters_variables_for_simulation_version_2(self):
111195
params, sims, vars, plots = get_parameters_variables_outputs_for_simulation(self.V2_FIXTURE_FILENAME, None, UniformTimeCourseSimulation, None)
112196
params, sims, vars, plots = get_parameters_variables_outputs_for_simulation(self.V2_FIXTURE_FILENAME, None, OneStepSimulation, None)
@@ -149,9 +233,9 @@ def test_get_parameters_variables_for_simulation_version_2(self):
149233

150234
def test_get_parameters_variables_for_simulation_version_2_native_ids_data_types(self):
151235
params, sims, vars, plots = get_parameters_variables_outputs_for_simulation(self.V2_FIXTURE_FILENAME, None, UniformTimeCourseSimulation, None,
152-
native_ids=True, native_data_types=True)
236+
native_ids=True, native_data_types=True)
153237
params, sims, vars, plots = get_parameters_variables_outputs_for_simulation(self.V2_FIXTURE_FILENAME, None, OneStepSimulation, None,
154-
native_ids=True, native_data_types=True)
238+
native_ids=True, native_data_types=True)
155239

156240
self.assertEqual(len(params), 1)
157241
self.assertEqual(len(vars), 3)

0 commit comments

Comments
 (0)