Repository navigation
Port the cart pole example to pyo3 and gymnasium - #112
Merged
Merged
Conversation
examples/openai.rs used the cpython and python3_sys crates, which are not dependencies, so `cargo check --features openai --examples` failed. It now uses the pyo3 setup of the lunar lander examples and the gymnasium API (reset() -> (obs, info), step() -> 5-tuple) on CartPole-v1. The episode loop lives in examples/cart_pole_common (no Python) and is tested by tests/cart_pole_tests.rs with a fake environment. It also fixes the old loop, which stepped once before ever activating the network and ignored the reset observation. Also removes the clippy warnings of openai_lunar_lander. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
examples/openai.rs(cart pole) no longer usescpython/python3_sys(which are not dependencies). It now uses the samepyo30.22 setup as the lunar lander examples and the gymnasium API:env.reset()returns(obs, info)andenv.step()returns(obs, reward, terminated, truncated, info). It runsCartPole-v1(v0 prints a gymnasium deprecation warning). The champion threshold is 475 and the telemetrymax_fitnessis 500.examples/cart_pole_common/mod.rs, which has no Python in it, andtests/cart_pole_tests.rstests it with a fake environment. This follows thelunar_lander_commonpattern. The old loop calledsteponce before it first activated the network, and it ignored the reset observation. The new loop activates on the reset observation first.threads() = 1, so concurrent episodes cannot interleave on that env. The champion is rendered in a separaterender_mode="human"env. If rendering fails (no pygame or no display), the example reports the error and does not panic.examples/openai_lunar_lander.rs.create_organismnow sits in a small module with#![allow(clippy::useless_conversion)], because that warning comes from the code pyo3 0.22's#[pyfunction]generates. An allow on the fn itself does not reach that code.Verification
cargo check --release --features openai --examplespasses with the pyo3 config stub, so CI: check the openai-feature examples #96 can enable it in CI.cargo clippy --release --features openai --examplesshows 0 warnings inopenai,openai_lunar_landerandtest_champion.cargo run --release --example openai --features openaireached a 500 reward in generation 1 in each of 3 runs. CartPole is easy even for the initial direct input→output networks. Rendering failed in the container because pygame is not installed, and the example reported the error as intended.cargo fmt -- --checkOK;cargo clippy --release --all-targetsgives the same warning count as develop, none of them in the new files;cargo build --release --examplesOK;cargo test --release --no-fail-fastall green (newcart_pole_tests: 4 passed).Closing criterion
cargo check --release --features openai --example openaisucceeds. The whole--examplescheck succeeds too.ref #95
Part of epic #55
🤖 Generated with Claude Code