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

Meta support for model/scenario levels #353

Merged
merged 38 commits into from
Aug 17, 2020
Merged

Meta support for model/scenario levels #353

merged 38 commits into from
Aug 17, 2020

Conversation

zikolach
Copy link
Contributor

@zikolach zikolach commented Jul 28, 2020

Implement full meta functionality.

Implement full meta functionality on the Platform level, and make some adaptions to the Scenario meta functionality too. Also, add the possibility of creating a model or scenario on Platform. This PR relies on https://github.com/iiasa/ixmp_source/pull/323.

Detailed list of changes:

  • add Platform.add_model using Backend.add_model
  • add Platform.add_scenario using Backend.add_scenario
  • add Platform.models using Backend.models
  • add Platform.scenarios using Backend.scenarios
  • add Platform.get_meta using Backend.get_meta
  • add Platform.set_meta using Backend.set_meta
  • add Platform.remove_meta using Backend.remove_meta
  • add Scenario.remove_meta using Backend.remove_scenario_meta
  • deprecate Scenario.delete_meta

How to review

  • make sure the tests pass
  • check that the built sphinx documentation is how you'd expect it

Problematic things relevant to this PR:

  • ambiguous use of the name Scenario. As an ixmp.Scenario is actually an ixmp_source run that has a scenario itself, distinguishing between these two types of Scenarios is hard. Hence Platform.scenarios() and Platform.scenario_list() are ambigous.

PR checklist

  • Tests added.
  • Documentation added.
  • Release notes updated.

ixmp/core.py Outdated
@@ -393,6 +393,39 @@ def check_access(self, user, models, access='view'):
else:
return {model: result.get(model) == 1 for model in models_list}

def get_meta(self, *args, **kwargs):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can avoid this redundant calls by adding get_meta and set_meta to _backend_direct list

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see this commit 121a876

@zikolach zikolach changed the title Feature/meta support Meta support for model/scenario levels Jul 28, 2020
version = None):
if not (model or scenario or version):
msg = ('At least one parameter has to be provided out of: '
'model, scenario, version')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think passing just version makes much sense. It should be one of:

  • model
  • scenario
  • model + scenario
  • model + scenario + version

from ixmp.testing import models


sample_meta = {'sample_string': 3, 'another_string': 'string_value'}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

first entry has not a string value. What is the idea? Maybe just called by mistake

@@ -902,8 +1020,8 @@ def get_meta(self, s: Scenario):
"""

@abstractmethod
def set_meta(self, s: Scenario, name_or_dict, value=None):
"""Set single or multiple meta entries.
def set_scenario_meta(self, s: Scenario, name_or_dict, value=None):
Copy link
Contributor Author

@zikolach zikolach Jul 30, 2020

Choose a reason for hiding this comment

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

seems to be duplicated after renaming

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fonfon fonfon marked this pull request as ready for review August 1, 2020 09:52
@fonfon fonfon requested a review from khaeru August 1, 2020 09:52
@fonfon fonfon marked this pull request as draft August 1, 2020 09:55
@khaeru
Copy link
Member

khaeru commented Aug 3, 2020

I'll wait to review until the tests pass and conflicts are resolved.

In the meantime, some questions:

  • In addition to worsening (with add_scenario()) the existing overlap between the semantics of scenario names and Scenario objects (as the description notes), this PR creates a new overlap between model names (add_model()) and the existing Model class. Can this be avoided, e.g. perhaps via the approach described in Harmonize handling of codelists #274?
  • What is the intended behaviour if a user calls add_timeseries with model name(s) or scenario name(s) that have not previously been declared with add_model or add_scenario?
  • What is the intended behaviour if a user instantiates ixmp.Scenario(..., version='new') with a model name or scenario name that have not been previously declared?

@zikolach
Copy link
Contributor Author

zikolach commented Aug 4, 2020

What is the intended behaviour if a user instantiates ixmp.Scenario(..., version='new') with a model name or scenario name that have not been previously declared?

This behavior did not change - it will create (register) new model/scenario names. Methods were added to allow to create entities which rely on specific model/scenario names before scenario version (run) is created.

@zikolach
Copy link
Contributor Author

zikolach commented Aug 4, 2020

What is the intended behaviour if a user calls add_timeseries with model name(s) or scenario name(s) that have not previously been declared with add_model or add_scenario?

Not sure how does it relate to add_timeseries. Can you please point on the code example or explain what you mean?

@zikolach
Copy link
Contributor Author

zikolach commented Aug 4, 2020

Can this be avoided, e.g. perhaps via the approach described in #274?

I think it makes sense to apply this paradigm of codelists in longer-term perspective. Add mode/scenario names methods are implemented in line with current (probably not efficient) aproach. So later on we can change all such occurrences as adding regions, timeslices, units and new model/scennario names to more generic API in one go.

fonfon and others added 15 commits August 6, 2020 14:15
To allow for the generic get_meta, set_meta, delete_meta methods,
rename the scenario specific meta methods.
- update ixmp.jar
- add Platform.get_meta, Platform.set_meta
- add some tests (only two pass so far)

TODO: make all tests pass, maybe add more tests
- remove redundant backend methods from platform
- use unwrap to handle BigDecimals
- fix tests
- replace ixmp.jar (freshly built from appropriate branch)
- look for more specific errors
- add new test for Model+Scenario Meta
- set_meta void return type
- set meta version parameter type
- implement Platform.remove_meta
- deprecate Scenario.delete_meta (Scenario.remove_meta should be used)
- add more tests
- add release notes
- update docstrings
- remove unused backend method delete_scenario_meta
describe valid args of getting/setting/deleting meta indicators
@codecov
Copy link

codecov bot commented Aug 6, 2020

Codecov Report

Merging #353 into master will increase coverage by 0.24%.
The diff coverage is 99.39%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #353      +/-   ##
==========================================
+ Coverage   96.26%   96.50%   +0.24%     
==========================================
  Files          44       45       +1     
  Lines        4843     5100     +257     
==========================================
+ Hits         4662     4922     +260     
+ Misses        181      178       -3     
Impacted Files Coverage Δ
ixmp/core.py 95.10% <85.71%> (-0.36%) ⬇️
ixmp/backend/base.py 98.81% <100.00%> (+0.06%) ⬆️
ixmp/backend/jdbc.py 95.84% <100.00%> (+0.68%) ⬆️
ixmp/tests/backend/test_base.py 98.66% <100.00%> (+0.09%) ⬆️
ixmp/tests/core/test_meta.py 100.00% <100.00%> (ø)
ixmp/tests/core/test_platform.py 100.00% <100.00%> (ø)
ixmp/tests/core/test_scenario.py 100.00% <100.00%> (ø)
ixmp/backend/io.py 98.54% <0.00%> (+0.01%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44f3bd2...8f78a8c. Read the comment docs.

@fonfon
Copy link
Contributor

fonfon commented Aug 6, 2020

This PR is now ready to be reviewed.

@fonfon fonfon marked this pull request as ready for review August 6, 2020 14:14
'strict' will only retrieve meta indicators from the exact given level
(model, scenario, version combination).
Copy link
Member

@khaeru khaeru left a comment

Choose a reason for hiding this comment

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

@zikolach, thanks for responses above, and @fonfon for the code additions.

Required changes:

  • I agree with @zikolach that set_scenario_meta and remove_scenario_meta duplicate set_meta and remove_meta, respectively. Please delete the former two. If the Java code has multiple methods/functions, then JDBCBackend.set_meta must choose the correct one to call.
  • For us to avoid confusing ourselves, please rename the new methods added to the Backend API as follows:
    • add_modeladd_model_name.
    • add_scenarioadd_scenario_name.
    • modelsget_model_names (this aligns with the existing get_units. Backend method names should have a verb for clarity.)
    • scenariosget_scenario_names
  • Ensure method implementations in JDBCBackend are in exactly the same order as base.Backend.

ixmp/backend/base.py Outdated Show resolved Hide resolved
ixmp/core.py Show resolved Hide resolved
@khaeru
Copy link
Member

khaeru commented Aug 12, 2020

General responses to @zikolach's comments:

This behavior did not change - it will create (register) new model/scenario names. Methods were added to allow to create entities which rely on specific model/scenario names before scenario version (run) is created.

The issue I was trying to highlight was that the existing behaviour was never clearly explained or documented; it was only implicit. Namely, it's not explained to the user anywhere that:

  • Model and scenario names are not simply attributes of TimeSeries/Scenario objects, but distinct entities in the data model, to which things (e.g. annotations/meta) can be attached.
  • These entities were automatically created when new values were used; now they can be created directly.

I think it makes sense to apply this paradigm of codelists in longer-term perspective. […] So later on we can change all such occurrences as adding regions, timeslices, units and new model/scennario names to more generic API in one go.

Totally agree with this. I think it will also be much easier to explain to the user via documentation, etc.: "ixmp tracks lists of strings or codes that are used for different purposes, and allows attaching meta information to these codes."

In any case, let's merge this PR once the above changes are made, then clean up the Backend API on the Python side in a separate PR, soon. The Java implementation could be simplified later, when time allows.

- to distinguish from Scenario/Model objects, rename methods to
  get/retrieve scenarios/models to scenario_name and model_name
- adapt documentation of parameters
- Adapt to renamed method names
- some minor documentation fixes/updates
@fonfon fonfon requested a review from khaeru August 17, 2020 07:24
@zikolach
Copy link
Contributor Author

@khaeru seems like all the requested changes are done. Could you please re-review/approve this PR?

- update release notes to changed method names
- remove methods from backend test
- correct method name to get_model_names() from model_names()
@khaeru
Copy link
Member

khaeru commented Aug 17, 2020

seems like all the requested changes are done. Could you please re-review/approve this PR?

Yep! I did see the review re-request from @fonfon a few minutes before your comment—also three commits since, but I guess those are the final ones. I will review as soon as I have time.

Copy link
Member

@khaeru khaeru left a comment

Choose a reason for hiding this comment

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

Thanks for making the requested changes, @fonfon.

There are some minor typos and other issues, but since a lot of this code will be simplified or removed when we make the changes described at #353 (comment), they can go in for now.

I will squash and merge.

@khaeru khaeru merged commit 9326f3b into master Aug 17, 2020
@zikolach zikolach deleted the feature/meta-support branch August 26, 2020 09:02
khaeru added a commit that referenced this pull request Aug 26, 2020
khaeru added a commit that referenced this pull request Oct 26, 2020
khaeru added a commit that referenced this pull request May 25, 2021
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.

3 participants