Skip to content

Commit

Permalink
LogTestExampleBuilder->self
Browse files Browse the repository at this point in the history
Created using spr 1.3.5
  • Loading branch information
mtrofin committed Feb 13, 2025
1 parent 2911977 commit c13a69c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions compiler_opt/rl/log_reader_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,27 @@ def __init__(

def write_buff(self, buffer: list, ct):
# we should get the ctypes array to bytes for pytype to be happy.
if self._introduce_error_pos == LogTestExampleBuilder.ErrorMarkers.TENSOR_BUF_POS: # pylint: disable=line-too-long
if self._introduce_error_pos == self.ErrorMarkers.TENSOR_BUF_POS:
buffer = buffer[len(buffer) // 2:]
# pytype:disable=wrong-arg-types
self._opened_file.write((ct * len(buffer))(*buffer))
# pytype:enable=wrong-arg-types

def write_newline(self, position=None):
self._opened_file.write(
LogTestExampleBuilder.error_newline if position ==
self._introduce_error_pos else LogTestExampleBuilder.newline)
self._opened_file.write(self.error_newline if position ==
self._introduce_error_pos else self.newline)

def write_context_marker(self, name: str):
self._opened_file.write(json_to_bytes({'context': name}))
self.write_newline(LogTestExampleBuilder.ErrorMarkers.CTX_MARKER_POS)
self.write_newline(self.ErrorMarkers.CTX_MARKER_POS)

def write_observation_marker(self, obs_idx: int):
self._opened_file.write(json_to_bytes({'observation': obs_idx}))
self.write_newline(LogTestExampleBuilder.ErrorMarkers.OBS_MARKER_POS)
self.write_newline(self.ErrorMarkers.OBS_MARKER_POS)

def write_outcome_marker(self, obs_idx: int):
self._opened_file.write(json_to_bytes({'outcome': obs_idx}))
self.write_newline(LogTestExampleBuilder.ErrorMarkers.OUTCOME_MARKER_POS)
self.write_newline(self.ErrorMarkers.OUTCOME_MARKER_POS)

def write_header(self, json_header: dict):
self._opened_file.write(json_to_bytes(json_header))
Expand Down

0 comments on commit c13a69c

Please sign in to comment.