Skip to content
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

Yaml2ck script #1286

Merged
merged 18 commits into from
Jul 11, 2022
Merged

Yaml2ck script #1286

merged 18 commits into from
Jul 11, 2022

Conversation

bryanwweber
Copy link
Member

@bryanwweber bryanwweber commented May 18, 2022

Changes proposed in this pull request

  • Add a yaml2ck script to convert YAML input files/Solution instances to Chemkin file(s)
  • TODO: Add a method to Solution to import and call yaml2ck.convert
  • TODO: Fix up the docstring

If applicable, fill in the issue number this pull request is fixing

Supersedes #1185
I tried to push an update to that branch and it closed the PR 🤷‍♂️

This also relies on the work in #1266 for some of the sorting, so it should be merged after that PR.

If applicable, provide an example illustrating new features this pull request is introducing

from cantera import yaml2ck
yaml2ck.convert("input_file.yaml")

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

@bryanwweber bryanwweber requested a review from ischoegl May 18, 2022 00:29
@bryanwweber bryanwweber mentioned this pull request May 18, 2022
5 tasks
@bryanwweber bryanwweber force-pushed the update-yaml2ck branch 2 times, most recently from f6b2b0b to 3140b20 Compare May 26, 2022 03:28
@bryanwweber bryanwweber added Input Input parsing and conversion (for example, ck2yaml) enhancement labels May 26, 2022
@bryanwweber bryanwweber force-pushed the update-yaml2ck branch 7 times, most recently from 0f29b61 to 06a18dd Compare May 27, 2022 17:01
@bryanwweber bryanwweber requested a review from a team June 24, 2022 19:41
Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryanwweber ... thanks for picking this up! This overall looks really good, and I don't have any significant comments (other than formatting suggestions for yaml2ck --help).

Running this on my (windows) machine, I am, however, running into the following issue:

(cantera-dev) PS C:\Users\ischo\GitHub\cantera> python --version
Python 3.10.2
(cantera-dev) PS C:\Users\ischo\GitHub\cantera> yaml2ck .\h2o2.yaml
Traceback (most recent call last):
  File "C:\Users\ischo\miniconda3\envs\cantera-dev\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\ischo\miniconda3\envs\cantera-dev\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\ischo\miniconda3\envs\cantera-dev\Scripts\yaml2ck.exe\__main__.py", line 7, in <module>
  File "C:\Users\ischo\miniconda3\envs\cantera-dev\lib\site-packages\cantera\yaml2ck.py", line 685, in main
    output_paths = convert(
  File "C:\Users\ischo\miniconda3\envs\cantera-dev\lib\site-packages\cantera\yaml2ck.py", line 511, in convert
    solution = ct.Solution(solution, phase_name)
  File "build\python\cantera\base.pyx", line 71, in cantera._cantera._SolutionBase.__cinit__
    self._cinit(infile=infile, name=name, adjacent=adjacent, origin=origin,
  File "build\python\cantera\base.pyx", line 126, in cantera._cantera._SolutionBase._cinit
    self._init_yaml(infile, name, adjacent, yaml, transport_model)
  File "build\python\cantera\base.pyx", line 210, in cantera._cantera._SolutionBase._init_yaml
    stringify(infile), stringify(name), cxx_transport, adjacent_solns)
  File "build\python\cantera\utils.pyx", line 27, in cantera._cantera.stringify
    tmp = bytes(x.encode())
AttributeError: 'NoneType' object has no attribute 'encode'

despite scons test-python-convert passing.

interfaces/cython/cantera/yaml2ck.py Outdated Show resolved Hide resolved
interfaces/cython/cantera/yaml2ck.py Show resolved Hide resolved
interfaces/cython/cantera/yaml2ck.py Show resolved Hide resolved
interfaces/cython/cantera/yaml2ck.py Outdated Show resolved Hide resolved
interfaces/cython/cantera/yaml2ck.py Outdated Show resolved Hide resolved
interfaces/cython/cantera/yaml2ck.py Outdated Show resolved Hide resolved
interfaces/cython/cantera/yaml2ck.py Outdated Show resolved Hide resolved
@bryanwweber
Copy link
Member Author

@ischoegl I think I fixed the problem you posted about NoneType, can you try now?

@ischoegl
Copy link
Member

ischoegl commented Jul 6, 2022

@bryanwweber ... better, but not quite:

(cantera-dev) PS C:\Users\ischo\GitHub\cantera> yaml2ck data/h2o2.yaml --mechanism=h2o2-test.ck --overwrite
Validating mechanism...PASSED.
Traceback (most recent call last):
  File "C:\Users\ischo\miniconda3\envs\cantera-dev\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\ischo\miniconda3\envs\cantera-dev\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\ischo\miniconda3\envs\cantera-dev\Scripts\yaml2ck.exe\__main__.py", line 7, in <module>
  File "C:\Users\ischo\miniconda3\envs\cantera-dev\lib\site-packages\cantera\yaml2ck.py", line 758, in main
    output = "\n".join(ck_paths)
TypeError: sequence item 0: expected str instance, WindowsPath found

Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryanwweber .... Thanks! Again, pretty minor things.

.github/workflows/main.yml Outdated Show resolved Hide resolved
interfaces/cython/cantera/yaml2ck.py Outdated Show resolved Hide resolved
interfaces/cython/cantera/yaml2ck.py Outdated Show resolved Hide resolved
interfaces/cython/cantera/yaml2ck.py Show resolved Hide resolved
@ischoegl
Copy link
Member

ischoegl commented Jul 6, 2022

Before I forget ... yaml2ck this should probably marked with .. versionadded:: 3.0

Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything else looks good

1 Outdated Show resolved Hide resolved
@ischoegl
Copy link
Member

@bryanwweber … will approve this once the merge conflict is resolved

tsikes and others added 2 commits July 10, 2022 15:20
Removed redundant yaml reading
Uses Cantera's new notes
Refactored to classes

Co-Authored-By: Kyle Niemeyer <kyleniemeyer@fastmail.com>
Co-Authored-By: Phillip Mestas <phillip.mestas51@gmail.com>
Co-Authored-By: Parker Clayton <17040941+parkerclayton@users.noreply.github.com>

Update

Chebyshev Fix

Bryan Changes - Part Thermo

Update yaml2ck.py
The error is just over 1e-7.
bryanwweber and others added 16 commits July 10, 2022 15:21
Add more tests of the script.
Document all the parameters for functions. Remove unused options from
the argument parser and change the default sorting to be in the source
order, rather than sort by default.
Since ck2yaml.convert_mech takes a file name, not an open file, we use
TemporaryDirectory and then create a file name relative to that folder.

This change also consistently formats the output from TROE and SRI
reaction types.
This method transparently passes arguments through to yaml2ck.convert.
The source keyword argument was removed when CTI/XML input was removed.
Python 3.7 requires the typing_extensions module. Scope it to 3.7 only
for now, so it's more obvious when it can be removed.
Co-authored-by: Ingmar Schoegl <ischoegl@lsu.edu>
Add option parsing for Boolean options to add "--no-" prefix. Add
version added directive and update docstrings.
Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@ischoegl ischoegl merged commit 51494f4 into Cantera:main Jul 11, 2022
@bryanwweber bryanwweber deleted the update-yaml2ck branch July 11, 2022 08:48
@bryanwweber
Copy link
Member Author

Tagging @tsikes thanks for all your work here!

@tsikes
Copy link
Contributor

tsikes commented Jul 11, 2022

@bryanwweber Thank you so much for carrying the torch the rest of the way! I'm happy to see this completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Input Input parsing and conversion (for example, ck2yaml)
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

3 participants