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

Eliminate drivers and refactor configuration #259

Merged
merged 37 commits into from
Jun 28, 2017

Conversation

jacg
Copy link
Collaborator

@jacg jacg commented Jun 28, 2017

  1. The driver functions for each city (the city name in uppercase) have been removed. They are all replaced with a single drive classmethod in City. This simplifies the code considerably and removes the copy-n-paste mess that has been growing an each new city was added.

  2. The city constructors no longer take and pass arguments explicitly by name, this is now achieved with **kwds. This closes Cities init method arguments #143 and has a number of consequences

    • Significant noise reduction in constructor definitions.
    • The config files become the sole source of
      • values of the parameters
      • documentation of what parameters are needed by each kind of city
  3. The config files are now written in Python syntax and parsed with Python's built-in parser. Our custom config parser for our ad-hoc config syntax has been thrown away and replaced with Python's parser. Do not re-invent the wheel.

  4. The ability to inculde config files within other config files has been added, allowing the use of hierarchical configurations. Thus the default configuration of some base city does not need to be repeated in each concrete city's config file, as in can be included.

  5. A new configuration printer has been added with the key abilities to

    • report the config file which provides any given value in an active configuration
    • highlight cases where a value set in one config file is overridden by a setting in another one.

    Improvements to the config printer are envisaged:

    • Displaying the comments from the config files.
    • Displaying the units used in the config files.
  6. The mandatory -c (config file) command line option has been turned into a positional argument.

(#203 has not been addressed at all here.)

jacg and others added 30 commits June 27, 2017 19:41
The drivers are an unnecessary copy-n-past complication. They can be
replaced by a single classmethod which feeds the configuration
directly to the constructor of the relevant class. To make this work
smoothly, the constructor parameter names must match the config file
parameter names exactly.

While working on this change, we decided that we want a single source
of parameter values. At present, any parameter value might come from
the config file or from various constructor defaults. This will lead
to confusion and subtle errors. So we have started to eliminate the
default values in the constructors ...

... but then the units disappear, so we want units to be stated
explicitly in the config file, which requires the config file parser
to be rewritten to understand units.
The first step is to make it work for Irene. The other Cities will
follow.

The config file is now written in Python syntax and parsed with
`exec`. Like this we do not need write our own parsers, for our own
dodgy syntax with lots of dodgy exceptions. In short, DO NOT REINVENT
THE WHEEL.

Config file parsing is done in the context of `system_of_units`, this
allowing specification of units simply by multiplying the value by any
available unit, without qualification. Compound units are trivially
catered for in this scheme. It's just pure Python.

    my_value = 12 * nm / s

Consequently, everything disappears from the constructors:

+ parameter names
+ units
+ etc.

The config file is now the sole source of documentation of the city
parameters.

The driver functions (same name as city, but uppercase) now disappear:
a single `drive` method in the base city replaces them all.
We are no longer using our own parser: we let Python do the job for
us.
These were used in combination with files_in and files out to to
produce the final files_in and files_out settings used by the cities.

This gained us nothing besides unnecessary complication of
configuration parsing and handling.
s12_selector.conf is added as part of the configuration tree, in spite
that there is no s12_selector city. It turns out that selectors are a
different species than cities in sofar that they cannot be passed by
inheritance (this would require double inheritance, something we want
to avoid) but at the same time they can be re-used by several
cities. Thus, it make sense to define default parameters for each
selector we introduce.

Several configuration files have been fixed to overwrite parameters
such as input/output file name, which are city-specific (although a
default is inherited from city).
jacg added 7 commits June 27, 2017 19:41
It seems that skip is not used anywhere. Can it be removed?

Verbosity isn't used either, but at least it's clear how it *might* be
used.
The `--do-not-run` option has been added to allow inspection of a
configuration without running the given city.

By default, when an option is set in more than one place (multiple
places in the same config file, or in an included file aswell as an
including file), the printer shows the overridden values (the ones
which were specified before the last one). This can be switched off
with the `--no-overrides` option.

By default, the names of the files in which any value was
set (incuding overridden ones) is shown. By default, just the basename
of the file (everything after the last `/`) is shown. Whether and how
these file names are displayed can be controlled with the options

+ `--no-files`   : do not show the names at all
+ `--full-files` : show fully qualified file names

By default, the configuration is printed when any city is run. This
can be suppressed with `--hide-config`.
It is a mandatory argument, and it is the *only* mandatory
argument. Thus it makes sense to make it the only positional argument
on the CLI.
Copy link
Collaborator

@jjgomezcadenas jjgomezcadenas left a comment

Choose a reason for hiding this comment

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

A major advance in the code. Good and well!

@jacg jacg merged commit e8d1287 into next-exp:master Jun 28, 2017
@jacg jacg deleted the eliminate-drivers branch June 28, 2017 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cities init method arguments
2 participants