Skip to content

Commit

Permalink
error messages for unsupported switchers
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Metelkin committed Nov 5, 2021
1 parent 21e45d7 commit 7152fec
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 15 deletions.
1 change: 1 addition & 0 deletions cases/9-c-switcher/src/index.heta
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ r1 @Reaction { actors: x1->x2 } := k1*x1*comp1;
#export { filepath: julia, format: Julia };
#export { filepath: matlab, format: Matlab };
#export { filepath: simbio, format: Simbio };
#export { filepath: mrgsolve, format: Mrgsolve };

// switcher
cond1 @Record := 6-x1;
Expand Down
22 changes: 20 additions & 2 deletions src/dbsolve-export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ class DBSolveExport extends AbstractExport{
let logger = this._container.logger;
if (this.spaceFilter.length === 0) {
let msg = 'spaceFilter for DBSolve format should include at least one namespace, got empty.';
logger.err(msg);
logger.error(msg);
var content = '';
} else if (!this._container.namespaceStorage.has(this.spaceFilter[0])) {
let msg = `Namespace "${this.spaceFilter[0]}" does not exist.`;
logger.err(msg);
logger.error(msg);
content = '';
} else if (this._container.namespaceStorage.get(this.spaceFilter[0]).isAbstract) { // if abstract
let msg = `Abstract Namespace "${this.spaceFilter[0]}" cannot be used for DBSolve export.`;
Expand Down Expand Up @@ -170,6 +170,15 @@ class DBSolveExport extends AbstractExport{
let discreteEvents = ns
.selectByClassName('DSwitcher')
.map((switcher) => {
let dynamicRecords = ns
.selectRecordsByContext(switcher.id)
.filter((record) => record.isDynamic)
.map((record) => record.index);
if (dynamicRecords.length > 0) {
let msg = `DBSolve doesn't support ${switcher.className} for dynamic records: ${dynamicRecords.join(', ')}.`;
logger.error(msg, {type: 'ExportError'});
}

// check boolean expression in trigger
if (!switcher.trigger.isComparison) {
let msg = `DBSolve supports only simple comparison operators in DSwitcher trigger, got: "${switcher.trigger.toString()}"`;
Expand Down Expand Up @@ -199,6 +208,15 @@ class DBSolveExport extends AbstractExport{
let continuousEvents = ns
.selectByClassName('CSwitcher')
.map((switcher) => {
let dynamicRecords = ns
.selectRecordsByContext(switcher.id)
.filter((record) => record.isDynamic)
.map((record) => record.index);
if (dynamicRecords.length > 0) {
let msg = `DBSolve doesn't support ${switcher.className} for dynamic records: ${dynamicRecords.join(', ')}.`;
logger.error(msg, {type: 'ExportError'});
}

let assignments = ns
.selectRecordsByContext(switcher.id)
.map((record) => {
Expand Down
6 changes: 3 additions & 3 deletions src/matlab-export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MatlabExport extends AbstractExport {
return 'MatlabExport';
}
get format(){
return 'Matlab'
return 'Matlab';
}
static get validate(){
return ajv.compile(schema);
Expand All @@ -45,13 +45,13 @@ class MatlabExport extends AbstractExport {
let logger = this._container.logger;
if (this.spaceFilter.length === 0) {
let msg = 'spaceFilter for Matlab format should include at least one namespace but get empty';
logger.err(msg);
logger.error(msg);
var modelContent = '';
var paramContent = '';
var runContent = '';
} else if (!this._container.namespaceStorage.has(this.spaceFilter[0])) {
let msg = `Namespace "${this.spaceFilter[0]}" does not exist.`;
logger.err(msg);
logger.error(msg);
modelContent = '';
paramContent = '';
runContent = '';
Expand Down
19 changes: 14 additions & 5 deletions src/mrgsolve-export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MrgsolveExport extends AbstractExport {
return 'MrgsolveExport';
}
get format(){
return 'Mrgsolve'
return 'Mrgsolve';
}
static get validate(){
return ajv.compile(schema);
Expand All @@ -40,18 +40,18 @@ class MrgsolveExport extends AbstractExport {
// use only one namespace
let logger = this._container.logger;
if (this.spaceFilter.length === 0) {
let msg = 'spaceFilter for Mrgsolve format should include at least one namespace but get empty';
logger.err(msg);
let msg = 'spaceFilter for Mrgsolve format should include at least one namespace, got empty.';
logger.error(msg);
var codeContent = '';
var runContent = '';
} else if (!this._container.namespaceStorage.has(this.spaceFilter[0])) {
let msg = `Namespace "${this.spaceFilter[0]}" does not exist.`;
logger.err(msg);
logger.error(msg);
codeContent = '';
runContent = '';
} else {
if (this.spaceFilter.length > 1) {
let msg = `Mrgsolve format does not support multispace export. Only first namespace "${this.spaceFilter[0]}" will be used.`;
let msg = `Mrgsolve format does not support multi-space export. Only first namespace "${this.spaceFilter[0]}" will be used.`;
logger.warn(msg);
}
let ns = this._container.namespaceStorage.get(this.spaceFilter[0]);
Expand Down Expand Up @@ -103,6 +103,15 @@ class MrgsolveExport extends AbstractExport {
}
});

// check if there are unsupported _Switcher components
let switchers = ns.selectByInstanceOf('_Switcher');
if (switchers.length > 0) {
let logger = ns.container.logger;
let switcherIds = switchers.map((sw) => sw.index).join(', ');
let msg = `Mrgsolve doesn't support Swichers, the following events will be skipped: ${switcherIds}.`;
logger.error(msg, {type: 'ExportError'});
}

// set array of output records
let output = ns
.selectByInstanceOf('Record')
Expand Down
4 changes: 2 additions & 2 deletions src/sbml-export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class SBMLExport extends AbstractExport {
let logger = this._container.logger;
if (this.spaceFilter.length === 0) {
let msg = 'spaceFilter for SBML format should include at least one namespace but get empty';
logger.err(msg);
logger.error(msg);
var content = '';
} else if (!this._container.namespaceStorage.has(this.spaceFilter[0])) {
let msg = `Namespace "${this.spaceFilter[0]}" does not exist.`;
logger.err(msg);
logger.error(msg);
content = '';
} else {
if (this.spaceFilter.length > 1) {
Expand Down
24 changes: 21 additions & 3 deletions src/slv-export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class SLVExport extends AbstractExport{
let logger = this._container.logger;
if (this.spaceFilter.length === 0) {
let msg = 'spaceFilter for SLV format should include at least one namespace, got empty.';
logger.err(msg);
logger.error(msg);
var content = '';
} else if (!this._container.namespaceStorage.has(this.spaceFilter[0])) {
let msg = `Namespace "${this.spaceFilter[0]}" does not exist.`;
logger.err(msg);
logger.error(msg);
content = '';
} else {
if (this.spaceFilter.length > 1) {
Expand Down Expand Up @@ -193,6 +193,15 @@ class SLVExport extends AbstractExport{
let assignments = ns
.selectRecordsByContext(switcher.id);

// unsupported events for dynamic
let dynamicRecords = assignments
.filter((record) => record.isDynamic)
.map((record) => record.index);
if (dynamicRecords.length > 0) {
let msg = `SLV doesn't support ${switcher.className} for dynamic records: ${dynamicRecords.join(', ')}.`;
logger.error(msg, {type: 'ExportError'});
}

return {
switcher,
assignments
Expand All @@ -205,7 +214,16 @@ class SLVExport extends AbstractExport{
.map((switcher) => {
let assignments = ns
.selectRecordsByContext(switcher.id);


// unsupported events for dynamic
let dynamicRecords = assignments
.filter((record) => record.isDynamic)
.map((record) => record.index);
if (dynamicRecords.length > 0) {
let msg = `SLV doesn't support ${switcher.className} for dynamic records: ${dynamicRecords.join(', ')}.`;
logger.error(msg, {type: 'ExportError'});
}

return {
switcher,
assignments
Expand Down

0 comments on commit 7152fec

Please sign in to comment.