Run

polyaxon.tracking.run.Run(owner=None, project=None, run_uuid=None, client=None, track_code=True, track_env=True, refresh_data=False, artifacts_path=None)

Run tracking is client to instrument your machine learning model and track experiments.

If no values are passed to this class, Polyaxon will try to resolve the owner, project, and run uuid from the environment:

  • If you have a configured CLI, Polyaxon will use the configuration of the cli.
  • If you have a cached run using the CLI, the client will default to that cached run unless you override the values.
  • If you use this client in the context of a job or a service managed by Polyaxon, a configuration will be available to resolve the values based on that run.

You can always access the self.client to execute more APIs.

  • Properties:

    • project: str.
    • owner: str.
    • run_uuid: str.
    • run_data: V1Run.
    • status: str.
    • namespace: str.
    • client: PolyaxonClient
  • Args:

    • owner: str, optional, the owner is the username or the organization name owning this project.
    • project: str, optional, project name owning the run(s).
    • run_uuid: str, optional, run uuid.
    • client: PolyaxonClient, optional, an instance of a configured client, if not passed, a new instance will be created based on the available environment.
    • track_code: bool, optional, default True, to track code version. Polyaxon will try to track information about any repo configured in the context where this client is instantiated.
    • track_env: bool, optional, default True, to track information about the environment.
    • refresh_data: bool, optional, default False, to refresh the run data at instantiation.
    • artifacts_path: str, optional, for in-cluster runs it will be set automatically.
  • Raises:

    • PolyaxonClientException: If no owner and/or project are passed and Polyaxon cannot resolve the values from the environment.

get_tensorboard_path

get_tensorboard_path(self, rel_path='tensorboard')

Returns a tensorboard path for this run relative to the outputs path.

  • Args:

    • rel_path: str, optional, default "tensorboard", the relative path to the outputs context.
  • Returns: str, outputs_path/rel_path

get_outputs_path

get_outputs_path(self)

Returns the current outputs path configured for this instance.

  • Returns: str, outputs_path

get_artifacts_path

get_artifacts_path(self)

Returns the current artifacts path configured for this instance.

  • Returns: str, artifacts_path

log_metric

log_metric(self, name, value, step=None, timestamp=None)

Logs a metric datapoint.

log_metric(name="loss", value=0.01, step=10)

It's very important to log step as one of your metrics if you want to compare experiments on the dashboard and use the steps in x-axis instead of timestamps.

  • Args:

    • name: str, metric name
    • value: float, metric value
    • step: int, optional
    • timestamp: datetime, optional

log_metrics

log_metrics(self, step=None, timestamp=None)

Logs multiple metrics.

log_metrics(step=123, loss=0.023, accuracy=0.91)

It's very important to log step as one of your metrics if you want to compare experiments on the dashboard and use the steps in x-axis instead of timestamps.

  • Args:

    • step: int, optional
    • timestamp: datetime, optional
    • **metrics: **kwargs, key: value

log_image

log_image(self, data, name=None, step=None, timestamp=None, rescale=1, dataformats='CHW')

Logs an image.

log_image(data="path/to/image.png", step=10)
log_image(data=np_array, name="generated_image", step=10)
  • Args:

    • data: str or numpy.array, a file path or numpy array
    • name: str, name of the image, if a path is passed this can be optional and the name of the file will be used
    • step: int, optional
    • timestamp: datetime, optional
    • rescale: int, optional
    • dataformats: str, optional

log_image_with_boxes

log_image_with_boxes(self, tensor_image, tensor_boxes, name=None, step=None, timestamp=None, rescale=1, dataformats='CHW')

Logs an image with bounding boxes.

log_image_with_boxes(
    name="my_image",
    tensor_image=np.arange(np.prod((3, 32, 32)), dtype=float).reshape((3, 32, 32)),
    tensor_boxes=np.array([[10, 10, 40, 40]]),
)
  • Args:

    • tensor_image: numpy.array or str: Image data or file name
    • tensor_boxes: numpy.array or str: Box data (for detected objects) box should be represented as [x1, y1, x2, y2]
    • name: str, name of the image
    • step: int, optional
    • timestamp: datetime, optional
    • rescale: int, optional
    • dataformats: str, optional

log_mpl_image

log_mpl_image(self, data, name=None, close=True, step=None, timestamp=None)

Logs a matplotlib image.

log_mpl_image(name="figure", data=figure, step=1, close=False)
  • Args:

    • data: matplotlib.pyplot.figure or List[matplotlib.pyplot.figure]
    • name: sre, optional, name
    • close: bool, optional, default True
    • step: int, optional
    • timestamp: datetime, optional

log_video

log_video(self, data, name=None, fps=4, step=None, timestamp=None, content_type=None)

Logs a video.

log_video("path/to/my_video1"),
log_video(name="my_vide2", data=np.arange(np.prod((4, 3, 1, 8, 8)), dtype=float).reshape((4, 3, 1, 8, 8)))  
  • Args:

    • data: video data or str.
    • name: str, optional, if data is a filepath the name will be the name of the file
    • fps: int, optional, frames per second
    • step: int, optional
    • timestamp: datetime, optional
    • content_type: str, optional, default "gif"

log_audio

log_audio(self, data, name=None, sample_rate=44100, step=None, timestamp=None, content_type=None)

Logs a audio.

log_audio("path/to/my_audio1"),
log_audio(name="my_audio2", data=np.arange(np.prod((42,)), dtype=float).reshape((42,)))
  • Args:

    • data: str or audio data
    • name: str, optional, if data is a filepath the name will be the name of the file
    • sample_rate: int, optional, sample rate in Hz
    • step: int, optional
    • timestamp: datetime, optional
    • content_type: str, optional, default "wav"

log_text

log_text(self, name, text, step=None, timestamp=None)

Logs a text.

log_text(name="text", text="value")
  • Args:

    • name: str, name
    • text: str, text value
    • step: int, optional
    • timestamp: datetime, optional

log_html

log_html(self, name, html, step=None, timestamp=None)

Logs an html.

log_html(name="text", html="<p>value</p>")
  • Args:

    • name: str, name
    • html: str, text value
    • step: int, optional
    • timestamp: datetime, optional

log_np_histogram

log_np_histogram(self, name, values, counts, step=None, timestamp=None)

Logs a numpy histogram.

values, counts = np.histogram(np.random.randint(255, size=(1000,)))
log_np_histogram(name="histo1", values=values, counts=counts, step=1)
  • Args:

    • name: str, name
    • values: np.array
    • counts: np.array
    • step: int, optional
    • timestamp: datetime, optional

log_histogram

log_histogram(self, name, values, bins, max_bins=None, step=None, timestamp=None)

Logs a histogram.

log_histogram(name="histo", values=np.arange(np.prod((1024,)), dtype=float).reshape((1024,)), bins="auto", step=1)  
  • Args:

    • name: str, name
    • values: np.array
    • bins: int or str
    • max_bins: int, optional
    • step: int, optional
    • timestamp: datetime, optional

log_model

log_model(self, path, name=None, framework=None, spec=None, step=None, timestamp=None)

Logs a model.

  • Args:

    • path: str, path to the model to log
    • name: str, name
    • framework: str, optional ,name of the framework
    • spec: Dict, optional, key, value information about the model
    • step: int, optional
    • timestamp: datetime, optional

log_dataframe

log_dataframe(self, path, name=None, content_type=None, step=None, timestamp=None)

Logs a dataframe.

  • Args:

    • path: path to the dataframe saved as file
    • name: str, optional, if not provided the name of the file will be used
    • content_type: str, optional
    • step: int, optional
    • timestamp: datetime, optional

log_artifact

log_artifact(self, path, name=None, artifact_kind=None, step=None, timestamp=None)

Logs a generic artifact.

  • Args:

    • path: str, path to the artifact
    • name: str, optional, if not provided the name of the file will be used
    • artifact_kind: optional, str
    • step: int, optional
    • timestamp: datetime, optional

log_roc_auc_curve

log_roc_auc_curve(self, name, fpr, tpr, auc=None, step=None, timestamp=None)

Logs ROC/AUC curve. This method expects an already processed values.

log_roc_auc_curve("roc_value", fpr, tpr, auc=0.6, step=1)
  • Args:

    • name: str, name of the curve
    • fpr: List[float] or numpy.array, false positive rate
    • tpr: List[float] or numpy.array, true positive rate
    • auc: float, optional, calculated area under curve
    • step: int, optional
    • timestamp: datetime, optional

log_sklearn_roc_auc_curve

log_sklearn_roc_auc_curve(self, name, y_preds, y_targets, step=None, timestamp=None)

Calculates and logs ROC/AUC curve using sklearn.

log_sklearn_roc_auc_curve("roc_value", y_preds, y_targets, step=10)
  • Args:

    • name: str, name of the curve
    • y_preds: List[float] or numpy.array
    • y_targets: List[float] or numpy.array
    • step: int, optional
    • timestamp: datetime, optional

log_pr_curve

log_pr_curve(self, name, precision, recall, average_precision=None, step=None, timestamp=None)

Logs PR curve. This method expects an already processed values.

log_pr_curve("pr_value", precision, recall, step=10)
  • Args:

    • name: str, name of the curve
    • y_preds: List[float] or numpy.array
    • y_targets: List[float] or numpy.array
    • step: int, optional
    • timestamp: datetime, optional

log_sklearn_pr_curve

log_sklearn_pr_curve(self, name, y_preds, y_targets, step=None, timestamp=None)

Calculates and logs PR curve using sklearn.

log_sklearn_pr_curve("pr_value", y_preds, y_targets, step=10)
  • Args:

    • name: str, name of the event
    • y_preds: List[float] or numpy.array
    • y_targets: List[float] or numpy.array
    • step: int, optional
    • timestamp: datetime, optional

log_curve

log_curve(self, name, x, y, annotation=None, step=None, timestamp=None)

Logs a custom curve.

log_curve("pr_value", x, y, annotation="more=info", step=10)
  • Args:

    • name: str, name of the curve
    • x: List[float] or numpy.array
    • y: List[float] or numpy.array
    • annotation: str, optional
    • step: int, optional
    • timestamp: datetime, optional

log_plotly_chart

log_plotly_chart(self, name, figure, step=None, timestamp=None)

Logs a plotly chart/figure.

  • Args:

    • name: str, name of the figure
    • figure: plotly.figure
    • step: int, optional
    • timestamp: datetime, optional

log_bokeh_chart

log_bokeh_chart(self, name, figure, step=None, timestamp=None)

Logs a bokeh chart/figure.

  • Args:

    • name: str, name of the figure
    • figure: bokeh.figure
    • step: int, optional
    • timestamp: datetime, optional

log_altair_chart

log_altair_chart(self, name, figure, step=None, timestamp=None)

Logs a vega/altair chart/figure.

  • Args:

    • name: str, name of the figure
    • figure: figure
    • step: int, optional
    • timestamp: datetime, optional

log_mpl_plotly_chart

log_mpl_plotly_chart(self, name, figure, step=None, timestamp=None)

Logs a matplotlib figure to plotly figure.

  • Args:

    • name: str, name of the figure
    • figure: figure
    • step: int, optional
    • timestamp: datetime, optional

set_description

set_description(self, description, async_req=True)

Sets a new description for the current run.

  • Args:

    • description: str, the description to set.
    • async_req: bool, optional, default: False, execute request asynchronously.

set_name

set_name(self, name, async_req=True)

Sets a new name for the current run.

  • Args:

    • name: str, the name to set.
    • async_req: bool, optional, default: False, execute request asynchronously.

log_status

log_status(self, status, reason=None, message=None)

Logs a new run status.

N.B. If you are executing a managed run, you don't need to call this method manually. This method is only useful for manual runs outside of Polyaxon.

N.B you will probably use one of the simpler methods:

  • log_succeeded
  • log_stopped
  • log_failed
  • start
  • end

Run API

  • Args:

    • status: str, a valid Statuses value.
    • reason: str, optional, reason for this status change.
    • message: str, optional, message to log with this status.

log_inputs

log_inputs(self, reset=False, async_req=True)

Logs or resets new inputs/params for the current run.

N.B. If you are starting a run from the CLI/UI polyaxon will track all inputs from the Polyaxonfile, so you generally don't need to set them manually. But you can always add or reset these params/inputs once your code starts running.
  • Args:

    • reset: bool, optional, if True, it will reset the whole inputs state. Note that Polyaxon will automatically populate the inputs based on the Polyaxonfile inputs definition and params passed.
    • async_req: bool, optional, default: False, execute request asynchronously.
    • inputs: **kwargs, e.g. param1=value1, param2=value2, ...

log_outputs

log_outputs(self, reset=False, async_req=True)

Logs a new outputs for the current run.

  • Args:

    • reset: bool, optional, if True, it will reset the whole outputs state. Note that Polyaxon will automatically populate some outputs based on the Polyaxonfile outputs definition and params passed.
    • async_req: bool, optional, default: False, execute request asynchronously.
    • outputs: **kwargs, e.g. output1=value1, metric2=value2, ...

log_tags

log_tags(self, tags, reset=False, async_req=True)

Logs new tags for the current run.

  • Args:

    • tags: str or List[str], tag or tags to log.
    • reset: bool, optional, if True, it will reset the whole tags state. Note that Polyaxon will automatically populate the tags based on the Polyaxonfile.
    • async_req: bool, optional, default: False, execute request asynchronously.

log_succeeded

log_succeeded(self, message='Operation has succeeded')

Sets the current run to succeeded status.

N.B. If you are executing a managed run, you don't need to call this method manually. This method is only useful for manual runs outside of Polyaxon.

log_stopped

log_stopped(self, message='Operation is stopped')

Sets the current run to stopped status.

N.B. If you are executing a managed run, you don't need to call this method manually. This method is only useful for manual runs outside of Polyaxon.

log_failed

log_failed(self, message=None, traceback=None)

Sets the current run to failed status.

N.B. If you are executing a managed run, you don't need to call this method manually. This method is only useful for manual runs outside of Polyaxon.
  • Args:

    • message: str, optional, message to log with this status.
    • traceback: str, optional, reason for this status change.

log_code_ref

log_code_ref(self, code_ref=None, is_input=True)

Logs code reference.

  • Args:

    • code_ref: dict, optional, if not provided, Polyaxon will detect the code reference from the git repo in the current path.
    • is_input: bool, if the code reference is an input or outputs.

log_data_ref

log_data_ref(self, name, hash=None, path=None, content=None, is_input=True)

Logs data reference.

  • Args:

    • name: str, name of the data.
    • hash: str, optional, default = None, the hash version of the data, if not provided it will be calculated based on the data in the content.
    • path: str, optional, path of where the data is coming from.
    • is_input: bool, if the data reference is an input or outputs.
    • content: the data content.

log_file_ref

log_file_ref(self, path, name=None, hash=None, content=None, is_input=False, rel_path=None)

Logs file reference.

  • Args:

    • path: str, filepath, the name is extracted from the filepath.
    • name: str, if the name is passed it will be used instead of the filename from the path.
    • hash: str, optional, default = None, the hash version of the file, if not provided it will be calculated based on the file content.
    • content: the file content.
    • is_input: bool, if the file reference is an input or outputs.
    • rel_path: str, optional relative path to the run artifacts path.

log_dir_ref

log_dir_ref(self, path, name=None, is_input=False, rel_path=None)

Logs dir reference.

  • Args:

    • path: str, dir path, the name is extracted from the path.
    • name: str, if the name is passed it will be used instead of the dirname from the path.
    • is_input: bool, if the dir reference is an input or outputs.
    • rel_path: str, optional relative path to the run artifacts path.

log_artifact_lineage

log_artifact_lineage(self, body)

Logs an artifact lineage.

  • Args:

    • body: dict or List[dict] or V1RunArtifact or List[V1RunArtifact], body of the lineage.

set_artifacts_path

set_artifacts_path(self, artifacts_path=None)

Sets an artifacts_path. Be careful, this method is called automatically when a job is running in-cluster and follows some flags that Polyaxon sets. Polyaxon has some processes to automatically sync your run's artifacts and outputs.

  • Args:

    • artifacts_path: str, optional