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

Fbc v3 matlab #277

Merged
merged 40 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
adbddc8
update for fbc v3
skeating Sep 29, 2022
e7053d1
added fbc v2 and v3
skeating Oct 11, 2022
98c0a11
need for strict includes
skeating Oct 13, 2022
1b1f0d1
one line
skeating Oct 13, 2022
3faec22
syntax warnings
skeating Oct 13, 2022
7826ecf
indents fixed
skeating Oct 13, 2022
84e0bd5
syntax changes
skeating Oct 13, 2022
9b83c5f
shouldnt commit
skeating Oct 13, 2022
f389fff
line endings
skeating Oct 14, 2022
1050b29
add comments on structure
skeating Oct 15, 2022
bcb20bd
fixing structure enum file
skeating Oct 26, 2022
87c18e4
get further with fbc tests
skeating Oct 29, 2022
3197f45
get tests working
skeating Nov 1, 2022
79d3ed4
get charge double value
skeating Nov 5, 2022
22f7a29
add test files for fbc v3
skeating Nov 5, 2022
555197e
getting there with key value pairs
skeating Nov 7, 2022
779a782
got the xmlns attribute sorted
skeating Nov 7, 2022
ac7ce67
read key value pairs
skeating Dec 12, 2022
5fb5197
order as written for comparison
skeating Dec 20, 2022
e75f55b
get output of kvp working
skeating Dec 21, 2022
8f30f23
Merge remote-tracking branch 'origin/development' into fbc-v3-matlab
skeating Feb 6, 2023
d3a85f8
add test for creating key-value-pair
skeating Feb 7, 2023
ddf1e17
add all fbc tests to octave test
skeating Feb 7, 2023
4c43b30
- try and add matlab test
fbergmann Feb 8, 2023
9de5561
- try another matlab action
fbergmann Feb 8, 2023
1526643
- add ninja
fbergmann Feb 8, 2023
5d357c9
- guess matlab path
fbergmann Feb 8, 2023
1515d03
- add new tests to octave
fbergmann Feb 8, 2023
c78ed9e
- debug session
fbergmann Feb 8, 2023
7ba7fa5
- update path, use matlab command to run
fbergmann Feb 8, 2023
7a972ef
- add octave test xml files, try other path for matlab
fbergmann Feb 8, 2023
cebfb41
- only compile mex files to speed build up
fbergmann Feb 8, 2023
3c47e44
- use latest matlab
fbergmann Feb 8, 2023
2d330f7
- find matlab in path
fbergmann Feb 8, 2023
d5b975b
- use older compiler
fbergmann Feb 8, 2023
55137b5
make model valid
skeating Feb 10, 2023
53a5ac8
make model valid
skeating Feb 10, 2023
a350334
format so comparison works
skeating Feb 11, 2023
065df3a
add test for namespace on key value pair
skeating Feb 11, 2023
69b340a
only run test if fbc enabled
skeating Feb 13, 2023
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
63 changes: 63 additions & 0 deletions .github/workflows/matlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Matlab (ubuntu) build and test

on: [push]

env:
MATLAB_VERSION: R2021a
CC: gcc-9
CXX: g++-9

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- uses: seanmiddleditch/gha-setup-ninja@master

- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v1
# with:
# release: ${{ env.MATLAB_VERSION }}

- name: Install Ubuntu dependencies
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y check ccache
git clone https://github.com/libexpat/libexpat
cmake -G Ninja -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DEXPAT_BUILD_TESTS=OFF -DEXPAT_BUILD_TOOLS=OFF -DEXPAT_BUILD_EXAMPLES=OFF -DEXPAT_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=./dependencies -B libexpat -S libexpat/expat
cmake --build libexpat
cmake --install libexpat

- name: Create Build Environment
run: cmake -E make_directory ${{runner.workspace}}/build

# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3

- name: Configure
shell: bash
working-directory: ${{runner.workspace}}/build
run: |
cmake $GITHUB_WORKSPACE \
-G "Ninja" \
-DCMAKE_BUILD_TYPE=Debug \
-DWITH_CHECK=ON \
-DWITH_LIBXML=OFF \
-DWITH_EXPAT=ON \
-DWITH_MATLAB=ON \
-DWITH_STABLE_PACKAGES=ON

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
run: |
cmake --build . --config Debug --target matlab_binding_TranslateSBML
cmake --build . --config Debug --target matlab_binding_OutputSBML

- name: Run Test
uses: matlab-actions/run-command@v1
with:
command: cd('../build/src/bindings/matlab/test'); runTests
2 changes: 1 addition & 1 deletion .github/workflows/octave.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
working-directory: ${{runner.workspace}}/build
shell: bash
run: |
cmake -DCMAKE_INSTALL_PREFIX=${{runner.workspace}}/install -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_BZIP2=ON -DWITH_CHECK=OFF -DWITH_EXPAT=ON -DWITH_LIBXML=OFF -DWITH_OCTAVE=ON $GITHUB_WORKSPACE
cmake -DCMAKE_INSTALL_PREFIX=${{runner.workspace}}/install -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_BZIP2=ON -DWITH_CHECK=OFF -DWITH_EXPAT=ON -DWITH_LIBXML=OFF -DWITH_OCTAVE=ON -DWITH_STABLE_PACKAGES=ON $GITHUB_WORKSPACE

- name: Build
working-directory: ${{runner.workspace}}/build
Expand Down
20 changes: 14 additions & 6 deletions src/bindings/matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@

if(WITH_MATLAB)
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}" ${CMAKE_MODULE_PATH})

if (NOT MATLAB_ROOT_PATH)
# try and find matlab in path
find_program(MATLAB_COMMAND NAMES matlab matlab.exe)
if (MATLAB_COMMAND)
# if we have it in the path, it will be of form <matlab_version>/bin/matlab,
# so take the DIRECTORY component twice
get_filename_component(MATLAB_BIN_PATH ${MATLAB_COMMAND} DIRECTORY)
get_filename_component(MATLAB_ROOT ${MATLAB_BIN_PATH} DIRECTORY)
set(MATLAB_ROOT_PATH ${MATLAB_ROOT} CACHE STRING "Matlab root directory" FORCE)
endif()
endif()

find_package(Matlab)

# on windows let us build the library using MSVC, on Linux and OS X we choose
Expand Down Expand Up @@ -124,12 +137,7 @@ file(GLOB matlab_scripts "${CMAKE_CURRENT_SOURCE_DIR}/../matlab/*.m"
install(FILES ${matlab_scripts} DESTINATION ${MATLAB_PACKAGE_INSTALL_DIR})

# add test cases
if (WITH_CHECK)

add_subdirectory(test)

endif()

add_subdirectory(test)

endif()

2 changes: 1 addition & 1 deletion src/bindings/matlab/OutputSBML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ dealWithAnomalies(SBMLDocument* sbmlDocument, GV& gv)

// the gene product associations in fbc v2
unsigned int vers = StructureFields::readUint(gv.modelArray, "fbc_version", 0, gv);
if (vers == 2)
if (vers > 1)
{
addGeneProductAssociations(sbmlDocument, gv);
}
Expand Down
65 changes: 49 additions & 16 deletions src/bindings/matlab/StructureFields.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <sbml/math/ASTNode.h>
#include <sbml/extension/SBasePlugin.h>
#include <sbml/extension/SBMLExtensionRegistry.h>
#ifdef USE_FBC
#include <sbml/packages/fbc/sbml/FbcAssociation.h>
#endif // USE_FBC



#ifdef USE_OCTAVE
Expand Down Expand Up @@ -233,6 +237,22 @@ StructureFields::populateFields()
mxDestroyArray(mxOutputs[2]);
mxDestroyArray(mxOutputs[3]);


// get structure returns fieldnames, default values and value types
// fieldnames are an array of arrays giving values for several aspects of the structure
// SBMLfieldnames = { {'typecode','','',0,0}, ...
//{'metaid', 'metaid', '', 1, 20}, ...
//{'notes', 'notes', '', 1, 1}, ...
//{'annotation', 'annotation', '', 1, 2}, ...
//{'formula', 'formula', '', 1, 5}, ...
//{'variable', 'variable', '', 1, 20}, ...
//{'species', 'species', '', 1, 20}, ...
//{'compartment', 'compartment', '', 1, 20}, ...
//{'name', 'name', '', 1, 20}, ...
//{'units', 'units', '', 1, 20}, ...
//
//{name of the field, sbml name, prefix, is sbml attribute, type enum}

for (unsigned int i = 0; i < nNumberFields; ++i)
{
FieldValues_t field;
Expand Down Expand Up @@ -383,13 +403,19 @@ StructureFields::getValueType(unsigned int i, const std::string& id)

void
StructureFields::createStructure(const std::string& functionId, SBase* base,
bool usePlugin, const std::string& prefix)
bool usePlugin_cs, const std::string& prefix)
{
std::string fieldname;
unsigned int total_no = base->getNumObjects(sbmlTC);
if (usePlugin)
if (usePlugin_cs && total_no == 0)
{
total_no = base->getPlugin(prefix)->getNumObjects(sbmlTC);
// we may have an SBase plugin
if (total_no == 0)
{
SBase * sbase = static_cast<SBase*>(base);
total_no = sbase->getPlugin(prefix)->getNumObjects(sbmlTC);
}
}
mwSize dims[2] = {1, total_no};

Expand All @@ -407,7 +433,7 @@ StructureFields::createStructure(const std::string& functionId, SBase* base,
for (unsigned int i = 0; i < total_no; ++i)
{
SBase* child = base->getObject(sbmlTC, i);
if (usePlugin)
if (usePlugin_cs)
{
child = base->getPlugin(prefix)->getObject(sbmlTC, i);
}
Expand All @@ -429,7 +455,7 @@ StructureFields::populateStructure(const std::string& functionId, SBase* base, u
FieldValues_t field = mFields.at(i);
type = field.type;
nameType = field.fieldnameType;
bool usePlugin = usingPlugin(field.prefix, base);
bool usePlugin_ps = usingPlugin(field.prefix, base, field.fieldName);

if (type == TYPE_ELEMENT)
{
Expand All @@ -442,7 +468,7 @@ StructureFields::populateStructure(const std::string& functionId, SBase* base, u
break;
default:
StructureFields *sf = new StructureFields(field.sbmlName, gv);
sf->createStructure(functionId + ":" + field.fieldName, base, usePlugin, field.prefix);
sf->createStructure(functionId + ":" + field.fieldName, base, usePlugin_ps, field.prefix);
mxSetField(mxStructure, index, field.fieldName.c_str(), mxDuplicateArray(sf->getStructure()));
sf->freeStructureMemory();
delete sf;
Expand All @@ -455,7 +481,7 @@ StructureFields::populateStructure(const std::string& functionId, SBase* base, u
}
else
{
addStructureField(functionId, base, index, field, usePlugin);
addStructureField(functionId, base, index, field, usePlugin_ps);
}

}
Expand Down Expand Up @@ -651,7 +677,7 @@ StructureFields::getCVTermsStructure(SBase* base)
void
StructureFields::addStructureField(const std::string& functionId, SBase* base,
unsigned int index, FieldValues_t field,
bool usePlugin)
bool usePlugin_sf)
{
std::string value;
int ivalue;
Expand All @@ -663,23 +689,23 @@ StructureFields::addStructureField(const std::string& functionId, SBase* base,
case TYPE_UNKNOWN:

case TYPE_CHAR:
value = getStringValue(functionId, base, field, usePlugin);
value = getStringValue(functionId, base, field, usePlugin_sf);
mxSetField(mxStructure, index, field.fieldName.c_str(), mxCreateString(value.c_str()));
break;
case TYPE_BOOL:
bvalue = getBoolValue(functionId, base, field, usePlugin);
bvalue = getBoolValue(functionId, base, field, usePlugin_sf);
mxSetField(mxStructure, index, field.fieldName.c_str(), CreateIntScalar(bvalue));
break;
case TYPE_UINT:
uvalue = getUintValue(functionId, base, field, usePlugin);
uvalue = getUintValue(functionId, base, field, usePlugin_sf);
mxSetField(mxStructure, index, field.fieldName.c_str(), CreateIntScalar(uvalue));
break;
case TYPE_INT:
ivalue = getIntValue(functionId, base, field, usePlugin);
ivalue = getIntValue(functionId, base, field, usePlugin_sf);
mxSetField(mxStructure, index, field.fieldName.c_str(), CreateIntScalar(ivalue));
break;
case TYPE_DOUBLE:
dvalue = getDoubleValue(functionId, base, field, usePlugin);
dvalue = getDoubleValue(functionId, base, field, usePlugin_sf);
mxSetField(mxStructure, index, field.fieldName.c_str(), mxCreateDoubleScalar(dvalue));
break;
case TYPE_ELEMENT:
Expand Down Expand Up @@ -1104,7 +1130,7 @@ StructureFields::dealWithRateOfSymbol(ASTNode* math)
// general need to know function

bool
StructureFields::usingPlugin(const std::string& prefix, SBase* base)
StructureFields::usingPlugin(const std::string& prefix, SBase* base, const std::string& name)
{
bool usePlugin = false;
if (prefix.size() > 0)
Expand All @@ -1113,10 +1139,17 @@ StructureFields::usingPlugin(const std::string& prefix, SBase* base)
{
usePlugin = true;
}
else if (base != NULL && base->getPlugin(prefix) != NULL)
// need to account for a sbase plugin from same pkg which will be on all elements
else if (base != NULL && base->getPackageName() != prefix) // THIS FIXES BUT WONT READ
{
usePlugin = true;
}
#ifdef USE_FBC
if (name == "fbc_keyValuePair" || name == "fbc_kvp_xmlns")
{
usePlugin = true;
}
#endif
}

return usePlugin;
Expand Down Expand Up @@ -1244,7 +1277,7 @@ StructureFields::addChildElement(FieldValues_t field, unsigned int index)
if (mxChild == NULL) return;
else if (n == 0) return;

bool usePlugin = usingPlugin(field.prefix);
bool usePlugin = usingPlugin(field.prefix, NULL, field.fieldName.c_str());

for (unsigned int i = 0; i < n; ++i)
{
Expand Down Expand Up @@ -1358,7 +1391,7 @@ StructureFields::setAttribute(FieldValues_t field,
unsigned int uvalue;
bool bvalue;
double dvalue;
bool usePlugin = usingPlugin(field.prefix);
bool usePlugin = usingPlugin(field.prefix, NULL, field.fieldName);
const ASTNode *ast = NULL;

switch(field.type)
Expand Down
6 changes: 3 additions & 3 deletions src/bindings/matlab/StructureFields.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class StructureFields
void addAttributes(const std::string& functionId, unsigned int index = 0,
unsigned int total_no = 0);

void createStructure(const std::string& functionId, SBase* base, bool usePlugin = false,
void createStructure(const std::string& functionId, SBase* base, bool usePlugin_cs = false,
const std::string& prefix = "");

const std::string& getTypeCode() const { return sbmlTC; };
Expand Down Expand Up @@ -60,7 +60,7 @@ class StructureFields
unsigned int index);

void addStructureField(const std::string& functionId, SBase* base,
unsigned int index, FieldValues_t field, bool usePlugin);
unsigned int index, FieldValues_t field, bool usePlugin_sf);

void addChildElement(FieldValues_t field, unsigned int index);

Expand Down Expand Up @@ -140,7 +140,7 @@ class StructureFields
unsigned int index, unsigned int total_no);


bool usingPlugin(const std::string& prefix, SBase* base = NULL);
bool usingPlugin(const std::string& prefix, SBase* base = NULL, const std::string& name = "" );

mxArray* getNamespacesStructure();

Expand Down
5 changes: 5 additions & 0 deletions src/bindings/matlab/TranslateSBML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
GV gv;
// we have not made persistent memory
gv.freeMemory = false;

// default values
gv.fbcUsingId = false;
gv.fbcAddGeneProducts = true;

std::ostringstream numErrs;
/* determine whether we are in octave or matlab */
unsigned int usingOctave = determinePlatform(gv);
Expand Down
Loading