Fix env.reset() to return (obs, info) tuple for SB3 v2.0+ compatibility#1402
Fix env.reset() to return (obs, info) tuple for SB3 v2.0+ compatibility#1402he-yufeng wants to merge 2 commits into
Conversation
…ompatibility Stable Baselines 3 v2.0+ expects env.reset() to return a (obs, info) tuple following the Gymnasium API. Four environments still returned only the observation, causing "too many values to unpack (expected 2)" when used with SB3's DummyVecEnv. Fixed environments: - env_btc_ccxt.py (BitcoinEnv) - env_multiple_crypto.py (CryptoEnv) - env_stocktrading_stoploss.py (StockTradingEnvStopLoss) - env_stocktrading_cashpenalty.py (StockTradingEnvCashpenalty) Fixes AI4Finance-Foundation#1051 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
for more information, see https://pre-commit.ci
atharvajoshi01
left a comment
There was a problem hiding this comment.
SB3 v2.0 changed the reset() API to return (obs, info) tuple. This fixes all the env classes to match. Clean and necessary for anyone using stable-baselines3 >= 2.0.
|
The remaining I am leaving this branch scoped to the SB3 reset API compatibility fix instead of widening it into a repository-wide formatting update. |
|
Any chance someone could take a look at this? It's been sitting here green for a few months — happy to rebase or adjust if anything's needed. |
Summary
Four environments'
reset()methods return only the observation instead of the(obs, info)tuple required by the Gymnasium API (and SB3 v2.0+), causingValueError: too many values to unpack (expected 2)when used withDummyVecEnv.Fixed Environments
env_btc_ccxt.py(BitcoinEnv)env_multiple_crypto.py(CryptoEnv)env_stocktrading_stoploss.py(StockTradingEnvStopLoss)env_stocktrading_cashpenalty.py(StockTradingEnvCashpenalty)Note:
env_stocktrading.pyandenv_stocktrading_np.pyalready return(obs, {})correctly.Change
Each fix is a single-line change:
return state→return state, {}Test plan
DummyVecEnvwrapping works with each fixed environmentFixes #1051
🤖 Generated with Claude Code