-
Notifications
You must be signed in to change notification settings - Fork 10
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
Implement BoutOptionsFile #94
Comments
Alternatively, if we are okay with breaking backwards compatibility, there are lots of ways in which (By breaking backwards compatibility I don't mean that the BOUT.inp structure would have to be changed, I just mean you wouldn't be able to just drop in Here's a list of things which I think an updated version of I/O
Evaluation and substitution
Indexing
Code structure
I'm not saying we should do all this, or do any of it now, but I wanted to write down all the ways I think it could be improved in one place, in case they are helpful in future. (xref boutproject/BOUT-dev#304 and boutproject/BOUT-dev#1066) |
I've just read BOUT's documentation on the input file in detail, and apparently BOUT++ does several weird things when parsing that I was not aware of. These all will have to also be in any
|
I didn't think so... is it only in options that are being read as |
I'm not sure I'm understanding the documentation correctly, what it says here is
|
I think the documentation needs re-phrasing. I believe it means:
|
Seems it might be easier to use |
I think this depends on what level you want to be able to reproduce the inputs (and at what point an input become a calculated result). The BOUT.inp is programmable, with a pretty complete parser. This functionality is really useful when doing MMS testing or complex inputs. |
It is useful to be able to get at least some settings evaluated from the input file, for things like normalisations. One could argue that the PhysicsModel code should just save everything necessary to the dump files, and I wouldn't argue with that, but it would be nice to have less code to write... would it make sense to save at least all the scalar options to the output files (which would then give us access to them in evaluated form)? Edit: I guess the problem would be that the |
But you would have to import BOUT's c++ code for that then right? So xBOUT would no longer be a pure python package.
I don't know if it will ever be worth it to change the format (BOUT v5 maybe?), but I think YAML would have been the best choice. It's clear and human-readable, supports nesting, and so parsers could be used out of the box in both python (
there is a nice example of a
I'm not sure it's that bad - string manipulation in python is pretty comprehensive and it's a task very amenable to unit testing.
Yes, even just my |
On 12/20/19 2:09 PM, Tom Nicholas wrote:
at that point it becomes easier to just use 'boutcore'.
But you would have to import BOUT's c++ code for that then right? So
xBOUT would no longer be a pure python package.
`boutcore` needs to link against the BOUT++ library. And a C++ compiler
is needed to compile the cython generated boutcore code. But I assume a
C/C++ compiler is anyway needed, as the netcdf python package needs also
a compiler.
If you would rely on boutcore as external package, xBOUT would still be
as pure python as it is today.
It will make however installation more difficult, as you not only need a
netcdf library (among others) but also the bout++ library for boutcore.
|
Thanks for the clarification David.
Well the user doesn't have to worry about this if they have installed netcdf-python via conda or some other way.
This was what I meant - we don't want people to have to download the bout++ library or install anything beyond just
It would be nice to include boutcore in xbout, but it should be as an optional dependency. |
Almost all the things that are hard about reading a BOUT.inp file are to do with evaluating expressions, which is the point where the escaping and special handling is needed. Reading the INI file is pretty trivial, and I think easier for both humans and machines to read and write than YAML: what I've read about YAML is not generally very positive. |
|
I imagine #97 could be made general enough to cover both. That PR is on the backburner for me now though. If someone wants to pick it up the comments and tests should make that easier. |
On thinking a bit more, a shared options class between
|
We want to fully integrate a class structure storing all input file options.
We can't just use
boutdata.BoutOptionsFile
though, because it usesboututils.DataFile
in places, so it will need at least a partial rewrite to work withxBOUT
.I actually tried to see if there was a way to rewrite
BoutOptionsFile
completely (aiming for a much shorter, less home-grown implementation), but the unique structure ofBOUT.inp
files foiled me.BOUT.inp
files are similar to.ini
files andYAML
files, but have distinguishing properties which make handling them with variations of standard python library config classes difficult:Missing initial section header. This is annoying but solvable - you can still read and write
.inp
files withconfigparser.ConfigParser
but you have to special-case the first line.Nested sections. This rules out easily subclassing
configparser.ConfigParser
- I thought maybe you could overrideConfigParser.sections()
with a recursive lookup method but asConfigParser
inherits its structure fromcollections.MutableMapping
I couldn't see any easy way to make this work.Specifying nesting in header names. The
[section:subsection]
syntax isn't shared by any commonly-used config file structure I could find. I think this rules out usingconfigobj.ConfigObj
, which is a shame because that one supports nesting (and nested substitution).While trying out these things I did write some tests though, so we could use them (
boutdata.BoutOptionsFile
currently has no direct tests).Therefore I suggest what we should do is:
Write some tests defining the expected behaviour of the options file class (I have some already, which I will submit later),
Copy over the basic parts of the
boutdata.BoutOptionsFile
code toxBOUT
,Reimplement the methods which rely on
boututils.DataFile
.This should hopefully allow us to improve the
boutdata.BoutOptionsFile
code if needed but without breaking backwards compatibility.The text was updated successfully, but these errors were encountered: