Using dynamically created classes for environments with a large number of actions #113
CinquilCinquil
started this conversation in
Ideas
Replies: 1 comment
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
0. The problem
Currently, in URNAI, actions should be represented as classes that inherit from an abstract class called
ActionBase
. The purpose of this framework is to keep things organized while also ensuring robustness of the code through tests, but it falls short when dealing with an environment with a large number of actions, like pysc2 (about 500 actions), because there would need to be an individual class for each one of those actions.Considering this, i propose the following solution: Create all of these classes dynamically, during execution of the code.
(this solution focuses on pysc2)
1. The initial solution
Python allows the creation of a class through the
type
method as shown in an example below:Given that, we should be able to iterate through all of the actions in pysc2, creating a class that inherits from
ActionBase
for each one of them, while storing them in alist
or adict
for later use. This process is simple seen that, for each class, we would be only encapsulating the core behaviour of an pysc2 action, wich is essentialy just a function call.2. Side-effects of the initial solution
Unfortunately, the current
ActionBase
class doesn't fit this ideia quite properly, because of two things:run
method would need to be more generalized to allow for the total encapsulation of a pysc2 action.check
andis_complete
would need to be removed from the class, seen that it would be too complex to implement them for every pysc2 action.3. Solution for the side-effects
run
in the second image below.ActionBase
(lets call itActionBaseStrict
for now) with the methodscheck
andis_complete
. This way, users of URNAI would have the choice of utilizingActionBaseStrict
if they saw it as a more fit for their experiment, while still keeping all of the actions inheriting fromActionBase
.(Image 1: ActionBase before proposed changes)
(Image 2: ActionBase after proposed changes)
Beta Was this translation helpful? Give feedback.
All reactions