-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
Make default value units consistent #2898
Merged
ChrisRackauckas
merged 12 commits into
SciML:master
from
contradict:variable_value_units
Aug 7, 2024
Merged
Make default value units consistent #2898
ChrisRackauckas
merged 12 commits into
SciML:master
from
contradict:variable_value_units
Aug 7, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I think it's desirable. Handling DynamicQuantities is essential. |
I need to evaluate the unit macro to know the types to put in the model definition. I need a type parameter to be generic over Unitful units or DynamicQuantities Dimensions, but that can't exist until after evaluation.
contradict
force-pushed
the
variable_value_units
branch
from
August 1, 2024 00:35
924de0f
to
8c70686
Compare
Interpolate types so the modules don't need to be imported add MethodError case
Values with units must provide units when supplied.
@ChrisRackauckas I think this is ready for a review. |
ChrisRackauckas
approved these changes
Aug 7, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using units in a component, it would be nice if those units could be checked on the default and initial values. With old ModelingToolkit, it was possible to do
@parameters p = ustrip(expected_unit, provided_value), [unit=expected_unit]
, but that is not longer possible. This PR is a draft of a way to restore that functionality. It only works with Unitful and only with scalar variables, but these could both be fixed if this is desirable.The result is a component defined like this
can be instantiated like this
And the units are converted correctly. Errors are given for incompatible or missing units.
Is this a desirable feature? If this PR were fleshed out to handle DynamicQuantities and array variables as well, is there a chance it could be merged?