Skip to content

Commit

Permalink
End-to-end tagging for everything Python
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Dec 4, 2024
1 parent 470cbd3 commit a59280a
Show file tree
Hide file tree
Showing 145 changed files with 579 additions and 252 deletions.
5 changes: 3 additions & 2 deletions crates/build/re_types_builder/src/codegen/python/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ impl PythonCodeGenerator {
Archetype,
BaseBatch,
ComponentBatchMixin,
ComponentDescriptor,
ComponentMixin,
)
from {rerun_path}_converters import (
Expand Down Expand Up @@ -1926,7 +1927,7 @@ fn quote_arrow_support_from_obj(
r#"
class {extension_batch}{batch_superclass_decl}:
_ARROW_DATATYPE = {datatype}
_COMPONENT_NAME: str = "{fqname}"
_COMPONENT_DESCRIPTOR: ComponentDescriptor = ComponentDescriptor("{fqname}")
@staticmethod
def _native_to_pa_array(data: {many_aliases}, data_type: pa.DataType) -> pa.Array:
Expand All @@ -1939,7 +1940,7 @@ fn quote_arrow_support_from_obj(
unindent(&format!(
r#"
class {extension_batch}{batch_superclass_decl}:
_COMPONENT_NAME: str = "{fqname}"
_COMPONENT_DESCRIPTOR: ComponentDescriptor = ComponentDescriptor("{fqname}")
"#
))
}
Expand Down
18 changes: 1 addition & 17 deletions crates/store/re_chunk/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,7 @@ impl Chunk {
.collect();
timelines == rhs_timelines
}
// TODO(cmc): we cannot compare tags yet, need to support Python & C++ first
// && *components == rhs.components
&& {
let lhs_components_no_tags: ChunkComponents = components
.clone()
.into_iter_flattened()
.map(|(descr, list_array)| (ComponentDescriptor::new(descr.component_name), list_array))
.collect();
let rhs_components_no_tags: ChunkComponents = rhs
.components
.clone()
.into_iter_flattened()
.map(|(descr, list_array)| (ComponentDescriptor::new(descr.component_name), list_array))
.collect();

lhs_components_no_tags == rhs_components_no_tags
}
&& *components == rhs.components
}

/// Check for equality while ignoring possible `Extension` type information
Expand Down
42 changes: 27 additions & 15 deletions crates/top/rerun/src/commands/rrd/print.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Context;
use itertools::Itertools as _;
use itertools::Itertools;

use re_log_types::{LogMsg, SetStoreInfo};
use re_sdk::log::Chunk;
Expand All @@ -15,8 +15,10 @@ pub struct PrintCommand {
path_to_input_rrds: Vec<String>,

/// If set, print out table contents.
#[clap(long, short, default_value_t = false)]
verbose: bool,
///
/// This can be specified more than once to toggle more and more verbose levels (e.g. -vvv).
#[clap(long, short, action = clap::ArgAction::Count)]
verbose: u8,

/// If set, will try to proceed even in the face of IO and/or decoding errors in the input data.
#[clap(long = "continue-on-error", default_value_t = true)]
Expand Down Expand Up @@ -63,7 +65,7 @@ impl PrintCommand {
}
}

fn print_msg(verbose: bool, msg: LogMsg) -> anyhow::Result<()> {
fn print_msg(verbose: u8, msg: LogMsg) -> anyhow::Result<()> {
match msg {
LogMsg::SetStoreInfo(msg) => {
let SetStoreInfo { row_id: _, info } = msg;
Expand All @@ -73,21 +75,31 @@ fn print_msg(verbose: bool, msg: LogMsg) -> anyhow::Result<()> {
LogMsg::ArrowMsg(_row_id, arrow_msg) => {
let chunk = Chunk::from_arrow_msg(&arrow_msg).context("skipped corrupt chunk")?;

if verbose {
println!("{chunk}");
} else {
print!(
"Chunk({}) with {} rows ({}) - {:?} - ",
chunk.id(),
chunk.num_rows(),
re_format::format_bytes(chunk.total_size_bytes() as _),
chunk.entity_path(),
);

if verbose == 0 {
let column_names = chunk
.component_names()
.map(|name| name.short_name())
.join(" ");

println!(
"Chunk({}) with {} rows ({}) - {:?} - columns: [{column_names}]",
chunk.id(),
chunk.num_rows(),
re_format::format_bytes(chunk.total_size_bytes() as _),
chunk.entity_path(),
);
println!("columns: [{column_names}]");
} else if verbose == 1 {
let column_descriptors = chunk
.component_descriptors()
.map(|descr| descr.short_name())
.collect_vec()
.join(" ");
println!("columns: [{column_descriptors}]",);
} else if verbose == 2 {
println!("\n{}", chunk.emptied()); // headers only
} else {
println!("\n{chunk}");
}
}

Expand Down
12 changes: 12 additions & 0 deletions docs/snippets/all/descriptors/descr_builtin_archetype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python3

from __future__ import annotations

import rerun as rr # pip install rerun-sdk

rr.init("rerun_example_descriptors_builtin_archetype")
rr.spawn()

rr.log("data", rr.Points3D([[1, 2, 3]], radii=[0.3, 0.2, 0.1]), static=True)

# The tags are indirectly checked by the Rust version (have a look over there for more info).
12 changes: 12 additions & 0 deletions docs/snippets/all/descriptors/descr_builtin_component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python3

from __future__ import annotations

import rerun as rr # pip install rerun-sdk

rr.init("rerun_example_descriptors_builtin_component")
rr.spawn()

rr.log("data", [rr.components.Position3DBatch([1, 2, 3])], static=True)

# The tags are indirectly checked by the Rust version (have a look over there for more info).
46 changes: 46 additions & 0 deletions docs/snippets/all/descriptors/descr_custom_archetype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3

from __future__ import annotations

from typing import Any, Iterable

import numpy.typing as npt
import pyarrow as pa
import rerun as rr # pip install rerun-sdk


class CustomPosition3DBatch(rr.ComponentBatchLike):
def __init__(self: Any, position: rr.components.Position3DBatch) -> None:
self.position = position

def component_descriptor(self) -> rr.ComponentDescriptor:
return rr.ComponentDescriptor(
"user.CustomPosition3D",
archetype_name="user.CustomArchetype",
archetype_field_name="user.CustomArchetypeField",
)

def as_arrow_array(self) -> pa.Array:
return self.position.as_arrow_array()


class CustomPoints3D(rr.AsComponents):
def __init__(self: Any, positions: npt.ArrayLike, colors: npt.ArrayLike) -> None:
self.positions = positions
self.colors = colors

def as_component_batches(self) -> Iterable[rr.ComponentBatchLike]:
return (
[rr.IndicatorComponentBatch("user.CustomArchetype")]
+ [CustomPosition3DBatch(rr.components.Position3DBatch(self.positions))]
+ [rr.components.ColorBatch(self.colors)]
)


rr.init("rerun_example_descriptors_custom_archetype")
rr.spawn()

position = CustomPosition3DBatch(rr.components.Position3DBatch([1, 2, 3]))
rr.log("data", [position], static=True)

# The tags are indirectly checked by the Rust version (have a look over there for more info).
32 changes: 32 additions & 0 deletions docs/snippets/all/descriptors/descr_custom_component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

from __future__ import annotations

from typing import Any

import pyarrow as pa
import rerun as rr # pip install rerun-sdk


class CustomPosition3DBatch(rr.ComponentBatchLike):
def __init__(self: Any, position: rr.components.Position3DBatch) -> None:
self.position = position

def component_descriptor(self) -> rr.ComponentDescriptor:
return rr.ComponentDescriptor(
"user.CustomPosition3D",
archetype_name="user.CustomArchetype",
archetype_field_name="user.CustomArchetypeField",
)

def as_arrow_array(self) -> pa.Array:
return self.position.as_arrow_array()


rr.init("rerun_example_descriptors_custom_component")
rr.spawn()

position = CustomPosition3DBatch(rr.components.Position3DBatch([1, 2, 3]))
rr.log("data", [position], static=True)

# The tags are indirectly checked by the Rust version (have a look over there for more info).
4 changes: 2 additions & 2 deletions docs/snippets/all/howto/any_batch_value_send_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
times=[rr.TimeSequenceColumn("step", timestamps)],
components=[
# log one value per timestamp
rr.AnyBatchValue("custom_component_single", one_per_timestamp),
rr.AnyBatchValue(rr.ComponentDescriptor("custom_component_single"), one_per_timestamp),
# log ten values per timestamp
rr.AnyBatchValue("custom_component_multi", ten_per_timestamp).partition([10] * N),
rr.AnyBatchValue(rr.ComponentDescriptor("custom_component_multi"), ten_per_timestamp).partition([10] * N),
],
)
6 changes: 3 additions & 3 deletions docs/snippets/all/tutorials/custom_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class ConfidenceBatch(rr.ComponentBatchLike):
def __init__(self: Any, confidence: npt.ArrayLike) -> None:
self.confidence = confidence

def component_name(self) -> str:
"""The name of the custom component."""
return "user.Confidence"
def component_descriptor(self) -> rr.ComponentDescriptor:
"""The descriptor of the custom component."""
return rr.ComponentDescriptor("user.Confidence")

def as_arrow_array(self) -> pa.Array:
"""The arrow batch representing the custom component."""
Expand Down
15 changes: 1 addition & 14 deletions docs/snippets/snippets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,10 @@
"cpp",
"rust",
]
"descriptors/descr_builtin_archetype" = [ # Python and C++ not yet supported (next PRs)
"py",
]
"descriptors/descr_builtin_component" = [ # Python and C++ not yet supported (next PRs)
"py",
]
"descriptors/descr_custom_archetype" = [ # Python and C++ not yet supported (next PRs)
"py",
]
"descriptors/descr_custom_component" = [ # Python and C++ not yet supported (next PRs)
"py",
]
views = [
"views" = [
"cpp", # TODO(#5520): C++ views are not yet implemented
"rust", # TODO(#5521): Rust views are not yet implemented
]

"archetypes/image_advanced" = [
"cpp", # Missing examples
"rust", # Missing examples
Expand Down
3 changes: 2 additions & 1 deletion examples/cpp/dna/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ static constexpr size_t NUM_POINTS = 100;

int main() {
const auto rec = rerun::RecordingStream("rerun_example_dna_abacus");
rec.spawn().exit_on_failure();
// rec.spawn().exit_on_failure();
rec.save("/tmp/dna.rrd").exit_on_failure();

std::vector<rerun::Position3D> points1, points2;
std::vector<rerun::Color> colors1, colors2;
Expand Down
4 changes: 1 addition & 3 deletions rerun_py/rerun_sdk/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
notebook as notebook,
remote as remote,
)
from ._baseclasses import (
ComponentColumn as ComponentColumn,
)
from ._baseclasses import ComponentColumn as ComponentColumn, ComponentDescriptor as ComponentDescriptor
from ._image_encoded import (
ImageEncoded as ImageEncoded,
ImageFormat as ImageFormat,
Expand Down
Loading

0 comments on commit a59280a

Please sign in to comment.