rheon.polars.stream.load_checkpoint¶
- rheon.polars.stream.load_checkpoint(source: str | PathLike[str] | bytes) dict[str, bytes][source]¶
Read back the stages of a checkpoint
save_checkpoint()wrote.Each stage’s state comes back as the bytes it was saved as, under its name and in the order it was saved. Hand each to the stage that saved it: a bank’s to
ModelBank.load_bytes, and a window run’s or a grid’s to that call’sload_state. Each loads there as a state file of its own would, in this release and every later one.Parameters
sourceThe checkpoint’s path, or its bytes.
Returns
A
dictof each stage’s name to its state’s bytes.Raises
ValueErrorThe file is not a checkpoint (another state is named for what it is), is damaged, or was written by a newer version of rheon.
FileNotFoundErrorsourceis a path that is not there.
Examples
A grid run over the first part of a file of ticks, its state checkpointed, and the run resumed on the rest from the checkpoint’s stage:
pl.DataFrame({ "symbol": ["A", "B", "A", "B", "A", "B"], "t": [0.5, 1.0, 1.5, 2.0, 2.5, 3.0], "px": [10.0, 20.0, 10.1, 20.2, 10.2, 20.1], }).write_parquet("ticks.parquet") ticks = pl.scan_parquet("ticks.parquet") grid = {"series": "symbol", "names": ["A", "B"], "clock": "t", "value": "px"} first = rp.stream.refresh_time( ticks.filter(pl.col("t") < 2.2), **grid, save_state="grid.state" ).collect() rp.stream.save_checkpoint("run.checkpoint", {"grid": "grid.state"}) stages = rp.stream.load_checkpoint("run.checkpoint") # a new process starts here print(list(stages)) rest = rp.stream.refresh_time( ticks.filter(pl.col("t") >= 2.2), **grid, load_state=stages["grid"] ).collect() print(first["time_refresh"].to_list(), rest["time_refresh"].to_list())
['grid'] [1.0, 2.0] [3.0]