Recursive AI

Seek a simulation replay on a custom axis in C#

OneScope is a free, open-source viewer for simulation recordings, with a desktop window or command-line control, from Recursive AI. MIT or Apache-2.0.

A custom axis is a set of numbered stages a module defines inside a tick, separate from the tick cursor. Use CounterModule.cs and counter.replay from the zip.

Terminal
dotnet add package RecursiveAI.OneScope.Sdk

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using OneScope.Sdk;
 
var history = CounterModule
    .OpenHistory("counter.replay");
history.Seek(1);
history.Seek("stage", 1);
var stage = (CounterWorld)history.View;
long tick = history.CurrentStep;
Console.WriteLine($"Tick: {tick}");
Console.WriteLine($"Stage count: {stage.Count}");

Unzip the example, then dotnet run.

Text
Tick: 1
Stage count: 3

Program and committed state

The included counter.replay contains:

Text
COUNT 4

OpenHistory is a helper in CounterModule.cs that reads the file, calls the module’s Open method, and creates a History. The full program does those steps directly.

The example module declares new AxisInfo("stage", "Stage", 2) and adds one to the counter per stage. At tick 1, stage 1 shows the first increment of tick 2. The program also prints the committed count and then clears the stage view:

C#
using OneScope.Sdk;
 
const string path = "counter.replay";
var bytes = File.ReadAllBytes(path);
var source = new CounterModule()
    .Open(bytes, path);
var history = new History(source);
history.Seek(1);
history.Seek("stage", 1);
var stage = (CounterWorld)history.View;
long tick = history.CurrentStep;
Console.WriteLine($"Tick: {tick}");
Console.WriteLine($"Stage count: {stage.Count}");
 
Console.WriteLine($"Committed count: {((CounterWorld)history.World).Count}");
history.Seek("stage", 0);
Console.WriteLine($"Count after clearing: {((CounterWorld)history.View).Count}");
Text
Tick: 1
Stage count: 3
Committed count: 2
Count after clearing: 2

A positive stage at EndStep throws InvalidOperationException: no next tick exists to inspect.

Variations

To move from stage 1 to the next stage without changing the tick, add this after the snippet at the top:

C#
if (history.Step("stage"))
    Console.WriteLine($"Stage: {history.ViewPosition}");
Text
Stage: 2

The short answer

Seek to the tick just before the work you want to inspect, then call History.Seek(axisId, position). Read the intermediate state from History.View, not History.World. The module must declare the axis and implement how to reconstruct its intermediate stages. This is not a second time cursor.

How do you inspect an intermediate stage of a simulation step?

Give the module’s axis a stable ID and define how many positions it has. The example declares two positions on stage. It starts at the committed count of 2 after tick 1, then shows a count of 3 at position 1 of the next tick. This works because AdvanceAxis applies the requested stage to a scratch world restored from the committed state. Position 2 shows the second increment but still leaves the time cursor at tick 1. To actually reach tick 2, seek on the time axis.

Use position 0 to discard the intermediate view. History.CurrentStep and History.StateHash refer to the committed state even while a stage is visible, so neither tells you which stage you are looking at. Use ViewAxis and ViewPosition for those labels. Custom axis positions are integer indexes declared by the module, not percentages or arbitrary times; if a format does not expose stages, calling Seek with a new axis name cannot create them. For a solver that does expose iterations, the same pattern lets you inspect how a value changes inside one tick without changing the world at that tick.

All onescope recipes