-
Notifications
You must be signed in to change notification settings - Fork 6
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
Include optimization parameter basis #79
Include optimization parameter basis #79
Conversation
import importlib.metadata | ||
|
||
from ixmp4.core import IndexSet as IndexSet |
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'm wondering if we really need to import all of these objects at the top-level? I guess that except for Platform, we will never call them directly, right?
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'm not sure if some downstream packages already use that syntax. We seem to only use it for our tests, where we regularly do from ixmp4 import Variable
, from ixmp4 import Model
, or from ixmp4 import IndexSet
. I don't think this is necessary, but I also don't know what harm it's causing.
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.
There are no downstream packages yet, so better to keep the top-namespace lean.
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.
So out of all these imports, which would we want to keep? Only Platform
?
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'd at least not add more imports at this point, and we can do a separate remove-imports-PR later.
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.
But yes, I think that only Platform
is the one that is already used - at least in pyam.
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.
Another useful one is "Datapoint" because we sometimes need the "Datapoint.Type" enum in user code.
But i think its time we find a better solution for that anyway...
from ixmp4.data.abstract.optimization import Column | ||
|
||
|
||
class Parameter(BaseModelFacade): |
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.
Why is this not a child-object of the Table
?
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.
They are extremely similar and to some extent, we could have Parameter
inherit from Table
. I didn't do that for now because I thought if we then go and update Table
, it might not be obvious that Parameter
changes, too. Maybe the cleanest option is to set up a BaseOptimizationItem
somewhere that contains the common ground between Table
, Parameter
, Variable
, and Equation
, and have all of them inherit from there.
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.
Not sure if there is any feature in Table
that we would not want to be inherited by the other optimization-objects... So better to keep the codebase simple for now and extend later once this becomes relevant.
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.
That's not as straightforward as I thought it would be. Naively trying to extract the maximum number of properties to a common base, I receive
E sqlalchemy.exc.NoForeignKeysError: Can't determine the inherit condition between inherited table 'optimization_baseoptimizationitemmodel' and inheriting table 'optimization_table'; tables have no foreign key relationships established. Please ensure the inheriting table has a foreign key relationship to the inherited table, or provide an 'on clause' using the 'inherit_condition' mapper argument.
So it looks like if I set up columns in a common base class, sqlalchemy interprets that as a separate table and inheriting tables need to be linked via ForeignKeys, which is not what we want.
cfcde48
to
5584755
Compare
I can't quite get the connection between
The advantages would be that other layers (such as the facade layer) would be able to access The alternative would be to simply keep @danielhuppmann, please let me know what you think. |
@glatterf42, I guess that this PR should now be directed to the |
This comment was marked as resolved.
This comment was marked as resolved.
The idea was to merge this PR to include/optimization-parameter, which could collect changes to this part of the DB model before it's merged to main. That collection branch should also recognize which commits are already part of main, but maybe this one doesn't since it doesn't know where the collection branch is aiming. |
I guess that you have to rebase |
True; at the moment, I'd have to rebase the mixin branch on top of main, the collection branch on top of that, and this branch on top of the new collection branch. |
Re the actual question, without looking at the code yet (because of the rebase-branch-mixin-mixup): I think that also our implementation of the "foreign-keys" using index-sets and columns can only be validated at the code level (not the database). Therefore, I think it's ok that we also do that for units, hence storing the columns plus units plus values in |
Great, thanks :) |
* Does not work currently, see #79 * commit for future reference for many-to-many relationship setup attempt
With this clarification, all uncommented tests should now work (and that's even more than before), so I'd be in favor of merging this PR and opening another one for the remaining tests and code layers :) |
* Covers: * run__id, data, name, uniqueness of name together with run__id * Adapts tests since default order of columns changes
* Does not work currently, see #79 * commit for future reference for many-to-many relationship setup attempt
5bd5a23
to
efd1160
Compare
* Enable remaining parameter tests * Include optimization parameter api layer (#89) * Bump several dependency versions * Let api/column handle both tables and parameters * Make api-layer tests pass * Include optimization parameter core layer (#90) * Enable parameter core layer and test it * Fix things after rebase * Ensure all intended changes survive the rebase * Adapt data validation function for parameters * Allow tests to pass again
* Make Column generic enough for multiple parents * Introduce optimization.Parameter * Add tests for add_data * Enable remaining parameter tests (#86) * Enable remaining parameter tests * Include optimization parameter api layer (#89) * Bump several dependency versions * Let api/column handle both tables and parameters * Make api-layer tests pass * Include optimization parameter core layer (#90) * Enable parameter core layer and test it * Fix things after rebase * Ensure all intended changes survive the rebase * Adapt data validation function for parameters * Allow tests to pass again
* Make Column generic enough for multiple parents * Introduce optimization.Parameter * Add tests for add_data * Enable remaining parameter tests (#86) * Enable remaining parameter tests * Include optimization parameter api layer (#89) * Bump several dependency versions * Let api/column handle both tables and parameters * Make api-layer tests pass * Include optimization parameter core layer (#90) * Enable parameter core layer and test it * Fix things after rebase * Ensure all intended changes survive the rebase * Adapt data validation function for parameters * Allow tests to pass again
* Make Column generic enough for multiple parents * Introduce optimization.Parameter * Add tests for add_data * Enable remaining parameter tests (#86) * Enable remaining parameter tests * Include optimization parameter api layer (#89) * Bump several dependency versions * Let api/column handle both tables and parameters * Make api-layer tests pass * Include optimization parameter core layer (#90) * Enable parameter core layer and test it * Fix things after rebase * Ensure all intended changes survive the rebase * Adapt data validation function for parameters * Allow tests to pass again
* Make Column generic enough for multiple parents * Introduce optimization.Parameter * Add tests for add_data * Enable remaining parameter tests (#86) * Enable remaining parameter tests * Include optimization parameter api layer (#89) * Bump several dependency versions * Let api/column handle both tables and parameters * Make api-layer tests pass * Include optimization parameter core layer (#90) * Enable parameter core layer and test it * Fix things after rebase * Ensure all intended changes survive the rebase * Adapt data validation function for parameters * Allow tests to pass again
* Include optimization parameter basis (#79) * Fix references to DB filters in docs * Streamline naming in tests * Fix and test parameter list and tabulate for specific runs * Make indexset-creation a test utility * Incorporate changes from #110 * Use pandas for updated add_data behaviour * Raise minimum pandas version to enable add_data upsert * Generalize UsageError for more optimization items * Use generalized UsageError for Table * Use own errors for Parameter
* Make Column generic enough for multiple parents * Introduce optimization.Parameter * Add tests for add_data * Enable remaining parameter tests (#86) * Enable remaining parameter tests * Include optimization parameter api layer (#89) * Bump several dependency versions * Let api/column handle both tables and parameters * Make api-layer tests pass * Include optimization parameter core layer (#90) * Enable parameter core layer and test it * Fix things after rebase * Ensure all intended changes survive the rebase * Adapt data validation function for parameters * Allow tests to pass again
* Include optimization parameter basis (#79) * Fix references to DB filters in docs * Streamline naming in tests * Fix and test parameter list and tabulate for specific runs * Make indexset-creation a test utility * Incorporate changes from #110 * Use pandas for updated add_data behaviour * Raise minimum pandas version to enable add_data upsert * Generalize UsageError for more optimization items * Use generalized UsageError for Table * Use own errors for Parameter
As promised in a recent team meeting, the next steps for the message_ix data model work will use a more trunk-based development approach. This is where I got to today with introducing
optimization.Parameter
s. The tests for creating and getting them pass for the DB layer, others are still disabled. Ruff might complain that some temporarily-commented lines in the test file are now too long.If the tests run at all, maybe they only trigger on PRs to main. I could enable them for PRs to include/optimization-parameter as well or we merge this one and then set up a soon-to-be-final PR to main to collect further changes.
I'm not yet sure this is the best way to handle the
values
andunits
: as separate lists. I will test if this behaves as desired/expected and will rework if it doesn't.