Skip to content

Commit

Permalink
Merge pull request #663 from sys-bio/develop
Browse files Browse the repository at this point in the history
Merge fixes for mac to 2.0.1
  • Loading branch information
luciansmith authored Aug 7, 2020
2 parents 3cbfbed + 814b8db commit b991368
Show file tree
Hide file tree
Showing 17 changed files with 162 additions and 72 deletions.
11 changes: 4 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(rr)

set(ROADRUNNER_VERSION_MAJOR 2)
set(ROADRUNNER_VERSION_MINOR 0)
set(ROADRUNNER_VERSION_PATCH 0)
set(ROADRUNNER_VERSION_PATCH 1)

set(ROADRUNNER_VERSION "${ROADRUNNER_VERSION_MAJOR}.${ROADRUNNER_VERSION_MINOR}.${ROADRUNNER_VERSION_PATCH}")

Expand Down Expand Up @@ -143,7 +143,6 @@ set(BUILD_SHARED_LIBS ON)

set(RR_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
set(RR_SOURCE_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/source)
set(THIRD_PARTY_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/third_party)

set(exe_path ${PROJECT_BINARY_DIR}/bin)
set(lib_path ${PROJECT_BINARY_DIR}/lib)
Expand Down Expand Up @@ -191,7 +190,7 @@ endif()

include_directories(
${RR_ROOT}
${THIRD_PARTY_FOLDER}
${THIRD_PARTY_INSTALL_FOLDER}
)

# TODO libxml2 handling is excedingly hackish, it is all homegrown
Expand Down Expand Up @@ -239,15 +238,13 @@ endif()
if (${BUILD_LLVM})
link_directories(
${LIBRARY_OUTPUT_PATH}
${THIRD_PARTY_FOLDER}/dependencies/libsbml/lib
${THIRD_PARTY_INSTALL_FOLDER}/lib
${THIRD_PARTY_INSTALL_FOLDER}/lib64
${LLVM_LIBRARY_DIRS}
)
else()
link_directories(
${LIBRARY_OUTPUT_PATH}
${THIRD_PARTY_FOLDER}/dependencies/libsbml/lib
${THIRD_PARTY_INSTALL_FOLDER}/lib
${THIRD_PARTY_INSTALL_FOLDER}/lib64
)
Expand Down Expand Up @@ -281,7 +278,7 @@ if(${MINGW})
endif()

if(${BORLAND})
link_directories(${THIRD_PARTY_FOLDER}/dependencies/libsbml/lib)
link_directories(${THIRD_PARTY_INSTALL_FOLDER}/lib)
add_definitions(
-DUSE_PCH #Enable pre-compiled headers
-H=${PROJECT_BINARY_DIR}/rr_pch.csm
Expand Down Expand Up @@ -442,7 +439,7 @@ if(${BORLAND})
set(CG_RUNTIMES cc32110MT.dll)
foreach(runtime ${CG_RUNTIMES})
install (FILES
${THIRD_PARTY_FOLDER}/dependencies/cg/xe/${runtime}
${THIRD_PARTY_INSTALL_FOLDER}/cg/xe/${runtime}
DESTINATION bin
COMPONENT rr_core)
endforeach()
Expand Down
16 changes: 16 additions & 0 deletions cmake/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ if (LLVM_CONFIG_EXECUTABLE)
)
message(STATUS "LLVM_LIBRARY_DIRS: ${LLVM_LIBRARY_DIRS}")

# System libs
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --system-libs
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "LLVM_SYSTEM_LIBS: ${LLVM_SYSTEM_LIBS}")
# For some reason, the return value for system-libs for macos is of the
# form '-llib1 -llib2 ...", but the return value for system-libs for windows
# is of the form "lib1.lib lib2.lib ..." which doesn't work the same way.
# The only system it was failing for was macos, so we'll just set it for that.
if(APPLE)
set(LLVM_SYSTEM_LIBS_THISOS ${LLVM_SYSTEM_LIBS})
endif()
message(STATUS "LLVM_SYSTEM_LIBS_THISOS: ${LLVM_SYSTEM_LIBS_THISOS}")

# C++ Flags, strip out stuff that CMake build adds
execute_process(
COMMAND ${LLVM_CONFIG_EXECUTABLE} --cxxflags
Expand Down
2 changes: 2 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ if(RR_BUILD_SHARED_CORE)
if(BUILD_LLVM)
target_link_libraries(${target}
${LLVM_LIBRARIES}
${LLVM_SYSTEM_LIBS_THISOS}
)
endif(BUILD_LLVM)

Expand Down Expand Up @@ -428,6 +429,7 @@ set_property(TARGET ${target}-static
if(BUILD_LLVM)
target_link_libraries(${target}-static
${LLVM_LIBRARIES}
${LLVM_SYSTEM_LIBS_THISOS}
)
endif(BUILD_LLVM)

Expand Down
3 changes: 2 additions & 1 deletion source/CVODEIntegrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,8 +1176,9 @@ namespace rr
Log(Logger::LOG_INFORMATION) << "Set tolerance to abs: " << setprecision(16) << "[";
vector<double> v = getValueAsDoubleVector("absolute_tolerance");
for (int i = 0; i < v.size(); i++) {
if (i != 0)
if (i != 0) {
Log(Logger::LOG_INFORMATION) << ", ";
}
Log(Logger::LOG_INFORMATION) << v[i];
}
Log(Logger::LOG_INFORMATION) << "], rel: " << getValueAsDouble("relative_tolerance") << endl;
Expand Down
2 changes: 1 addition & 1 deletion source/llvm/CodeGenBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class LLVMCodeGenTest
BasicBlock *basicBlock = BasicBlock::Create(context, "entry", func);
builder.SetInsertPoint(basicBlock);

assert(func->getArgumentList().size() == N);
assert(func->arg_size() == N);

int i = 0;

Expand Down
60 changes: 52 additions & 8 deletions source/llvm/LLVMModelDataSymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,19 @@ std::string LLVMModelDataSymbols::getFloatingSpeciesId(size_t indx) const
}
}

throw std::out_of_range("attempted to access floating species id at index " + rr::toStringSize(indx));
std::stringstream errSS;
errSS << "attempted to access floating species id at index " << indx << ", but ";
auto size = floatingSpeciesMap.size();
if (size == 0) {
errSS << "there are no floating species in the model.";
}
else if (size == 1) {
errSS << "there is only a single floating species in the model with index '0'.";
}
else {
errSS << "there are only " << size << "floating species in the model with indexes '0'-'" << (size - 1) << "'.";
}
throw std::out_of_range(errSS.str());
}


Expand Down Expand Up @@ -567,8 +579,19 @@ std::string rrllvm::LLVMModelDataSymbols::getRateRuleId(size_t indx) const
}
}

throw std::out_of_range("attempted to access rate rule id at index " +
rr::toStringSize(indx));
std::stringstream errSS;
errSS << "attempted to access global parameter at index " << indx << ", but ";
auto size = rateRules.size();
if (size == 0) {
errSS << "there are no rate rules in the model.";
}
else if (size == 1) {
errSS << "there is only a single rate rule in the model with index '0'.";
}
else {
errSS << "there are only " << size << "rate rules in the model with indexes '0'-'" << (size - 1) << "'.";
}
throw std::out_of_range(errSS.str());
}

bool LLVMModelDataSymbols::isIndependentElement(const std::string& id) const
Expand Down Expand Up @@ -1017,7 +1040,19 @@ std::string LLVMModelDataSymbols::getGlobalParameterId(size_t indx) const
}
}

throw std::out_of_range("attempted to access global parameter id at index " + rr::toStringSize(indx));
std::stringstream errSS;
errSS << "attempted to access global parameter at index " << indx << ", but ";
auto size = globalParametersMap.size();
if (size == 0) {
errSS << "there are no global parameters in the model.";
}
else if (size == 1) {
errSS << "there is only a single global parameter in the model with index '0'.";
}
else {
errSS << "there are only " << size << "global parameters in the model with indexes '0'-'" << (size - 1) << "'.";
}
throw std::out_of_range(errSS.str());
}

int LLVMModelDataSymbols::getCompartmentIndexForFloatingSpecies(
Expand Down Expand Up @@ -1169,9 +1204,6 @@ void LLVMModelDataSymbols::initReactions(const libsbml::Model* model)
if (isValidFloatingSpeciesReference(p, "product"))
{
uint speciesIdx = getFloatingSpeciesIndex(p->getSpecies());
if (speciesIdx < 0) {
continue;
}

UIntUMap::const_iterator si = speciesMap.find(speciesIdx);

Expand Down Expand Up @@ -1494,7 +1526,19 @@ std::string LLVMModelDataSymbols::getEventId(size_t indx) const
}
}

throw std::out_of_range("attempted to access event id at index " + rr::toStringSize(indx));
std::stringstream errSS;
errSS << "attempted to access event id at index " << indx << ", but ";
auto size = eventIds.size();
if (size == 0) {
errSS << "there are no events in the model.";
}
else if (size == 1) {
errSS << "there is only a single event in the model with index '0'.";
}
else {
errSS << "there are only " << size << "events in the model with indexes '0'-'" << (size - 1) << "'.";
}
throw std::out_of_range(errSS.str());
}

int LLVMModelDataSymbols::getEventIndex(const std::string& id) const
Expand Down
6 changes: 0 additions & 6 deletions source/llvm/LLVMModelSymbols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ LLVMModelSymbols::LLVMModelSymbols(const libsbml::Model *m, LLVMModelDataSymbols
if (model->getInitialAssignment(id) == NULL &&
model->getAssignmentRule(id) == NULL)
{
Log(Logger::LOG_WARNING) << "Global parameter, \'"
<< param->getId() << "\' missing value and missing init "
"assignment and assignment rule!, defaulting value to 0.0.";
Log(Logger::LOG_WARNING) << "This probably is NOT what you want "
"with global parameter \'" << param->getId() << "\'.";
value->setValue(0.0);
std::stringstream ss;
ss << "Global parameter '" << param->getId() << "' missing value and missing init assignment and assignment rule!";
rr::UninitializedValue(ss.str());
Expand Down
88 changes: 51 additions & 37 deletions source/rrRoadRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1089,14 +1089,18 @@ void RoadRunner::load(const string& uriOrSbml, const Dictionary *dict)
}
}
try {

// the following lines load and compile the model. If anything fails here,
// we validate the model to provide explicit details about where it
// failed. Its *VERY* expensive to pre-validate the model.
libsbml::SBMLReader reader;
impl->document = std::unique_ptr<libsbml::SBMLDocument>(reader.readSBMLFromString(mCurrentSBML));
impl->model = std::unique_ptr<ExecutableModel>(ExecutableModelFactory::createModel(mCurrentSBML, &impl->loadOpt));
} catch (std::exception& e) {

// the following lines load and compile the model. If anything fails here,
// we validate the model to provide explicit details about where it
// failed. Its *VERY* expensive to pre-validate the model.
libsbml::SBMLReader reader;
impl->document = std::unique_ptr<libsbml::SBMLDocument>(reader.readSBMLFromString(mCurrentSBML));
impl->model = std::unique_ptr<ExecutableModel>(ExecutableModelFactory::createModel(mCurrentSBML, &impl->loadOpt));
} catch (const rr::UninitializedValueException& e) {
// catch specifically for UninitializedValueException, otherwise for some
// reason the message is erased, and an 'unknown error' is displayed to the user.
throw e;
} catch (const std::exception& e) {
string errors = validateSBML(mCurrentSBML);

if(!errors.empty()) {
Expand Down Expand Up @@ -2324,43 +2328,53 @@ DoubleMatrix RoadRunner::getFullJacobian()

get_self();

// function pointers to the model get values and get init values based on
// if we are doing amounts or concentrations.
typedef int (ExecutableModel::*GetValueFuncPtr)(size_t len, int const *indx,
double *values);
typedef int (ExecutableModel::*SetValueFuncPtr)(size_t len, int const *indx,
double const *values);
typedef int (ExecutableModel::* SetValueFuncPtrSize)(size_t len, int const* indx,
double const* values);

GetValueFuncPtr getValuePtr = 0;
GetValueFuncPtr getInitValuePtr = 0;
SetValueFuncPtr setValuePtr = 0;
SetValueFuncPtrSize setInitValuePtr = 0;

if (Config::getValue(Config::ROADRUNNER_JACOBIAN_MODE).convert<unsigned>()
== Config::ROADRUNNER_JACOBIAN_MODE_AMOUNTS)
{
getValuePtr = &ExecutableModel::getFloatingSpeciesAmounts;
getInitValuePtr = &ExecutableModel::getFloatingSpeciesInitAmounts;
setValuePtr = &ExecutableModel::setFloatingSpeciesAmounts;
setInitValuePtr = &ExecutableModel::setFloatingSpeciesInitAmounts;
}
else
{
getValuePtr = &ExecutableModel::getFloatingSpeciesConcentrations;
getInitValuePtr = &ExecutableModel::getFloatingSpeciesInitConcentrations;
setValuePtr = &ExecutableModel::setFloatingSpeciesConcentrations;
setInitValuePtr = &ExecutableModel::setFloatingSpeciesInitConcentrations;
}


if (self.model->getNumReactions() == 0 && self.model->getNumRateRules() > 0)
{
if (self.model->getNumFloatingSpecies() < self.model->getNumRateRules()) {
std::stringstream errSS;
errSS << "cannot compute full Jacobian because there are fewer floating species (" <<
self.model->getNumFloatingSpecies() << ")" << " than rate rules (" << self.model->getNumRateRules() << ").";
errSS << " You may need to declare one or more of your variables as a species. See " <<
"https://tellurium.readthedocs.io/en/latest/antimony.html#rate-rules if you are using Antimony.";
throw std::out_of_range(errSS.str());
}
DoubleMatrix jac(self.model->getNumRateRules(), self.model->getNumRateRules());

for (int i = 0; i < self.model->getNumRateRules(); i++)
{
for (int j = 0; j < self.model->getNumRateRules(); j++)
{
// function pointers to the model get values and get init values based on
// if we are doing amounts or concentrations.
typedef int (ExecutableModel::*GetValueFuncPtr)(size_t len, int const *indx,
double *values);
typedef int (ExecutableModel::*SetValueFuncPtr)(size_t len, int const *indx,
double const *values);
typedef int (ExecutableModel::* SetValueFuncPtrSize)(size_t len, int const* indx,
double const* values);

GetValueFuncPtr getValuePtr = 0;
GetValueFuncPtr getInitValuePtr = 0;
SetValueFuncPtr setValuePtr = 0;
SetValueFuncPtrSize setInitValuePtr = 0;

if (Config::getValue(Config::ROADRUNNER_JACOBIAN_MODE).convert<unsigned>()
== Config::ROADRUNNER_JACOBIAN_MODE_AMOUNTS)
{
getValuePtr = &ExecutableModel::getFloatingSpeciesAmounts;
getInitValuePtr = &ExecutableModel::getFloatingSpeciesInitAmounts;
setValuePtr = &ExecutableModel::setFloatingSpeciesAmounts;
setInitValuePtr = &ExecutableModel::setFloatingSpeciesInitAmounts;
}
else
{
getValuePtr = &ExecutableModel::getFloatingSpeciesConcentrations;
getInitValuePtr = &ExecutableModel::getFloatingSpeciesInitConcentrations;
setValuePtr = &ExecutableModel::setFloatingSpeciesConcentrations;
setInitValuePtr = &ExecutableModel::setFloatingSpeciesInitConcentrations;
}

double value;
double originalConc = 0;
Expand Down
2 changes: 1 addition & 1 deletion source/rrStringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ vector<string> splitString(const string &text, const string &separators)
size_t n = text.length();
size_t start = text.find_first_not_of(separators);

while( (start >= 0) && (start < n) )
while( (start < n) )
{
size_t stop = text.find_first_of(separators, start);
if( (stop == string::npos) || (stop > n) )
Expand Down
14 changes: 14 additions & 0 deletions source/rrUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,20 @@ bool hasUnimplementedTags(const string& descriptionFileName)
return false;
}

bool isSemiStochasticTest(const string& descriptionFileName)
{
ifstream descfile(descriptionFileName);
if (descfile.good()) {
string line;
while (getline(descfile, line)) {
if (line.find("synopsis") != string::npos && line.find("STOCHASTIC") != string::npos) {
return true;
}
}
}
return false;
}

bool isFBCTest(const string& descriptionFileName)
{
ifstream descfile(descriptionFileName);
Expand Down
2 changes: 2 additions & 0 deletions source/rrUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ RR_DECLSPEC string getTestSuiteSubFolderName(int caseNr);

RR_DECLSPEC bool hasUnimplementedTags(const string& descriptionFileName);

RR_DECLSPEC bool isSemiStochasticTest(const string& descriptionFileName);

RR_DECLSPEC bool isFBCTest(const string& descriptionFileName);

//CArray utilities
Expand Down
2 changes: 1 addition & 1 deletion source/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ${THIRD_PARTY_INSTALL_FOLDER}/lib
include_directories(
src
${RR_ROOT}
${THIRD_PARTY_FOLDER}/unit_test/src
${THIRD_PARTY_INSTALL_FOLDER}/include/
)

if(UNIX)
Expand Down
5 changes: 5 additions & 0 deletions source/testing/tests/sbml_test_suite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,11 @@ bool RunTest(int caseNumber)
else {
if (!first.empty()) {
ret = RunTest(first, caseNumber);
if (!ret && isSemiStochasticTest(modelFilePath + "/" + descriptionFileName)) {
//semistochastic tests fail once in a great while, but very very rarely twice in a row.
Log(Logger::LOG_WARNING) << "Test " << caseNumber << " failed, but we expect it to fail every so often. Trying again...";
ret = RunTest(first, caseNumber);
}
}
else {
Log(Logger::LOG_ERROR) << "No models found for test case" << caseNumber << endl;
Expand Down
Loading

0 comments on commit b991368

Please sign in to comment.