How to use the amici.runAmiciSimulation 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 / pyPESTO / test / test_sbml_conversion.py View on Github external
verbose=False)

    # 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 / tests / testPreequilibration.py View on Github external
def test_parameter_reordering(self):
        rdata_ordered = amici.runAmiciSimulation(
            self.model, self.solver, self.edata
        )

        for plist in self.plists:
            with self.subTest(plist=plist):

                self.model.setParameterList(plist)
                rdata_reordered = amici.runAmiciSimulation(
                    self.model, self.solver, self.edata
                )

                for ip, p_index in enumerate(plist):
                    self.assertTrue(np.isclose(
                        rdata_ordered['sx'][:, p_index, :],
                        rdata_reordered['sx'][:, ip, :],
                        1e-6, 1e-6
github ICB-DCM / AMICI / tests / testPYSB.py View on Github external
def get_results(model, edata):
    solver = model.getSolver()
    solver.setSensitivityOrder(1)
    model.setTimepoints(np.linspace(0, 60, 61))
    model.setReinitializeFixedParameterInitialStates(True)
    model.setSteadyStateSensitivityMode(
        amici.SteadyStateSensitivityMode_simulationFSA
    )
    return amici.runAmiciSimulation(model, solver, edata)
github ICB-DCM / AMICI / tests / testPreequilibration.py View on Github external
settings = itertools.product(self.pscales, self.plists)

        for pscale, plist in settings:

            self.model.setInitialStates([])
            self.model.setInitialStateSensitivities([])
            self.model.setParameterList(plist)
            self.model.setParameterScale(pscale)

            # combined
            rdata_auto = amici.runAmiciSimulation(
                self.model, self.solver, self.edata
            )

            # manual preqquilibration
            rdata_preeq = amici.runAmiciSimulation(
                self.model, self.solver, self.edata_preeq
            )

            # manual reinitialization + presimulation
            x0 = rdata_preeq['x'][0, :]
            x0[1] = self.edata_presim.fixedParameters[0]
            x0[2] = self.edata_presim.fixedParameters[1]
            sx0 = rdata_preeq['sx'][0, :, :]
            sx0[:, 1] = 0
            sx0[:, 2] = 0
            self.model.setInitialStates(x0)
            self.model.setInitialStateSensitivities(
                sx0.flatten()
            )
            rdata_presim = amici.runAmiciSimulation(
                self.model, self.solver, self.edata_presim
github ICB-DCM / AMICI / tests / testPreequilibration.py View on Github external
# otherwise we will mess up parameter value
        self.model.setParameterScale(amici.parameterScalingFromIntVector([
            amici.ParameterScaling_log10
            if scaling == amici.ParameterScaling_none
            else amici.ParameterScaling_none
            for scaling in self.model.getParameterScale()
        ]))

        self.edata.x0 = rdata['x_ss']
        self.edata.sx0 = rdata['sx_ss'].flatten()

        # perturb model initial states
        self.model.setInitialStates(rdata['x_ss'] * 4)
        self.model.setInitialStateSensitivities(rdata['sx_ss'].flatten() / 2)

        rdata_edata = amici.runAmiciSimulation(
            self.model, self.solver, self.edata
        )
        for variable in ['x', 'sx']:
            with self.subTest(variable=variable):
                self.assertTrue(np.isclose(
                    rdata[variable][0, :],
                    rdata_edata[variable][0, :],
                    1e-6, 1e-6
                ).all())
github ICB-DCM / AMICI / tests / testPYSB.py View on Github external
verbose=False,
                    compute_conservation_laws=compute_conservation_laws
                )
                sys.path.insert(0, outdir)

                amici_model_module = importlib.import_module(pysb_model.name)

                model_pysb = amici_model_module.getModel()

                model_pysb.setTimepoints(tspan)

                solver = model_pysb.getSolver()
                solver.setMaxSteps(int(1e5))
                solver.setAbsoluteTolerance(atol)
                solver.setRelativeTolerance(rtol)
                rdata = amici.runAmiciSimulation(model_pysb, solver)

                # check agreement of species simulation

                self.assertTrue(np.isclose(
                    rdata['x'],
                    pysb_simres.species,
                    1e-4, 1e-4
                ).all())
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 / AMICI / tests / testPreequilibration.py View on Github external
rdata_presim = amici.runAmiciSimulation(
                self.model, self.solver, self.edata_presim
            )

            # manual reinitialization + simulation
            x0 = rdata_presim['x'][0, :]
            x0[1] = self.edata_sim.fixedParameters[0]
            x0[2] = self.edata_sim.fixedParameters[1]
            sx0 = rdata_presim['sx'][0, :, :]
            sx0[:, 1] = 0
            sx0[:, 2] = 0
            self.model.setInitialStates(x0)
            self.model.setInitialStateSensitivities(
                sx0.flatten()
            )
            rdata_sim = amici.runAmiciSimulation(
                self.model, self.solver, self.edata_sim
            )

            for variable in ['x', 'sx']:
                with self.subTest(pscale=pscale, plist=plist,
                                  variable=variable):
                    self.assertTrue(np.isclose(
                        rdata_auto[variable],
                        rdata_sim[variable],
                        1e-6, 1e-6
                    ).all())
github ICB-DCM / AMICI / tests / testPreequilibration.py View on Github external
rdata_preeq = amici.runAmiciSimulation(
                self.model, self.solver, self.edata_preeq
            )

            # manual reinitialization + presimulation
            x0 = rdata_preeq['x'][0, :]
            x0[1] = self.edata_presim.fixedParameters[0]
            x0[2] = self.edata_presim.fixedParameters[1]
            sx0 = rdata_preeq['sx'][0, :, :]
            sx0[:, 1] = 0
            sx0[:, 2] = 0
            self.model.setInitialStates(x0)
            self.model.setInitialStateSensitivities(
                sx0.flatten()
            )
            rdata_presim = amici.runAmiciSimulation(
                self.model, self.solver, self.edata_presim
            )

            # manual reinitialization + simulation
            x0 = rdata_presim['x'][0, :]
            x0[1] = self.edata_sim.fixedParameters[0]
            x0[2] = self.edata_sim.fixedParameters[1]
            sx0 = rdata_presim['sx'][0, :, :]
            sx0[:, 1] = 0
            sx0[:, 2] = 0
            self.model.setInitialStates(x0)
            self.model.setInitialStateSensitivities(
                sx0.flatten()
            )
            rdata_sim = amici.runAmiciSimulation(
                self.model, self.solver, self.edata_sim