-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
Fix #853 raise an error when there is number in an element symbol during ck2yaml conversion #857
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.
Thanks for this change @12Chao! It's a great start. I have a few comments below. One additional comment is, rather than including a large mechanism, we'd rather have the smallest possible mechanism that can reproduce the error condition. You can have it as small as one species, and even put the thermo data into the input file.
interfaces/cython/cantera/ck2yaml.py
Outdated
for symbol in composition.keys(): | ||
# Here it checks if there is a number in the symbol string and if this is | ||
# in the element list as a customized element | ||
if any(map(str.isdigit, symbol)) == True and symbol not in self.elements: |
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.
The way Python works, you don't need the == True
, just any(map(str.isdigit, symbol))
should be enough.
a9fcd42
to
e94f782
Compare
Hi @bryanwweber, thanks for the comments! I rebased the commit, and I think I have got all the changes you mentioned earlier in the comments. Please let me know if I should change anything. |
e94f782
to
9c04851
Compare
Hi @12Chao I made a few more changes to simplify things a bit and change the comment to clarify what I meant about explaining why 😄 Let me know what you think! |
Thanks @bryanwweber! I think these changes really help make thinge clear. One thing I am not sure is that should we mention that there is a specified chemkin format about how to add large element number in the thermo entry. I feel like that is helpful but it will probably affect the simplicity of the error message. |
@12Chao That's a good point. I can't quite think of a better way to phrase it to point out there is an alternate syntax, without, as you say, removing the simplicity of the error message. It's not that elements can't have more than 3 digits, it's that they can't have more than three digits when specified in the default location. But I don't know how to point that out in a way that is useful for the end user. |
Would it be helpful to include the URL to our help on debugging issues in Chemkin files (https://cantera.org/tutorials/ck2yaml-tutorial.html#debugging-common-errors-in-ck-files)? One flaw with this option is that our instructions there don't currently provide any help for this type of error, and don't describe the supported syntax for extended composition information, but those are things that you could fix. |
I think it is a good option, and the syntax for extended composition information is something good to have on the Cantera website no matter if we add url to the error message or not. I can work on adding the instruction about that syntax on Cantera website, and it would be nice to add the url to other error messages raised due to the indentation error or other format errors so that people can compare the format there as a template. I am thinking that would it be helpful if we add a flag like |
Thanks, @12Chao, adding that documentation would be helpful. And adding links to other error messages would be helpful as well. If you want to avoid repeating the URL in many places, you could just assign it to a global variable and substitute that into the error messages. I wouldn't worry too much about adding a |
I don't think you need to close this PR. All you need to do is push a branch that contains the current |
…lement symbol during ck2yaml conversion Cantera#857
Thanks @speth, I just pulled branch 'main' and pushed it with the commit to the same b |
ad3d9c4
to
8f65ef7
Compare
I believe I've fixed the merge conflicts that were happening and reset this branch to the correct state, rebased onto the current tip of I have one suggestion here, which is that since the same message is added to every
Then, each time |
By the way @12Chao, to get your branch the same as this one, do
The first command updates the reference for this branch, and the second one resets your working directory and history to match the updated reference. Just make sure you there are no uncommitted changes in your folder before you run the second one. |
Thanks for the fix @bryanwweber, that's really helpful. I have added the message with url to the |
Elements are limited to 3 digits per the NASA format standard. For users, the error message should be clear what the problem is. Fixes issue Cantera#835
Clarify reason for error and comment. The code does not need to be inside the else statement, since the if can only raise the error.
08e00d1
to
016636b
Compare
Thanks @speth for the revision. I have pulled the latest version of Cantera and made the suggested changes, but it seems ruamel-yaml cannot be built successfully on system with Python3.8 on Travis. I am not sure how to fix that, and it would be really appreciated if you can give me some hints about how to fix that |
016636b
to
61d8b4a
Compare
@12Chao, the revision I made was mostly to get rid of the merge commit and to combine a few commits which were just modifying the same bits of code. As a reminder for the future, please do not merge changes from the The test failures have nothing to do with any of your code, so it isn't necessary for those to pass for this PR to be merged. See #924 for what we currently know about those test failures. |
Thanks @speth, I will do what you said on another pull request I made. |
Problem:
Regarding to #853, When there is large element number(more than 3 digits) in the thermo file trying to fit everything in one line, instead writing an additional line with element numbers like this:
cantera/test/data/soot-therm.dat
Lines 39 to 49 in 7d87534
The ck2yaml file could accidentally convert an incorrect element symbol in species composition, which includes part of the element number in the element symbol string for example: The composition for
BIN7AJ C 1250H 812 G 300.00 3500.00 1260.00 1
is parsed as{'1': 250, H: 812}
It won't pass the validation, but raise an error before a yaml file gets created maybe more helpful.Fix:
Check if there is any number in the symbol and if the symbol is in the elements list when creating the element symbol. If the check failed, raise the error thermo entry and mention the first line has an incorrect format.
Checklist
scons build
&scons test
) and unit tests address code coverageIf applicable, fill in the issue number this pull request is fixing
Fixes #853
Changes proposed in this pull request
raise an error including the entire thermo entry when parsing a species thermo data with big element number in incorrect format