Skip to content

Setup and maintenance update#5

Merged
eisDNV merged 84 commits intomainfrom
setup-and-maintenance-update
Apr 24, 2026
Merged

Setup and maintenance update#5
eisDNV merged 84 commits intomainfrom
setup-and-maintenance-update

Conversation

@ClaasRostock
Copy link
Copy Markdown
Collaborator

Changed

  • CI: Skip slow test_algorithm_strategies test in GitHub workflow runs by adding a slow pytest marker and passing -m "not slow" in _test.yml and _test_future.yml
  • Adjusted and partly amended package structure to be in sync with latest changes in python_project_template v0.2.11
  • Typing:
    • Added type annotations across all source, test, and script modules
    • Added type stubs for torch, matplotlib, and stable-baselines3
  • Docstrings:
    • Reformatted all existing docstrings to numpy-style
    • Added missing docstrings across all source and script modules
  • Resolved all issues raised by ruff, pyright, and mypy

Fixed

  • Restored deterministic AntiPendulum environment seeding and aligned reset/step behavior with the existing environment tests.

- Add AntiPendulumObs type alias (tuple[int, ...] | np.ndarray)
- Parameterize AntiPendulumEnv as gym.Env[AntiPendulumObs, int]
- Parameterize ControlledCraneEnv as gym.Env[CraneObs, int]
- Type crane parameter as Callable[..., Crane], wire as Wire
- Replace MappingProxyType metadata with ClassVar[dict[str, object]]
- Add TYPE_CHECKING imports for Callable, Crane, Wire, Line2D
- Suppress py_crane stub gaps (cm_v, damping_time) with type: ignore
- Add type arguments to RewardWrapper, ActionWrapper, ObservationWrapper, Wrapper
- Suppress gymnasium invariant type parameter errors with type: ignore[type-arg]
- Suppress env arg-type and observation_space assignment errors
- Use AntiPendulumEnv for env parameter types instead of bare gym.Env
- Add TYPE_CHECKING imports for AntiPendulumEnv, Callable, Sequence
- Narrow obs to tuple[int, ...] with assert in q_agent call sites
- Cast obs to np.asarray in ppo_agent and reinforce_agent for predict/sample
- Fix variable shadowing in reinforce_agent (state -> state_tensor)
- Remove unnecessary type: ignore comments on q_agent
- Type crane fixture as Callable[..., Crane] across all test modules
- Add TYPE_CHECKING imports for Crane in test files
- Cast np_random.integers to int in test_environment
- Remove unnecessary type: ignore in test_ppo
- Add plans/add-type-hints/plan.md with phased execution plan
- Update CHANGELOG.md Unreleased section with type-annotation entry
- Pyright: 54 errors -> 0, 188 warnings -> 106
Provide minimal .pyi stubs for torch, torch.cuda, torch.nn, torch.optim,

and torch.distributions.normal covering every symbol used by this project.

stubPath stubs completely shadow inline package types, so all used

submodules are explicitly re-exported.

Pyright warnings: 106 -> 101 (-5 reportUnknownMemberType)
Provide minimal .pyi stubs for matplotlib.pyplot, matplotlib.axes,

matplotlib._axes, matplotlib.figure, matplotlib.lines, and matplotlib.text.

The _axes submodule is required because seaborn's return types resolve

to matplotlib.axes._axes.Axes (the private submodule).

Pyright warnings: 101 -> 79 (-22 reportUnknownMemberType)
Provide minimal .pyi stubs for PPO (load, learn, save, predict),

make_vec_env, evaluate_policy, BaseCallback, and VecEnv.

Pyright warnings: 79 -> 77 (-2 reportUnknownMemberType)
Remove 7 '# type: ignore' comments that became unnecessary after

adding type stubs for torch, matplotlib, and stable-baselines3.

Pyright informations: 15 -> 8 (-7 reportUnnecessaryTypeIgnoreComment)
Document the addition of type stubs and stale type-ignore removal.

Include the implementation plan under plans/add-type-stubs/.
ClaasRostock and others added 7 commits April 23, 2026 16:58
Add a `slow` pytest marker and apply it to `test_algorithm_strategies`.
Both `_test.yml` and `_test_future.yml` workflows now pass
`-m "not slow"` to pytest, deselecting slow tests in CI while
keeping them available for local runs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI and others added 3 commits April 24, 2026 05:30
…anup) into setup-and-maintenance-update branch

Conflicts resolved by keeping setup-and-maintenance-update improvements (type
annotations, numpy-style docstrings, logging, ruff compliance) and integrating
the functional changes from main:

- src/crane_controller/envs/controlled_crane_pendulum.py: apply dtype=np.float64
  fix to continuous observation space (PR #3)
- src/crane_controller/ppo_agent.py: integrate VecNormalize wrapping, fix dead-code
  bug in __init__ (inference_only flag), add _stats_path helper, save vecnorm stats
  in do_training, normalize obs in do_one_episode (PR #3)
- scripts/train_ppo.py: add VecNormalize stats path log after training (PR #3)
- tests/test_environment.py: add test_observation_space_dtype and
  test_observations_are_float (PR #3)
- tests/test_ppo.py: add test_ppo_saves_vecnorm and test_ppo_vecnorm_updates (PR #3)
- tests/conftest.py: change fixture scope from "session" to "package" for chdir
  and test_dir (PR #4)
- tests/test_algorithm.py: accept auto-merged improvements from PR #4
- 8 stale test data files removed: anti-pendulum*.json, pendulum*.json,
  antipendulum.zip, ppo_AntiPendulumEnv.zip, interval.json (PR #4)

Co-authored-by: ClaasRostock <48752696+ClaasRostock@users.noreply.github.com>
Add plan.md files for:
- fix-ruff-check
- add-type-stubs
- add-type-hints
- fix-pyright
- fix-mypy
- reformat-existing-docstrings
- add-missing-docstrings

Agent-Logs-Url: https://github.com/dnv-opensource/crane-controller/sessions/163e9664-1e2f-468c-ac5f-6c97fb375c29

Co-authored-by: ClaasRostock <48752696+ClaasRostock@users.noreply.github.com>
Comment thread tests/conftest.py
Comment thread src/crane_controller/reinforce_agent.py
Comment thread src/crane_controller/reinforce_agent.py
Copilot AI and others added 9 commits April 24, 2026 06:44
Add isinstance(obs, np.ndarray) assertion in test_observations_are_float
to narrow the AntiPendulumObs union type for pyright.

Also removes extraneous blank lines in vec_env.pyi stub (ruff format).
Add isinstance assertion to narrow obs_rms from the union type
dict[str, RunningMeanStd] | RunningMeanStd to RunningMeanStd.
Remove 13 # type: ignore comments that mypy no longer needs.
Where pyright still requires suppression, convert to
# pyright: ignore[rule]. Trim multi-code comments to keep
only the still-needed error codes for mypy.
… learnings

- fix-mypy/plan-draft: add --warn-unused-ignores to baseline, add
  pyright/mypy divergence guidance
- fix-pyright/plan-draft: add mypy compat check when modifying ignores
- add-type-stubs/plan-draft: add py.typed check constraint
- .instructions.md: clarify # type: ignore vs # pyright: ignore semantics
Comment thread stubs/torch-stubs/distributions/__init__.pyi
Comment thread src/crane_controller/reinforce_agent.py
Copy link
Copy Markdown
Collaborator

@eisDNV eisDNV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go

@eisDNV eisDNV merged commit ef1b88e into main Apr 24, 2026
10 checks passed
@eisDNV eisDNV deleted the setup-and-maintenance-update branch April 24, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants