Skip to content
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

[@card] Realtime cards (3/N) #1552

Merged
merged 7 commits into from
Jan 11, 2024
Merged

[@card] Realtime cards (3/N) #1552

merged 7 commits into from
Jan 11, 2024

Conversation

valayDave
Copy link
Collaborator

@valayDave valayDave commented Sep 26, 2023

[card/components] internal MetaflowCard classes support realtime behavior

  • Markdown and Artifact Component support real-time updates.
  • default/blank cards support real-time update
  • Vega Charts And Progress Bar support in Python Land

TODO

  • Image Update support
  • [ ]

@valayDave valayDave changed the title [card/components] internal MetaflowCard classes support realtime behavior [@card] Realtime cards (3/N) Sep 26, 2023
@valayDave valayDave mentioned this pull request Sep 26, 2023
2 tasks
@valayDave valayDave marked this pull request as ready for review September 26, 2023 22:48
Copy link
Contributor

@romain-intel romain-intel left a comment

Choose a reason for hiding this comment

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

Minor nit but I think LGTM.

metaflow/plugins/cards/card_modules/basic.py Outdated Show resolved Hide resolved
@valayDave valayDave changed the base branch from valay/rtc-stack-1 to master November 19, 2023 21:06
@valayDave valayDave changed the base branch from master to valay/rtc-stack-1 November 19, 2023 21:07
Comment on lines 148 to 149
disable_updates: bool, optional
A boolean value to disable realtime updates for all components within the table. Default: False
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Surface level API change to disable table updates when we want. cc @tuulos

Copy link
Collaborator

Choose a reason for hiding this comment

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

do you have a particular use case in mind for this Table-level disable_updates?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will Remove docstring cc @tuulos ; So that it's not a part of the public API

metaflow/plugins/cards/card_modules/components.py Outdated Show resolved Hide resolved
Comment on lines 623 to 703
def __init__(self, max=100, label=None, value=0, unit=None, metadata=None):
self._label = label
self._max = max
self._value = value
self._unit = unit
self._metadata = metadata

def update(self, new_value, metadata=None):
self._value = new_value
if metadata is not None:
self._metadata = metadata

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

User API signature needs validation : cc @tuulos

Copy link
Collaborator

Choose a reason for hiding this comment

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

what's metadata?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

metadata is any additional piece of information you want to add in the progressbar:

    native_progress_bar = ProgressBar(
        max=sleep_cycles,
        label="Native Progress Bar",
        value=0,
        metadata="0 iter/s",
    )
Screenshot 2023-12-08 at 12 29 06 PM

Comment on lines 658 to 736
def __init__(self, spec, data=None):
self._spec = spec
self._data = data

def update(self, data=None, spec=None):
if spec is not None:
self._spec = spec
if data is not None:
self._data = data

@classmethod
def from_altair_chart(cls, altair_chart):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

User API signature needs validation : cc @tuulos

Copy link
Collaborator

Choose a reason for hiding this comment

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

if I create a chart with from_altair_chart initially, do I then update the data with update(spec=None, data=my_data) or how would it work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I think you should be able to as long as the data object is the "full object"; The VegaChart object needs the full data object in the data update.

self._spec = spec
self._data = data

def update(self, data=None, spec=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

spec is a JSON (a Python dict?) following the VegaLite spec here, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes

@valayDave valayDave changed the base branch from valay/rtc-stack-1 to master December 6, 2023 05:03
@valayDave valayDave changed the base branch from master to valay/rtc-stack-1 December 6, 2023 05:03
@@ -82,20 +82,28 @@ class Artifact(UserComponent):
Use a truncated representation.
"""

REALTIME_UPDATABLE = True

def update(self, artifact):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cc @tuulos

self._spec = spec
self._data = data

def update(self, data=None, spec=None):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes

Comment on lines 623 to 703
def __init__(self, max=100, label=None, value=0, unit=None, metadata=None):
self._label = label
self._max = max
self._value = value
self._unit = unit
self._metadata = metadata

def update(self, new_value, metadata=None):
self._value = new_value
if metadata is not None:
self._metadata = metadata

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

metadata is any additional piece of information you want to add in the progressbar:

    native_progress_bar = ProgressBar(
        max=sleep_cycles,
        label="Native Progress Bar",
        value=0,
        metadata="0 iter/s",
    )
Screenshot 2023-12-08 at 12 29 06 PM

Comment on lines 658 to 736
def __init__(self, spec, data=None):
self._spec = spec
self._data = data

def update(self, data=None, spec=None):
if spec is not None:
self._spec = spec
if data is not None:
self._data = data

@classmethod
def from_altair_chart(cls, altair_chart):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I think you should be able to as long as the data object is the "full object"; The VegaChart object needs the full data object in the data update.

metaflow/plugins/cards/card_modules/components.py Outdated Show resolved Hide resolved
Comment on lines 293 to 294
disable_updates: bool
Disable realtime updates for the image. Default: True
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will Remove docstring cc @tuulos ; So that it's not a part of the public API

Comment on lines 148 to 149
disable_updates: bool, optional
A boolean value to disable realtime updates for all components within the table. Default: False
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will Remove docstring cc @tuulos ; So that it's not a part of the public API

…vior

- Markdown and Artifact Component made realtime.
- default/blank cards made realtime
- default component ids to realtime-updatable UserComponents
- Add a variable in the HTML template to enable/disable `metaflow_card_update` function
- Set options that allows disabling realtime updates for components that may have lots of data like `Image` / `Table`. This can be useful when we are calling refresh often and don't want to update data which maybe static.
- Image.update supports multi-type object
- remove `disable_updates` from public api
- property in vega chart to show controls
- remove `data` argument from Vega Chart.
- It only takes `spec` as an argument.
- VegaChart default width set to `container`
Copy link
Contributor

@romain-intel romain-intel left a comment

Choose a reason for hiding this comment

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

Haven't looked at things in great detail but I plan to test everything once it is all merged over the next week. My only big comment is that we should add docstrings/typehints to anything the user will use.


REALTIME_UPDATABLE = True

def __init__(self, max=100, label=None, value=0, unit=None, metadata=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm going to be a stickler and say we should add type hints and docs :)

* [card-server] cli command to expose a card server
- Server helps view realtime updates
- Added a card viewer html file
- Created a simple HTTP based card server that will help showcase the realtime cards from querying the server
- The API response contains the task status for the data api
- reload on run change : A background thread checks if there are new runs created via the latest_run file.
- pass down poll_interval to card viewer
- card server is also resiliant to no runs
- You can set `METAFLOW_DEBUG_CARD_SERVER` to debug card server logs, Logging is off by default
- clean url parsing for requests : needed to ensure calls to card server are resiliant to query params in requests.
- also need clean url parsing for setting `embed` query param in the card iframe
- run-info API sends task finished information which is useful when switching cards automatically when new tasks start.
- it Always logs when run-ids change

* [card-viewer-html] UI + Structure
- Cleanup HTML template
- Handles edge case where no runs are available
- Shows errors when things are not working
- leverages a configurable poll interval
- set `embed` query param in the card iframe source.
- it automatically switches to new card when tasks finish and other tasks are running.
- Fix bug when card data is not available
- checks for `final` reload token to stop polling updates

* [@card] [card-core] always call `refresh` after first `render_runtime` (5/N) (#1670)

* [card-core] always call `refresh` after first `render_runtime`
- Added a `sync` argument to the card creator

[@card][bug fixes] Address comments and squashing bugs (6/N) (#1678)

* [card-components] type-hints + doc string Fix.

* [card-core] fix function signature in tests.

* [card-server] address comments on debug mode and hygiene

* [card-components] vega charts special case inside table

---------

Co-authored-by: adam <203779+seethroughdev@users.noreply.github.com>
@valayDave valayDave merged commit fc430d4 into valay/rtc-stack-1 Jan 11, 2024
1 check passed
@valayDave valayDave deleted the valay/rtc-stack-2 branch January 11, 2024 16:09
valayDave added a commit that referenced this pull request Jan 11, 2024
* [card-components] internal MetaflowCard classes support realtime behavior
- Markdown and Artifact Component made realtime.
- default/blank cards made realtime
- default component ids to realtime-updatable UserComponents

* [default-card-python] add runtime check
- Add a variable in the HTML template to enable/disable `metaflow_card_update` function

* [card-components] progressbar / vegacharts

* [card-components] customize updates for Tables/Images
- Set options that allows disabling realtime updates for components that may have lots of data like `Image` / `Table`. This can be useful when we are calling refresh often and don't want to update data which maybe static.

* [card-components] address comments on Image class
- Image.update supports multi-type object
- remove `disable_updates` from public api

* [card-components][vega-chart][bug-fix]
- property in vega chart to show controls
- remove `data` argument from Vega Chart.
- It only takes `spec` as an argument.
- VegaChart default width set to `container`

* [@card] Realtime cards (4/N) (#1553)

* [card-server] cli command to expose a card server
- Server helps view realtime updates
- Added a card viewer html file
- Created a simple HTTP based card server that will help showcase the realtime cards from querying the server
- The API response contains the task status for the data api
- reload on run change : A background thread checks if there are new runs created via the latest_run file.
- pass down poll_interval to card viewer
- card server is also resiliant to no runs
- You can set `METAFLOW_DEBUG_CARD_SERVER` to debug card server logs, Logging is off by default
- clean url parsing for requests : needed to ensure calls to card server are resiliant to query params in requests.
- also need clean url parsing for setting `embed` query param in the card iframe
- run-info API sends task finished information which is useful when switching cards automatically when new tasks start.
- it Always logs when run-ids change

* [card-viewer-html] UI + Structure
- Cleanup HTML template
- Handles edge case where no runs are available
- Shows errors when things are not working
- leverages a configurable poll interval
- set `embed` query param in the card iframe source.
- it automatically switches to new card when tasks finish and other tasks are running.
- Fix bug when card data is not available
- checks for `final` reload token to stop polling updates

* [@card] [card-core] always call `refresh` after first `render_runtime` (5/N) (#1670)

* [card-core] always call `refresh` after first `render_runtime`
- Added a `sync` argument to the card creator

[@card][bug fixes] Address comments and squashing bugs (6/N) (#1678)

* [card-components] type-hints + doc string Fix.

* [card-core] fix function signature in tests.

* [card-server] address comments on debug mode and hygiene

* [card-components] vega charts special case inside table

---------

Co-authored-by: adam <203779+seethroughdev@users.noreply.github.com>

---------

Co-authored-by: adam <203779+seethroughdev@users.noreply.github.com>
savingoyal pushed a commit that referenced this pull request Jan 11, 2024
* [default-card][ui] default card realtime updatable
- cleanup the ui component code and add naive progress-bar

* [default-card][ui] Add custom progress bar

* [default-card][ui] vegachart component
- Chart support within tables and anywhere across the page
- Chart mutation done based on spec/data changes.

* [default-card][ui] remove chart.js deps.

* [default-card][ui] migrate to vite

* [default-card][ui] update progress bar styles

* [default-card][ui] Fixes to chart/css/progess bar
- pass down options in vega chart
- progress-bar min width for mf UI
- Fix bug when vega-chart spec changes.
- fix `embed` class CSS

* [@card] Realtime cards (3/N)  (#1552)

* [card-components] internal MetaflowCard classes support realtime behavior
- Markdown and Artifact Component made realtime.
- default/blank cards made realtime
- default component ids to realtime-updatable UserComponents

* [default-card-python] add runtime check
- Add a variable in the HTML template to enable/disable `metaflow_card_update` function

* [card-components] progressbar / vegacharts

* [card-components] customize updates for Tables/Images
- Set options that allows disabling realtime updates for components that may have lots of data like `Image` / `Table`. This can be useful when we are calling refresh often and don't want to update data which maybe static.

* [card-components] address comments on Image class
- Image.update supports multi-type object
- remove `disable_updates` from public api

* [card-components][vega-chart][bug-fix]
- property in vega chart to show controls
- remove `data` argument from Vega Chart.
- It only takes `spec` as an argument.
- VegaChart default width set to `container`

* [@card] Realtime cards (4/N) (#1553)

* [card-server] cli command to expose a card server
- Server helps view realtime updates
- Added a card viewer html file
- Created a simple HTTP based card server that will help showcase the realtime cards from querying the server
- The API response contains the task status for the data api
- reload on run change : A background thread checks if there are new runs created via the latest_run file.
- pass down poll_interval to card viewer
- card server is also resiliant to no runs
- You can set `METAFLOW_DEBUG_CARD_SERVER` to debug card server logs, Logging is off by default
- clean url parsing for requests : needed to ensure calls to card server are resiliant to query params in requests.
- also need clean url parsing for setting `embed` query param in the card iframe
- run-info API sends task finished information which is useful when switching cards automatically when new tasks start.
- it Always logs when run-ids change

* [card-viewer-html] UI + Structure
- Cleanup HTML template
- Handles edge case where no runs are available
- Shows errors when things are not working
- leverages a configurable poll interval
- set `embed` query param in the card iframe source.
- it automatically switches to new card when tasks finish and other tasks are running.
- Fix bug when card data is not available
- checks for `final` reload token to stop polling updates

* [@card] [card-core] always call `refresh` after first `render_runtime` (5/N) (#1670)

* [card-core] always call `refresh` after first `render_runtime`
- Added a `sync` argument to the card creator

[@card][bug fixes] Address comments and squashing bugs (6/N) (#1678)

* [card-components] type-hints + doc string Fix.

* [card-core] fix function signature in tests.

* [card-server] address comments on debug mode and hygiene

* [card-components] vega charts special case inside table

---------

Co-authored-by: adam <203779+seethroughdev@users.noreply.github.com>

---------

Co-authored-by: adam <203779+seethroughdev@users.noreply.github.com>

---------

Co-authored-by: adam <203779+seethroughdev@users.noreply.github.com>
madhur-ob pushed a commit to madhur-ob/metaflow that referenced this pull request Jan 18, 2024
* [default-card][ui] default card realtime updatable
- cleanup the ui component code and add naive progress-bar

* [default-card][ui] Add custom progress bar

* [default-card][ui] vegachart component
- Chart support within tables and anywhere across the page
- Chart mutation done based on spec/data changes.

* [default-card][ui] remove chart.js deps.

* [default-card][ui] migrate to vite

* [default-card][ui] update progress bar styles

* [default-card][ui] Fixes to chart/css/progess bar
- pass down options in vega chart
- progress-bar min width for mf UI
- Fix bug when vega-chart spec changes.
- fix `embed` class CSS

* [@card] Realtime cards (3/N)  (Netflix#1552)

* [card-components] internal MetaflowCard classes support realtime behavior
- Markdown and Artifact Component made realtime.
- default/blank cards made realtime
- default component ids to realtime-updatable UserComponents

* [default-card-python] add runtime check
- Add a variable in the HTML template to enable/disable `metaflow_card_update` function

* [card-components] progressbar / vegacharts

* [card-components] customize updates for Tables/Images
- Set options that allows disabling realtime updates for components that may have lots of data like `Image` / `Table`. This can be useful when we are calling refresh often and don't want to update data which maybe static.

* [card-components] address comments on Image class
- Image.update supports multi-type object
- remove `disable_updates` from public api

* [card-components][vega-chart][bug-fix]
- property in vega chart to show controls
- remove `data` argument from Vega Chart.
- It only takes `spec` as an argument.
- VegaChart default width set to `container`

* [@card] Realtime cards (4/N) (Netflix#1553)

* [card-server] cli command to expose a card server
- Server helps view realtime updates
- Added a card viewer html file
- Created a simple HTTP based card server that will help showcase the realtime cards from querying the server
- The API response contains the task status for the data api
- reload on run change : A background thread checks if there are new runs created via the latest_run file.
- pass down poll_interval to card viewer
- card server is also resiliant to no runs
- You can set `METAFLOW_DEBUG_CARD_SERVER` to debug card server logs, Logging is off by default
- clean url parsing for requests : needed to ensure calls to card server are resiliant to query params in requests.
- also need clean url parsing for setting `embed` query param in the card iframe
- run-info API sends task finished information which is useful when switching cards automatically when new tasks start.
- it Always logs when run-ids change

* [card-viewer-html] UI + Structure
- Cleanup HTML template
- Handles edge case where no runs are available
- Shows errors when things are not working
- leverages a configurable poll interval
- set `embed` query param in the card iframe source.
- it automatically switches to new card when tasks finish and other tasks are running.
- Fix bug when card data is not available
- checks for `final` reload token to stop polling updates

* [@card] [card-core] always call `refresh` after first `render_runtime` (5/N) (Netflix#1670)

* [card-core] always call `refresh` after first `render_runtime`
- Added a `sync` argument to the card creator

[@card][bug fixes] Address comments and squashing bugs (6/N) (Netflix#1678)

* [card-components] type-hints + doc string Fix.

* [card-core] fix function signature in tests.

* [card-server] address comments on debug mode and hygiene

* [card-components] vega charts special case inside table

---------

Co-authored-by: adam <203779+seethroughdev@users.noreply.github.com>

---------

Co-authored-by: adam <203779+seethroughdev@users.noreply.github.com>

---------

Co-authored-by: adam <203779+seethroughdev@users.noreply.github.com>
emattia pushed a commit to emattia/metaflow that referenced this pull request Jan 23, 2024
* [default-card][ui] default card realtime updatable
- cleanup the ui component code and add naive progress-bar

* [default-card][ui] Add custom progress bar

* [default-card][ui] vegachart component
- Chart support within tables and anywhere across the page
- Chart mutation done based on spec/data changes.

* [default-card][ui] remove chart.js deps.

* [default-card][ui] migrate to vite

* [default-card][ui] update progress bar styles

* [default-card][ui] Fixes to chart/css/progess bar
- pass down options in vega chart
- progress-bar min width for mf UI
- Fix bug when vega-chart spec changes.
- fix `embed` class CSS

* [@card] Realtime cards (3/N)  (Netflix#1552)

* [card-components] internal MetaflowCard classes support realtime behavior
- Markdown and Artifact Component made realtime.
- default/blank cards made realtime
- default component ids to realtime-updatable UserComponents

* [default-card-python] add runtime check
- Add a variable in the HTML template to enable/disable `metaflow_card_update` function

* [card-components] progressbar / vegacharts

* [card-components] customize updates for Tables/Images
- Set options that allows disabling realtime updates for components that may have lots of data like `Image` / `Table`. This can be useful when we are calling refresh often and don't want to update data which maybe static.

* [card-components] address comments on Image class
- Image.update supports multi-type object
- remove `disable_updates` from public api

* [card-components][vega-chart][bug-fix]
- property in vega chart to show controls
- remove `data` argument from Vega Chart.
- It only takes `spec` as an argument.
- VegaChart default width set to `container`

* [@card] Realtime cards (4/N) (Netflix#1553)

* [card-server] cli command to expose a card server
- Server helps view realtime updates
- Added a card viewer html file
- Created a simple HTTP based card server that will help showcase the realtime cards from querying the server
- The API response contains the task status for the data api
- reload on run change : A background thread checks if there are new runs created via the latest_run file.
- pass down poll_interval to card viewer
- card server is also resiliant to no runs
- You can set `METAFLOW_DEBUG_CARD_SERVER` to debug card server logs, Logging is off by default
- clean url parsing for requests : needed to ensure calls to card server are resiliant to query params in requests.
- also need clean url parsing for setting `embed` query param in the card iframe
- run-info API sends task finished information which is useful when switching cards automatically when new tasks start.
- it Always logs when run-ids change

* [card-viewer-html] UI + Structure
- Cleanup HTML template
- Handles edge case where no runs are available
- Shows errors when things are not working
- leverages a configurable poll interval
- set `embed` query param in the card iframe source.
- it automatically switches to new card when tasks finish and other tasks are running.
- Fix bug when card data is not available
- checks for `final` reload token to stop polling updates

* [@card] [card-core] always call `refresh` after first `render_runtime` (5/N) (Netflix#1670)

* [card-core] always call `refresh` after first `render_runtime`
- Added a `sync` argument to the card creator

[@card][bug fixes] Address comments and squashing bugs (6/N) (Netflix#1678)

* [card-components] type-hints + doc string Fix.

* [card-core] fix function signature in tests.

* [card-server] address comments on debug mode and hygiene

* [card-components] vega charts special case inside table

---------

Co-authored-by: adam <203779+seethroughdev@users.noreply.github.com>

---------

Co-authored-by: adam <203779+seethroughdev@users.noreply.github.com>

---------

Co-authored-by: adam <203779+seethroughdev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants