-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
End-to-end cross-language roundtrip tests for our archetypes (#2601)
With this PR, the CI will now compare the results of logging our archetypes across all of our SDKs. You can run it locally with: ``` ./scripts/ci/run_e2e_roundtrip_tests.py --no-build ``` E.g.: ![image](https://github.com/rerun-io/rerun/assets/2910679/38f1541e-20ef-4ebd-8d55-ee6215fefd3c) Requires #2597 Fixes #2383 Fixes #2384 Fixes #2386 --- ### 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 [demo.rerun.io](https://demo.rerun.io/pr/2601) (if applicable) - [PR Build Summary](https://build.rerun.io/pr/2601) - [Docs preview](https://rerun.io/preview/pr%3Acmc%2Fend_to_end_roundtrips_ci/docs) - [Examples preview](https://rerun.io/preview/pr%3Acmc%2Fend_to_end_roundtrips_ci/examples)
- Loading branch information
Showing
10 changed files
with
249 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ screenshot*.png | |
web_demo | ||
|
||
.nox/ | ||
out.rrd |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Run our end-to-end cross-language roundtrip tests for all SDKs. | ||
The list of archetypes is read directly from `crates/re_types/definitions/rerun/archetypes`. | ||
If you create a new archetype definition without end-to-end tests, this will fail. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import argparse | ||
import os | ||
import subprocess | ||
import sys | ||
import time | ||
from os import listdir | ||
from os.path import isfile, join | ||
|
||
ARCHETYPES_PATH = "crates/re_types/definitions/rerun/archetypes" | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser(description="Run our end-to-end cross-language roundtrip tests for all SDK") | ||
parser.add_argument("--no-build", action="store_true", help="Skip building rerun-sdk") | ||
parser.add_argument("--release", action="store_true", help="Run cargo invocations with --release") | ||
parser.add_argument("--target", type=str, default=None, help="Target used for cargo invocations") | ||
parser.add_argument("--target-dir", type=str, default=None, help="Target directory used for cargo invocations") | ||
|
||
args = parser.parse_args() | ||
|
||
if args.no_build: | ||
print("Skipping building rerun-sdk - assuming it is already built and up-to-date!") | ||
else: | ||
build_env = os.environ.copy() | ||
if "RUST_LOG" in build_env: | ||
del build_env["RUST_LOG"] # The user likely only meant it for the actual tests; not the setup | ||
|
||
print("----------------------------------------------------------") | ||
print("Building rerun-sdk…") | ||
start_time = time.time() | ||
subprocess.Popen(["just", "py-build"], env=build_env).wait() | ||
elapsed = time.time() - start_time | ||
print(f"rerun-sdk built in {elapsed:.1f} seconds") | ||
print("") | ||
|
||
files = [f for f in listdir(ARCHETYPES_PATH) if isfile(join(ARCHETYPES_PATH, f))] | ||
archetypes = [filename for filename, extension in [os.path.splitext(file) for file in files] if extension == ".fbs"] | ||
|
||
for arch in archetypes: | ||
python_output_path = run_roundtrip_python(arch) | ||
rust_output_path = run_roundtrip_rust(arch, args.release, args.target, args.target_dir) | ||
run_comparison(python_output_path, rust_output_path) | ||
|
||
|
||
def run_roundtrip_python(arch: str) -> str: | ||
main_path = f"tests/python/roundtrips/{arch}/main.py" | ||
output_path = f"tests/python/roundtrips/{arch}/out.rrd" | ||
|
||
# sys.executable: the absolute path of the executable binary for the Python interpreter | ||
python_executable = sys.executable | ||
if python_executable is None: | ||
python_executable = "python3" | ||
|
||
cmd = [python_executable, main_path, "--save", output_path] | ||
print(cmd) | ||
roundtrip_process = subprocess.Popen(cmd) | ||
returncode = roundtrip_process.wait(timeout=30) | ||
assert returncode == 0, f"python roundtrip process exited with error code {returncode}" | ||
|
||
return output_path | ||
|
||
|
||
def run_roundtrip_rust(arch: str, release: bool, target: str | None, target_dir: str | None) -> str: | ||
project_name = f"roundtrip_{arch}" | ||
output_path = f"tests/rust/roundtrips/{arch}/out.rrd" | ||
|
||
cmd = ["cargo", "r", "-p", project_name] | ||
|
||
if target is not None: | ||
cmd += ["--target", target] | ||
|
||
if target_dir is not None: | ||
cmd += ["--target-dir", target_dir] | ||
|
||
if release: | ||
cmd += ["--release"] | ||
|
||
cmd += ["--", "--save", output_path] | ||
|
||
print(cmd) | ||
roundtrip_process = subprocess.Popen(cmd) | ||
returncode = roundtrip_process.wait(timeout=12000) | ||
assert returncode == 0, f"rust roundtrip process exited with error code {returncode}" | ||
|
||
return output_path | ||
|
||
|
||
def run_comparison(python_output_path: str, rust_output_path: str): | ||
cmd = ["rerun", "compare", python_output_path, rust_output_path] | ||
print(cmd) | ||
roundtrip_process = subprocess.Popen(cmd) | ||
returncode = roundtrip_process.wait(timeout=30) | ||
assert returncode == 0, f"comparison process exited with error code {returncode}" | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Logs a `Points2D` archetype for roundtrip checks.""" | ||
|
||
#!/usr/bin/env python3 | ||
|
||
from __future__ import annotations | ||
|
||
import argparse | ||
|
||
import numpy as np | ||
import rerun as rr | ||
|
||
|
||
def main() -> None: | ||
points = np.array([1, 2, 3, 4], dtype=np.float32) | ||
radii = np.array([0.42, 0.43], dtype=np.float32) | ||
colors = np.array( | ||
[ | ||
0xAA0000CC, | ||
0x00BB00DD, | ||
], | ||
dtype=np.uint32, | ||
) | ||
labels = ["hello", "friend"] | ||
draw_order = 300 | ||
class_ids = np.array([126, 127], dtype=np.uint64) | ||
keypoint_ids = np.array([2, 3], dtype=np.uint64) | ||
instance_keys = np.array([66, 666], dtype=np.uint64) | ||
|
||
points2d = rr.Points2D( | ||
points, | ||
radii=radii, | ||
colors=colors, | ||
labels=labels, | ||
draw_order=draw_order, | ||
class_ids=class_ids, | ||
keypoint_ids=keypoint_ids, | ||
instance_keys=instance_keys, | ||
) | ||
|
||
parser = argparse.ArgumentParser(description="Logs rich data using the Rerun SDK.") | ||
rr.script_add_args(parser) | ||
args = parser.parse_args() | ||
|
||
rr.script_setup(args, "roundtrip_points2d") | ||
|
||
rr.log_any("points2d", points2d) | ||
# Hack to establish 2d view bounds | ||
rr.log_rect("rect", [0, 0, 4, 6]) | ||
|
||
rr.script_teardown(args) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "roundtrip_points2d" | ||
edition.workspace = true | ||
license.workspace = true | ||
publish = false | ||
rust-version.workspace = true | ||
version.workspace = true | ||
|
||
[dependencies] | ||
rerun = { path = "../../../../crates/rerun", features = ["native_viewer"] } | ||
|
||
anyhow = "1.0" | ||
clap = { version = "4.0", features = ["derive"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//! Logs a `Points2D` archetype for roundtrip checks. | ||
|
||
use rerun::{ | ||
components::Rect2D, experimental::archetypes::Points2D, external::re_log, MsgSender, | ||
RecordingStream, | ||
}; | ||
|
||
#[derive(Debug, clap::Parser)] | ||
#[clap(author, version, about)] | ||
struct Args { | ||
#[command(flatten)] | ||
rerun: rerun::clap::RerunArgs, | ||
} | ||
|
||
fn run(rec_stream: &RecordingStream, _args: &Args) -> anyhow::Result<()> { | ||
MsgSender::from_archetype( | ||
"points2d", | ||
&Points2D::new([(1.0, 2.0), (3.0, 4.0)]) | ||
.with_radii([0.42, 0.43]) | ||
.with_colors([0xAA0000CC, 0x00BB00DD]) | ||
.with_labels(["hello", "friend"]) | ||
.with_draw_order(300.0) | ||
.with_class_ids([126, 127]) | ||
.with_keypoint_ids([2, 3]) | ||
.with_instance_keys([66, 666]), | ||
)? | ||
.send(rec_stream)?; | ||
|
||
// Hack to establish 2d view bounds | ||
MsgSender::new("rect") | ||
.with_component(&[Rect2D::from_xywh(0.0, 0.0, 4.0, 6.0)])? | ||
.send(rec_stream)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() -> anyhow::Result<()> { | ||
re_log::setup_native_logging(); | ||
|
||
use clap::Parser as _; | ||
let args = Args::parse(); | ||
|
||
let default_enabled = true; | ||
args.rerun | ||
.clone() | ||
.run("roundtrip_points2d", default_enabled, move |rec_stream| { | ||
run(&rec_stream, &args).unwrap(); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4360deb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.25
.datastore/num_rows=1000/num_instances=1000/packed=false/latest_at/default
400
ns/iter (± 2
)310
ns/iter (± 1
)1.29
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/primary/default
296
ns/iter (± 0
)226
ns/iter (± 4
)1.31
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/secondaries/default
452
ns/iter (± 0
)337
ns/iter (± 0
)1.34
datastore/num_rows=1000/num_instances=1000/gc/default
2670174
ns/iter (± 17361
)1737052
ns/iter (± 22249
)1.54
mono_points_arrow/encode_log_msg
232509405
ns/iter (± 1558845
)180851932
ns/iter (± 1455612
)1.29
mono_points_arrow_batched/generate_messages
5284593
ns/iter (± 130226
)3595567
ns/iter (± 160426
)1.47
mono_points_arrow_batched/encode_log_msg
644501
ns/iter (± 5660
)514725
ns/iter (± 2301
)1.25
arrow_mono_points/insert
2974611045
ns/iter (± 11845596
)1784116029
ns/iter (± 10778167
)1.67
arrow_mono_points/query
1314034
ns/iter (± 15343
)960249
ns/iter (± 5412
)1.37
This comment was automatically generated by workflow using github-action-benchmark.