Skip to content

Commit

Permalink
Create release v0.5.0-rc.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
abi-git-user committed Oct 16, 2023
1 parent 2b7bdd4 commit d1bdc4d
Show file tree
Hide file tree
Showing 16 changed files with 464 additions and 34 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15 CACHE STRING "Minimum OS X deployment vers
set(PROJECT_NAME libCellML)
set(PROJECT_URL https://libcellml.org)
set(_PROJECT_VERSION 0.5.0)
set(PROJECT_DEVELOPER_VERSION -rc.4)
set(PROJECT_DEVELOPER_VERSION -rc.5)
project(${PROJECT_NAME} VERSION ${_PROJECT_VERSION} LANGUAGES CXX)

# Set policies that affect the build.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
libCellML v0.5.0-rc.4 Changelog
libCellML v0.5.0-rc.5 Changelog
===============================

Analyser
--------

* AnaylserModel: Fix loss of Units definition information by `@hsorby <https://github.com/hsorby>`_ [`#1196 <https://github.com/cellml/libcellml/pull/1196>`_].
* Analyser: add support for unknown variables that have been marked as external by `@agarny <https://github.com/agarny>`_ [`#1184 <https://github.com/cellml/libcellml/pull/1184>`_].
* AnalyserVariable: hold onto the owning component reference by `@agarny <https://github.com/agarny>`_ [`#1185 <https://github.com/cellml/libcellml/pull/1185>`_].
* Analyser: don't optimise the order of variables and equations by `@agarny <https://github.com/agarny>`_ [`#1090 <https://github.com/cellml/libcellml/pull/1090>`_].
* Analyser: reworked the analysis of a model with external variables by `@agarny <https://github.com/agarny>`_ [`#1077 <https://github.com/cellml/libcellml/pull/1077>`_].
* Analyser: allow for the unknown variable to be either on the LHS or RHS of an equation by `@agarny <https://github.com/agarny>`_ [`#1071 <https://github.com/cellml/libcellml/pull/1071>`_].
Expand Down Expand Up @@ -79,11 +81,6 @@ Miscellaneous
* Analyser/Generator: replace if...else statements with switch ones wherever possible by `@agarny <https://github.com/agarny>`_ [`#1135 <https://github.com/cellml/libcellml/pull/1135>`_].
* Tests: added support for libXml2 2.9.11+ by `@agarny <https://github.com/agarny>`_ [`#1069 <https://github.com/cellml/libcellml/pull/1069>`_].

No category
-----------

* AnalyserVariable: hold onto the owning component reference by `@agarny <https://github.com/agarny>`_ [`#1185 <https://github.com/cellml/libcellml/pull/1185>`_].

Validation
----------

Expand Down
2 changes: 1 addition & 1 deletion docs/changelogs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelogs

.. toctree::

changelog_v0.5.0-rc.4
changelog_v0.5.0-rc.5
changelog_v0.4.0
changelog_v0.3.104
changelog_v0.3.103
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.in.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
extlinks = {
# NB for deployment outside of the libcellml.org domain, you will need to include the root of the href for the
# :api: shortcut here. This only works internally.
'api': ('/documentation/api/latest/classlibcellml_1_1%s', ''),
'api': ('/documentation/api/latest/classlibcellml_1_1%s', ''),
'buildbot': ('https://buildbot.net/%s',''),
'cellml': ('https://www.cellml.org/%s',''),
'cellml2spec': ('https://www.cellml.org/specifications/cellml_2.0%s', ''),
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Changelogs

.. toctree::

changelogs/changelog_v0.5.0-rc.4
changelogs/changelog_v0.5.0-rc.5
changelogs/changelog_v0.4.0
changelogs/changelog_v0.3.104
changelogs/changelog_v0.3.103
Expand Down
2 changes: 1 addition & 1 deletion src/analyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,7 @@ void Analyser::AnalyserImpl::analyseModel(const ModelPtr &model)
// Reset a few things in case this analyser was to be used to analyse more
// than one model.

mModel = AnalyserModel::AnalyserModelImpl::create();
mModel = AnalyserModel::AnalyserModelImpl::create(model);

mInternalVariables.clear();
mInternalEquations.clear();
Expand Down
13 changes: 9 additions & 4 deletions src/analysermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ limitations under the License.

namespace libcellml {

AnalyserModelPtr AnalyserModel::AnalyserModelImpl::create()
AnalyserModelPtr AnalyserModel::AnalyserModelImpl::create(const ModelPtr &model)
{
return std::shared_ptr<AnalyserModel> {new AnalyserModel {}};
return std::shared_ptr<AnalyserModel> {new AnalyserModel(model)};
}

AnalyserModel::AnalyserModel()
: mPimpl(new AnalyserModelImpl())
AnalyserModel::AnalyserModelImpl::AnalyserModelImpl(const ModelPtr &model)
: mModel(model)
{
}

AnalyserModel::AnalyserModel(const ModelPtr &model)
: mPimpl(new AnalyserModelImpl(model))
{
}

Expand Down
6 changes: 5 additions & 1 deletion src/analysermodel_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace libcellml {
*/
struct AnalyserModel::AnalyserModelImpl
{
ModelPtr mModel;

AnalyserModel::Type mType = Type::UNKNOWN;

bool mHasExternalVariables = false;
Expand Down Expand Up @@ -65,7 +67,9 @@ struct AnalyserModel::AnalyserModelImpl

std::map<uintptr_t, bool> mCachedEquivalentVariables;

static AnalyserModelPtr create();
static AnalyserModelPtr create(const ModelPtr &model = nullptr);

AnalyserModelImpl(const ModelPtr &model);
};

} // namespace libcellml
2 changes: 1 addition & 1 deletion src/api/libcellml/analysermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ class LIBCELLML_EXPORT AnalyserModel
const VariablePtr &variable2);

private:
AnalyserModel(); /**< Constructor, @private. */
AnalyserModel(const ModelPtr &model); /**< Constructor, @private. */

struct AnalyserModelImpl;
AnalyserModelImpl *mPimpl; /**< Private member to implementation pointer, @private. */
Expand Down
23 changes: 10 additions & 13 deletions src/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,14 +787,12 @@ void retrieveUnitsDependencies(const ModelPtr &flatModel, const ModelPtr &model,
auto childUnits = model->units(reference);
if (childUnits->isImport()) {
size_t flatModelUnitsIndex = flatModel->unitsCount();
UnitsPtr clonedChildUnits = childUnits->clone();
flatModel->addUnits(clonedChildUnits);
flattenUnitsImports(flatModel, clonedChildUnits, flatModelUnitsIndex, component);
flatModel->addUnits(childUnits);
flattenUnitsImports(flatModel, childUnits, flatModelUnitsIndex, component);
} else {
auto clonedChildUnits = childUnits->clone();
transferUnitsRenamingIfRequired(model, flatModel, clonedChildUnits, component);
u->setUnitAttributeReference(unitIndex, clonedChildUnits->name());
retrieveUnitsDependencies(flatModel, model, clonedChildUnits, component);
transferUnitsRenamingIfRequired(model, flatModel, childUnits, component);
u->setUnitAttributeReference(unitIndex, childUnits->name());
retrieveUnitsDependencies(flatModel, model, childUnits, component);
}
}
}
Expand All @@ -803,12 +801,11 @@ void retrieveUnitsDependencies(const ModelPtr &flatModel, const ModelPtr &model,
void flattenUnitsImports(const ModelPtr &flatModel, const UnitsPtr &units, size_t index, const ComponentPtr &component)
{
auto importSource = units->importSource();
auto importingModel = importSource->model();
auto importedUnits = importingModel->units(units->importReference());
auto importedUnitsCopy = importedUnits->clone();
importedUnitsCopy->setName(units->name());
flatModel->replaceUnits(index, importedUnitsCopy);
retrieveUnitsDependencies(flatModel, importingModel, importedUnitsCopy, component);
auto importingModelCopy = importSource->model()->clone();
auto importedUnits = importingModelCopy->units(units->importReference());
importedUnits->setName(units->name());
flatModel->replaceUnits(index, importedUnits);
retrieveUnitsDependencies(flatModel, importingModelCopy, importedUnits, component);
}

ComponentPtr flattenComponent(const ComponentEntityPtr &parent, ComponentPtr &component, size_t index)
Expand Down
45 changes: 41 additions & 4 deletions tests/generator/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1840,19 +1840,22 @@ TEST(Generator, variableInitialisedUsingAConstant)

TEST(Generator, modelOutOfScope)
{
auto analyser = libcellml::Analyser::create();
libcellml::AnalyserModelPtr analyserModel;

{
auto analyser = libcellml::Analyser::create();
auto parser = libcellml::Parser::create();
auto model = parser->parseModel(fileContents("generator/ode_multiple_dependent_odes/model.cellml"));

EXPECT_EQ(size_t(0), parser->issueCount());

analyser->analyseModel(model);
}

EXPECT_EQ(size_t(0), analyser->errorCount());
EXPECT_EQ(size_t(0), analyser->errorCount());

analyserModel = analyser->model();
}

auto analyserModel = analyser->model();
auto generator = libcellml::Generator::create();

generator->setModel(analyserModel);
Expand Down Expand Up @@ -1893,3 +1896,37 @@ TEST(Generator, unknownVariableMarkedAsExternalVariable)

EXPECT_EQ(fileContents("generator/unknown_variable_as_external_variable/model.py"), generator->implementationCode());
}

TEST(Generator, modelWithComplexUnitsOutOfScope)
{
libcellml::AnalyserModelPtr analyserModel;

{
auto analyser = libcellml::Analyser::create();
auto parser = libcellml::Parser::create();
auto importer = libcellml::Importer::create();
auto model = parser->parseModel(fileContents("generator/cellml_slc_example/slc_model.cellml"));

EXPECT_EQ(size_t(0), parser->issueCount());

importer->resolveImports(model, resourcePath("generator/cellml_slc_example"));
EXPECT_FALSE(model->hasUnresolvedImports());

model = importer->flattenModel(model);

analyser->analyseModel(model);
EXPECT_EQ(size_t(0), analyser->errorCount());

analyserModel = analyser->model();
}

auto generator = libcellml::Generator::create();

generator->setModel(analyserModel);

auto profile = libcellml::GeneratorProfile::create(libcellml::GeneratorProfile::Profile::PYTHON);

generator->setProfile(profile);

EXPECT_EQ(fileContents("generator/cellml_slc_example/model.py"), generator->implementationCode());
}
36 changes: 36 additions & 0 deletions tests/importer/model_flattening.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1863,3 +1863,39 @@ TEST(ModelFlattening, resolveImportsInvalidInput)
EXPECT_EQ(size_t(1), importer->issueCount());
EXPECT_EQ("Cannot resolve imports for null model.", importer->issue(0)->description());
}

TEST(ModelFlattening, flatteningImportedUnitsThatNeedEquivalence)
{
const std::string e =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<model xmlns=\"http://www.cellml.org/cellml/2.0#\" name=\"test_model\">\n"
" <units name=\"per_fmol\">\n"
" <unit exponent=\"-1\" units=\"fmol\"/>\n"
" </units>\n"
" <units name=\"fmol\">\n"
" <unit prefix=\"femto\" units=\"mole\"/>\n"
" </units>\n"
" <units name=\"per_fmol_sec4\">\n"
" <unit units=\"per_fmol\"/>\n"
" <unit exponent=\"4\" units=\"per_sec\"/>\n"
" </units>\n"
" <units name=\"per_sec\">\n"
" <unit exponent=\"-1\" units=\"second\"/>\n"
" </units>\n"
"</model>\n";

auto parser = libcellml::Parser::create();
auto importer = libcellml::Importer::create();

auto model = parser->parseModel(fileContents("generator/cellml_slc_example/slc_model_units_only.cellml"));

EXPECT_EQ(size_t(0), parser->issueCount());

importer->resolveImports(model, resourcePath("generator/cellml_slc_example"));
EXPECT_FALSE(model->hasUnresolvedImports());

auto flatModel = importer->flattenModel(model);

auto printer = libcellml::Printer::create();
EXPECT_EQ(e, printer->printModel(flatModel));
}
54 changes: 54 additions & 0 deletions tests/resources/generator/cellml_slc_example/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# The content of this file was generated using the Python profile of libCellML 0.5.0.

from enum import Enum
from math import *


__version__ = "0.4.0"
LIBCELLML_VERSION = "0.5.0"

VARIABLE_COUNT = 10


class VariableType(Enum):
CONSTANT = 0
COMPUTED_CONSTANT = 1
ALGEBRAIC = 2


VARIABLE_INFO = [
{"name": "v", "units": "fmol_per_sec", "component": "SLC_template3_ss", "type": VariableType.COMPUTED_CONSTANT},
{"name": "E", "units": "fmol", "component": "SLC_template3_ss", "type": VariableType.CONSTANT},
{"name": "P_0", "units": "per_fmol_sec4", "component": "SLC_template3_ss", "type": VariableType.CONSTANT},
{"name": "q_Ao", "units": "fmol", "component": "SLC_template3_ss", "type": VariableType.CONSTANT},
{"name": "P_1", "units": "per_fmol_sec4", "component": "SLC_template3_ss", "type": VariableType.CONSTANT},
{"name": "q_Ai", "units": "fmol", "component": "SLC_template3_ss", "type": VariableType.CONSTANT},
{"name": "P_2", "units": "per_fmol_sec3", "component": "SLC_template3_ss", "type": VariableType.CONSTANT},
{"name": "P_5", "units": "per_sec3", "component": "SLC_template3_ss", "type": VariableType.CONSTANT},
{"name": "P_4", "units": "per_fmol2_sec3", "component": "SLC_template3_ss", "type": VariableType.CONSTANT},
{"name": "P_3", "units": "per_fmol_sec3", "component": "SLC_template3_ss", "type": VariableType.CONSTANT}
]


def create_variables_array():
return [nan]*VARIABLE_COUNT


def initialise_variables(variables):
variables[1] = 1.1
variables[2] = 21262500.0
variables[3] = 150.0
variables[4] = 3402000.0
variables[5] = 2.0
variables[6] = 2902500.0
variables[7] = 810000.0
variables[8] = 247140.0
variables[9] = 2902500.0


def compute_computed_constants(variables):
variables[0] = variables[1]*(variables[2]*variables[3]-variables[4]*variables[5])/(variables[6]*variables[5]+variables[9]*variables[3]+variables[8]*variables[5]*variables[3]+variables[7])


def compute_variables(variables):
pass
71 changes: 71 additions & 0 deletions tests/resources/generator/cellml_slc_example/slc_model.cellml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<model xmlns="http://www.cellml.org/cellml/2.0#" name="test_model">
<import xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="units_BG.cellml">
<units units_ref="per_sec" name="per_sec"/>
<units units_ref="fmol_per_sec" name="fmol_per_sec"/>
<units units_ref="per_fmol" name="per_fmol"/>
<units units_ref="fmol" name="fmol"/>
<units units_ref="per_fmol_sec4" name="per_fmol_sec4"/>
<units units_ref="per_fmol_sec3" name="per_fmol_sec3"/>
<units units_ref="per_fmol2_sec3" name="per_fmol2_sec3"/>
<units units_ref="per_sec3" name="per_sec3"/>
</import>
<component name="SLC_template3_ss">
<variable name="v" units="fmol_per_sec" />
<variable name="E" units="fmol" initial_value="1.1" />
<variable name="q_Ai" units="fmol" initial_value="2"/>
<variable name="q_Ao" units="fmol" initial_value="150" />
<variable name="P_0" units="per_fmol_sec4" initial_value="21262500" id="b4da6c"/>
<variable name="P_1" units="per_fmol_sec4" initial_value="3402000" id="b4da6d"/>
<variable name="P_2" units="per_fmol_sec3" initial_value="2902500" id="b4da6e"/>
<variable name="P_3" units="per_fmol_sec3" initial_value="2902500" interface="public" id="b4da6f"/>
<variable name="P_4" units="per_fmol2_sec3" initial_value="247140" id="b4da70"/>
<variable name="P_5" units="per_sec3" initial_value="810000" id="b4da71"/>
<math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:cellml="http://www.cellml.org/cellml/2.0#">
<apply>
<eq/>
<ci>v</ci>
<apply>
<divide/>
<apply>
<times/>
<ci>E</ci>
<apply>
<minus/>
<apply>
<times/>
<ci>P_0</ci>
<ci>q_Ao</ci>
</apply>
<apply>
<times/>
<ci>P_1</ci>
<ci>q_Ai</ci>
</apply>
</apply>
</apply>
<apply>
<plus/>
<apply>
<times/>
<ci>P_2</ci>
<ci>q_Ai</ci>
</apply>
<apply>
<times/>
<ci>P_3</ci>
<ci>q_Ao</ci>
</apply>
<apply>
<times/>
<ci>P_4</ci>
<ci>q_Ai</ci>
<ci>q_Ao</ci>
</apply>
<ci>P_5</ci>
</apply>
</apply>
</apply>
</math>
</component>
</model>
Loading

0 comments on commit d1bdc4d

Please sign in to comment.