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

Supporting kwargs in log figure #9179

Merged
merged 7 commits into from
Aug 14, 2023
Merged

Conversation

stroblme
Copy link
Contributor

@stroblme stroblme commented Jul 31, 2023

Related Issues/PRs

Resolve #9149

What changes are proposed in this pull request?

  • added **kwargs to log_figure(..) and passed them to corresponding export methods for both matplotlib and plotly
  • using setdefault to merge previously existing arguments in kwargs
  • updated docstring

How is this patch tested?

  • Existing unit/integration tests

  • New unit/integration tests

  • Manual tests (describe details, including test results, below)

  • ran only tracking related unit tests (pytest tests/tracking/test_log_figure.py)

  • manual test code based on example provided in method documentation:

from mlflow import MlflowClient
from plotly import graph_objects as go

client = MlflowClient()

fig = go.Figure(go.Scatter(x=[0, 1], y=[2, 3]))
fig.update_layout(
    title={
        'text': r"$\text{A line with slope}\quad \frac{3-2}{1-0}=1$",
    })

run = client.create_run(experiment_id="0")
client.log_figure(run.info.run_id, fig, "figure.html", include_mathjax="cdn")
  • manual test results (with and without include_mathjax="cdn") :
    image
    image

Does this PR change the documentation?

  • No. You can skip the rest of this section.
  • Yes. Make sure the changed pages / sections render correctly in the documentation preview.

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release notes for MLflow users.

(Details in 1-2 sentences. You can just refer to another PR with a description if this PR is part of a larger change.)

Additional arguments can be passed to both Matplotlib and Plotly export methods. This enables specifying e.g. MathJax CDN
required for Plotly figures with formulas as mentioned in #9149

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/artifacts: Artifact stores and artifact logging
  • area/build: Build and test infrastructure for MLflow
  • area/docs: MLflow documentation pages
  • area/examples: Example code
  • area/gateway: AI Gateway service, Gateway client APIs, third-party Gateway integrations
  • area/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registry
  • area/models: MLmodel format, model serialization/deserialization, flavors
  • area/recipes: Recipes, Recipe APIs, Recipe configs, Recipe Templates
  • area/projects: MLproject format, project running backends
  • area/scoring: MLflow Model server, model deployment tools, Spark UDFs
  • area/server-infra: MLflow Tracking server backend
  • area/tracking: Tracking Service, tracking client APIs, autologging

Interface

  • area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev server
  • area/docker: Docker use across MLflow's components, such as MLflow Projects and MLflow Models
  • area/sqlalchemy: Use of SQLAlchemy in the Tracking Service or Model Registry
  • area/windows: Windows support

Language

  • language/r: R APIs and clients
  • language/java: Java APIs and clients
  • language/new: Proposals for new client languages

Integrations

  • integrations/azure: Azure and Azure ML integrations
  • integrations/sagemaker: SageMaker integrations
  • integrations/databricks: Databricks integrations

How should the PR be classified in the release notes? Choose one:

  • rn/breaking-change - The PR will be mentioned in the "Breaking Changes" section
  • rn/none - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section
  • rn/feature - A new user-facing feature worth mentioning in the release notes
  • rn/bug-fix - A user-facing bug fix worth mentioning in the release notes
  • rn/documentation - A user-facing documentation change worth mentioning in the release notes

@mlflow-automation
Copy link
Collaborator

mlflow-automation commented Jul 31, 2023

Documentation preview for d8b9e02 will be available here when this CircleCI job completes successfully.

More info

@github-actions github-actions bot added area/tracking Tracking service, tracking client APIs, autologging rn/feature Mention under Features in Changelogs. labels Jul 31, 2023
@@ -1234,6 +1234,7 @@ def log_figure(
run_id: str,
figure: Union["matplotlib.figure.Figure", "plotly.graph_objects.Figure"],
artifact_file: str,
**kwargs,
Copy link
Member

@harupy harupy Aug 10, 2023

Choose a reason for hiding this comment

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

Suggested change
**kwargs,
*,
kwargs,

Can we make this a separate argument? In the future, we might add a new argument to this function and it may conflict with plotly or matplotlib. I think this is a little inconvenient but better than argument name collisions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, good point! Should we then also rename kwargs to sth. more expressive, e.g. figure_args or plotting_args (open to other suggestions), so that it is clear that those arguments are being passed to the plotting backend?

Copy link
Member

@harupy harupy Aug 10, 2023

Choose a reason for hiding this comment

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

xxx_args sounds like it takes a tuple. I'd prefer xxx_kwargs.

  • figure_kwargs
  • plot_kwargs
  • plotting_kwargs
  • extra_kwargs
  • save_kwargs
  • extras

Copy link
Member

@harupy harupy Aug 10, 2023

Choose a reason for hiding this comment

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

save_kwargs (meaning keyword arguments used when saving)?

Copy link
Member

Choose a reason for hiding this comment

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

kwargs doesn't sound bad because we probably won't add an argument named kwargs to log_figure.

Copy link
Contributor Author

@stroblme stroblme Aug 10, 2023

Choose a reason for hiding this comment

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

save_kwargs sound good, the other suggestions like figure_kwargs might cause confusion as it could be interpreted as altering the figure itself. Also sticking with kwargs is fine by me 😃
Is there maybe another (similar) case in the mlflow api where we could reuse the naming convention for additional kwargs passed to the backend?

Copy link
Member

@harupy harupy Aug 10, 2023

Choose a reason for hiding this comment

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

I like save_kwargs :) It's more descriptive than kwargs. We have saved_model_kwargs here in the mlflow.tensorflow module:

:param saved_model_kwargs: a dict of kwargs to pass to ``tensorflow.saved_model.save`` method.

save_kwargs aligns with this pattern.

figure.write_html(tmp_path, include_plotlyjs="cdn", auto_open=False)
kwargs.setdefault("include_plotlyjs", "cdn")
kwargs.setdefault("auto_open", False)

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

@harupy
Copy link
Member

harupy commented Aug 10, 2023

@stroblme Sorry for the late review, left a few comments!

Signed-off-by: harupy <[email protected]>
@harupy
Copy link
Member

harupy commented Aug 14, 2023

@stroblme I pushed a commit to use save_kwargs. Let me know if it looks ok :)

Copy link
Contributor Author

@stroblme stroblme left a comment

Choose a reason for hiding this comment

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

Thanks, looks good!
Good idea to add a test as well, wasn't sure how to check if it actually renders the Latex, but at least the interface is tested now.

Signed-off-by: harupy <[email protected]>
Signed-off-by: harupy <[email protected]>
Copy link
Member

@harupy harupy left a comment

Choose a reason for hiding this comment

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

LGTM!

@harupy harupy merged commit c747dd0 into mlflow:master Aug 14, 2023
23 of 24 checks passed
@harupy
Copy link
Member

harupy commented Aug 14, 2023

@stroblme Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/tracking Tracking service, tracking client APIs, autologging rn/feature Mention under Features in Changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FR] Allow Poetry MathJax Specification
3 participants