Skip to content

Archetype based overrides & defaults #9209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Mar 10, 2025
Merged

Conversation

Wumpf
Copy link
Member

@Wumpf Wumpf commented Mar 6, 2025

Related

What

Defaults and overrides can now be set using archetypes. This not only leads to a much more ergonomic API with working auto-complete for archetype fields, but also paves the way for handling tagging in blueprint overrides/defaults which in the future will allow more fine grained defaults/overrides using the archetype "context information".

Examples

Setting default & override for radius

Before:

rrb.Spatial2DView(
    name="Rect 1",
    origin="/",
    contents=["/**"],
    defaults=[rr.components.Radius(2)],
    overrides={"rect/0": [rr.components.Radius(1)]},
)

After:

rrb.Spatial2DView(
    name="Rect 1",
    origin="/",
    contents=["/**"],
    defaults=[rr.Boxes2D.from_fields(radii=1)],
    overrides={"rect/0": rr.Boxes2D.from_fields(radii=2)},
)

Setting up styles for a plot.

Before:

rrb.TimeSeriesView(
    name="Trig",
    origin="/trig",
    overrides={
        "/trig/sin": [rr.components.Color([255, 0, 0]), rr.components.Name("sin(0.01t)")],
        "/trig/cos": [rr.components.Color([0, 255, 0]), rr.components.Name("cos(0.01t)")],
    },
),
rrb.TimeSeriesView(
    name="Classification",
    origin="/classification",
    overrides={
        "classification/line": [rr.components.Color([255, 255, 0]), rr.components.StrokeWidth(3.0)],
        "classification/samples": [rrb.VisualizerOverrides("SeriesPoint")], # This ensures that the `SeriesPoint` visualizers is used for this entity.
    },
),

After:

rrb.TimeSeriesView(
    name="Trig",
    origin="/trig",
    overrides={
        "/trig/sin": rr.SeriesLine.from_fields(color=[255, 0, 0], name="sin(0.01t)"),
        "/trig/cos": rr.SeriesLine.from_fields(color=[0, 255, 0], name="cos(0.01t)"),
    },
),
rrb.TimeSeriesView(
    name="Classification",
    origin="/classification",
    overrides={
        "classification/line": rr.SeriesLine.from_fields(color=[255, 255, 0], width=3.0),
        "classification/samples": rrb.VisualizerOverrides("SeriesPoint"), # This ensures that the `SeriesPoint` visualizers is used for this entity.
    },
),

Technical notes on corner cases

There's two special cases that were loose component so far:

  • VisualizerOverrides
    • the former component becomes an archetype with a list of VisualizerOverride components each being a rerun.datatypes.Utf8. rerun.datatypes.Utf8List which was previously used goes away
  • VisualTimeRange
    • we already have an archetype for this, it's called VisualTimeRanges. There's a bit of an ergonomic issue with this since VisualTimeRanges has to be constructed from one or more VisualTimeRange. But decided to enforce the archetype here. To avoid accidentally using the component instead of the datatype with the same name, I moved the component out and the datatype in to the rrb namespace

  • go through override/default docs & associated snippets

@Wumpf Wumpf force-pushed the andreas/archetype-driven-overrides branch from 2e8b494 to 24490ea Compare March 6, 2025 10:59
Copy link

github-actions bot commented Mar 6, 2025

Web viewer built successfully. If applicable, you should also test it:

  • I have tested the web viewer
Result Commit Link Manifest
ce585be https://rerun.io/viewer/pr/9209 +nightly +main

Note: This comment is updated whenever you push a commit.

Copy link

github-actions bot commented Mar 6, 2025

Latest documentation preview deployed successfully.

Result Commit Link
ce585be https://landing-o1ka242ud-rerun.vercel.app/docs

Note: This comment is updated whenever you push a commit.

@Wumpf Wumpf added the 🐍 Python API Python logging API label Mar 7, 2025
@Wumpf Wumpf marked this pull request as ready for review March 7, 2025 15:22
@Wumpf Wumpf marked this pull request as draft March 7, 2025 15:25
@Wumpf
Copy link
Member Author

Wumpf commented Mar 7, 2025

back to draft: Really unhappy with how I handled VisualTimeRange. It's mega confusing imho

(Edit: Fixed, see updated description)

@Wumpf Wumpf force-pushed the andreas/archetype-driven-overrides branch from a0c7254 to b66ff13 Compare March 7, 2025 16:40
@Wumpf Wumpf requested review from abey79 and oxkitsune March 7, 2025 16:44
@Wumpf Wumpf marked this pull request as ready for review March 7, 2025 16:45
Copy link
Member

@abey79 abey79 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff!

@Wumpf Wumpf merged commit 38a760b into main Mar 10, 2025
42 checks passed
@Wumpf Wumpf deleted the andreas/archetype-driven-overrides branch March 10, 2025 22:07
Wumpf pushed a commit that referenced this pull request Mar 11, 2025
…coverage (#9257)

### Related

* Improves on #9209 

### What

This PR improves the signatures of the `View` python class (and
subclasses), and adds `tests/python` in the coverage of `mypy`.
jprochazk pushed a commit that referenced this pull request Mar 11, 2025
### Related

* Fixes #9059

### What

Defaults and overrides can now be set using archetypes. This not only
leads to a much more ergonomic API with working auto-complete for
archetype fields, but also paves the way for handling tagging in
blueprint overrides/defaults which in the future will allow more fine
grained defaults/overrides using the archetype "context information".



### Examples

Setting default & override for radius

Before:
```py
rrb.Spatial2DView(
    name="Rect 1",
    origin="/",
    contents=["/**"],
    defaults=[rr.components.Radius(2)],
    overrides={"rect/0": [rr.components.Radius(1)]},
)
```
After:
```py
rrb.Spatial2DView(
    name="Rect 1",
    origin="/",
    contents=["/**"],
    defaults=[rr.Boxes2D.from_fields(radii=1)],
    overrides={"rect/0": rr.Boxes2D.from_fields(radii=2)},
)
```

Setting up styles for a plot.

Before:
```py
rrb.TimeSeriesView(
    name="Trig",
    origin="/trig",
    overrides={
        "/trig/sin": [rr.components.Color([255, 0, 0]), rr.components.Name("sin(0.01t)")],
        "/trig/cos": [rr.components.Color([0, 255, 0]), rr.components.Name("cos(0.01t)")],
    },
),
rrb.TimeSeriesView(
    name="Classification",
    origin="/classification",
    overrides={
        "classification/line": [rr.components.Color([255, 255, 0]), rr.components.StrokeWidth(3.0)],
        "classification/samples": [rrb.VisualizerOverrides("SeriesPoint")], # This ensures that the `SeriesPoint` visualizers is used for this entity.
    },
),
```
After:
```py
rrb.TimeSeriesView(
    name="Trig",
    origin="/trig",
    overrides={
        "/trig/sin": rr.SeriesLine.from_fields(color=[255, 0, 0], name="sin(0.01t)"),
        "/trig/cos": rr.SeriesLine.from_fields(color=[0, 255, 0], name="cos(0.01t)"),
    },
),
rrb.TimeSeriesView(
    name="Classification",
    origin="/classification",
    overrides={
        "classification/line": rr.SeriesLine.from_fields(color=[255, 255, 0], width=3.0),
        "classification/samples": rrb.VisualizerOverrides("SeriesPoint"), # This ensures that the `SeriesPoint` visualizers is used for this entity.
    },
),
```

---

### Technical notes on corner cases

There's two special cases that were loose component so far:
* `VisualizerOverrides`
* the former component becomes an archetype with a list of
VisualizerOverride components each being a rerun.datatypes.Utf8.
rerun.datatypes.Utf8List which was previously used goes away
* `VisualTimeRange`
* we _already_ have an archetype for this, it's called
`VisualTimeRanges`. There's a bit of an ergonomic issue with this since
`VisualTimeRanges` has to be constructed from one or more
`VisualTimeRange`. But decided to enforce the archetype here. To avoid
accidentally using the component instead of the datatype with the same
name, I moved the component out and the datatype in to the rrb namespace


---

* [x] go through override/default docs & associated snippets

---------

Co-authored-by: Antoine Beyeler <[email protected]>
jprochazk pushed a commit that referenced this pull request Mar 11, 2025
…coverage (#9257)

### Related

* Improves on #9209 

### What

This PR improves the signatures of the `View` python class (and
subclasses), and adds `tests/python` in the coverage of `mypy`.
abey79 added a commit that referenced this pull request Mar 13, 2025
…9260)

### Related

* Some more leftovers from #9209 

### What

Snippets, a key aspect of our documentation, were not typed checked by
mypy so far... 😱 No longer. This lead to several fixes in user-facing
typing annotation in the python SDK. Plus the usual load of fixes in the
snippets themselves.

Note: snippets that are "not runnable" (as per `snippets.toml`) must now
also be mypy-ignore in our `pyproject.toml`. I don't mind this added
complexity a single second: make your snippets runnable! :)
@emilk emilk mentioned this pull request Apr 11, 2025
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Archetype based override/default logging
3 participants