How to use the amici.runAmiciSimulations 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
model.setTimepoints(np.linspace(0, 60, 60))
        solver = model.getSolver()
        solver.setSensitivityOrder(amici.SensitivityOrder_first)

        # run model once to create an edata
        rdata = amici.runAmiciSimulation(model, solver)
        edata = [amici.ExpData(rdata, 1, 0)]

        # just make all observables positive since some are logarithmic
        for ed in edata:
            y = ed.getObservedData()
            y = tuple([max(val, 1e-4) for val in y])
            ed.setObservedData(y)

        # and now run for real and also compute likelihood values
        rdata = amici.runAmiciSimulations(model, solver, edata)[0]

        # output for easy debugging
        for key in ['llh', 'sllh']:
            print(key, rdata[key])

        # it would be good to compute the expected llh+sllh by hand,
        # here, we only check if they make overall sense
        self.assertTrue(np.isfinite(rdata['llh']))
        self.assertTrue(np.all(np.isfinite(rdata['sllh'])))
        self.assertTrue(np.any(rdata['sllh']))
github ICB-DCM / AMICI / tests / testModels.py View on Github external
if model_name == 'model_steadystate' and \
                            case == 'sensiforwarderrorint':
                        edata = amici.amici.ExpData(self.model.get())

                    if edata and model_name != 'model_neuron_o2' and not (
                        model_name == 'model_robertson' and
                        case == 'sensiforwardSPBCG'
                    ):
                        # Test runAmiciSimulations: ensure running twice
                        # with same ExpData yields same results
                        if isinstance(edata, amici.amici.ExpData):
                            edatas = [edata, edata]
                        else:
                            edatas = [edata.get(), edata.get()]

                        rdatas = amici.runAmiciSimulations(
                            self.model, self.solver, edatas, num_threads=2,
                            failfast=False
                        )
                        verify_simulation_results(
                            rdatas[0],
                            expected_results[subTest][case]['results'],
                            assert_fun, **verify_simulation_opts
                        )
                        verify_simulation_results(
                            rdatas[1],
                            expected_results[subTest][case]['results'],
                            assert_fun, **verify_simulation_opts
                        )

                    self.assertRaises(
                        RuntimeError,
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(
                amici.ExpDataView(edata[0])
github ICB-DCM / pyPESTO / pypesto / objective / amici_calculator.py View on Github external
amici_solver.setSensitivityOrder(sensi_order-1)
        else:
            amici_solver.setSensitivityOrder(sensi_order)

        # fill in parameters
        # TODO (#226) use plist to compute only required derivatives
        amici.parameter_mapping.fill_in_parameters(
            edatas=edatas,
            problem_parameters=x_dct,
            scaled_parameters=True,
            parameter_mapping=parameter_mapping,
            amici_model=amici_model
        )

        # run amici simulation
        rdatas = amici.runAmiciSimulations(
            amici_model,
            amici_solver,
            edatas,
            num_threads=min(n_threads, len(edatas)),
        )
        if not self._known_least_squares_safe and mode == MODE_RES and \
                sensi_order > 0:
            if any(
                ((r['ssigmay'] is not None and np.any(r['ssigmay']))
                 or
                 (r['ssigmaz'] is not None and np.any(r['ssigmaz'])))
                for r in rdatas
            ):
                raise RuntimeError('Cannot use least squares solver with'
                                   'parameter dependent sigma!')
            self._known_least_squares_safe = True  # don't check this again