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

[API] Deprecate player_id in observe #1292

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pgx/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import warnings
import abc
from typing import Literal, Optional, Tuple, get_args

Expand Down Expand Up @@ -184,7 +185,7 @@ def init(self, key: PRNGKey) -> State:

"""
state = self._init(key)
observation = self.observe(state, state.current_player)
observation = self.observe(state)
return state.replace(observation=observation) # type: ignore

def step(
Expand Down Expand Up @@ -221,13 +222,17 @@ def step(
lambda: state,
)

observation = self.observe(state, state.current_player)
observation = self.observe(state)
state = state.replace(observation=observation) # type: ignore

return state

def observe(self, state: State, player_id: Array) -> Array:
def observe(self, state: State, player_id: Optional[Array] = None) -> Array:
"""Observation function."""
if player_id is None:
player_id = state.current_player
else:
warnings.warn("[Pgx] `player_id` in `observe` is deprecated. This argument will be removed in the future.", DeprecationWarning)
obs = self._observe(state, player_id)
return jax.lax.stop_gradient(obs)

Expand Down