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

Add missing fields in ExpData HDF5 I/O #2593

Merged
merged 2 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions include/amici/hdf5.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ void writeSimulationExpData(
void writeSimulationExpData(
ExpData const& edata, std::string const& hdf5Filename,
std::string const& hdf5Location
);

);

/**
* @brief Check whether an attribute with the given name exists
Expand Down
94 changes: 94 additions & 0 deletions src/hdf5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,47 @@
));
}

if (locationExists(file, hdf5Root + "/parameters")) {
edata->parameters = getDoubleDataset1D(file, hdf5Root + "/parameters");

Check warning on line 199 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L199

Added line #L199 was not covered by tests
}

if (locationExists(file, hdf5Root + "/x0")) {
edata->x0 = getDoubleDataset1D(file, hdf5Root + "/x0");

Check warning on line 203 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L203

Added line #L203 was not covered by tests
}

if (locationExists(file, hdf5Root + "/sx0")) {
edata->sx0 = getDoubleDataset1D(file, hdf5Root + "/sx0");

Check warning on line 207 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L207

Added line #L207 was not covered by tests
}

if (locationExists(file, hdf5Root + "/pscale")) {
auto pscaleInt = getIntDataset1D(file, hdf5Root + "/pscale");
edata->pscale.resize(pscaleInt.size());

Check warning on line 212 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L211-L212

Added lines #L211 - L212 were not covered by tests
for (int i = 0; (unsigned)i < pscaleInt.size(); ++i)
edata->pscale[i] = static_cast<ParameterScaling>(pscaleInt[i]);
}

Check warning on line 215 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L214-L215

Added lines #L214 - L215 were not covered by tests

if (locationExists(file, hdf5Root + "/plist")) {
edata->plist = getIntDataset1D(file, hdf5Root + "/plist");

Check warning on line 218 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L218

Added line #L218 was not covered by tests
}

if (locationExists(
file, hdf5Root + "/reinitialization_state_idxs_presim"
)) {
edata->reinitialization_state_idxs_presim = getIntDataset1D(
file, hdf5Root + "/reinitialization_state_idxs_presim"
);

Check warning on line 226 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L224-L226

Added lines #L224 - L226 were not covered by tests
}

if (locationExists(file, hdf5Root + "/reinitialization_state_idxs_sim")) {
edata->reinitialization_state_idxs_sim = getIntDataset1D(
file, hdf5Root + "/reinitialization_state_idxs_sim"
);

Check warning on line 232 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L230-L232

Added lines #L230 - L232 were not covered by tests
}

if (attributeExists(file, hdf5Root, "tstart")) {
edata->tstart_ = getDoubleScalarAttribute(file, hdf5Root, "tstart");

Check warning on line 236 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L236

Added line #L236 was not covered by tests
}

return edata;
}

Expand Down Expand Up @@ -262,6 +303,59 @@
file.getId(), hdf5Location.c_str(),
"reinitializeFixedParameterInitialStates", &int_attr, 1
);

if (!edata.parameters.empty())
createAndWriteDouble1DDataset(
file, hdf5Location + "/parameters", edata.parameters

Check warning on line 309 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L308-L309

Added lines #L308 - L309 were not covered by tests
);

if (!edata.x0.empty())
createAndWriteDouble1DDataset(file, hdf5Location + "/x0", edata.x0);

Check warning on line 313 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L313

Added line #L313 was not covered by tests
if (!edata.sx0.empty())
createAndWriteDouble1DDataset(file, hdf5Location + "/sx0", edata.sx0);

Check warning on line 315 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L315

Added line #L315 was not covered by tests

std::vector<int> int_buffer;

if (!edata.pscale.empty()) {
int_buffer.resize(edata.pscale.size());

Check warning on line 320 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L320

Added line #L320 was not covered by tests
for (int i = 0; (unsigned)i < edata.pscale.size(); i++)
int_buffer[i] = static_cast<int>(edata.pscale[i]);
createAndWriteInt1DDataset(file, hdf5Location + "/pscale", int_buffer);

Check warning on line 323 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L322-L323

Added lines #L322 - L323 were not covered by tests
}

if (!edata.plist.empty()) {
int_buffer.resize(edata.plist.size());

Check warning on line 327 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L327

Added line #L327 was not covered by tests
for (int i = 0; (unsigned)i < edata.plist.size(); i++)
int_buffer[i] = static_cast<int>(edata.plist[i]);
createAndWriteInt1DDataset(file, hdf5Location + "/plist", int_buffer);

Check warning on line 330 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L329-L330

Added lines #L329 - L330 were not covered by tests
}

if (!edata.reinitialization_state_idxs_presim.empty()) {
int_buffer.resize(edata.reinitialization_state_idxs_presim.size());
for (int i = 0;
(unsigned)i < edata.reinitialization_state_idxs_presim.size(); i++)
int_buffer[i]
= static_cast<int>(edata.reinitialization_state_idxs_presim[i]);
createAndWriteInt1DDataset(
file, hdf5Location + "/reinitialization_state_idxs_presim",

Check warning on line 340 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L334-L340

Added lines #L334 - L340 were not covered by tests
int_buffer
);
}

if (!edata.reinitialization_state_idxs_sim.empty()) {
int_buffer.resize(edata.reinitialization_state_idxs_sim.size());
for (int i = 0;
(unsigned)i < edata.reinitialization_state_idxs_sim.size(); i++)
int_buffer[i]
= static_cast<int>(edata.reinitialization_state_idxs_sim[i]);
createAndWriteInt1DDataset(
file, hdf5Location + "/reinitialization_state_idxs_sim", int_buffer

Check warning on line 352 in src/hdf5.cpp

View check run for this annotation

Codecov / codecov/patch

src/hdf5.cpp#L346-L352

Added lines #L346 - L352 were not covered by tests
);
}

H5LTset_attribute_double(
file.getId(), hdf5Location.c_str(), "tstart", &edata.tstart_, 1
);
}

void writeReturnData(
Expand Down
Loading