Unit conversion in Simbiology model

16 views (last 30 days)
I am trying to understand how unit conversion has been implemented in model developed in Simbiology model being executed in matlab envioronemt. If unit conversion is enabled - will it convert only time unit or other parameters as well. This becomes critical in my work. My questions are listed below-
1. If unit conversion feature enables in simbiology project - What units are being converted? Can you provide the general script to access this information?
2. What are the global units of such model (simbiology developed models?)
3. How to access the parameter names and values which are being used to solve equations using ode solver?
Please take this query as urgent.
Thanks in advance for your help.

Accepted Answer

Arthur Goldsipe
Arthur Goldsipe on 8 Oct 2024
Hi, I'm a developer on the SimBiology team. I'm not sure I fully understand your question, but I'll try to answer based on my current understand. However, since you mention that this query is urgent, I also want to mention that MATLAB Answers is may not the best venue for urgent questions. You may prefer to directly contact MathWorks, so that an experienced engineer can work cirectly with you to answer your questions. You can find options for that here.
You can find more information about unit conversion on this reference page. Unit conversion applies to all quantities in your model, not just time. When you enable unit conversion in SimBiology, you must add unit information to all quantities in your model. Then, when you write expressions, SimBiology will ensure that your expression is dimensionally consistent and perform all the appropriate unit conversions to perform. For example, let's say you have an assignment rule "x = y + z", x has units of mole, y has units of millimole, and z has units of micromole. SimBiology can see that all three quantities have the same dimensions of amount, and so the rule expression is dimensionally consistent. Then, it will internally convert everything to consistent units before performing the addition, but all values will be reported back to you in the units you specify.
I'm not sure what you mean by global units. You can specify whatever units you want on the model. Perhaps you are asking what units SimBiology uses internally when simulating the model. If so, those are implementation details that we don't generally provide to users, becaue for the most part they shouldn't affect the user's results. This allows us to change the implementation as needed for future enhancements. That said, we do document a couple a few aspects of the internal units used during simulation. If you look at this page, you will see the options AmountUnits, MassUnits, and TimeUnits. These options can be used to control the internal amount, mass, and time units used by SimBiology. If you need more details, I can provide them. But I would need to understand your question better to provide an appropriate answer. What information do you need and why do you need it?
As for your final question, the person who creates the SimBiology model determines the names of parameters. You can then reference parameters by names wherever you need to reference their values.
I also recommend you take a look at the SimBiology documentation. In particular, you may find wnat to look at the Getting Started section and the Examples (many of which use unit conversion).
  3 Comments
Arthur Goldsipe
Arthur Goldsipe on 9 Oct 2024
Let me rephrase your question to make sure I understand it. You'd like to be able inspect the internal values that species or parameters have over the course of a simulation, so that you can debug the model.
For debugging, I generally recommend downloading and using the SimBiology Model Debugger. That tool allows you to step through simulations interactively and inspect how values change. However, it only reports the values to you in the units you specify. The tool does not report the internal values used.
If you really want to see the internal values during simulation, I can only think of one way to do that, and it has at least one major (and one minor) caveat. My idea is related to the Tip listed under UnitConversion on this reference page. Specifically, you must write your own MATLAB function and use it in your model. Anything you specify as an input will be passed to the function in internal engine units. Let's continue the "x = y + z" example. You could move that addition into your own function named "myAdd". Then, change the repeated assignment rule in your model to "x = myAdd(y, z)". Then, function myAdd will receive inputs y and z in the same internal "engine" units. You can then debug myAdd using whatever approach you like to "see" those values. However, here's the caveat: The function may be called with intermediate results that are ultimately discarded by the solver; there is no way to know within this function whether the values you get are part of the solution or an intermediate result. A second minor caveat is that you will see a warning that SimBiology cannot do dimensional analysis the myAdd function (or whatever you name it). You can safely ignore this messafe, one you confirm that your function behaves as desired.
In case the above caveats are acceptable, I've attached a couple of files that illlustrate the approach. In the model, y is converted to z, and x = y + z. So x should remain constant throughout the simulation. My function prints out time, x, y, and z in internal units every time the function is called. The internal units could be different in different releases, but in R2024b this shows that x, y, and z are internally stored with units of micromole. And if you compare this output to the final results, you'lll see that the function is called many more times. But perhaps that is good enough for your needs.
inspectUnits
time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 10000.0; z = 100.0
Warning: Reported from Dimensional Analysis:
Unable to perform dimensional analysis for rule 'Rule_1' because of the function 'myAdd' 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.
time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 9999.9; z = 100.1 time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 10000.0; z = 100.0 time = 0.00; x = 10100.0; y = 9997.5; z = 102.5 time = 0.00; x = 10100.0; y = 9997.5; z = 102.5 time = 0.00; x = 10100.0; y = 9997.5; z = 102.5 time = 0.00; x = 10100.0; y = 9994.9; z = 105.1 time = 0.00; x = 10100.0; y = 9994.9; z = 105.1 time = 0.00; x = 10100.0; y = 9994.9; z = 105.1 time = 0.00; x = 10100.0; y = 9992.4; z = 107.6 time = 0.00; x = 10100.0; y = 9992.4; z = 107.6 time = 0.00; x = 10100.0; y = 9992.4; z = 107.6 time = 0.00; x = 10100.0; y = 9967.1; z = 132.9 time = 0.00; x = 10100.0; y = 9967.2; z = 132.8 time = 0.00; x = 10100.0; y = 9967.2; z = 132.8 time = 0.01; x = 10100.0; y = 9942.0; z = 158.0 time = 0.01; x = 10100.0; y = 9942.0; z = 158.0 time = 0.01; x = 10100.0; y = 9942.0; z = 158.0 time = 0.01; x = 10100.0; y = 9916.9; z = 183.1 time = 0.01; x = 10100.0; y = 9916.9; z = 183.1 time = 0.01; x = 10100.0; y = 9916.9; z = 183.1 time = 0.03; x = 10100.0; y = 9735.4; z = 364.6 time = 0.03; x = 10100.0; y = 9735.3; z = 364.7 time = 0.03; x = 10100.0; y = 9735.3; z = 364.7 time = 0.05; x = 10100.0; y = 9556.9; z = 543.1 time = 0.05; x = 10100.0; y = 9556.9; z = 543.1 time = 0.05; x = 10100.0; y = 9556.9; z = 543.1 time = 0.06; x = 10100.0; y = 9381.9; z = 718.1 time = 0.06; x = 10100.0; y = 9381.8; z = 718.2 time = 0.06; x = 10100.0; y = 9381.8; z = 718.2 time = 0.08; x = 10100.0; y = 9210.0; z = 890.0 time = 0.08; x = 10100.0; y = 9210.0; z = 890.0 time = 0.08; x = 10100.0; y = 9210.0; z = 890.0 time = 0.16; x = 10100.0; y = 8555.4; z = 1544.6 time = 0.16; x = 10100.0; y = 8553.8; z = 1546.2 time = 0.16; x = 10100.0; y = 8553.8; z = 1546.2 time = 0.23; x = 10100.0; y = 7947.1; z = 2152.9 time = 0.23; x = 10100.0; y = 7944.3; z = 2155.7 time = 0.23; x = 10100.0; y = 7944.3; z = 2155.7 time = 0.30; x = 10100.0; y = 7381.4; z = 2718.6 time = 0.30; x = 10100.0; y = 7378.2; z = 2721.8 time = 0.30; x = 10100.0; y = 7378.2; z = 2721.8 time = 0.38; x = 10100.0; y = 6855.6; z = 3244.4 time = 0.38; x = 10100.0; y = 6852.5; z = 3247.5 time = 0.38; x = 10100.0; y = 6852.5; z = 3247.5 time = 0.60; x = 10100.0; y = 5455.8; z = 4644.2 time = 0.60; x = 10100.0; y = 5461.0; z = 4639.0 time = 0.60; x = 10100.0; y = 5461.0; z = 4639.0 time = 0.83; x = 10100.0; y = 4342.2; z = 5757.8 time = 0.83; x = 10100.0; y = 4353.3; z = 5746.7 time = 0.83; x = 10100.0; y = 4353.3; z = 5746.7 time = 1.06; x = 10100.0; y = 3455.7; z = 6644.3 time = 1.06; x = 10100.0; y = 3470.4; z = 6629.6 time = 1.06; x = 10100.0; y = 3470.4; z = 6629.6 time = 1.29; x = 10100.0; y = 2752.9; z = 7347.1 time = 1.29; x = 10100.0; y = 2766.1; z = 7333.9 time = 1.29; x = 10100.0; y = 2766.1; z = 7333.9 time = 1.51; x = 10100.0; y = 2194.7; z = 7905.3 time = 1.51; x = 10100.0; y = 2204.6; z = 7895.4 time = 1.51; x = 10100.0; y = 2204.6; z = 7895.4 time = 1.76; x = 10100.0; y = 1717.2; z = 8382.8 time = 1.76; x = 10100.0; y = 1726.0; z = 8374.0 time = 1.76; x = 10100.0; y = 1726.0; z = 8374.0 time = 2.00; x = 10100.0; y = 1343.7; z = 8756.3 time = 2.00; x = 10100.0; y = 1351.3; z = 8748.7 time = 2.00; x = 10100.0; y = 1351.3; z = 8748.7 time = 2.25; x = 10100.0; y = 1051.6; z = 9048.4 time = 2.25; x = 10100.0; y = 1058.0; z = 9042.0 time = 2.25; x = 10100.0; y = 1058.0; z = 9042.0 time = 2.49; x = 10100.0; y = 823.2; z = 9276.8 time = 2.49; x = 10100.0; y = 828.3; z = 9271.7 time = 2.49; x = 10100.0; y = 828.3; z = 9271.7 time = 2.74; x = 10100.0; y = 644.6; z = 9455.4 time = 2.74; x = 10100.0; y = 648.4; z = 9451.6 time = 2.74; x = 10100.0; y = 648.4; z = 9451.6 time = 2.99; x = 10100.0; y = 504.5; z = 9595.5 time = 2.99; x = 10100.0; y = 503.4; z = 9596.6 time = 2.99; x = 10100.0; y = 503.4; z = 9596.6 time = 3.25; x = 10100.0; y = 391.3; z = 9708.7 time = 3.25; x = 10100.0; y = 390.7; z = 9709.3 time = 3.25; x = 10100.0; y = 390.7; z = 9709.3 time = 3.50; x = 10100.0; y = 303.9; z = 9796.1 time = 3.50; x = 10100.0; y = 303.2; z = 9796.8 time = 3.50; x = 10100.0; y = 303.2; z = 9796.8 time = 3.75; x = 10100.0; y = 235.9; z = 9864.1 time = 3.75; x = 10100.0; y = 235.3; z = 9864.7 time = 3.75; x = 10100.0; y = 235.3; z = 9864.7 time = 4.01; x = 10100.0; y = 183.0; z = 9917.0 time = 4.01; x = 10100.0; y = 182.7; z = 9917.3 time = 4.01; x = 10100.0; y = 182.7; z = 9917.3 time = 4.26; x = 10100.0; y = 142.0; z = 9958.0 time = 4.26; x = 10100.0; y = 141.8; z = 9958.2 time = 4.26; x = 10100.0; y = 141.8; z = 9958.2 time = 4.57; x = 10100.0; y = 103.9; z = 9996.1 time = 4.57; x = 10100.0; y = 103.5; z = 9996.5 time = 4.57; x = 10100.0; y = 103.5; z = 9996.5 time = 4.89; x = 10100.0; y = 76.1; z = 10023.9 time = 4.89; x = 10100.0; y = 75.6; z = 10024.4 time = 4.89; x = 10100.0; y = 75.6; z = 10024.4 time = 5.20; x = 10100.0; y = 55.6; z = 10044.4 time = 5.20; x = 10100.0; y = 55.2; z = 10044.8 time = 5.20; x = 10100.0; y = 55.2; z = 10044.8 time = 5.51; x = 10100.0; y = 40.6; z = 10059.4 time = 5.51; x = 10100.0; y = 40.3; z = 10059.7 time = 5.51; x = 10100.0; y = 40.3; z = 10059.7 time = 5.83; x = 10100.0; y = 29.6; z = 10070.4 time = 5.83; x = 10100.0; y = 29.4; z = 10070.6 time = 5.83; x = 10100.0; y = 29.4; z = 10070.6 time = 6.14; x = 10100.0; y = 21.6; z = 10078.4 time = 6.14; x = 10100.0; y = 21.5; z = 10078.5 time = 6.14; x = 10100.0; y = 21.5; z = 10078.5 time = 6.53; x = 10100.0; y = 14.8; z = 10085.2 time = 6.53; x = 10100.0; y = 14.6; z = 10085.4 time = 6.53; x = 10100.0; y = 14.6; z = 10085.4 time = 6.91; x = 10100.0; y = 10.1; z = 10089.9 time = 6.91; x = 10100.0; y = 9.9; z = 10090.1 time = 6.91; x = 10100.0; y = 9.9; z = 10090.1 time = 7.30; x = 10100.0; y = 6.9; z = 10093.1 time = 7.30; x = 10100.0; y = 6.7; z = 10093.3 time = 7.30; x = 10100.0; y = 6.7; z = 10093.3 time = 7.69; x = 10100.0; y = 4.7; z = 10095.3 time = 7.69; x = 10100.0; y = 4.6; z = 10095.4 time = 7.69; x = 10100.0; y = 4.6; z = 10095.4 time = 8.07; x = 10100.0; y = 3.2; z = 10096.8 time = 8.07; x = 10100.0; y = 3.1; z = 10096.9 time = 8.07; x = 10100.0; y = 3.1; z = 10096.9 time = 8.46; x = 10100.0; y = 2.1; z = 10097.9 time = 8.46; x = 10100.0; y = 2.1; z = 10097.9 time = 8.46; x = 10100.0; y = 2.1; z = 10097.9 time = 9.05; x = 10100.0; y = 1.3; z = 10098.7 time = 9.05; x = 10100.0; y = 1.1; z = 10098.9 time = 9.05; x = 10100.0; y = 1.1; z = 10098.9 time = 9.64; x = 10100.0; y = 0.8; z = 10099.2 time = 9.64; x = 10100.0; y = 0.6; z = 10099.4 time = 9.64; x = 10100.0; y = 0.6; z = 10099.4 time = 10.00; x = 10100.0; y = 0.5; z = 10099.5 time = 10.00; x = 10100.0; y = 0.4; z = 10099.6 time = 10.00; x = 10100.0; y = 0.4; z = 10099.6
Rajeev Kumar
Rajeev Kumar on 3 Nov 2024 at 22:55
Thanks Arthur, This worked and resolved my queries.

Sign in to comment.

More Answers (0)

Communities

More Answers in the  SimBiology Community

Categories

Find more on Extend Modeling Environment in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!