Repository navigation
b2plot.py #52
Replies: 3 comments
|
In 30 years of using b2plot, I have never seen such pixellation. Similarly, we had not yet ported the plotting of wall data, simply because there was no wall data yet to plot. I don't think defaming b2plot is the way to justify this project. But I do agree that NCAR is very difficult to install and no longer supported, so a new approach will be needed. |
Yes, very likely it is because of how X11-powered windows are rendered on my Mac, for this case... anyways, that was not the main point. I am sorry if I delivered a wrong message.
Yes, absolutely, this is the good thing of this approach: the underlying Fortran code stays as it is.
Yes... or, to be more precise: it's not that it works in the Python "clone": what Python does is just the final drawing, via Matplotlib. The underlying data, including the contour levels, are still the same computed by the Fortran code. Indeed, for doing this, it was necessary to work directly on As a result, as usual, the NCAR-based b2plot and the Python-based one generate the same result:
|
|
Well, a PR with the changes to the Fortran code only would be a good start. |


Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Triggered by our Code Camp's discussion about post-processing tools for SOLPS-ITER, I kept wondering about what is (and has always been) available in-house, i.e.
b2plot. I have personally never really used it, and in general using it nowadays brings with it several "inconveniencies", so to say. Firstly, visual graphics which is not really modern. Secondly, and most important: The NCAR scripting language, on whichb2plotis based, is officially unsupported, since 2019 (source). Not surprisingly, indeed, it was by far the hardest dependency to get installed when I wroteinstall_dependencies. If the goal is to be farsighted, probably NCAR is not anymore the way to go.The nice thing about
b2plot, though, is that it can be an integrated and very easy-to-use (though still powerful) "visualizer" for the plasma solution and for several classes of standard plots. In this sense, I think that it does not overlap to any external post-processing library (like Quixote), with which the user can interact with simulation data with much higher flexibility: rather, it serves as single-run-based tool for a quick look to a simulation. Therefore,b2plotcan still play its role. Just, not in its current form.I have analyzed the background Fortran code of
b2plot, which is quite big. Turns out that most of is (still several tens of thousands of line) does not really have to do anything with the final NCAR-related plotting, but just extracts/manipulates the fields which are to be plotted later. The code purely related to NCAR plotting is, instead, few thousands of lines of code. Trashing completelyb2plotaway, therefore, would mean discarding tens of thousands of perfectly valid Fortran code, which would really be a shame. Therefore, I just thought that all this could be recycled, and rather be redirected towards a more modern visualization pipeline, e.g. Python-based.With this considerations (and, of course, with heavy agentic support, still closely supervised by myself), I have created
b2plot.py. This is nothing else but a Python code running a new executable,b2pl_py.exe, which relies on the same Fortran code asb2pl.exein terms of IO and computation, but with the NCAR graphic layer replaced by message to Python, which draws with Matplotlib. The same commands give the same plots, and the Python version can be used with or without NCAR.For example: this is what comes out if, in a run directory, I type

echo "phys te surf" | b2plot(note the quite badly pixellated live result...)and this is what comes out if, instead, I type

echo "phys te surf" | b2plot.pyUsing automated testing scripts, I have tested each possible
b2plotcommand existing and working in the WG version, and the Python pipeline gives the exact same result as the NCAR pipeline. This effectively makes the NCAR dependency, if one wants, obsolete. To the best of my knowledge, I have already reached an effective 100% parity with that NCAR delivers. All this avoiding as much as possible code duplication, since it is based on the same Fortran code existing since decades.On top of this, based on the same tools, I have created also a more "modern" GUI version of

b2plot(still in progress), which can be invoked by just executingb2plot.pyin a run directory. Based on the same underlying Fortran code andb2pl_py.exeexecutable, it uses more modern Python functionalities for producing the same class of plots, but interactively and with a more modern style.)
In my opinion this this can be something that, differently from any other more advanced post-processing library, can be integrated within the repository. Currently it lives into the branches named
feature/b2plot.pyof my forks for both SOLPS-ITER and B2.5. Along the line, I have also fixed few bugs here and there, and re-enabled stuff which, in the Fortran code, was still enclosed in aWG_TODOcondition (most notably, the wall-related plots).Regarding the Python dependency: until now, everything that SOLPS-ITER does with Python (generating pieces of documentation, few scripts) is very simple and only relies on ingredients included in any (reasonably modern) official Python distribution. Hence, "any" Python version that the user might have would be already compatible with what was needed, without requiring to check e.g. whether the user has any external Python modules installed. With these additions, this is not the case anymore since what is done within SOLPS-ITER with Python becomes much heavier. In order to prevent the users needing to enter any Python dependency hell, what I did was the following: when
b2plot.pyis executed, it checks the user's Python environment (i.e. whatever the terminal spits out with a which python), in terms of whether the Python version and the external modules that the user has installed in their own Python environment are compatible with whatb2plot.pyneeds. If yes, then all good, andb2plot.pyjust runs on the user's own Python environment. Otherwise, an error message pops out prompting the user to install a minimal SOLPS-local Python environment, through a new scriptinstall_python, which will for sure meet the requirements ofb2plot.py, since this is self-consistently enforced. The path of the SOLPS-local Python environment are then written into the local setup files, so that, at every startup of a SOLPS-ITER session, the SOLPS-local Python environment will replace whatever Python environment that the user was using until that moment.I just "disclose" this now in a discussion, even before thinking to opening any PR. Clearly, I am building this already with the idea in mind that this can be, indeed, end up in the main SOLPS-ITER distribution. While, as already stated, this is mostly an agentic-driven development, I have been (and I will be) following it very closely, by making sure that everything really works as it should. And, before even opening a PR (which will be of course extremely detailed in terms of description of the new features), I will review the new code, both myself (as far as my abilities allow) and through independent agents. Also, if the PR will end up being too big (which will most likely be the case), I can try to split it in several parts.
Right now, the NCAR and Python version of
b2plotstill coexist, so everything stays backwards-compatible. At this point, one could also choose to completely drop the NCAR dependency, but that's up for discussion.Another question mark is: while all this is only there for the unstructured branch of the code for now, it could be wondered if to keep it only there (to push users to switch to the unstructured code), or to also port it back to the develop branch (which, still using agents, would really be not much of an effort). I have not made up my mind yet about this.
All reactions