xarray MergeError; when running more than one agent for different sectors

24 views
Skip to first unread message

Alaa Qassabi

unread,
Oct 29, 2023, 9:26:59 AM10/29/23
to MUSE
Dear MUSE team,

I created a model with 3 agents as follows
A1: LCOE; POWER/INDUSTRY/EXPORT sectors, TRUE (minimisation)
A2: EAC; RESIDENTIAL/SERVICE/TRANSPORT sectors, TRUE (minimisation)
A3: NPV; UPSTREAM/WATERDESAL, FALSE (maximisation)

the sectors above will have a value of 1 for the respective agent in the technodata.csv file, and zero for the other two agents

If I run the simulation, it hits this error:

Traceback (most recent call last):

  File "…/opt/anaconda3/envs/muse/lib/python3.8/site-packages/xarray-2022.3.0-py3.8.egg/xarray/core/dataarray.py", line 3120, in _inplace_binary_op

    with self.coords._merge_inplace(other_coords):

  File "…/opt/anaconda3/envs/muse/lib/python3.8/contextlib.py", line 113, in __enter__

    return next(self.gen)

  File "…/opt/anaconda3/envs/muse/lib/python3.8/site-packages/xarray-2022.3.0-py3.8.egg/xarray/core/coordinates.py", line 191, in _merge_inplace

    variables, indexes = merge_coordinates_without_align(

  File "…/opt/anaconda3/envs/muse/lib/python3.8/site-packages/xarray-2022.3.0-py3.8.egg/xarray/core/merge.py", line 345, in merge_coordinates_without_align

    return merge_collected(filtered, prioritized, combine_attrs=combine_attrs)

  File "…/opt/anaconda3/envs/muse/lib/python3.8/site-packages/xarray-2022.3.0-py3.8.egg/xarray/core/merge.py", line 217, in merge_collected

    raise MergeError(

xarray.core.merge.MergeError: conflicting values for index 'timeslice' on objects to be combined:

first value: <xarray.core.indexes.PandasIndex object at 0x7f8bf4c62540>

second value: <xarray.core.indexes.PandasMultiIndex object at 0x7f8d08938880>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

  File "…/opt/anaconda3/envs/muse/lib/python3.8/runpy.py", line 194, in _run_module_as_main

    return _run_code(code, main_globals, None,

  File "…/opt/anaconda3/envs/muse/lib/python3.8/runpy.py", line 87, in _run_code

    exec(code, run_globals)

  File "…/.local/lib/python3.8/site-packages/muse/__main__.py", line 57, in <module>

    muse_main()

  File "…/opt/anaconda3/envs/muse/lib/python3.8/site-packages/click-8.1.3-py3.8.egg/click/core.py", line 1130, in __call__

    return self.main(*args, **kwargs)

  File "…/opt/anaconda3/envs/muse/lib/python3.8/site-packages/click-8.1.3-py3.8.egg/click/core.py", line 1055, in main

    rv = self.invoke(ctx)

  File "…/opt/anaconda3/envs/muse/lib/python3.8/site-packages/click-8.1.3-py3.8.egg/click/core.py", line 1404, in invoke

    return ctx.invoke(self.callback, **ctx.params)

  File "…/opt/anaconda3/envs/muse/lib/python3.8/site-packages/click-8.1.3-py3.8.egg/click/core.py", line 760, in invoke

    return __callback(*args, **kwargs)

  File "…/.local/lib/python3.8/site-packages/muse/__main__.py", line 50, in muse_main

    MCA.factory(settings).run()

  File "…/.local/lib/python3.8/site-packages/muse/mca.py", line 346, in run

    _, new_market, self.sectors = self.find_equilibrium(new_market)

  File "…/.local/lib/python3.8/site-packages/muse/mca.py", line 209, in find_equilibrium

    return find_equilibrium(

  File "…/.local/lib/python3.8/site-packages/muse/mca.py", line 559, in find_equilibrium

    market, equilibrium_sectors = single_year_iteration(market, sectors)

  File "…/.local/lib/python3.8/site-packages/muse/mca.py", line 466, in single_year_iteration

    sector_market = sector.next(

  File "…/.local/lib/python3.8/site-packages/muse/sectors/sector.py", line 233, in next

    subsector.invest(

  File "…/.local/lib/python3.8/site-packages/muse/sectors/subsector.py", line 74, in invest

    lp_problem = self.aggregate_lp(

  File "…/.local/lib/python3.8/site-packages/muse/sectors/subsector.py", line 147, in aggregate_lp

    result = agent.next(

  File "…/.local/lib/python3.8/site-packages/muse/agents/agent.py", line 402, in next

    search = super().next(technologies, market, demand, time_period=time_period)

  File "…/.local/lib/python3.8/site-packages/muse/agents/agent.py", line 268, in next

    decision = self._compute_objective(demand, search_space, technologies, market)

  File "…/.local/lib/python3.8/site-packages/muse/agents/agent.py", line 280, in _compute_objective

    objectives = self.objectives(self, demand, search_space, technologies, market)

  File "…/.local/lib/python3.8/site-packages/muse/objectives.py", line 142, in objectives

    result[name] = objective(agent, demand, search_space, *args, **kwargs)

  File "…/.local/lib/python3.8/site-packages/muse/registration.py", line 172, in decorated

    result = inner_decorated(*args, **kwargs)

  File "…/.local/lib/python3.8/site-packages/muse/objectives.py", line 173, in decorated_objective

    result = function(agent, reduced_demand, search_space, *args, **kwargs)

  File "…/.local/lib/python3.8/site-packages/muse/objectives.py", line 836, in net_present_value

    results -= fuel_costs

  File "…/opt/anaconda3/envs/muse/lib/python3.8/site-packages/xarray-2022.3.0-py3.8.egg/xarray/core/_typed_ops.py", line 290, in __isub__

    return self._inplace_binary_op(other, operator.isub)

  File "…/opt/anaconda3/envs/muse/lib/python3.8/site-packages/xarray-2022.3.0-py3.8.egg/xarray/core/dataarray.py", line 3123, in _inplace_binary_op

    raise MergeError(

xarray.core.merge.MergeError: Automatic alignment is not supported for in-place operations.

Consider aligning the indices manually or using a not-in-place operation.

See https://github.com/pydata/xarray/issues/3910 for more explanations.


Python version : 3.8.13
using Terminal in mac

Thanks a lot!
Alaa

sgiarols

unread,
Nov 3, 2023, 11:17:28 AM11/3/23
to MUSE
Dear Alaa,
We can't replicate the error.
It would be useful to have a demo case with the error for us to be able to help.
Best
MUSE team
Reply all
Reply to author
Forward
0 new messages