Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve debugging info in ReturnData #2349

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/amici/forwardproblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class ForwardProblem {
* @brief Creates a carbon copy of the current simulation state variables
* @return state
*/
SimulationState getSimulationState() const;
SimulationState getSimulationState();

/** array of index vectors (dimension ne) indicating whether the respective
* root has been detected for all so far encountered discontinuities,
Expand Down
7 changes: 5 additions & 2 deletions include/amici/rdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ class ReturnData : public ModelDimensions {
*/
std::vector<realtype> ts;

/** time derivative (shape `nx`) */
/** time derivative (shape `nx`) evaluated at `t_last`. */
std::vector<realtype> xdot;

/**
* Jacobian of differential equation right hand side (shape `nx` x `nx`,
* row-major)
* row-major) evaluated at `t_last`.
*/
std::vector<realtype> J;

Expand Down Expand Up @@ -456,6 +456,9 @@ class ReturnData : public ModelDimensions {
/** log messages */
std::vector<LogItem> messages;

/** The final internal time of the solver. */
realtype t_last{std::numeric_limits<realtype>::quiet_NaN()};

protected:
/** offset for sigma_residuals */
realtype sigma_offset;
Expand Down
1 change: 1 addition & 0 deletions python/sdist/amici/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class ReturnDataView(SwigPtrView):
"cpu_timeB",
"cpu_time_total",
"messages",
"t_last",
]

def __init__(self, rdata: Union[ReturnDataPtr, ReturnData]):
Expand Down
2 changes: 2 additions & 0 deletions src/amici.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ std::unique_ptr<ReturnData> runAmiciSimulation(
);
}

rdata->t_last = solver.gett();

rdata->cpu_time_total = cpu_timer.elapsed_milliseconds();

// verify that reported CPU times are plausible
Expand Down
5 changes: 4 additions & 1 deletion src/forwardproblem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,10 @@ void ForwardProblem::getAdjointUpdates(Model& model, ExpData const& edata) {
}
}

SimulationState ForwardProblem::getSimulationState() const {
SimulationState ForwardProblem::getSimulationState() {
if(std::isfinite(solver->gett())) {
solver->writeSolution(&t_, x_, dx_, sx_, dx_);
}
auto state = SimulationState();
state.t = t_;
state.x = x_;
Expand Down
4 changes: 4 additions & 0 deletions src/hdf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,10 @@
&rdata.cpu_time_total, 1
);

H5LTset_attribute_double(
file.getId(), hdf5Location.c_str(), "t_last", &rdata.t_last, 1

Check warning on line 536 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L535-L536

Added lines #L535 - L536 were not covered by tests
);

if (!rdata.J.empty())
createAndWriteDouble2DDataset(
file, hdf5Location + "/J", rdata.J, rdata.nx, rdata.nx
Expand Down
Loading