Skip to content

Commit

Permalink
Added processes commad-line param
Browse files Browse the repository at this point in the history
  • Loading branch information
QueensGambit committed Aug 5, 2024
1 parent 8b5b1d2 commit 1b05aff
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,21 @@ def sort_concat_data(data_dic: dict):
return np.concatenate(data, axis=0)


def process_chunk(chunk_id: int, chunksize: int, df_chunk: pd.DataFrame, export_dir: Path):
def process_chunk(chunk_id: int, chunksize: int, df_chunk: pd.DataFrame, export_dir: Path, processes: int):
"""
Processes a data frame chunk by exporting all chess puzzle positions in this chunk.
:param chunk_id: Unique id of the data chunk
:param chunksize: Size of each chunk
:param df_chunk: Data frame chunk
:param export_dir: Export directory where the .zip files will be stored
:param processes: Number of processes
return: None
"""

# engine = chess.engine.SimpleEngine.popen_uci(r"stockfish")

logging.info("starting conversion to planes...")
pool = Pool()
pool = Pool(processes=processes)
x_dic = {}
y_value_dic = {}
y_policy_dic = {}
Expand Down Expand Up @@ -168,6 +169,7 @@ def _export_data(chunk_id, export_dir, phase_vector_dic, plys_to_end_dic, x_dic,

parser.add_argument('--puzzle-csv-dir', type=str, default='./', help='Directory where the puzzle csv file is stored.')
parser.add_argument('--export-dir', type=str, default='./', help='Directory where the .zip files will be exported to.')
parser.add_argument('--processes', type=int, default='4', help='Number of parallel processes.')

args = parser.parse_args()

Expand Down Expand Up @@ -199,4 +201,4 @@ def _export_data(chunk_id, export_dir, phase_vector_dic, plys_to_end_dic, x_dic,
with pd.read_csv(puzzle_file_path, chunksize=chunksize) as reader:
for chunk_id, df_chunk in enumerate(reader):
print('chunk:', df_chunk)
process_chunk(chunk_id, chunksize, df_chunk, export_dir)
process_chunk(chunk_id, chunksize, df_chunk, export_dir, args.processes)

0 comments on commit 1b05aff

Please sign in to comment.