Skip to content

Commit

Permalink
MVP Blueprint APIs for layout and contents (#5408)
Browse files Browse the repository at this point in the history
### What
- Remove the old experimental blueprint flags from init
- Introduces a new file `rerun_py/rerun_sdk/rerun/blueprint/api.py`
which defines the beginning of an API surface
- Create declarative-object-helpers for Viewport, Container, and
SpaceView
- These follow a pattern of recursively logging their content +
themselves to a stream.
- Introduce a new mechanism for optionally sending a blueprint on
connect. This is sent inline on the sink before setting up the reset of
the stream.
  - On the rust side we just take an optional `Vec<LogMsg>`
- On the python side we use the MemorySink as a convenient mechanism of
logging to the stream APIs and then re-extracting the data as messages.
- Fix some assorted errors:
  -  space_views should have been optional
  - stream.log apparently never worked
 
### Known issues:
 - There are several fields that we still need to plumb through.
 - The old blueprint example is broken.

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using newly built examples:
[app.rerun.io](https://app.rerun.io/pr/5408/index.html)
* Using examples from latest `main` build:
[app.rerun.io](https://app.rerun.io/pr/5408/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[app.rerun.io](https://app.rerun.io/pr/5408/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/5408)
- [Docs
preview](https://rerun.io/preview/9a4aff23ac532eb7bf08cf6aa6cf3d9ce6d8bfd9/docs)
<!--DOCS-PREVIEW-->
- [Examples
preview](https://rerun.io/preview/9a4aff23ac532eb7bf08cf6aa6cf3d9ce6d8bfd9/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
  • Loading branch information
jleibs authored Mar 12, 2024
1 parent 1d6274a commit 6275a33
Show file tree
Hide file tree
Showing 17 changed files with 560 additions and 85 deletions.
20 changes: 17 additions & 3 deletions crates/re_sdk/src/recording_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,11 @@ impl RecordingStream {
/// terms of data durability and ordering.
/// See [`Self::set_sink`] for more information.
pub fn connect(&self) {
self.connect_opts(crate::default_server_addr(), crate::default_flush_timeout());
self.connect_opts(
crate::default_server_addr(),
crate::default_flush_timeout(),
None,
);
}

/// Swaps the underlying sink for a [`crate::log_sink::TcpSink`] sink pre-configured to use
Expand All @@ -1539,13 +1543,23 @@ impl RecordingStream {
&self,
addr: std::net::SocketAddr,
flush_timeout: Option<std::time::Duration>,
blueprint: Option<Vec<LogMsg>>,
) {
if forced_sink_path().is_some() {
re_log::debug!("Ignored setting new TcpSink since _RERUN_FORCE_SINK is set");
return;
}

self.set_sink(Box::new(crate::log_sink::TcpSink::new(addr, flush_timeout)));
let sink = crate::log_sink::TcpSink::new(addr, flush_timeout);

// If a blueprint was provided, send it first.
if let Some(blueprint) = blueprint {
for msg in blueprint {
sink.send(msg);
}
}

self.set_sink(Box::new(sink));
}

/// Spawns a new Rerun Viewer process from an executable available in PATH, then swaps the
Expand Down Expand Up @@ -1598,7 +1612,7 @@ impl RecordingStream {

spawn(opts)?;

self.connect_opts(opts.connect_addr(), flush_timeout);
self.connect_opts(opts.connect_addr(), flush_timeout, None);

Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ table ViewportBlueprint (
) {
// --- Required ---

/// All of the space-views that belong to the viewport.
space_views: [rerun.blueprint.components.IncludedSpaceView] ("attr.rerun.component_required", order: 1000);

// --- Optional ---
/// All of the space-views that belong to the viewport.
space_views: [rerun.blueprint.components.IncludedSpaceView] ("attr.rerun.component_optional", nullable, order: 1000);

/// The layout of the space-views
root_container: rerun.blueprint.components.RootContainer ("attr.rerun.component_optional", nullable, order: 2500);
Expand Down
62 changes: 37 additions & 25 deletions crates/re_viewport/src/blueprint/archetypes/viewport_blueprint.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions crates/re_viewport/src/viewport_blueprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ impl ViewportBlueprint {
}
};

let space_view_ids: Vec<SpaceViewId> =
space_views.into_iter().map(|id| id.0.into()).collect();
let space_view_ids: Vec<SpaceViewId> = space_views
.unwrap_or(vec![])
.iter()
.map(|id| id.0.into())
.collect();

let space_views: BTreeMap<SpaceViewId, SpaceViewBlueprint> = space_view_ids
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion crates/rerun_c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ fn rr_recording_stream_connect_impl(
} else {
None
};
stream.connect_opts(tcp_addr, flush_timeout);
stream.connect_opts(tcp_addr, flush_timeout, None);

Ok(())
}
Expand Down
5 changes: 1 addition & 4 deletions examples/python/blueprint/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
"""Example of using the blueprint APIs to configure Rerun."""
# TODO(jleibs): Update this example to use the new APIs
from __future__ import annotations

import argparse
Expand All @@ -26,15 +27,11 @@ def main() -> None:
rr.init(
"Blueprint demo",
init_logging=False,
exp_init_blueprint=not args.skip_blueprint,
exp_add_to_app_default_blueprint=args.no_append_default,
spawn=True,
)
else:
rr.init(
"Blueprint demo",
exp_init_blueprint=not args.skip_blueprint,
exp_add_to_app_default_blueprint=args.no_append_default,
spawn=True,
)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions rerun_cpp/src/rerun/blueprint/archetypes/viewport_blueprint.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 @@ -142,6 +142,7 @@
ViewCoordinates,
)
from .archetypes.boxes2d_ext import Box2DFormat
from .blueprint.api import BlueprintLike
from .components import (
Material,
MediaType,
Expand Down Expand Up @@ -230,6 +231,7 @@ def _init_recording_stream() -> None:
set_time_nanos,
disable_timeline,
reset_time,
log,
]
+ [fn for name, fn in getmembers(sys.modules[__name__], isfunction) if name.startswith("log_")]
)
Expand All @@ -247,8 +249,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: BlueprintLike | None = None,
) -> None:
"""
Initialize the Rerun SDK with a user-chosen application id (name).
Expand Down Expand Up @@ -316,10 +317,8 @@ 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
A blueprint to use for this application. If not provided, a new one will be created.
"""

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
3 changes: 3 additions & 0 deletions rerun_py/rerun_sdk/rerun/_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ def log_components(
if None, use the global default from `rerun.strict_mode()`
"""
# Convert to a native recording
recording = RecordingStream.to_native(recording)

instanced: dict[str, pa.Array] = {}
splats: dict[str, pa.Array] = {}

Expand Down
15 changes: 14 additions & 1 deletion rerun_py/rerun_sdk/rerun/blueprint/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6275a33

Please sign in to comment.