-
Notifications
You must be signed in to change notification settings - Fork 41
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
Type checking versus unit checking #3382
Comments
To me, this sounds like either a tooling issue, or a problem to be solved by proper library design using existing language features. Did you see something also missing on the language side?
To me, numerical errors in a successful simulation are the worst kind of errors. It ruins trust in the tools we use and the models we develop. For this reason, I strongly believe that unit errors should not be allowed by the specification. As @qlambert-pro pointed out, tools may give an option to bypass the specification and ignore unit errors, but in my opinion models with these errors should have no place in the world of valid Modelica models. |
I can see that the library design is somewhat missing in that we have Modelica.Units.SI for normal variables, but nothing similar for causal connectors, and we could imagine some way of extending the language to make declaring e.g., a Length-connector easier. However, obviously tools can help without any design changes, e.g., Dymola 2020 introduced "Set Unit" for connectors and connections.
I don't think anyone wants to ignore actual unit errors. However, in several cases it may be good to have the possibility to disable the detailed unit-checking for an equation (or entire model) - as discussed in modelica/ModelicaStandardLibrary#4097 Note in particular:
So, I see some reasons for giving users the possibility to disable unit-checking:
One might even see an additional benefit of not unit-casting correlations, since a major risk is instead that the numbers are just a bit incorrect as in modelica/ModelicaStandardLibrary#4097 and thus easily finding the use of such models has a benefit. |
Yes, a lot of this may be a "tooling" issue. System Modeler, for example, allows the user to address I may simply have missed how to fit "my list of preferred types" into the
I am quite thankful for the examples given by HansOlsson above and it irritates me to read your replay as if I had demanded to abandon unit checks—I am all in for unit checks and in fact I made sure users are nudged to select appropriate types even on a component level as to make finding unit errors easier, while it had not yet been implemented in my tool of choice! What I was trying to argue for was to come up with a framework that is convenient and easy to use. To me working with something like Dimensional analysis extends the concept of unit checking—it does not bypass it... |
Just as a loose idea: Could there be sections within a model that are encapsulated with regard to unit checking? Ultimately, at the boundary of a model we already deal with information sources and we will "paint numbers" that is we will enter or read in say a |
I'm of the opposite opinion; I find unit errors to be fundamental, whereas quantity errors (given consistent units) may be of a softer kind. For example, this quantity inconsistency doesn't necessarily look like a fundamental modeling error to me:
Note that the two are defined side by side in
My guess is that this was simply the easy part to define for a connection set. I believe it is generally expected that tools will also reject connection sets where units do not agree, even though it isn't stated in the specification (probably because defining unit checking is complicated). |
I agree as ultimately units can be broken down to elementary base units in SI (dimensional analysis). I had something like torque as opposed to work/energy in mind, which have compatible or even identical units ( EDIT: The examples torque, work, energy are instructive as the base |
Sure, it would be cool if such errors could also be detected. It's just not on the agenda, probably mostly because we don't have a system that allows us to determine whether a force multiplied by a length is a torque, a work, or something else (possibly library-defined quantity).
No, or at least I haven't seen any indication of anyone wanting to tear up the quantity rule for connection sets. I'd expect a conversion from |
Thinking about this a bit more, I believe I should find myself corrected with regard to
A |
Excellent comment to be linked from here: |
Cursory (don't beat me) reading of some recent discussions(e.g., #3259, #3381) finds me wondering about whether the
unit
attribute is to become the "one attribute to rule them all". As the author of theBusiness Simulation
library—a system dynamics library making use of acausal connectors and (notoriously) unconventionaltypes
likeAmount
andAmountRate
—I am coming more from the "cybernetic" side of "cyber-physical" modeling. Nonetheless—or even exactly because of this more abstract nature—verification(e.g., will the model result in a solvable set of equations) and validation(e.g., is it meaningful with regard to the intended purpose) of models are important.In programming, we typically use
type
to catch errors (statically or dynamically inferred by compilers). And indeed I adapted this principle by having modellers maketype
choices for causal (mostlyoutput
) connectors, which then are used within a component forvariables
andparameters
(the nature of abstract libraries makes it much harder to make these definite choices when designing components).But setting an explicit
quantity
attribute for causal connectors has just been called "inconvenient" and "unusual" (#3381) by Hans Olsson. I would argue on the contrary: It could be very convenient to set thetype
using areplaceable type
and the beauty of it is that next to thequantity
andunit
attribute one can also setdisplayUnit
ormin
/max
in a single choice as to nudge users not to change theunit
when what they need is a differentdisplayUnit
(e.g, have a derived type `Time_months).I note that the predefined types
Boolean
,Integer
,String
, and evenEnumeration
all carry thequantity
attribute. Maybe it should help us to distinguish fundamental differences even when aunit-system
is not applicable:Make no mistake: It is absolutely essential that
unit
errors are caught (e.g., as to not mixmm
andm
in Quentins example in #3381). But to mequantity
is more likely to catch fundamental equation errors (e.g., there is no meaningful way to propagatemagnitudes
from one side of an equation to the other), whileunit
mismatch has a higher likeliness to be an error in the order ofmagnitudes
(e.g., numerical error only).I had believed that this fundamental quality of
quantity
was the reason to make it—not theunit
attribute—a restriction for connections in the section 9.3 of the specs:Hans Olssons post suggests that setting the
quantity
attribute for causal connectors is "inconvenient" to do and that it "cannot even be inferred". But that is exactly what makesquantity
so valuable in catching fundamental errors and this even applies to causal connections because if you want to measureTime
you should not connect to a sensor that measuresLength
orSpeed
.I would like to stipulate the discussion here with the following:
While
unit
checking is important, make settingquantity
and especiallytype
more convenient for modelers in order to catch fundamental errors in equation formulation and to make it convenient to set multiple attributes at once.A model may have numerical errors, but still give a solvable set of equations, if quantities match up, "mere" unit errors should give a warning, but not necessarily prevent models from being simulated (Note, that many of the
unit
error examples given in Infering units for empty unit variable. #3381 are in fact (dimensional)quantity
errors mixing saym
ands
).The text was updated successfully, but these errors were encountered: