Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow python subclasses of pyspiel.Policy #999

Closed
VitamintK opened this issue Jan 20, 2023 · 3 comments
Closed

allow python subclasses of pyspiel.Policy #999

VitamintK opened this issue Jan 20, 2023 · 3 comments
Labels
contribution welcome It's a nice feature! But we do not have the time to do it ourselves. Contribution welcomed!

Comments

@VitamintK
Copy link
Contributor

It would be nice if we could subclass pyspiel.Policy, and then pass those policies to pyspiel functions which expect pyspiel.Policys.

So something like this:

import pyspiel
class PolicySubclass(pyspiel.Policy):
    def __init__(self, game):
        pyspiel.Policy.__init__(self)
   def get_state_policy_from_state(self, state, player):
       ...
   def get_state_policy_from_infostate_string(self, infostate_string):
      ...

Currently, trying to do so throws an error __init__ must be called when overriding __init__ (pybind/pybind11#2152), presumably because Policy has no constructor defined in policy.h. It looks like Game had the same issue, so a "trampoline class" was defined in open_spiel/python/pybind11/python_games.h. Would a similar solution should work for Policy?

@lanctot
Copy link
Collaborator

lanctot commented Jan 21, 2023

From a quick read of the thread it seems like the trampoline class was needed because Game is not default constructible.

I wonder if we can just add an empty constructor in this case. @elkhrt, do you know?

@elkhrt
Copy link
Member

elkhrt commented Jan 23, 2023

This would be a great contribution! You'll still need a trampoline class, but the overall setup should be a lot simpler than with Game. There's an overview of the necessary setup here: https://pybind11.readthedocs.io/en/stable/advanced/classes.html

@lanctot lanctot added the contribution welcome It's a nice feature! But we do not have the time to do it ourselves. Contribution welcomed! label Apr 13, 2023
@lanctot
Copy link
Collaborator

lanctot commented Dec 15, 2023

This is quite old, seems abandoned. @VitamintK please feel free to re-open if you ever get to this.

@lanctot lanctot closed this as completed Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome It's a nice feature! But we do not have the time to do it ourselves. Contribution welcomed!
Projects
None yet
Development

No branches or pull requests

3 participants