Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: StockTradingEnv.reset() got an unexpected keyword argument 'seed' #1022

Closed
LunbiWa opened this issue Jun 1, 2023 · 18 comments
Closed
Labels
bug Something isn't working

Comments

@LunbiWa
Copy link

LunbiWa commented Jun 1, 2023

Run Stock_NeurIPS2018_2_Train.ipynb in FinRL/examples

Colab report error

image

thanks!

@YangletLiu YangletLiu added the bug Something isn't working label Jun 2, 2023
@thinkscriptfan
Copy link

i am running to the same error
TypeError: StockTradingEnv.reset() got an unexpected keyword argument 'seed'

@Dharmendra-G-1
Copy link

Hello, I am also getting same above error on Colab, when running the Stock_NeurIPS2018_2_Train.ipynb from FinRL-Tutorials/1-Introduction/Stock_NeurIPS2018/Stock_NeurIPS2018_2_Train.ipynb python at

Environment for training command

env_train, _ = e_train_gym.get_sb_env()
print(type(env_train))

@MariamaB
Copy link

MariamaB commented Jun 3, 2023

Hi, I have the same issue when running:

df_summary = ensemble_agent.run_ensemble_strategy(A2C_model_kwargs,
PPO_model_kwargs,
DDPG_model_kwargs,
timesteps_dict)

in: FinRL/examples/FinRL_Ensemble_StockTrading_ICAIF_2020.ipynb

@Abhilaksh1498
Copy link

With the latest version of stable-baselines3 (2.0.0a10), I also get the same error.
image

However when I downgrade it to say v1.5.0 I get the following error.

image

Any help would be greatly appreciated!
Thanks in advance

@AkashKarnatak
Copy link
Contributor

StockTradingEnv.reset()' doesn't take any arguments. You can fix this by changing line 358 of finrl/meta/env_stock_trading/env_stocktrading.py from

    def reset(self):

to

    def reset(self, seed=None):

@thinkscriptfan
Copy link

tired the proposed change to the file line 358 def reset(self, seed=None): , got this:
TypeError: StockTradingEnv.reset() , got an unexpected keyword argument 'seed'

@AkashKarnatak
Copy link
Contributor

Which file did you exactly change? Was it directly inside site-packages folder?

@thinkscriptfan
Copy link

i made a copy of the finrl to my own repository from : https://github.com/AI4Finance-Foundation/FinRL/tree/master/
changed this file finrl/meta/env_stock_trading)
/env_stocktrading.py

@ZCKAO
Copy link

ZCKAO commented Jun 7, 2023

Hi! I'm running into the same error and also tried the above way, changing to the file line 358, when running the Stock_NeurIPS2018_SB3.ipynb on Colab from
AI4Finance-Foundation/FinRL/examples/Stock_NeurIPS2018_SB3.ipynb
TypeError: StockTradingEnv.reset() got an unexpected keyword argument 'seed'

@thinkscriptfan
Copy link

the proposed change from
finrl/meta/env_stock_trading/env_stocktrading.py from

def reset(self):
to
def reset(self, seed=None):
does work .
I was not pulling the repository correctly. thank you .

@thinkscriptfan
Copy link

there is now error symthom as bug #1010

ValueError: If using all scalar values, you must pass an index #1010

@kilmern
Copy link

kilmern commented Jun 8, 2023

Also getting the same error @thinkscriptfan pointed.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-19-f7216cfcab9f> in <module>
----> 1 df_summary = ensemble_agent.run_ensemble_strategy(A2C_model_kwargs,
      2                                                  PPO_model_kwargs,
      3                                                  DDPG_model_kwargs,
      4                                                  timesteps_dict)

~/.local/lib/python3.10/site-packages/finrl/agents/stablebaselines3/models.py in run_ensemble_strategy(self, A2C_model_kwargs, PPO_model_kwargs, DDPG_model_kwargs, timesteps_dict)
    666             )
    667             # print("Used Model: ", model_ensemble)
--> 668             last_state_ensemble = self.DRL_prediction(
    669                 model=model_ensemble,
    670                 name="ensemble",

~/.local/lib/python3.10/site-packages/finrl/agents/stablebaselines3/models.py in DRL_prediction(self, model, name, last_state, iter_num, turbulence_threshold, initial)
    319                 last_state = trade_env.render()
    320 
--> 321         df_last_state = pd.DataFrame({"last_state": last_state})
    322         df_last_state.to_csv(f"results/last_state_{name}_{i}.csv", index=False)
    323         return last_state

~/.local/lib/python3.10/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
    707         elif isinstance(data, dict):
    708             # GH#38939 de facto copy defaults to False only in non-dict cases
--> 709             mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager)
    710         elif isinstance(data, ma.MaskedArray):
    711             from numpy.ma import mrecords

~/.local/lib/python3.10/site-packages/pandas/core/internals/construction.py in dict_to_mgr(data, index, columns, dtype, typ, copy)
    479             arrays = [x.copy() if hasattr(x, "dtype") else x for x in arrays]
    480 
--> 481     return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)
    482 
    483 

~/.local/lib/python3.10/site-packages/pandas/core/internals/construction.py in arrays_to_mgr(arrays, columns, index, dtype, verify_integrity, typ, consolidate)
    113         # figure out the index, if necessary
    114         if index is None:
--> 115             index = _extract_index(arrays)
    116         else:
    117             index = ensure_index(index)

~/.local/lib/python3.10/site-packages/pandas/core/internals/construction.py in _extract_index(data)
    643 
    644     if not indexes and not raw_lengths:
--> 645         raise ValueError("If using all scalar values, you must pass an index")
    646 
    647     if have_series:

ValueError: If using all scalar values, you must pass an index

@srikantamehta
Copy link

You can fix this by making modified class for StockTradingEnv:

class MyStockTradingEnv(StockTradingEnv):
    def reset(self, seed=None):
        # Call the parent class's reset method, which doesn't expect a seed
        return super().reset()

@thinkscriptfan
Copy link

I am new to Python , can you please clarify which area the above code was inserted ? thanks in advance.

@srikantamehta
Copy link

Right before calling the StockTradingEnv class. Place this before and then change StockTradingEnv to MyStockTradingEnv

@thinkscriptfan
Copy link

Sorry , Still not clear . , where is StockTradingEnv class called ? which file , which line ?

@AkashKarnatak
Copy link
Contributor

AkashKarnatak commented Jun 10, 2023

srikantamehta is suggesting an alternative to my solution of fixing the above unexpected keyword problem. For #1010, you can try this solution #1010 (comment)

AkashKarnatak added a commit to AkashKarnatak/FinRL that referenced this issue Jun 10, 2023
…, DummyVecEnv.reset() method passes a `seed` argument to its list of envs. Since StockTradingEnv.reset() does not expect any argument it results in an error. This commit fixes AI4Finance-Foundation#1022.
Dharmendra-G-1 added a commit to Dharmendra-G-1/Financial_ReLearn_v6-23-2023 that referenced this issue Jun 11, 2023
AI4Finance-Foundation#1022

StockTradingEnv.reset()' doesn't take any arguments. You can fix this by changing line 358 of finrl/meta/env_stock_trading/env_stocktrading.py from

    def reset(self):
to

    def reset(self, seed=None):
@sardpl
Copy link

sardpl commented Jun 13, 2023

The "StockTradingEnv.reset()" error should be related to modifications to the Release 2.0.0aXX (WIP) of Stable-Baselines3.
The Change log says:
"Because of new Gym API (0.26+), the random seed passed to vec_env.seed(seed=seed) will only be effective after then env.reset() call."
The standard installation procedure for Windows of FinRL gets the latest version of stable baselines. I have manually downgraded to v. 2.0.0a5 and the error disappears, but I don't know if something is broken within Gym.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests