Skip to content

Commit dadb715

Browse files
locross93copybara-github
authored andcommitted
Guard checkpointing on checkpoint_path or get_state_callback
Makes save_checkpoint a no-op when neither checkpoint_path nor get_state_callback is provided. This avoids spurious checkpoint errors in the Go engine where Spanner handles state persistence. PiperOrigin-RevId: 975818621 Change-Id: I183e5f10ef2c44902dedb1ec5fd00876710415d7
1 parent 9c6150c commit dadb715

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

concordia/prefabs/simulation/generic.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,13 @@ def play(
276276

277277
self._get_state_callback = get_state_callback
278278

279-
checkpoint_callback = functools.partial(
280-
# pyrefly: ignore [bad-argument-type]
281-
self.save_checkpoint, checkpoint_path=checkpoint_path
282-
)
279+
if checkpoint_path or get_state_callback:
280+
checkpoint_callback = functools.partial(
281+
# pyrefly: ignore [bad-argument-type]
282+
self.save_checkpoint, checkpoint_path=checkpoint_path
283+
)
284+
else:
285+
checkpoint_callback = None
283286

284287
# Ensure game masters are ordered Initializers first
285288
initializers = [
@@ -518,6 +521,9 @@ def set_component_dynamic_state(
518521

519522
def save_checkpoint(self, step: int, checkpoint_path: str):
520523
"""Saves the state of all entities at the current step."""
524+
if not checkpoint_path and not self._get_state_callback:
525+
return
526+
521527
checkpoint_data = self.make_checkpoint_data()
522528

523529
if self._get_state_callback:

0 commit comments

Comments
 (0)