-
Notifications
You must be signed in to change notification settings - Fork 112
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
Conversation
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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see this commit 121a876
ixmp/backend/jdbc.py
Outdated
version = None): | ||
if not (model or scenario or version): | ||
msg = ('At least one parameter has to be provided out of: ' | ||
'model, scenario, version') |
There was a problem hiding this comment.
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
ixmp/tests/core/test_meta.py
Outdated
from ixmp.testing import models | ||
|
||
|
||
sample_meta = {'sample_string': 3, 'another_string': 'string_value'} |
There was a problem hiding this comment.
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
1d81c13
to
af481d0
Compare
ixmp/backend/base.py
Outdated
@@ -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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d0e4227
to
de61b9b
Compare
I'll wait to review until the tests pass and conflicts are resolved. In the meantime, some questions:
|
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. |
Not sure how does it relate to add_timeseries. Can you please point on the code example or explain what you mean? |
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. |
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
- update jar
- add tests
- add release notes - update docstrings - remove unused backend method delete_scenario_meta
describe valid args of getting/setting/deleting meta indicators
b2eafd5
to
9ba12e3
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
This PR is now ready to be reviewed. |
'strict' will only retrieve meta indicators from the exact given level (model, scenario, version combination).
58354a6
to
6205c42
Compare
There was a problem hiding this 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
andremove_scenario_meta
duplicateset_meta
andremove_meta
, respectively. Please delete the former two. If the Java code has multiple methods/functions, thenJDBCBackend.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_model
→add_model_name
.add_scenario
→add_scenario_name
.models
→get_model_names
(this aligns with the existingget_units
. Backend method names should have a verb for clarity.)scenarios
→get_scenario_names
- Ensure method implementations in JDBCBackend are in exactly the same order as base.Backend.
General responses to @zikolach's comments:
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:
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
@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()
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. |
There was a problem hiding this 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.
Implement full meta functionality.
Implement full meta functionality on the
Platform
level, and make some adaptions to theScenario
meta functionality too. Also, add the possibility of creating a model or scenario onPlatform
. This PR relies on https://github.com/iiasa/ixmp_source/pull/323.Detailed list of changes:
Platform.add_model
usingBackend.add_model
Platform.add_scenario
usingBackend.add_scenario
Platform.models
usingBackend.models
Platform.scenarios
usingBackend.scenarios
Platform.get_meta
usingBackend.get_meta
Platform.set_meta
usingBackend.set_meta
Platform.remove_meta
usingBackend.remove_meta
Scenario.remove_meta
usingBackend.remove_scenario_meta
Scenario.delete_meta
How to review
Problematic things relevant to this PR:
Scenario
. As anixmp.Scenario
is actually an ixmp_sourcerun
that has ascenario
itself, distinguishing between these two types of Scenarios is hard. HencePlatform.scenarios()
andPlatform.scenario_list()
are ambigous.PR checklist