iiasa / ixmp

The ix modeling platform for integrated and cross-cutting scenario analysis
https://docs.messageix.org/ixmp
Apache License 2.0
38 stars 111 forks source link

Cannot commit a change to a certain model #324

Closed Jihoon closed 4 years ago

Jihoon commented 4 years ago

Code sample or context

It may not be an IXMP issue, in which case please let me know where to move this.

I was trying to add or remove time series from a specific model (REMIND) through IXMP API from/to NGFS-internal DB.

mp = ixmp.Platform(name='ngfs-internal')
mm = 'REMIND-MAgPIE 1.7-3.0' 
ss = 'CD-LINKS_NPi'
vv = 'Diagnostics|Investment|Energy Supply|Electricity|Transmission and Distribution'

scen = ixmp.Scenario(mp, mm, ss)
df = scen.timeseries(variable=vv)
scen.check_out()
scen.remove_timeseries(df)  # Or `scen.add_timeseries(df)`  for no-harm debugging
scen.commit('Test: Remove an REMIND investment variable')

Expected result

I expect it just removes the df and commits to the scenario. I do the same for other models on the DB (GCAM & MESSAGE) without any problems.

Problem description

I get the following error:

RuntimeError                              Traceback (most recent call last)
<ipython-input-252-9dba29eb9447> in <module>
     18                 print('Remove variable: ' + vv)
     19                 scen.remove_timeseries(df)
---> 20             scen.commit('Remove an investment variable')
     21 #         data.to_csv('REMIND_'+ss+'.csv')
     22 

h:\mydocuments\message\ixmp\ixmp\core.py in commit(self, comment)
    478         return False
    479 
--> 480     def check_out(self, timeseries_only=False):
    481         """Check out the TimeSeries.
    482 

h:\mydocuments\message\ixmp\ixmp\core.py in _backend(self, method, *args, **kwargs)
    442         # Set attributes
    443         self.model = model
--> 444         self.scenario = scenario
    445 
    446         # Store a weak reference to the Platform object. This reference is not

h:\mydocuments\message\ixmp\ixmp\backend\base.py in __call__(self, obj, method, *args, **kwargs)
     20         for the method name, e.g. 'ts_{method}'.
     21         """
---> 22         return getattr(self, method)(obj, *args, **kwargs)
     23 
     24     def close_db(self):

h:\mydocuments\message\ixmp\ixmp\backend\jdbc.py in commit(self, ts, comment)
    511             # Load a TimeSeries of specific version
    512             args.append(ts.version)
--> 513 
    514         # either getTimeSeries or getScenario
    515         method = getattr(self.jobj, 'get' + ts.__class__.__name__)

h:\mydocuments\message\ixmp\ixmp\backend\jdbc.py in _raise_jexception(exc, msg)
    120             properties[match.group(1)] = match.group(2)
    121     return properties
--> 122 
    123 
    124 def _raise_jexception(exc, msg='unhandled Java exception: '):

RuntimeError: unhandled Java exception: There was a problem writing data to the IXMP database - no changes were saved!
Cannot write change log!

Versions

Output of ixmp show-versions ``` C:\ProgramData\Anaconda3\lib\site-packages\statsmodels\tools\_testing.py:19: FutureWarning: pandas.util.testing is deprecated. Use the functions in the public API at pandas.testing instead. import pandas.util.testing as tm ixmp: 2.0.0.post.dev328 8c247a5 (HEAD -> origin/master, origin/master, origin/HEAD) Merge pull request #298 from iiasa/jdbc-memory-mgmt message_ix: 2.0.0 adcf0e7 (HEAD -> hackathon-reporting) Fix the bug in the previous commit message_data: installed 0fb9acd (HEAD -> add_generic_baseline_and_runscripts, Jihoon/fertilizer) Merge remote-tracking branch 'Jihoon/add_generic_baseline_and_runscripts' into add_generic_baseline_and_runscripts click: 7.0 dask: 2.14.0 graphviz: 0.12 jpype: 0.7.0 pandas: 1.0.3 pint: 0.11 xarray: 0.15.1 xlrd: 1.2.0 xlsxwriter: 1.2.7 yaml: 5.2 iam_units: installed jupyter: installed matplotlib: 3.0.2 plotnine: None pyam: 0.2.0+16.gdd7ae0c python: 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 94 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None ```
Jihoon commented 4 years ago

I find the same code runs fine with vv = 'Investment|Energy Supply|Electricity|Transmission and Distribution'.

These two variables are already in the DB.

zikolach commented 4 years ago

running with debug log level:

java.sql.BatchUpdateException: ORA-12899: value too large for column "IXMP_NGFS_INTERNAL"."CHANGE_LOG"."ITEM" (actual: 261, maximum: 256)
danielhuppmann commented 4 years ago

so this means the variable name is just too long?

Jihoon commented 4 years ago

so this means the variable name is just too long?

That was one of my suspicions, but even longer names for MESSAGE didn't cause problems..

zikolach commented 4 years ago

No, it was bug in ixmp java code. Strange that it was not detected earlier. There was wrong value written instead of timeseries variable name - a combination of variable, region, unit etc

zikolach commented 4 years ago

One more PR https://github.com/iiasa/ixmp_source/pull/304

zikolach commented 4 years ago

PR was merged. Could you please install ixmp from master and test (seems that issue was closed automatically by comment on PR).