-
-
Notifications
You must be signed in to change notification settings - Fork 361
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
Reactor net visualization #1624
Conversation
Whoopsi, that's a lot of trailing whitespaces. Is it best practice to do a cleanup commit or should I try to rework them into the existing commits? |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1624 +/- ##
==========================================
+ Coverage 72.68% 72.74% +0.05%
==========================================
Files 370 371 +1
Lines 56302 56500 +198
Branches 20403 20443 +40
==========================================
+ Hits 40923 41100 +177
- Misses 12371 12385 +14
- Partials 3008 3015 +7 ☔ View full report in Codecov by Sentry. |
Thank you! This is very cool
A cleanup commit is fine 😁 |
I think the issue is mainly that |
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, @Naikless, this is a really nice contribution, and addresses a feature request that I know has been made by many users.
To answer your questions:
- Using
dict
s forReactor.node_attr
and the like are a fine way of storing styling information. The only thing I might suggest changing is the name, since talking about "nodes" and "edges" really only makes sense if you understand that this is a graph in the mathematical sense. One alternative that comes to mind isappearance
, which would work for both reactors and flow devices. - The lazy import of
graphviz
looks good to me - I think you can just omit the imports in
__init__.py
, leaving the member functions as the main API. - I'd suggest adding the tests to
test_reactor.py
, but I'm guessing you'll want to configure some different reactor networks than the ones that it uses, so you probably want to create a separateTestDrawNetwork
or similar class.
Some additional comments:
- A way of including
ReactorSurface
objects would be useful - Is there a way to indicate wall motion? I guess at some level, this is a transfer of volume from one reactor to another, though it might look a little funny.
- It would be good add some example usage. I was going to suggest adding this to some of the existing examples, but most of them have almost trivial network structures. I guess
mix1.py
at least has a reactor with two inlets and one outlet.ic_engine.py
has two inlets as well, but it's less clear what the right thing to show would be, given the transients that it's simulating. - The fact that
ReactorNet.draw()
plays nicely with Jupyter is great. - I think you need to add a couple of entries in
zerodim.rst
so the standalone functions will be included in the API docs.
Thanks for the encouragement and the review. I'll try get to it in the next days. Just before I get started and not to over engineer this, but this is my first code review process: And also to already address one of your suggestions @speth: |
We don't have a hard-and-fast rule on this. I tend to prefer squashing certain changes if it makes the history cleaner, and
It's definitely worth mentioning the corresponding |
922c335
to
3eea700
Compare
2f503f7
to
79bcf39
Compare
Any hints on how to get code coverage data reported from my fork? The CI workflow exits with:
My local machine is a Windows so I can't really get these information here either. As far as I understand, I can create my own token for the repo with codecov, add it as a secret and use it in |
It is supposed to work without a token, but Codecov seems to have occasional hiccups that require re-running the job. I just triggered a new run, which will hopefully work. |
Thanks. My workaround using an additional branch on my fork worked as well. The PR ist still WIP, I just wanted to check which spots I missed in my unit tests. How do I have to invoke pytest to test the python modules locally? Simply calling |
The recommended way to run the tests is through SCons, e.g. I find getting coverage reports to be finicky enough that I usually just rely on the GitHub Actions / Codecov build. |
That is correct. However, I thought about this once more: If each function only had a single Dict for these options, I would agree that naming it But if anyone comes up with good names that fit the above criteria, I am more than happy to change my mind. |
This comment was marked as resolved.
This comment was marked as resolved.
I think you just have to make a new PR, GitHub doesn't allow reconnecting to closed PRs once the branch is deleted as far as I know. |
66c1bef
to
d373841
Compare
Alright, I believe I have added all the functionality now that would make sense in my eyes. The representation of the latter currently looks like this: import cantera as ct
gas = ct.Solution('h2o2.yaml')
r = ct.Reactor(gas)
surf = ct.Interface('methane_pox_on_pt.yaml', 'Pt_surf')
s = ct.ReactorSurface(kin=surf, r=r)
s.draw() r2 = ct.Reactor(gas)
w = ct.Wall(r, r2, velocity=1)
w.draw() (Although it seems the little arrow at the wall sometimes isn't rendered.) I also added the possibility to group reactors using a r3 = ct.Reactor(gas, groupname='group 1')
r.groupname = 'group 1'
net = ct.ReactorNet((r, r2, r3))
net.draw() (Note that automatic reactor names increase regardless of the fact that reactors are repeatedly created) Because a reactor's name defines its identity in the graphviz output, I had to ensure that each reactor is drawn with a unique name. However, until now there was nothing preventing people from giving the same name to multiple reactors and enforcing this now would be a potential breaking change. So, from my point of view, the code is ready for another review. What I haven't adressed yet:
|
87ed8fc
to
1f4b7f1
Compare
Thank you for your patience, implementing the changes again took me much longer than anticipated. Or I am just very bad at anticipating. You can have another look if you like. Replacing the logic for renaming the objects if they share the same name with a simple assertion as well as splitting the branches for walls and flow controllers into their own functions hopefully made things a bit more concise. I still get some error when compiling the docs. Is it still the formatting? |
Otherwise, graphviz will consider them to be the same object.
This introduces an additional `groupname` attribute for the `Reactor` extention class
This allows to display reactors' species as either percent or ppm
If names are not unique, raise AssertionError Regroup keyword arguments for functions
Requires graphviz >= 9.0
Since these are pip-related files , the correct name is `graphviz` while `python-graphviz` is the name of the conda package.
made sure attributes set during calls overwrite everything
1f4b7f1
to
647dd90
Compare
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 the updates, @Naikless. I made a few fixes to the formatting of the documentation, so I think this is good to go assuming the CI completes without error.
Thanks a lot for merging this! Although I realize that the 3.0 release was quite recently, is there already a rough time frame for the next (pre-) release? |
Changes proposed in this pull request
This PR is based on the enhancement I suggested here. It includes functions and methods to directly visualize components and their connections in a
ReactorNet
or on their own using thegrahpviz
package.I wrote the functionality as a standalone module and included the functions as methods in the corresponding objects. If this is considered too intrusive, skipping 2ad20c4 leaves them separated.
Other things I would be happy to receive feedback about:
graphviz
I have copied the behavior found for theSolution
methods that requirepandas
. I don't know if this is still best practice.__init__.py
.TestReactor
class?If applicable, fill in the issue number this pull request is fixing
Closes Cantera/enhancements#180
If applicable, provide an example illustrating new features this pull request is introducing
Adds functions and methods based on them that can draw
ReactorBase
,WallBase
andFlowDevice
objects(not defining a phase for the reactors causes
Wall
to throw an Access Violation, as reported here)Reactors can be drawn plain or with their current state (T, P, composition) displayed
Detects all connections between these objects and draws them as arrows. Corresponding mass and heat flows are added as labels. Connections between identical objects are summed up. Here is the visualization of the
ic_engine.py
sample:The style of these elements can be fully customized using
graphviz
regularnode_attr
andedge_attr
keywords. This can be done either generally when calling thedraw
function or individually for each object by setting corresponding attributes, in which case the latter takes precedence:Checklist
scons build
&scons test
)