inlab-geo / espresso

Earth Science PRoblems for the Evaluation of Strategies, Solvers and Optimizers
https://geo-espresso.readthedocs.io
Other
15 stars 9 forks source link

More flexible handling of problem metadata #58

Closed valentineap closed 2 years ago

valentineap commented 2 years ago

At present we have embedded all the problem metadata into class variables:

class MyShinyProblem(EspressoProblem):
    problem_title = "Shiny"
    author_names  = ["Andrew"]
    ...

I wonder if we should change to have a class variable, metadata, which holds a dictionary containing the metadata:

class MyShinyProblem(EspressoProblem):
    metadata = {'problem_title':"Shiny", 'author_names':["Andrew"], ...}

The motivation would be two-fold: first, it makes it much easier to write functions that parse metadata, since they just need to operate on dictionaries; second, it becomes easier for us (or users) to define new metadata fields in future. We can still enforce required fields, e.g.

if not 'problem_title' in shiny.metadata.keys(): raise StupidUserError

but metadata-using-functions don't necessarily need to know about all metadata fields by name.

Thoughts?

valentineap commented 2 years ago

We could consider making this a defaultdict to make it easy to assign default values to 'optional' fields...

jwhhh commented 2 years ago

Yeah, I like the idea of defaultdict. (And the exception name above 🤣)

This separates metadata from other problem-related fields 👍

Edit: defaultdict isn't as handy as I thought. The inbuilt data structure can't handle default values for different keys.