vivarium-collective / vivarium-biosimulators

A Vivarium wrapper for BioSimulators
1 stars 0 forks source link

Fba update #22

Closed eagmon closed 3 years ago

eagmon commented 3 years ago

more changes toward getting the ODE_FBA composite working.

eagmon commented 3 years ago

@jonrkarr -- I got fba to successfully update targets! The next error comes when running the tellurium process, in biosimulators_tellurium.core.preprocess_sed_task. This calls get_model_change_target_tellurium_change_map, which raises a ValueError for most of the parameters that I preprocesses because they are not included in component_ids.

Allowable component_ids include:

component_ids ['ACCOA', 'ACO', 'ACP', 'AKG', 'BPG', 'CIT', 'DAP', 'E4P', 'F6P', 'FDP', 'FUM', 'G6P', 'GAP', 'GL6P', 'GLX', 'ICIT', 'KDPG', 'MAL', 'NAD', 'NADH', 'NADP', 'NADPH', 'OAA', 'PEP', 'PGA2', 'PGA3', 'PGN', 'PYR', 'Q', 'QH2', 'R5P', 'RU5P', 'S7P', 'SUC', 'SUCCOA', 'X5P', 'ei', 'eiP', 'eiia', 'eiiaP', 'eiicb', 'eiicbP', 'hpr', 'hprP', 'icd', 'icdP', 'tal', 'talC3', 'tkt', 'tktC2', 'ADP', 'AMP', 'ATP', 'CAMP', 'P', 'FAD', 'FADH2', 'ACEx', 'GLCx', 'ACEx_0', 'Hout', 'GLCp', 'Pp', 'ACEp', 'COA', 'HCO3', 'MG', 'ASP', 'CYS', 'MN', 'Hin', 'H2O', 'O2', 'Px', 'MgADP', 'MgATP', 'MgFDP', 'FEED', 'KdADPMg', 'KdATPMg', 'KdFDPMg', 'KmICIT_ACN', 'KmCIT_ACN', 'KmACO_ACN', 'KeqNDH', 'cell', 'extracellular', 'cell_periplasm']

A very small sample of what is not allowed:

These are all inputs that were pulled out of the model using get_parameters_variables_outputs_for_simulation, with native_ids=True.

Any thoughts about what could be going wrong? Do I need to somehow process the inputs to ones that are allowed in the simulator? Or maybe component_ids in biosimulators_tellurium needs to be more extensive?

jonrkarr commented 3 years ago

Any attribute that you might want to change needs to be pre-processed so that we can build a map from its XML targets to each simulation tool' internal representation

jonrkarr commented 3 years ago

The error is indicating that we don't know how to make those changes because its not part of the map from XML targets to the simulation tool.

eagmon commented 3 years ago

@jonrkarr -- Is this not sufficient:

        self.task.model.changes = []
        for variable in self.inputs:
            self.task.model.changes.append(ModelAttributeChange(
                target=variable.target,
                target_namespaces=variable.target_namespaces,
            ))

self.inputs comes from get_parameters_variables_outputs_for_simulation with native_ids. Right after this step we do the preprocessing, which is where the mapping fails:

        self.sed_task_config = Config(LOG=False)
        self.preprocessed_task = self.preprocess_sed_task(
            self.task,
            self.outputs,
            config=self.sed_task_config,
        )
jonrkarr commented 3 years ago

I think issue is that these are instances of SBML LocalParameter (parameters nested within rate laws for specific reactions), and tellurium doesn't expose the ability to change the local parameters. I don't see why other simulation tools would have a similar limitation. I'll have to add an option to filter these out from the list of possible inputs.

eagmon commented 3 years ago

Yes, these come from a bunch of listOfParameters in the xml file. If they are filtered out, I think the problem would be avoided. Is there a way to know which inputs are not compatible with preprocessing?

jonrkarr commented 3 years ago

Different simulators expose different capabilities, which largely aren't documented. Unfortunately, we're going to have to discover them by trial and error.

There are some clues in http://sbml.org/Facilities/Database. But, there's a variety of limitations. It only includes a few tools, this tests SBML feature support, not the ability to programmatically make changes through APIs, most of the information is old, etc.

jonrkarr commented 3 years ago

SBML has two kinds of parameters. Global parameters (Parameter) and rate law-specific parameters (LocalParameter). To add more complexity, these slightly differently in different versions of SBML.

tellurium probably doesn't allow changes because in older SBML these local parameters didn't have to have unique ids (i.e. there wasn't a clear way to address them).

eagmon commented 3 years ago

I could make an option for allowable_inputs to BiosimulatorProcess, which would make the user specify which inputs can be used. But if this option is not provided, it would try to use all the inputs and some models would fail with the above ValueError.

jonrkarr commented 3 years ago

I'll push a change in a minute. By default, local parameters won't be included. No need to change your code.

You

jonrkarr commented 3 years ago

This should be released to PyPI in a few minutes. It might be easier to work from the version in GitHub.

jonrkarr commented 3 years ago

We're keeping track of this information in a Google sheet until we understand the landscape and know how to manage this information. https://docs.google.com/spreadsheets/d/1j1A-UuTntD6eis9akyIB_dWgqZvSOWWG-NSRQOFzMLo/edit?usp=sharing

The main way we're discovering this is by seeing what published models have done and trying them with multiple tools. We've already worked through the BiGG models. For SMBL kinetic, we're working through BioModels. As we work through models, they'll be published to https://biosimulations.org. These would be guaranteed to be reusable (with at least 1 tool). For SBML, we have to pay careful attention to the ability to use models with multiple tools.

eagmon commented 3 years ago

@jonrkarr Thanks! That seems to have worked. Next error:

  File "/Users/eranagmon/code/vivarium-biosimulators/vivarium_biosimulators/processes/biosimulator_process.py", line 315, in run_task
    raw_results, log = self.exec_sed_task(
  File "/Users/eranagmon/.pyenv/versions/v-tellurium/lib/python3.9/site-packages/biosimulators_tellurium/core.py", line 241, in exec_sed_task
    road_runner.model[component_id] = new_value
  File "/Users/eranagmon/.pyenv/versions/v-tellurium/lib/python3.9/site-packages/roadrunner/roadrunner.py", line 2402, in __setitem__
    return _roadrunner.ExecutableModel___setitem__(self, id, value)
RuntimeError: could not set value for MgADP, it is defined by an assignment rule, can not be set independently., at int rrllvm::LLVMExecutableModel::setValues(bool (*)(rrllvm::LLVMModelData *, int, double), GetNameFuncPtr, size_t, const int *, const double *)
Uncaught exception. Entering post mortem debugging

This is coming from in biosimulators_tellurium's exec_sed_task, when trying to update a value in roadrunner.model:

    # apply model changes
    if model.changes:
        raise_errors_warnings(validation.validate_model_change_types(model.changes, (ModelAttributeChange, )),
                              error_summary='Changes for model `{}` are not supported.'.format(model.id))
        for change in model.changes:
            component_id = preprocessed_task.model_change_target_tellurium_id_map[change.target]
            new_value = float(change.new_value)
            road_runner.model[component_id] = new_value  # THIS IS WHERE THE ERROR HAPPENS

road_runner.model['MgADP'] has a value already, but it can not be changed. "it is defined by an assignment rule, can not be set independently."

jonrkarr commented 3 years ago

I'll filter this out too. This is another trivial change. I'll take care of this around 9pm.

This a parameter or variable set via an instance of SBML AssignmentRule or InitialAssignment. Such variables/parameters have an associated value/initial conditions stored in SBML files. However, these values basically are irrelevant because the values are controlled by algebraic expressions derived from the values of other parameters and/or variables. Changes at the XML level are possible, although meaningless. Simulation tools seem to handle such parameters/variables differently.

jonrkarr commented 3 years ago

I filtered out all inputs that have an associated initialAssigment or assignmentRule in 0.1.136.

FYI, I'm not sure this isn't overly restrictive -- I'm sure all simulation tools behave the same way tellurium does for assignments.