EnergySystemsModellingLab / MUSE_OS

Welcome to the MUSE-OS repository
https://muse-os.readthedocs.io/en/latest/
GNU General Public License v3.0
22 stars 9 forks source link

Model fails when existing capacity for all technologies in a sector is set to zero [BUG] #427

Open tsmbland opened 1 month ago

tsmbland commented 1 month ago

Describe the bug

Probably a niche scenario, but has come up for one of Sumin's models

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\tbland\AppData\Local\anaconda3\envs\muse_env\Scripts\muse.exe\__main__.py", line 7, in <module>  
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\__main__.py", line 61, in run
    muse_main(args.settings, args.model, args.copy)
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\__main__.py", line 56, in muse_main
    MCA.factory(settings).run()
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\mca.py", line 343, in run
    _, new_market, self.sectors = self.find_equilibrium(new_market)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\mca.py", line 208, in find_equilibrium
    return find_equilibrium(
           ^^^^^^^^^^^^^^^^^
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\mca.py", line 552, in find_equilibrium
    market, equilibrium_sectors = single_year_iteration(market, sectors)
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\mca.py", line 464, in single_year_iteration
    sector_market = sector.next(
                    ^^^^^^^^^^^^
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\sectors\sector.py", line 231, in next
    subsector.invest(
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\sectors\subsector.py", line 68, in invest
    lp_problem = self.aggregate_lp(
                 ^^^^^^^^^^^^^^^^^^
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\sectors\subsector.py", line 110, in aggregate_lp
    demands = self.demand_share(
              ^^^^^^^^^^^^^^^^^^
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\demand_share.py", line 105, in demand_share
    return function(agents, market, technologies, **keyword_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\registration.py", line 174, in decorated
    result = inner_decorated(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\demand_share.py", line 286, in new_and_retro
    retro_demands: MutableMapping[Hashable, xr.DataArray] = _inner_split(
                                                            ^^^^^^^^^^^^^
  File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\demand_share.py", line 472, in _inner_split
    .groupby("technology")
     ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tbland\AppData\Local\anaconda3\envs\muse_env\Lib\site-packages\xarray\core\dataarray.py", line 6759, in groupby
    rgrouper = ResolvedGrouper(UniqueGrouper(), group, self)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 6, in __init__
  File "C:\Users\tbland\AppData\Local\anaconda3\envs\muse_env\Lib\site-packages\xarray\core\groupby.py", line 440, in __post_init__
    self.group: T_Group = _resolve_group(self.obj, self.group)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\tbland\AppData\Local\anaconda3\envs\muse_env\Lib\site-packages\xarray\core\groupby.py", line 785, in _resolve_group
    raise ValueError(f"{newgroup.name} must not be empty")
ValueError: technology must not be empty

To Reproduce

Set all values in the ExistingCapacity.csv for a sector to zero (current and future years)

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Context

Please, complete the following to better understand the system you are using to run MUSE.

ahawkes commented 1 month ago

Thanks for this. I think zero capacity should only be allowed (for the base year) when demand is also zero for the base year. The idea is that modellers calibrate the base year - i.e. they tell the model what the existing capacity is for any process that gas capacity in the base year. If they enter a capacity value that is not sufficient to meet demand in the peak time slice, then the model should throw a helpful error telling them that they need to calibrate the base year.


From: Tom Bland @.> Sent: 23 July 2024 10:57 To: EnergySystemsModellingLab/MUSE_OS @.> Cc: Subscribed @.***> Subject: [EnergySystemsModellingLab/MUSE_OS] Model fails when existing capacity for all technologies in a sector is set to zero [BUG] (Issue #427)

This email from @.*** originates from outside Imperial. Do not click on links and attachments unless you recognise the sender. If you trust the sender, add them to your safe senders listhttps://spam.ic.ac.uk/SpamConsole/Senders.aspx to disable email stamping for this address.

Describe the bug

Probably a niche scenario, but has come up for one of Sumin's models

Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "C:\Users\tbland\AppData\Local\anaconda3\envs\muse_env\Scripts\muse.exe__main.py", line 7, in File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse__main.py", line 61, in run muse_main(args.settings, args.model, args.copy) File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\main__.py", line 56, in muse_main MCA.factory(settings).run() File "C:\Users\tbland\Documents\Code\MUSEOS\src\muse\mca.py", line 343, in run , new_market, self.sectors = self.find_equilibrium(new_market) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\mca.py", line 208, in find_equilibrium return find_equilibrium( ^^^^^^^^^^^^^^^^^ File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\mca.py", line 552, in find_equilibrium market, equilibrium_sectors = single_year_iteration(market, sectors) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\mca.py", line 464, in single_year_iteration sector_market = sector.next( ^^^^^^^^^^^^ File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\sectors\sector.py", line 231, in next subsector.invest( File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\sectors\subsector.py", line 68, in invest lp_problem = self.aggregate_lp( ^^^^^^^^^^^^^^^^^^ File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\sectors\subsector.py", line 110, in aggregate_lp demands = self.demand_share( ^^^^^^^^^^^^^^^^^^ File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\demand_share.py", line 105, in demand_share return function(agents, market, technologies, *keyword_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\registration.py", line 174, in decorated result = inner_decorated(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\demand_share.py", line 286, in new_and_retro retro_demands: MutableMapping[Hashable, xr.DataArray] = _inner_split( ^^^^^^^^^^^^^ File "C:\Users\tbland\Documents\Code\MUSE_OS\src\muse\demand_share.py", line 472, in _inner_split .groupby("technology") ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\tbland\AppData\Local\anaconda3\envs\muse_env\Lib\site-packages\xarray\core\dataarray.py", line 6759, in groupby rgrouper = ResolvedGrouper(UniqueGrouper(), group, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 6, in init File "C:\Users\tbland\AppData\Local\anaconda3\envs\muse_env\Lib\site-packages\xarray\core\groupby.py", line 440, in __post_init self.group: T_Group = _resolve_group(self.obj, self.group) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\tbland\AppData\Local\anaconda3\envs\muse_env\Lib\site-packages\xarray\core\groupby.py", line 785, in _resolve_group raise ValueError(f"{newgroup.name} must not be empty") ValueError: technology must not be empty

To Reproduce

Set all values in the ExistingCapacity.csv for a sector to zero

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Context

Please, complete the following to better understand the system you are using to run MUSE.

— Reply to this email directly, view it on GitHubhttps://github.com/EnergySystemsModellingLab/MUSE_OS/issues/427, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AC37JLPMVXM4SZSI4LKGDT3ZNYSHHAVCNFSM6AAAAABLKCHS4CVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQZDINZXGQ2DGNQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

tsmbland commented 1 month ago

Ok makes sense. I've noticed that most of the models I've been working with don't meet demand in the base year (e.g. see #316), and don't give any kind of warning. So I guess we'll need to go through all the example/tutorial models to make sure they're sufficiently calibrated.

tsmbland commented 1 month ago

Also just linking #286, as this issue has come up (and been fixed) before, but it looks like it's back

tsmbland commented 1 month ago

Note: this also happens when an agent has no initial capacity assigned to it