Experience ID class to uniquely identify an experience. To enable the full functionality of the experience grouping, user should manually set the `run` and `step` fields in custom workflows.
| 21 | |
| 22 | @dataclass |
| 23 | class EID: |
| 24 | """Experience ID class to uniquely identify an experience. |
| 25 | |
| 26 | To enable the full functionality of the experience grouping, user should manually set the `run` and `step` fields in custom workflows. |
| 27 | """ |
| 28 | |
| 29 | # TODO: do we need to add project/name here to make it unique across different projects? |
| 30 | # Batch number, e.g., the explorer step num |
| 31 | # Automatically set by the workflow runner |
| 32 | batch: Union[int, str] = "" |
| 33 | # Task number, e.g., the task sequence in the batch, the first task in the batch has task=0 |
| 34 | # Automatically set by the workflow runner |
| 35 | task: Union[int, str] = "" |
| 36 | # Run id, e.g., the first run in the task has run=0 |
| 37 | # User should set this field in custom workflows when creating experiences |
| 38 | run: int = 0 |
| 39 | # Step number when running the task, e.g., the first step in the task has step=0 |
| 40 | # User should set this field in custom workflows when creating experiences |
| 41 | step: int = 0 |
| 42 | suffix: str = field( |
| 43 | default_factory=lambda: uuid.uuid4().hex[:6] |
| 44 | ) # Unique identifier suffix, e.g., a UUID |
| 45 | |
| 46 | @property |
| 47 | def uid(self) -> str: |
| 48 | """An unique identifier for the experience.""" |
| 49 | return f"{self.batch}/{self.task}/{self.run}/{self.step}/{self.suffix}" |
| 50 | |
| 51 | @property |
| 52 | def sid(self) -> str: |
| 53 | """Step ID of the experience. |
| 54 | |
| 55 | For example, experiences generated by all runs of a same task at the same step will have the same sid. |
| 56 | """ |
| 57 | return f"{self.batch}/{self.task}/{self.step}" |
| 58 | |
| 59 | @property |
| 60 | def rid(self) -> str: |
| 61 | """Run ID of the experience. |
| 62 | |
| 63 | For example, experiences generated by one run of a task at all steps will have the same run_id. |
| 64 | """ |
| 65 | return f"{self.batch}/{self.task}/{self.run}" |
| 66 | |
| 67 | @property |
| 68 | def tid(self) -> str: |
| 69 | """Task ID for the experience. |
| 70 | |
| 71 | For example, experiences generated by a all run of a same task in GRPO-like algorithms will have the same tid. |
| 72 | """ |
| 73 | return f"{self.batch}/{self.task}" |
| 74 | |
| 75 | def __str__(self): |
| 76 | return self.uid |
| 77 | |
| 78 | def __repr__(self): |
| 79 | return f"EID(batch={self.batch}, task={self.task}, run={self.run}, step={self.step}, uuid={self.suffix})" |
| 80 |
no outgoing calls