microsoft / qlib

Qlib is an AI-oriented quantitative investment platform that aims to realize the potential, empower research, and create value using AI technologies in quantitative investment, from exploring ideas to implementing productions. Qlib supports diverse machine learning modeling paradigms. including supervised learning, market dynamics modeling, and RL.
https://qlib.readthedocs.io/en/latest/
MIT License
15.25k stars 2.61k forks source link

TypeError in qlib/examples/workflow_by_code.ipynb #799

Open vitorying opened 2 years ago

vitorying commented 2 years ago

šŸ› Bug Description

When I run the analyze graphs section in the workflow_by_code.ipynb in Google colab, I got the following error message. The error came from the line of "from qlib.contrib.report import analysis_model, analysis_position". Everything above that line was running fine. May I know what is the reason for it and how to fix it?

TypeError Traceback (most recent call last)

in () ----> 1 from qlib.contrib.report import analysis_model, analysis_position 2 from qlib.data import D 3 recorder = R.get_recorder(recorder_id=ba_rid, experiment_name="backtest_analysis") 4 print(recorder) 5 pred_df = recorder.load_object("pred.pkl") 14 frames /usr/local/lib/python3.7/dist-packages/distributed/config.py in () 18 19 with open(fn) as f: ---> 20 defaults = yaml.load(f) 21 22 dask.config.update_defaults(defaults) TypeError: load() missing 1 required positional argument: 'Loader' ## To Reproduce Steps to reproduce the behavior: 1.Load qlib/examples/workflow_by_code.ipynb in Google Colab 2.Run the code from the beginning to the "analyze graphs" section 3.The error will show up when runs the line "from qlib.contrib.report import analysis_model, analysis_position" ## Expected Behavior ## Screenshot ![image](https://user-images.githubusercontent.com/60383122/147944560-b3664728-3242-4bed-a9a2-8a3a49568245.png) ## Environment **Note**: User could run `cd scripts && python collect_info.py all` under project directory to get system information and paste them here directly. - Qlib version: - Python version: - OS (`Windows`, `Linux`, `MacOS`): - Commit number (optional, please provide it if you are using the dev version): ## Additional Notes
wan9c9 commented 2 years ago

The first thing I'll try is to see if the fn exists: os.path.exists(fn) and start from there.

Waterkin commented 2 years ago

Me too when doing 'python run_all_model.py run 3' .

Waterkin commented 2 years ago

My bugs: File "run_all_model.py", line 385, in fire.Fire(ModelRunner) # run all the model File "/home/wlh/anaconda3/envs/qlib/lib/python3.7/site-packages/fire/core.py", line 141, in Fire component_trace = _Fire(component, args, parsed_flag_args, context, name) File "/home/wlh/anaconda3/envs/qlib/lib/python3.7/site-packages/fire/core.py", line 471, in _Fire target=component.name) File "/home/wlh/anaconda3/envs/qlib/lib/python3.7/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace component = fn(*varargs, *kwargs) File "run_all_model.py", line 40, in _return_wrapped return function_to_decorate(args, **kwargs) File "run_all_model.py", line 320, in run yaml_path = gen_yaml_file_without_seed_kwargs(yaml_path, temp_dir) File "run_all_model.py", line 190, in gen_yaml_file_without_seed_kwargs config = yaml.load(fp) TypeError: load() missing 1 required positional argument: 'Loader'

vitorying commented 2 years ago

May I know any advice from Microsoft team?

wan9c9 commented 2 years ago

This is likely due to your pyyaml version. See here https://stackoverflow.com/questions/69564817/typeerror-load-missing-1-required-positional-argument-loader-in-google-col for a similar problem.

If your pyyaml version is 6.0 in your environment, try downgrade it to 5.4.1 to see if the problem goes away: pip install pyyaml==5.4.1

vitorying commented 2 years ago

I have added pip install pyyaml==5.4.1 in

# install qlib
! pip install --upgrade numpy
! pip install pyqlib
! pip install pyyaml==5.4.1

but got another error ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. yellowbrick 1.3.post1 requires numpy<1.20,>=1.16.0, but you have numpy 1.21.5 which is incompatible. datascience 0.10.6 requires folium==0.2.1, but you have folium 0.8.3 which is incompatible. albumentations 0.1.12 requires imgaug<0.2.7,>=0.2.5, but you have imgaug 0.2.9 which is incompatible. Successfully installed numpy-1.21.5 WARNING: The following packages were previously imported in this runtime: [numpy] You must restart the runtime in order to use newly installed versions.

you-n-g commented 2 years ago

Will https://github.com/microsoft/qlib/pull/853/files#diff-25cbd3758720e92892899650518bd0168c8d742ad65cdf895ce75c437ae7ea08R189 fix this issue ?

Newtoniano commented 2 years ago

@you-n-g running !pip install pyyaml==5.4.1 before anything else in the notebook, with pyqlib v0.8.4 everything in the file runs and is displayed correctly. Your merged PR seems to have fixed the issue, provided you downgrade to that version of pyyaml first (otherwise the error is still there).