-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
Cantera Units #991
Cantera Units #991
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @hallaali This is fantastic! I've made a few comments for you to review below. Feel free to ask questions about the comments here.
As a follow up to our discussion today, the next step is to add some tests. You'll need to create a file called test_units.py
in the tests
subfolder here. At the top of that file do
import cantera.units as ct
from . import utilities
then each test is put as a method on a class. So you would do something like
class TestSolutionUnits(utilities.CanteraTest):
def setUp(self):
self.phase = ct.Solution("h2o2.yaml")
def test_mass_basis(self):
self.assertEqual(self.phase.basis_units, 'kg')
self.assertQuantityNear(self.phase.density_mass, self.phase.density)
def test_dimensions(self):
dims = self.phase.T.dimensionality
self.assertIn("[temperature]", dims)
self.assertEqual(dims["[temperature]"], 1.0)
Check out the test_thermo.py
file, and specifically the methods test_mass_basis
, test_molar_basis
, check_setters
, test_setState_mass
, test_setState_mole
, test_setters_hold_constant
, check_getters
, test_getState_mass
, and test_getState_mole
. The test_isothermal_compressibility
could be a good case for a dimensionality check as well.
For PureFluid
tests, the test_purefluid.py
, in the TestPureFluid
class, you can pretty much just copy that class and add units. You don't need to worry about the PureFluidTestCases
though, which just test that the numerical results don't change.
Lastly, to actually run the tests (after you do scons build
every time you make a change), the command is
python -m unittest -v cantera.test.file_name.class_name.method_name
(making sure to set the PYTHONPATH
first) where file_name
, class_name
, and method_name
are all optional. If you omit file_name.class_name.method_name
, it runs all the tests. If you omit class_name.method_name
, it runs all the tests in the specified file, and so on.
Let me know if you have any questions or run into any problems!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I showed this feature off at a meeting with some other developers yesterday, and they were very impressed! Great work!
One small fix here based on your latest changes 😊
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
To clarify the 'mentioned in #984': there will be a new property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @hallaali
I squashed the commits, so now there are only 3 on this branch. Remember to do
git fetch origin
git status
git reset --hard origin/units
to incorporate the changes. I made a few small comments for formatting on the examples for you to look at, in addition to the tests. This is very close to being ready for review now!
Some notes after exploring the implementation here a bit:
I think my personal preference is for option 3, given the constraints of option 2. |
Well, it's not that they can't be subclassed, it's just that the arguments passed to the derived class constructor go straight to I realized that the same problem exists for the existing def Methane():
return PureFluid('liquidvapor.yaml', 'methane') And that solution (sorry) would work here, too. |
@speth Ah, wonderful! We'll go with the class inheritance method then. |
@speth OK, further tries with class inheritance. I can't figure out how to set properties on the superclass. The naive approach of:
works fine to get the property, but
See: https://stackoverflow.com/a/15989250 Other suggested solutions, like directly using the super class name (
which is presumably not raised for the Edit to add: Last, trying to set So, as suggested in that Stackoverflow link, I'm inclined to go back to setting an instance attribute on these classes to hold an instance of the "super class", and use |
@hallaali If you think this is good now, I think it's ready for review, so you can hit the button to mark it ready! |
Sounds good, I'll do that now!
…On Mon, May 3, 2021 at 5:24 PM Bryan W. Weber ***@***.***> wrote:
*Message sent from a system outside of UConn.*
@hallaali <https://github.com/hallaali> If you think this is good now, I
think it's ready for review, so you can hit the button to mark it ready!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#991 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ASSB5U2CUZT5Z3UJWNDUOXDTL4IAPANCNFSM4ZC4Z32A>
.
|
Most of the docs are copied from the upstream object. Some updates are included for units.
This is required to find the version of Cantera in the dist folder. By default, pip only finds stable versions, and in this case, was going out to PyPI to find Cantera rather than use the local artifact. However, we can't set --no-index because we also need to install other dependencies from PyPI.
Ensure that we only install the wheel from the archive and don't accidentally reach out to PyPI.
Co-authored-by: Ray Speth <yarmond@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks good to me. I think there are just two last things:
- @bryanwweber - Can you add Hallaali to the
AUTHORS
file? - @ischoegl - Would adding
:no-members:
to the two new classes to suppress all the duplicated member function / property documentation address your concern about the redundancy of the documentation? This way, the new classes would just have their class docstrings in the Sphinx docs, which do include some content specific to this interface.
@speth … yes, I was about to suggest just that. That way, Sphinx documents where units are available, without creating unnecessary (and confusing) information. |
Awesome, thanks guys! I'll take care of both of those tonight |
@speth there's a segfault on the Python 3.8 tests, I'm not sure why. Do you have any immediate insight? I'm not sure why it's just one platform, hope it's not due to any of the changes I made to build-related stuff |
It's failing somewhere in the |
Changes proposed in this pull request
gas.TP = Q_(80, "degF"), Q_(1, "atm")
If applicable, fill in the issue number this pull request is fixing
Related to Cantera/enhancements#3
Checklist
scons build
&scons test
) and unit tests address code coverage