Skip to content

Commit

Permalink
Merge branch 'develop' into fix_cmake_dbg
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl authored Dec 3, 2023
2 parents 983bb82 + dff4ec3 commit 014d348
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_branch.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Deploy Branch
on: [push, merge_group, workflow_dispatch]
on: [push, pull_request, merge_group, workflow_dispatch]

jobs:
sdist:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_install.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Installation
on: [push, merge_group, workflow_dispatch]
on: [push, pull_request, merge_group, workflow_dispatch]

jobs:
archive:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_petab_test_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
tests/petab_test_suite/
- name: Codecov
if: github.event_name == 'pull_request' || github.repository_owner == 'AMICI-dev'
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/test_python_cplusplus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
branches:
- master
- develop

jobs:
ubuntu-cpp-python-tests:
Expand Down Expand Up @@ -65,6 +66,7 @@ jobs:
${AMICI_DIR}/python/tests/test_splines.py
- name: Codecov Python
if: github.event_name == 'pull_request' || github.repository_owner == 'AMICI-dev'
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -84,6 +86,7 @@ jobs:
&& lcov -a coverage_cpp.info -a coverage_py.info -o coverage.info
- name: Codecov CPP
if: github.event_name == 'pull_request' || github.repository_owner == 'AMICI-dev'
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -92,6 +95,7 @@ jobs:
fail_ci_if_error: true

- name: Run sonar-scanner
if: ${{ env.SONAR_TOKEN != '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down Expand Up @@ -137,6 +141,7 @@ jobs:
${AMICI_DIR}/python/tests/test_splines_short.py
- name: Codecov Python
if: github.event_name == 'pull_request' || github.repository_owner == 'AMICI-dev'
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -156,6 +161,7 @@ jobs:
&& lcov -a coverage_cpp.info -a coverage_py.info -o coverage.info
- name: Codecov CPP
if: github.event_name == 'pull_request' || github.repository_owner == 'AMICI-dev'
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -164,6 +170,7 @@ jobs:
fail_ci_if_error: true

- name: Run sonar-scanner
if: ${{ env.SONAR_TOKEN != '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_sbml_semantic_test_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
path: tests/amici-semantic-results

- name: Codecov SBMLSuite
if: github.event_name == 'pull_request' || github.repository_owner == 'AMICI-dev'
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- cron: '48 4 * * *'
pull_request:
branches:
- develop
- master

jobs:
Expand Down
15 changes: 15 additions & 0 deletions include/amici/forwardproblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ class ForwardProblem {

void handleEvent(realtype* tlastroot, bool seflag, bool initial_event);

/**
* @brief Store pre-event model state
*
* @param seflag Secondary event flag
* @param initial_event initial event flag
*/
void store_pre_event_state(bool seflag, bool initial_event);

/**
* @brief Check for, and if applicable, handle any secondary events
*
* @param tlastroot pointer to the timepoint of the last event
*/
void handle_secondary_event(realtype* tlastroot);

/**
* @brief Extract output information for events
*/
Expand Down
138 changes: 73 additions & 65 deletions src/forwardproblem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,77 @@ void ForwardProblem::handleEvent(
if (model->nz > 0)
storeEvent();

store_pre_event_state(seflag, initial_event);

if (!initial_event)
model->updateHeaviside(roots_found_);

applyEventBolus();

if (solver->computingFSA()) {
/* compute the new xdot */
model->fxdot(t_, x_, dx_, xdot_);
applyEventSensiBolusFSA();
}

handle_secondary_event(tlastroot);

/* only reinitialise in the first event fired */
if (!seflag) {
solver->reInit(t_, x_, dx_);
if (solver->computingFSA()) {
solver->sensReInit(sx_, sdx_);
}
}
}

void ForwardProblem::storeEvent() {
if (t_ == model->getTimepoint(model->nt() - 1)) {
// call from fillEvent at last timepoint
model->froot(t_, x_, dx_, rootvals_);
for (int ie = 0; ie < model->ne; ie++) {
roots_found_.at(ie) = (nroots_.at(ie) < model->nMaxEvent()) ? 1 : 0;
}
root_idx_.push_back(roots_found_);
}

if (getRootCounter() < getEventCounter()) {
/* update stored state (sensi) */
event_states_.at(getRootCounter()) = getSimulationState();
} else {
/* add stored state (sensi) */
event_states_.push_back(getSimulationState());
}

/* EVENT OUTPUT */
for (int ie = 0; ie < model->ne; ie++) {
/* only look for roots of the rootfunction not discontinuities */
if (nroots_.at(ie) >= model->nMaxEvent())
continue;

/* only consider transitions false -> true or event filling */
if (roots_found_.at(ie) != 1
&& t_ != model->getTimepoint(model->nt() - 1)) {
continue;
}

if (edata && solver->computingASA())
model->getAdjointStateEventUpdate(
slice(dJzdx_, nroots_.at(ie), model->nx_solver * model->nJ), ie,
nroots_.at(ie), t_, x_, *edata
);

nroots_.at(ie)++;
}

if (t_ == model->getTimepoint(model->nt() - 1)) {
// call from fillEvent at last timepoint
// loop until all events are filled
fillEvents(model->nMaxEvent());
}
}

void ForwardProblem::store_pre_event_state(bool seflag, bool initial_event) {
/* if we need to do forward sensitivities later on we need to store the old
* x and the old xdot */
if (solver->getSensitivityOrder() >= SensitivityOrder::first) {
Expand Down Expand Up @@ -212,18 +283,9 @@ void ForwardProblem::handleEvent(
xdot_disc_.push_back(xdot_);
xdot_old_disc_.push_back(xdot_old_);
}
}

if (!initial_event)
model->updateHeaviside(roots_found_);

applyEventBolus();

if (solver->computingFSA()) {
/* compute the new xdot */
model->fxdot(t_, x_, dx_, xdot_);
applyEventSensiBolusFSA();
}

void ForwardProblem::handle_secondary_event(realtype* tlastroot) {
int secondevent = 0;

/* check whether we need to fire a secondary event */
Expand Down Expand Up @@ -260,60 +322,6 @@ void ForwardProblem::handleEvent(
);
handleEvent(tlastroot, true, false);
}

/* only reinitialise in the first event fired */
if (!seflag) {
solver->reInit(t_, x_, dx_);
if (solver->computingFSA()) {
solver->sensReInit(sx_, sdx_);
}
}
}

void ForwardProblem::storeEvent() {
if (t_ == model->getTimepoint(model->nt() - 1)) {
// call from fillEvent at last timepoint
model->froot(t_, x_, dx_, rootvals_);
for (int ie = 0; ie < model->ne; ie++) {
roots_found_.at(ie) = (nroots_.at(ie) < model->nMaxEvent()) ? 1 : 0;
}
root_idx_.push_back(roots_found_);
}

if (getRootCounter() < getEventCounter()) {
/* update stored state (sensi) */
event_states_.at(getRootCounter()) = getSimulationState();
} else {
/* add stored state (sensi) */
event_states_.push_back(getSimulationState());
}

/* EVENT OUTPUT */
for (int ie = 0; ie < model->ne; ie++) {
/* only look for roots of the rootfunction not discontinuities */
if (nroots_.at(ie) >= model->nMaxEvent())
continue;

/* only consider transitions false -> true or event filling */
if (roots_found_.at(ie) != 1
&& t_ != model->getTimepoint(model->nt() - 1)) {
continue;
}

if (edata && solver->computingASA())
model->getAdjointStateEventUpdate(
slice(dJzdx_, nroots_.at(ie), model->nx_solver * model->nJ), ie,
nroots_.at(ie), t_, x_, *edata
);

nroots_.at(ie)++;
}

if (t_ == model->getTimepoint(model->nt() - 1)) {
// call from fillEvent at last timepoint
// loop until all events are filled
fillEvents(model->nMaxEvent());
}
}

void ForwardProblem::handleDataPoint(int /*it*/) {
Expand Down

0 comments on commit 014d348

Please sign in to comment.