From 8108aa46303e2b44f35f95a452593a34a632e728 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Sat, 1 Mar 2025 13:54:48 +0100 Subject: [PATCH 1/5] Add _BuilderMixinActorFactory_DiscreteOnly, applying it in DiscreteSACExperimentBuilder --- tianshou/highlevel/experiment.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tianshou/highlevel/experiment.py b/tianshou/highlevel/experiment.py index 774902b40..d39e8f3f9 100644 --- a/tianshou/highlevel/experiment.py +++ b/tianshou/highlevel/experiment.py @@ -801,6 +801,28 @@ def with_actor_factory_default( return super()._with_actor_factory_default(hidden_sizes, hidden_activation) +class _BuilderMixinActorFactory_DiscreteOnly(_BuilderMixinActorFactory): + """Specialization of the actor mixin where only environments with discrete action spaces are supported.""" + + def __init__(self) -> None: + super().__init__(ContinuousActorType.UNSUPPORTED) + + def with_actor_factory_default( + self, + hidden_sizes: Sequence[int], + hidden_activation: ModuleType = torch.nn.ReLU, + ) -> Self: + """Defines use of the default actor factory, allowing its parameters it to be customized. + + The default actor factory uses an MLP-style architecture. + + :param hidden_sizes: dimensions of hidden layers used by the network + :param hidden_activation: the activation function to use for hidden layers + :return: the builder + """ + return super()._with_actor_factory_default(hidden_sizes, hidden_activation) + + class _BuilderMixinCriticsFactory: def __init__(self, num_critics: int, actor_future_provider: ActorFutureProviderProtocol): self._actor_future_provider = actor_future_provider @@ -1333,7 +1355,7 @@ def _create_agent_factory(self) -> AgentFactory: class DiscreteSACExperimentBuilder( ExperimentBuilder, - _BuilderMixinActorFactory, + _BuilderMixinActorFactory_DiscreteOnly, _BuilderMixinDualCriticFactory, ): def __init__( @@ -1343,7 +1365,7 @@ def __init__( sampling_config: SamplingConfig | None = None, ): super().__init__(env_factory, experiment_config, sampling_config) - _BuilderMixinActorFactory.__init__(self, ContinuousActorType.UNSUPPORTED) + _BuilderMixinActorFactory_DiscreteOnly.__init__(self) _BuilderMixinDualCriticFactory.__init__(self, self) self._params: DiscreteSACParams = DiscreteSACParams() From aca24f431ee1461589e40a41b35ed2a650feae17 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Sat, 1 Mar 2025 13:55:00 +0100 Subject: [PATCH 2/5] Fix docstring --- tianshou/highlevel/experiment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tianshou/highlevel/experiment.py b/tianshou/highlevel/experiment.py index d39e8f3f9..c0be23dca 100644 --- a/tianshou/highlevel/experiment.py +++ b/tianshou/highlevel/experiment.py @@ -981,7 +981,7 @@ def with_critic2_factory_default( return self def with_critic2_factory_use_actor(self) -> Self: - """Makes the first critic reuse the actor's preprocessing network (parameter sharing).""" + """Makes the second critic reuse the actor's preprocessing network (parameter sharing).""" return self._with_critic_factory_use_actor(1) From 910d6b9bba9ce03252443cb664700732387c73a9 Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Sat, 1 Mar 2025 14:07:45 +0100 Subject: [PATCH 3/5] Add Windows-specific configuration instructions --- docs/04_contributing/04_contributing.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/04_contributing/04_contributing.rst b/docs/04_contributing/04_contributing.rst index 01764fc36..7cfcc136b 100644 --- a/docs/04_contributing/04_contributing.rst +++ b/docs/04_contributing/04_contributing.rst @@ -13,6 +13,17 @@ to install all relevant requirements in editable mode you can simply call $ poetry install --with dev +Platform-Specific Configuration +------------------------------- + +**Windows**: +Since the repository contains symbolic links, make sure to set the following git configuration: + + * Enable symlinks for this repository: `git config core.symlinks true` + * Enable developer mode to allow symlinks to be created: Search Start Menu for "Developer Settings" and enable "Developer Mode" + * Re-checkout the current git state: `git checkout .` + + PEP8 Code Style Check and Formatting ---------------------------------------- From 9142dacb8711ba4f928b75fef7c63a716c3eff6a Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Sat, 1 Mar 2025 14:48:54 +0100 Subject: [PATCH 4/5] Add information on Windows-specific developer configuration --- docs/04_contributing/04_contributing.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/04_contributing/04_contributing.rst b/docs/04_contributing/04_contributing.rst index 7cfcc136b..1397e3473 100644 --- a/docs/04_contributing/04_contributing.rst +++ b/docs/04_contributing/04_contributing.rst @@ -17,11 +17,11 @@ Platform-Specific Configuration ------------------------------- **Windows**: -Since the repository contains symbolic links, make sure to set the following git configuration: +Since the repository contains symbolic links, make sure this is supported: - * Enable symlinks for this repository: `git config core.symlinks true` - * Enable developer mode to allow symlinks to be created: Search Start Menu for "Developer Settings" and enable "Developer Mode" - * Re-checkout the current git state: `git checkout .` + * Enable Windows Developer Mode to allow symbolic links to be created: Search Start Menu for "Developer Settings" and enable "Developer Mode" + * Enable symbolic links for this repository: ``git config core.symlinks true`` + * Re-checkout the current git state: ``git checkout .`` PEP8 Code Style Check and Formatting From 8b2aae3207dd12c839c21c6b9fba3b559f71638a Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Sat, 1 Mar 2025 15:07:47 +0100 Subject: [PATCH 5/5] Update change log --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c8195689..c032e5553 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ # Changelog -## Release 1.2.0 +## Unreleased ### Changes/Improvements - trainer: - Custom scoring now supported for selecting the best model. #1202 +- highlevel: + - `DiscreteSACExperimentBuilder`: Expose method `with_actor_factory_default` #1248 #1250 ### Breaking Changes