iiasa / climate-assessment

https://climate-assessment.readthedocs.io/en/latest
MIT License
19 stars 18 forks source link

Issue related to get_version() for Windows users #54

Closed adrivinca closed 6 months ago

adrivinca commented 6 months ago

Hi all, I have been trying to run MAGICC through the climate-processor, which calls climate-assessment on a fresh environment with Windows10. But I run into an issue with the function .get_version() that is not compatible with Windows applications.

me running either with CLI or from script

run_magicc(input_data_file="ENGAGE_SSP2_v4.1.8.3.1_T4.5v2_r3.1_NPi2020_GDP_CI_rcp2p6_PS.xlsx",
           results_file="MAGICC_rcp6p0_res2.xlsx",
           input_data_directory=path_all ,
           results_directory=path_all ,
           logging_directory=path_all
           )
[69 rows x 86 columns]
2024-02-13 15:27:55 INFO     Python-dotenv could not find configuration file .env.
Traceback (most recent call last):

  Cell In[17], line 1
    run_magicc(input_data_file="ENGAGE_SSP2_v4.1.8.3.1_T4.5v2_r3.1_NPi2020_GDP_CI_rcp2p6_PS.xlsx",

  File ~\Documents\Github\climate-processor\climate_processor\__init__.py:210 in run_magicc
    ).apply(IamDataFrame(input_data_directory / input_data_file)).to_excel(

  File ~\Documents\Github\climate-processor\climate_processor\__init__.py:115 in apply
    self.apply_magicc(

  File ~\Documents\Github\climate-processor\climate_processor\__init__.py:137 in apply_magicc
    run_workflow(

  File ~\AppData\Local\anaconda3\envs\message_gdp\Lib\site-packages\climate_assessment\cli.py:608 in run_workflow
    df_climate = climate_assessment(

  File ~\AppData\Local\anaconda3\envs\message_gdp\Lib\site-packages\climate_assessment\climate\__init__.py:126 in climate_assessment
    climate_model_cfgs, climate_models_out_config = _get_model_configs_and_out_configs(

  File ~\AppData\Local\anaconda3\envs\message_gdp\Lib\site-packages\climate_assessment\climate\__init__.py:434 in _get_model_configs_and_out_configs
    magicc7_cfgs, magicc7_out_config = get_magicc7_configurations(

  File ~\AppData\Local\anaconda3\envs\message_gdp\Lib\site-packages\climate_assessment\climate\magicc7.py:23 in get_magicc7_configurations
    if MAGICC7.get_version() != magicc_version:

  File ~\AppData\Local\anaconda3\envs\message_gdp\Lib\site-packages\openscm_runner\adapters\magicc7\magicc7.py:220 in get_version
    check_output([cls._executable(), "--version"])  # nosec

  File ~\AppData\Local\anaconda3\envs\message_gdp\Lib\subprocess.py:466 in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,

  File ~\AppData\Local\anaconda3\envs\message_gdp\Lib\subprocess.py:548 in run
    with Popen(*popenargs, **kwargs) as process:

  File ~\AppData\Local\anaconda3\envs\message_gdp\Lib\site-packages\spyder_kernels\customize\spydercustomize.py:109 in __init__
    super(SubprocessPopen, self).__init__(*args, **kwargs)

  File ~\AppData\Local\anaconda3\envs\message_gdp\Lib\subprocess.py:1026 in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,

  File ~\AppData\Local\anaconda3\envs\message_gdp\Lib\subprocess.py:1538 in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,

OSError: [WinError 193] %1 is not a valid Win32 application

If I comment the part with .get_version() in climate_assessment\climate\magicc7.py, I still get the same error in openscm_runner

C:\Users\vinca\AppData\Local\anaconda3\envs\message_gdp\Lib\site-packages\openscm_runner\adapter │
│ s\magicc7\magicc7.py:184 in _write_scen_files_and_make_full_cfgs                                 │
│                                                                                                  │
│   181 │   │   │   scen_file_name = os.path.join(out_directory, scen_file_name)                   │
│   182 │   │   │   writer.write(                                                                  │
│   183 │   │   │   │   scen_file_name,                                                            │
│ ❱ 184 │   │   │   │   magicc_version=self.get_version()[1],                                      │
│   185 │   │   │   )                                                                              │
│   186 │   │   │                                                                                  │
│   187 │   │   │   scenario_cfg = [

@jkikstra @znicholls Do you have any quick fix or solutions to be implemented? Hopefully it is not a huge fix. Thanks!

znicholls commented 6 months ago

Looks like the executable isn't happy with your system. If you just run e.g. ./magicc.exe in a terminal (having navigated to wherever your MAGICC executable is first), do you get anything? If yes, then probably just an environment issue. If no, then the binary is incompatible with your system which is not so easy to fix.

@phackstock will probably know best about how to make this behave. Perhaps the container you've built is the best option @phackstock ?

phackstock commented 6 months ago

@znicholls since I've only ever run MAGICC on ubuntu, locally and on my machine, I have never encountered this and don't know how to fix it. In principle the container that I've built would work but the build is currently failing and I haven't had the time to fix it yet.

jkikstra commented 6 months ago

I'm on leave this month, so won't be able to help out much. I run on Windows, but have never myself played around with climate-processor before. And didn't come across this issue when I have been running MAGICC.

Just one thing to try: this wouldn't happen to have anything to do with setting an environment variable? https://climate-assessment.readthedocs.io/en/latest/emulator.html#setup-instructions-for-a-windows-computer

E.g. this is what it looks like for me (where MAGICC_RUN_DIR i believe is a leftover from previous times - so try without specifying that): image

phackstock commented 6 months ago

You're raising a good point @jkikstra. I'm setting theses variables and I'm using str(pathlib.Path) for this. This could mean that the paths are written unix style. I'll check on climate-processor side. EDIT: Never mind, that was not the error.

adrivinca commented 6 months ago

Thank all for the prompt feedbacks. So in my environment, I don't find any magicc.exe only magicc6.exe

I had downloaded magicc-v7.5.3 and there there is an executable that if I run I get the error below. But this is just the MAGICC folder I downloaded, completely disconnected from python and environments.. so I am a bit confused

image

phackstock commented 6 months ago

@adrivinca in https://github.com/iiasa/climate-processor it's all bundled together so you don't have to download any MAGICC by yourself.

phackstock commented 6 months ago

Never mind, found the error. Should be fixed on climate-processor side in 5 minutes.