Invalid assignment syntax or parse error for event function (Simbiology)

I am adding an event to a QSP model to impose a function to be a small positive number (say epsilon) if its value goes below epsilon. Snippet of the code is:
f_HPD1 = '((syn_CT.PD1_PDL1+syn_CT.PD1_PDL2)/PD1_50)';
addevent(model, [f_HPD1 '< 1e-10'], [f_HPD1 '= 1e-10']);
Where,
syn_CT is compartment name,
PD1_PDL1, PD1_PDL2 are species in the compartment syn_CT
PD1_50 is model parameter
But I get this error message:
Error using SimBiology.internal.simulate
--> Error reported from Expression Validation:
Invalid assignment syntax or parse error for event function '((syn_CT.PD1_PDL1+syn_CT.PD1_PDL2)/PD1_50) = 1e-10' in event with
trigger '((syn_CT.PD1_PDL1+syn_CT.PD1_PDL2)/PD1_50)< 1e-10'. Event functions must be valid MATLAB expressions and cannot end in
semicolons, commas, comments ('%' and optional text), or line continuations ('...' and optional text).
Error in sbiosimulate (line 140)
simResultsCell = SimBiology.internal.simulate(mobj, cs, variants, doses);
Error in initial_conditions (line 84)
simData = sbiosimulate(model,variant);
Please help me resolve this, any suggestion is really appreciated.
Thank you

2 Comments

No, I am assigning the epsilon (1e-10) values to the H_PD1 function so it should be = and not ==

Sign in to comment.

 Accepted Answer

Hi,
Events can only assign a value to a component, not to an expression. So your assignment ((syn_CT.PD1_PDL1+syn_CT.PD1_PDL2)/PD1_50) = 1e-10 is invalid because the left-hand side is not a single component name. A valid assignment would look more like syn_CT.PD1_PDL1 = 1e-10. Note that the component on the left-hand side also has to have its Constant property set to false.
Looking at the bigger picture of what you're trying to do, I'm guessing what you might want to do instead is to create a parameter (let's call it HPD1), set its Constant property set to false, and update its value with a repeated assignment rule of the form HPD1 = max(1e-10, ((syn_CT.PD1_PDL1+syn_CT.PD1_PDL2)/PD1_50)).
-Arthur

9 Comments

Hi Arthur,
Thank you for your suggestion. I tried implementing it the following way but this gives dimensional analysis error.
f_HPD1 = '((syn_CT.PD1_PDL1+syn_CT.PD1_PDL2)/PD1_50)';
addevent(model, [f_HPD1 '< 1e-10'], {'syn_CT.PD1_PDL1 = 1e-7','syn_CT.PD1_PDL2 = 1e-7'});
Error message:
Error using SimBiology.internal.simulate
--> Error reported from Dimensional Analysis:
Dimensional analysis failed for event with trigger '((syn_CT.PD1_PDL1+syn_CT.PD1_PDL2)/PD1_50)<
1e-10'. The units of the left- and right-hand sides of all event functions must agree.
Error in sbiosimulate (line 140)
simResultsCell = SimBiology.internal.simulate(mobj, cs, variants, doses);
Error in initial_conditions (line 84)
simData = sbiosimulate(model,variant);
Please note: Here, the dimension of PD1_PDL1, PD1_PDL2 and PD1_50 are same.
Thank you for helping me with this.
- BK
f_HPD1 '< 1e-10'
less than 1e-10 of what units?
syn_CT.PD1_PDL1 = 1e-7
Set it to 1e-7 of what units ?
I got it, I had to assign unit to 1e-7 in the EventFcns.
f_HPD1 is unitless, so I don't need to specify unit for this.
Thank you that helped!
-BK
Hi Walter,
On similar line when I use rules for the same implementation, I again get dimensional analysis error. Could you please help me resolve this.
Code Snippet:
f_HPD1 = 'max(1e-10,((syn_CT.PD1_PDL1+syn_CT.PD1_PDL2)/PD1_50))';
addrule(model,['H_PD1=' f_HPD1 '^n_PD1/(' f_HPD1 '^n_PD1+1)'],'repeatedAssignment');
Error message:
Warning: Reported from Dimensional Analysis:
Cannot perform dimensional analysis for rule 'H_PD1 =
max(1e-10,((syn_CT.PD1_PDL1+syn_CT.PD1_PDL2)/PD1_50))^n_PD1/(max(1e-10,((syn_CT.PD1_PDL1+syn_CT.PD1_PDL2)/PD1_50))^n_PD1+1)'
because of the function 'max' in the rule. Because UnitConversion is on, correct simulation results will depend on this expression being dimensionally correct. Additionally, SimBiology simulates the model in a unit system determined at runtime. The units are determined by the units used in the model and the model's configset. Unless the inputs and outputs to the function are dimensionless, results may change due to configset option changes, changes to the model, or version changes in SimBiology. It is recommended that input and output arguments to functions be dimensionless to ensure correct results.
> In sbiosimulate (line 140)
Please note the fractional function inside max is dimensionless and n_PD1 is dimensionless.
Thank you again.
-BK
The warning about 'max' is informational. You will need to manually check that the expression is dimensionally consistent. Once you do that, you can safely ignore this message.
Hi Arthur and Walter,
Along similar lines, when I use max or abs function in rules for the same implementation, I get dimensional analysis error for both these function. Is it that the simbiology addrule function does not accept any inbuilt function of matlab like max and abs function here and give warning. Please see below:
Code snippet:
f_HPD1 = '((max(syn_CT.PD1_PDL1,(syn_CT.PD1_PDL1+abs(syn_CT.PD1_PDL1))/2)+max(syn_CT.PD1_PDL2,(syn_CT.PD1_PDL2+abs(syn_CT.PD1_PDL2))/2))/PD1_50)';
addrule(model,['H_PD1=' f_HPD1 '^n_PD1/(' f_HPD1 '^n_PD1+1)'],'repeatedAssignment');
Error message:
Warning: Reported from Dimensional Analysis:
Cannot perform dimensional analysis for rule 'H_PD1 =
((max(syn_CT.PD1_PDL1,(syn_CT.PD1_PDL1+abs(syn_CT.PD1_PDL1))/2)+max(syn_CT.PD1_PDL2,(syn_CT.PD1_PDL2+abs(syn_CT.PD1_PDL2))/2))/PD1_50)^n_PD1/(((max(syn_CT.PD1_PDL1,(syn_CT.PD1_PDL1+abs(syn_CT.PD1_PDL1))/2)+max(syn_CT.PD1_PDL2,(syn_CT.PD1_PDL2+abs(syn_CT.PD1_PDL2))/2))/PD1_50)^n_PD1+1)'
because of the function 'abs' in the rule. Because UnitConversion is on, correct simulation results will
depend on this expression being dimensionally correct. Additionally, SimBiology simulates the model in a unit
system determined at runtime. The units are determined by the units used in the model and the model's
configset. Unless the inputs and outputs to the function are dimensionless, results may change due to
configset option changes, changes to the model, or version changes in SimBiology. It is recommended that
input and output arguments to functions be dimensionless to ensure correct results.
> In sbiosimulate (line 140)
In initial_conditions (line 84)
Warning: Reported from Dimensional Analysis:
Cannot perform dimensional analysis for rule 'H_PD1 =
((max(syn_CT.PD1_PDL1,(syn_CT.PD1_PDL1+abs(syn_CT.PD1_PDL1))/2)+max(syn_CT.PD1_PDL2,(syn_CT.PD1_PDL2+abs(syn_CT.PD1_PDL2))/2))/PD1_50)^n_PD1/(((max(syn_CT.PD1_PDL1,(syn_CT.PD1_PDL1+abs(syn_CT.PD1_PDL1))/2)+max(syn_CT.PD1_PDL2,(syn_CT.PD1_PDL2+abs(syn_CT.PD1_PDL2))/2))/PD1_50)^n_PD1+1)'
because of the function 'max' in the rule. Because UnitConversion is on, correct simulation results will
depend on this expression being dimensionally correct. Additionally, SimBiology simulates the model in a unit
system determined at runtime. The units are determined by the units used in the model and the model's
configset. Unless the inputs and outputs to the function are dimensionless, results may change due to
configset option changes, changes to the model, or version changes in SimBiology. It is recommended that
input and output arguments to functions be dimensionless to ensure correct results.
Could you please help me resolve these warnings? Thank you
-BK
my memory is that Simscape offers a way to strip units from an expression, and offers a way to wrap a dimensionless quantity in a unit. So keep dimensions until you are just about to call max, then strip unit, then max, then wrap in a unit.
It is a bit of a nuisance, but it should prevent the warnings
As I mention above, "The warning about 'max' is informational. You will need to manually check that the expression is dimensionally consistent. Once you do that, you can safely ignore this message." The same is true for 'abs'. Unfortunately, SimBiology does not currently have any way to strip the units from expressions or otherwise eliminate this warning. If you want, you can turn this warning off for the duration of your MATLAB session with warning('off', 'SimBiology:DimAnalysisNotDone_MatlabFcn_Dimensionless')
Thank you, I did check the units are consistent so was not sure why do these warnings appear. I cannot turn off the unit conversion since some of the data that we input are in different units and so unit conversion is needed.

Sign in to comment.

More Answers (0)

Communities

More Answers in the  SimBiology Community

Categories

Products

Asked:

on 28 Sep 2021

Commented:

on 5 Oct 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!