How to use the amici.ExpData function in amici

To help you get started, we’ve selected a few amici examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ICB-DCM / AMICI / tests / testSBML.py View on Github external
def steadystate_simulation(self, model_module):
        def assert_fun(x):
            return self.assertTrue(x)

        model = model_module.getModel()
        model.setTimepoints(np.linspace(0, 60, 60))
        solver = model.getSolver()
        solver.setSensitivityOrder(amici.SensitivityOrder_first)
        rdata = amici.runAmiciSimulation(model, solver)
        edata = [amici.ExpData(rdata, 1, 0)]
        rdata = amici.runAmiciSimulations(model, solver, edata)

        # check roundtripping of DataFrame conversion
        df_edata = amici.getDataObservablesAsDataFrame(model, edata)
        edata_reconstructed = amici.getEdataFromDataFrame(model, df_edata)

        self.assertTrue(
            np.isclose(
                amici.ExpDataView(edata[0])
                ['observedData'],
                amici.ExpDataView(edata_reconstructed[0])
                ['observedData'],
            ).all()
        )
        self.assertTrue(
            np.isclose(
github ICB-DCM / AMICI / tests / testPreequilibration.py View on Github external
self.model = modelModulePYSB.getModel()
        self.model.setReinitializeFixedParameterInitialStates(True)

        self.solver = self.model.getSolver()
        self.solver.setSensitivityOrder(amici.SensitivityOrder_first)
        self.solver.setSensitivityMethod(amici.SensitivityMethod_forward)

        self.edata = get_data(self.model)
        self.edata.t_presim = 2
        self.edata.fixedParameters = [10, 2]
        self.edata.fixedParametersPresimulation = [3, 2]
        self.edata.fixedParametersPreequilibration = [3, 0]
        self.edata.setTimepoints([1, 5])

        self.edata_preeq = amici.ExpData(self.edata)
        self.edata_preeq.t_presim = 0
        self.edata_preeq.setTimepoints([np.infty])
        self.edata_preeq.fixedParameters = \
            self.edata.fixedParametersPreequilibration
        self.edata_preeq.fixedParametersPresimulation = ()
        self.edata_preeq.fixedParametersPreequilibration = ()

        self.edata_presim = amici.ExpData(self.edata)
        self.edata_presim.t_presim = 0
        self.edata_presim.setTimepoints([self.edata.t_presim])
        self.edata_presim.fixedParameters = \
            self.edata.fixedParametersPresimulation
        self.edata_presim.fixedParametersPresimulation = ()
        self.edata_presim.fixedParametersPreequilibration = ()

        self.edata_sim = amici.ExpData(self.edata)
github ICB-DCM / AMICI / tests / testSBML.py View on Github external
observables=observables,
                                constantParameters=constantParameters)
        sys.path.insert(0, outdir)
        import test_model_presimulation as modelModule
        model = modelModule.getModel()
        solver = model.getSolver()
        solver.setNewtonMaxSteps(0)
        model.setTimepoints(np.linspace(0, 60, 61))
        model.setSteadyStateSensitivityMode(
            amici.SteadyStateSensitivityMode_simulationFSA
        )
        solver.setSensitivityOrder(amici.SensitivityOrder_first)
        model.setReinitializeFixedParameterInitialStates(True)

        rdata = amici.runAmiciSimulation(model, solver)
        edata = amici.ExpData(rdata, 0.1, 0.0)
        edata.fixedParameters = [10, 2]
        edata.fixedParametersPresimulation = [10, 2]
        edata.fixedParametersPreequilibration = [3, 0]
        self.assertIsInstance(
            amici.runAmiciSimulation(model, solver, edata),
            amici.ReturnDataView)

        solver.setRelativeTolerance(1e-12)
        solver.setAbsoluteTolerance(1e-12)
        check_derivatives(model, solver, edata, assert_fun, epsilon=1e-4)
github ICB-DCM / AMICI / tests / testPYSB.py View on Github external
def get_data(model):
    solver = model.getSolver()
    model.setTimepoints(np.linspace(0, 60, 61))
    model.setReinitializeFixedParameterInitialStates(True)
    model.setSteadyStateSensitivityMode(
        amici.SteadyStateSensitivityMode_simulationFSA
    )

    rdata = amici.runAmiciSimulation(model, solver)
    edata = amici.ExpData(rdata, 0.1, 0.0)
    edata.t_presim = 2
    edata.fixedParameters = [10, 2]
    edata.fixedParametersPresimulation = [3, 2]
    edata.fixedParametersPreequilibration = [3, 0]
    return edata
github ICB-DCM / pyPESTO / test / test_sbml_conversion.py View on Github external
# load amici module (the usual starting point later for the analysis)
    sys.path.insert(0, os.path.abspath(model_output_dir))
    model_module = importlib.import_module(model_name)
    model = model_module.getModel()
    model.requireSensitivitiesForAllParameters()
    model.setTimepoints(np.linspace(0, 10, 11))
    model.setParameterScale(amici.ParameterScaling_log10)
    model.setParameters([-0.3, -0.7])
    solver = model.getSolver()
    solver.setSensitivityMethod(amici.SensitivityMethod_forward)
    solver.setSensitivityOrder(amici.SensitivityOrder_first)

    # generate experimental data
    rdata = amici.runAmiciSimulation(model, solver, None)
    edata = amici.ExpData(rdata, 0.05, 0.0)

    return (pypesto.AmiciObjective(model, solver, [edata], 2),
            model)
github ICB-DCM / AMICI / python / amici / pandas.py View on Github external
condition: pd.Series with FixedParameter Names/Ids as columns.
            Preequilibration conditions may be specified by appending '_preeq' as suffix.
            Presimulation conditions may be specified by appending '_presim' as suffix.
        by_id: bool, optional (default = False)
            Indicate whether in the arguments, column headers are based on ids or names.
            This should correspond to the way `df` and `condition` was created in the
            first place.

    Returns:
        ExpData instance.

    Raises:

    """
    # initialize edata
    edata = ExpData(model.get())

    # timepoints
    df = df.sort_values(by='time', ascending=True)
    edata.setTimepoints(df['time'].values.astype(float))

    # get fixed parameters from condition
    overwrite_preeq = {}
    overwrite_presim = {}
    for par in list(_get_names_or_ids(model, 'FixedParameter', by_id=by_id)):
        if par + '_preeq' in condition.keys() \
                and not math.isnan(condition[par + '_preeq']):
            overwrite_preeq[par] = condition[par + '_preeq']
        if par + '_presim' in condition.keys() \
                and not math.isnan(condition[par + '_presim']):
            overwrite_presim[par] = condition[par + '_presim']