Skip to content

Commit

Permalink
Support blueprint with init
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Mar 7, 2024
1 parent fdd13ef commit 50d6106
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
23 changes: 6 additions & 17 deletions rerun_py/rerun_sdk/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ def init(
init_logging: bool = True,
default_enabled: bool = True,
strict: bool = False,
exp_init_blueprint: bool = False,
exp_add_to_app_default_blueprint: bool = True,
blueprint: MemoryRecording | None = None,
) -> None:
"""
Initialize the Rerun SDK with a user-chosen application id (name).
Expand Down Expand Up @@ -316,12 +315,12 @@ def init(
strict
If `True`, an exceptions is raised on use error (wrong parameter types, etc.).
If `False`, errors are logged as warnings instead.
exp_init_blueprint
(Experimental) Should we initialize the blueprint for this application?
exp_add_to_app_default_blueprint
(Experimental) Should the blueprint append to the existing app-default blueprint instead of creating a new one.
blueprint: Optional[MemoryRecording]
A blueprint to use for this application. If not provided, a new one will be created.
"""
# TODO(jleibs): MemoryRecording here should just be the direct blueprint object with a helper function
# to convert it to the MemoryRecording object in place right here.

if application_id.startswith("rerun_example_"):
# Make all our example code deterministic.
Expand All @@ -346,21 +345,11 @@ def init(
spawn=False,
default_enabled=default_enabled,
)
if exp_init_blueprint:
experimental.new_blueprint(
application_id=application_id,
blueprint_id=recording_id,
make_default=True,
make_thread_default=False,
spawn=False,
add_to_app_default_blueprint=exp_add_to_app_default_blueprint,
default_enabled=default_enabled,
)

if spawn:
from rerun.sinks import spawn as _spawn

_spawn()
_spawn(blueprint=blueprint)


# TODO(#3793): defaulting recording_id to authkey should be opt-in
Expand Down
9 changes: 7 additions & 2 deletions rerun_py/rerun_sdk/rerun/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def connect(
addr: str | None = None,
*,
flush_timeout_sec: float | None = 2.0,
blueprint: MemoryRecording | None,
blueprint: MemoryRecording | None = None,
recording: RecordingStream | None = None,
) -> None:
"""
Expand Down Expand Up @@ -216,6 +216,7 @@ def spawn(
port: int = 9876,
connect: bool = True,
memory_limit: str = "75%",
blueprint: MemoryRecording | None = None,
recording: RecordingStream | None = None,
) -> None:
"""
Expand All @@ -240,8 +241,12 @@ def spawn(
Specifies the [`rerun.RecordingStream`][] to use if `connect = True`.
If left unspecified, defaults to the current active data recording, if there is one.
See also: [`rerun.init`][], [`rerun.set_global_data_recording`][].
blueprint: MemoryRecording
A memory recording of a blueprint.
"""
# TODO(jleibs): MemoryRecording here should just be the direct blueprint object with a helper function
# to convert it to the MemoryRecording object in place right here.

if not bindings.is_enabled():
logging.warning("Rerun is disabled - spawn() call ignored.")
Expand Down Expand Up @@ -298,4 +303,4 @@ def spawn(
sleep(0.1)

if connect:
_connect(f"127.0.0.1:{port}", recording=recording)
_connect(f"127.0.0.1:{port}", recording=recording, blueprint=blueprint)
16 changes: 9 additions & 7 deletions tests/python/blueprint/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def log(self, stream):
rr.log(self.path(), bp, recording=stream)

def to_blueprint(self):
stream = rr.experimental.new_blueprint("rerun_example_blueprint_test", blueprint_id="TEST_BLUEPRINT")
stream = rr.experimental.new_blueprint("rerun_example_blueprint_test")
stream_native = stream.to_native()

rr.set_time_seconds("blueprint", 1, recording=stream)
Expand All @@ -125,11 +125,6 @@ def to_blueprint(self):
colors = rng.uniform(0, 255, size=[10, 3])
radii = rng.uniform(0, 1, size=[10])

rr.init("rerun_example_blueprint_test")

rr.log("test1", rr.Points3D(positions, colors=colors, radii=radii))
rr.log("test2", rr.Points2D(positions[:, :2], colors=colors, radii=radii))

root = Vertical(
Spatial3D(origin="/test1"),
Horizontal(
Expand All @@ -142,4 +137,11 @@ def to_blueprint(self):
)
viewport = Viewport(root)

rr.connect(blueprint=viewport.to_blueprint())
rr.init(
"rerun_example_blueprint_test",
spawn=True,
blueprint=viewport.to_blueprint(),
)

rr.log("test1", rr.Points3D(positions, colors=colors, radii=radii))
rr.log("test2", rr.Points2D(positions[:, :2], colors=colors, radii=radii))

0 comments on commit 50d6106

Please sign in to comment.