Skip to content

Commit

Permalink
Merge pull request #1016 from sys-bio/issue-1008-capi-rates
Browse files Browse the repository at this point in the history
Fix C API rates of change functions.
  • Loading branch information
luciansmith committed May 25, 2022
2 parents 783907d + 4927ab5 commit c34c407
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 31 deletions.
68 changes: 48 additions & 20 deletions test/c_api_core/CAPICoreTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,34 +98,34 @@ TEST_F(CAPICoreTest, ReloadingModelModelRecompilation) {
std::cout << testModelFilePath << std::endl;
EXPECT_TRUE(std::filesystem::exists(testModelFilePath));

EXPECT_TRUE(loadSBMLFromFileE(aRR, testModelFilePath.string().c_str(), true));
ASSERT_TRUE(loadSBMLFromFileE(aRR, testModelFilePath.string().c_str(), true));

//Load the same model again, but do not recompile the model DLL..
EXPECT_TRUE(loadSBMLFromFileE(aRR, testModelFilePath.string().c_str(), true));
ASSERT_TRUE(loadSBMLFromFileE(aRR, testModelFilePath.string().c_str(), true));
freeRRInstance(aRR);
}

TEST_F(CAPICoreTest, ReloadingModelNoModelRecompilation) {
RRHandle aRR = createRRInstance();
EXPECT_TRUE(std::filesystem::exists(testModelFilePath));

EXPECT_TRUE(loadSBMLFromFileE(aRR, testModelFilePath.string().c_str(), true));
ASSERT_TRUE(loadSBMLFromFileE(aRR, testModelFilePath.string().c_str(), true));

//Load the same model again, but do not recompile the model DLL..
EXPECT_TRUE(loadSBMLFromFileE(aRR, testModelFilePath.string().c_str(), false));
ASSERT_TRUE(loadSBMLFromFileE(aRR, testModelFilePath.string().c_str(), false));
freeRRInstance(aRR);
}

TEST_F(CAPICoreTest, LoadingModelMultipleInstances) {
RRHandle aRR1 = createRRInstance();
RRHandle aRR2 = createRRInstance();

EXPECT_TRUE(loadSBMLFromFileE(aRR1, testModelFilePath.string().c_str(), true));
EXPECT_TRUE(loadSBMLFromFileE(aRR2, testModelFilePath.string().c_str(), true));
ASSERT_TRUE(loadSBMLFromFileE(aRR1, testModelFilePath.string().c_str(), true));
ASSERT_TRUE(loadSBMLFromFileE(aRR2, testModelFilePath.string().c_str(), true));

//Load the same model again, but do not recompile the model DLL..
EXPECT_TRUE(loadSBMLFromFileE(aRR1, testModelFilePath.string().c_str(), false));
EXPECT_TRUE(loadSBMLFromFileE(aRR2, testModelFilePath.string().c_str(), false));
ASSERT_TRUE(loadSBMLFromFileE(aRR1, testModelFilePath.string().c_str(), false));
ASSERT_TRUE(loadSBMLFromFileE(aRR2, testModelFilePath.string().c_str(), false));

freeRRInstance(aRR1);
freeRRInstance(aRR2);
Expand All @@ -149,20 +149,20 @@ TEST_F(CAPICoreTest, LoadModelFromString) {
string xml = getFileContent((testModelFilePath.string()));
RRHandle aRR1 = createRRInstance();
RRHandle aRR2 = createRRInstance();
EXPECT_TRUE(loadSBML(aRR1, xml.c_str()));
EXPECT_TRUE(loadSBMLEx(aRR2, xml.c_str(), true));
ASSERT_TRUE(loadSBML(aRR1, xml.c_str()));
ASSERT_TRUE(loadSBMLEx(aRR2, xml.c_str(), true));

//Load the same model again, but do not recompile the model DLL..
EXPECT_TRUE(loadSBMLEx(aRR1, xml.c_str(), false));
EXPECT_TRUE(loadSBMLEx(aRR2, xml.c_str(), false));
ASSERT_TRUE(loadSBMLEx(aRR1, xml.c_str(), false));
ASSERT_TRUE(loadSBMLEx(aRR2, xml.c_str(), false));
freeRRInstance(aRR1);
freeRRInstance(aRR2);
}

TEST_F(CAPICoreTest, SimulateTimes) {
string xml = getFileContent((testModelFilePath.string()));
RRHandle aRR1 = createRRInstance();
EXPECT_TRUE(loadSBML(aRR1, xml.c_str()));
ASSERT_TRUE(loadSBML(aRR1, xml.c_str()));
double times[4] = {0, 1, 5, 10};
RRCDataPtr results = simulateTimes(aRR1, times, 4);
EXPECT_EQ(results->RSize, 4);
Expand Down Expand Up @@ -274,7 +274,7 @@ TEST_F(CAPICoreTest, CheckRK4WorksFromC) {
TEST_F(CAPICoreTest, SetAndGetMDiffStepSize) {
string xml = getFileContent((testModelFilePath.string()));
RRHandle rr = createRRInstance();
EXPECT_TRUE(loadSBML(rr, xml.c_str()));
ASSERT_TRUE(loadSBML(rr, xml.c_str()));

double mDiffStepSize;
EXPECT_TRUE(getDiffStepSize(rr, &mDiffStepSize));
Expand All @@ -291,7 +291,7 @@ TEST_F(CAPICoreTest, SetAndGetMDiffStepSize) {
TEST_F(CAPICoreTest, CheckGetCC) {

RRHandle rrH = createRRInstance();
EXPECT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));
ASSERT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));

double K = 0.8;
double ss_val;
Expand Down Expand Up @@ -330,7 +330,7 @@ TEST_F(CAPICoreTest, CheckGetCC) {
TEST_F(CAPICoreTest, CheckGetEC) {

RRHandle rrH = createRRInstance();
EXPECT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));
ASSERT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));

RRListPtr actual = getElasticityCoefficientIds(rrH);
std::vector<std::string> expectedRxns(
Expand All @@ -357,7 +357,7 @@ TEST_F(CAPICoreTest, CheckGetEC) {
TEST_F(CAPICoreTest, CheckGetUEC) {

RRHandle rrH = createRRInstance();
EXPECT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));
ASSERT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));

RRListPtr actual = getUnscaledElasticityCoefficientIds(rrH);
std::vector<std::string> expectedRxns(
Expand All @@ -384,7 +384,7 @@ TEST_F(CAPICoreTest, CheckGetUEC) {
TEST_F(CAPICoreTest, CheckSetTimeCourseSelectionListEx) {

RRHandle rrH = createRRInstance();
EXPECT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));
ASSERT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));

char* sel_list[] = { "time", "uec(_J0, A)", "ec(_J1, K)" };

Expand All @@ -406,7 +406,7 @@ TEST_F(CAPICoreTest, CheckSetTimeCourseSelectionListEx) {
TEST_F(CAPICoreTest, CheckSetSteadyStateSelectionListEx) {

RRHandle rrH = createRRInstance();
EXPECT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));
ASSERT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));

char* sel_list[] = { "A", "uec(_J0, A)", "ec(_J1, K)" };

Expand All @@ -433,7 +433,7 @@ TEST_F(CAPICoreTest, CheckSetSteadyStateSelectionListEx) {
TEST_F(CAPICoreTest, CheckGetStoichiometryMatrix) {

RRHandle rrH = createRRInstance();
EXPECT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));
ASSERT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));

RRDoubleMatrixPtr stoichs = getStoichiometryMatrix(rrH);
ASSERT_EQ(stoichs->CSize, 2);
Expand All @@ -444,6 +444,34 @@ TEST_F(CAPICoreTest, CheckGetStoichiometryMatrix) {
EXPECT_EQ(stoichs->Data[2], 1.0);
EXPECT_EQ(stoichs->Data[3], -1.0);

delete rrH;
}

TEST_F(CAPICoreTest, CheckRatesOfChangeFunctions) {

RRHandle rrH = createRRInstance();
ASSERT_TRUE(loadSBMLFromFileE(rrH, (cAPICoreModelsDir / path("steadystate.xml")).string().c_str(), true));
bool ret = setComputeAndAssignConservationLaws(rrH, true);

RRVectorPtr roc = getRatesOfChange(rrH);
ASSERT_EQ(roc->Count, 1);
EXPECT_NEAR(roc->Data[0], -0.496, 0.001);
delete roc;

RRStringArrayPtr roc_ids = getRatesOfChangeIds(rrH);
ASSERT_EQ(roc_ids->Count, 1);
EXPECT_STREQ(roc_ids->String[0], "A'");
delete roc_ids;

roc_ids = getIndependentFloatingSpeciesIds(rrH);
ASSERT_EQ(roc_ids->Count, 1);
EXPECT_STREQ(roc_ids->String[0], "A");
delete roc_ids;

roc_ids = getDependentFloatingSpeciesIds(rrH);
ASSERT_EQ(roc_ids->Count, 1);
EXPECT_STREQ(roc_ids->String[0], "AP");
delete roc_ids;

delete rrH;
}
9 changes: 0 additions & 9 deletions test/c_api_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,3 @@ add_test_executable(test_c_api_core test_targets

# make test_targets list global to all tests
set(test_targets ${test_targets} PARENT_SCOPE)









19 changes: 18 additions & 1 deletion wrappers/C/rrc_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,22 @@ RRStringArrayPtr rrcCallConv getDependentFloatingSpeciesIds(RRHandle handle)
}


RRStringArrayPtr rrcCallConv getIndependentFloatingSpeciesIds(RRHandle handle)
{
start_try
RoadRunner* rri = castToRoadRunner(handle);
StringList fNames = rri->getIndependentFloatingSpeciesIds();

if (!fNames.Count())
{
return NULL;
}

return createList(fNames);
catch_ptr_macro
}


RRStringArrayPtr rrcCallConv getFloatingSpeciesConcentrationIds(RRHandle handle)
{
start_try
Expand Down Expand Up @@ -3367,7 +3383,8 @@ vector<double> rr_getRatesOfChange(RoadRunner* rr)
}

mModel->computeAllRatesOfChange();
vector<double> result(mModel->getNumFloatingSpecies());
//vector<double> result(mModel->getNumFloatingSpecies());
vector<double> result(mModel->getNumIndFloatingSpecies());
mModel->getFloatingSpeciesAmountRates(result.size(), 0, &result[0]);
return result;
}
Expand Down
16 changes: 15 additions & 1 deletion wrappers/C/rrc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2612,10 +2612,24 @@ C_DECL_SPEC RRStringArrayPtr rrcCallConv getBoundarySpeciesConcentrationIds(RRHa
*/
C_DECL_SPEC RRStringArrayPtr rrcCallConv getFloatingSpeciesIds(RRHandle handle);

/*!
\brief Obtain the list of dependent floating species Id

\param[in] handle Handle to a RoadRunner instance
\return Returns null if it fails, if successful it returns a pointer to a RRStringArrayPtr struct
\ingroup floating
*/
C_DECL_SPEC RRStringArrayPtr rrcCallConv getDependentFloatingSpeciesIds(RRHandle handle);

/*!
\brief Obtain the list of independent floating species Id
\param[in] handle Handle to a RoadRunner instance
\return Returns null if it fails, if successful it returns a pointer to a RRStringArrayPtr struct
\ingroup floating
*/
C_DECL_SPEC RRStringArrayPtr rrcCallConv getIndependentFloatingSpeciesIds(RRHandle handle);


/*!
\brief Obtain the list of floating species concentrations Id
Expand Down

0 comments on commit c34c407

Please sign in to comment.