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

Flame restart and initial guess examples and fix issue #1288 #1293

Merged
merged 7 commits into from
Jun 9, 2022

Conversation

rwest
Copy link
Member

@rwest rwest commented May 26, 2022

Changes proposed in this pull request

  • Allow set_initial_guess to receive a Pandas DataFrame object, as documented.
  • Provide an example file with lots of examples of ways to save and load flame solutions and initial guesses

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

Closes #1288

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

Most of the pull request is providing examples (including one of the fixed bug).

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

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.

@rwest ... thanks for looking into this! Restarts and improved file IO from SolutionArray (and FlameBase) were among the first things I implemented when I started contributing for 2.5.1 (I had used restarts from HDF extensively in the past). The pandas issue slipped through, which should have been secured by unit tests (which were never added). Fwiw, pandas itself was just a vehicle to write an earlier HDF version that never made it into a release, but it was kept around ...

While this PR may not be fully developed (some catch blocks look like this is still work in progress), I added a couple of comments. Also, several of your tests read like unit tests ... let me know if you have questions ...

@codecov
Copy link

codecov bot commented May 31, 2022

Codecov Report

Merging #1293 (ef32e50) into main (8fbb4bc) will increase coverage by 0.00%.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #1293   +/-   ##
=======================================
  Coverage   67.18%   67.19%           
=======================================
  Files         314      314           
  Lines       41904    41905    +1     
  Branches    16863    16862    -1     
=======================================
+ Hits        28155    28156    +1     
  Misses      11518    11518           
  Partials     2231     2231           
Impacted Files Coverage Δ
include/cantera/base/Solution.h 93.33% <0.00%> (ø)
samples/cxx/flamespeed/flamespeed.cpp 91.89% <0.00%> (ø)
samples/cxx/openmp_ignition/openmp_ignition.cpp 84.84% <0.00%> (ø)
src/base/Solution.cpp 81.50% <0.00%> (+0.12%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@rwest
Copy link
Member Author

rwest commented May 31, 2022

Thanks for the comments @ischoegl. I think I've addressed them (and tidied some other things up on the rebase).

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.

@rwest ... thank you for updating. To follow up on my initial comments, I have a couple of more substantive suggestions.

I don't think that the example needs to check / demonstrate equivalence of restored solutions, as there are already unit tests for that purpose (I linked those that do exist - pandas is the main one that is missing). On the other hand, the pruning checks are very informative - I think it would be nice to just play around with tolerances, pruning, and refine criteria as these are not necessarily well understood by users, while giving ample opportunity to demonstrate file I/O.

Fwiw, there's another relevant example that is a little more advanced - see diffusion_flame_batch.py. I think a simpler example like the one you are proposing here is a great addition.

rwest added 4 commits June 7, 2022 09:19
Allows you to pass a pandas DataFrame as the data argument
to a flame's set_initial_guess method.
Closes Cantera#1288
Examples of different ways to do this, saving via yaml, HDF5 and CSV,
then loading either as a restart or as an initial guess, including
with some modifications to the data (eg. fewer grid points, or species).
There are some subtleties, like you have to create the correct boundary
conditions before you load the initial guess.

There is one method (loading an initial guess from an HDF file) that
is currently not working, so this is anticipated.

Because of issue Cantera#1288 in 2.6.0 the required version is set to 3.0
The ability to get an initial guess from an h5 file does not work.
Removing the broken attempt, documentation, and example that suggests it should.
As per ishoegl's suggestion Cantera#1293 (comment)

For a work-around, restore a flame from the hdf5 file with 
flame.read_hdf then make a SolutionArray (or pandas.DataFrame) from that
and use one of those to create an initial guess (both of which work)
- don't make it look like unit tests
- print some output
- keep under 88 characters
- always create one solution, then save it in several formats
@rwest
Copy link
Member Author

rwest commented Jun 9, 2022

I think I have addressed all @ischoegl's comments and suggestions in the last 2 commits.

@ischoegl
Copy link
Member

ischoegl commented Jun 9, 2022

@rwest ... thanks for the updates (:+1: on the describe function!) ... I ended up looking into the HDF failure, which was much easier to fix than anticipated - there was a missing subgroup kwarg identifying the flame domain (a2f2fff). Also, the HDF cases require h5py, which is an optional dependency that needs to be handled gracefully (1f002c1). I added both commits to a branch on my own repo, see: https://github.com/ischoegl/cantera/tree/flamestart - feel free to cherry-pick!

@rwest
Copy link
Member Author

rwest commented Jun 9, 2022

Thanks. done.

@ischoegl
Copy link
Member

ischoegl commented Jun 9, 2022

Thanks! ... but - ugh - pandas is optional also. I pushed the fix here directly.

@rwest
Copy link
Member Author

rwest commented Jun 9, 2022

The pandas fix looks ok to me. Good catch. Thanks

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.

@rwest - thanks for the fix and the example! It all looks good to me.

@ischoegl ischoegl merged commit 399142e into Cantera:main Jun 9, 2022
ischoegl pushed a commit that referenced this pull request Jun 9, 2022
The ability to get an initial guess from an h5 file does not work.
Removing the broken attempt, documentation, and example that suggests it should.
As per ishoegl's suggestion #1293 (comment)

For a work-around, restore a flame from the hdf5 file with 
flame.read_hdf then make a SolutionArray (or pandas.DataFrame) from that
and use one of those to create an initial guess (both of which work)
@rwest rwest deleted the flamestart branch June 9, 2022 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flame.set_initial_guess(data=df) gives error when passed a Pandas DataFrame
2 participants