flows
openml.flows
#
OpenMLFlow
#
OpenMLFlow(name: str, description: str, model: object, components: dict, parameters: dict, parameters_meta_info: dict, external_version: str, tags: list, language: str, dependencies: str, class_name: str | None = None, custom_name: str | None = None, binary_url: str | None = None, binary_format: str | None = None, binary_md5: str | None = None, uploader: str | None = None, upload_date: str | None = None, flow_id: int | None = None, extension: Extension | None = None, version: str | None = None)
Bases: OpenMLBase
OpenML Flow. Stores machine learning models.
Flows should not be generated manually, but by the function
:meth:openml.flows.create_flow_from_model. Using this helper function
ensures that all relevant fields are filled in.
Implements openml.implementation.upload.xsd
<https://github.com/openml/openml/blob/master/openml_OS/views/pages/api_new/v1/xsd/
openml.implementation.upload.xsd>_.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Name of the flow. Is used together with the attribute
TYPE:
|
description
|
Human-readable description of the flow (free text).
TYPE:
|
model
|
ML model which is described by this flow.
TYPE:
|
components
|
Mapping from component identifier to an OpenMLFlow object. Components are usually subfunctions of an algorithm (e.g. kernels), base learners in ensemble algorithms (decision tree in adaboost) or building blocks of a machine learning pipeline. Components are modeled as independent flows and can be shared between flows (different pipelines can use the same components).
TYPE:
|
parameters
|
Mapping from parameter name to the parameter default value. The
parameter default value must be of type
TYPE:
|
parameters_meta_info
|
Mapping from parameter name to
TYPE:
|
external_version
|
Version number of the software the flow is implemented in. Is used
together with the attribute
TYPE:
|
tags
|
List of tags. Created on the server by other API calls.
TYPE:
|
language
|
Natural language the flow is described in (not the programming language).
TYPE:
|
dependencies
|
A list of dependencies necessary to run the flow. This field should contain all libraries the flow depends on. To allow reproducibility it should also specify the exact version numbers.
TYPE:
|
class_name
|
The development language name of the class which is described by this flow.
TYPE:
|
custom_name
|
Custom name of the flow given by the owner.
TYPE:
|
binary_url
|
Url from which the binary can be downloaded. Added by the server. Ignored when uploaded manually. Will not be used by the python API because binaries aren't compatible across machines.
TYPE:
|
binary_format
|
Format in which the binary code was uploaded. Will not be used by the python API because binaries aren't compatible across machines.
TYPE:
|
binary_md5
|
MD5 checksum to check if the binary code was correctly downloaded. Will not be used by the python API because binaries aren't compatible across machines.
TYPE:
|
uploader
|
OpenML user ID of the uploader. Filled in by the server.
TYPE:
|
upload_date
|
Date the flow was uploaded. Filled in by the server.
TYPE:
|
flow_id
|
Flow ID. Assigned by the server.
TYPE:
|
extension
|
The extension for a flow (e.g., sklearn).
TYPE:
|
version
|
OpenML version of the flow. Assigned by the server.
TYPE:
|
Source code in openml/flows/flow.py
openml_url
property
#
The URL of the object on the server, if it was uploaded, else None.
from_filesystem
classmethod
#
from_filesystem(input_directory: str | Path) -> OpenMLFlow
Read a flow from an XML in input_directory on the filesystem.
Source code in openml/flows/flow.py
get_structure
#
Returns for each sub-component of the flow the path of identifiers that should be traversed to reach this component. The resulting dict maps a key (identifying a flow by either its id, name or fullname) to the parameter prefix.
| PARAMETER | DESCRIPTION |
|---|---|
key_item
|
The flow attribute that will be used to identify flows in the structure. Allowed values {flow_id, name}
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, List[str]]
|
The flow structure |
Source code in openml/flows/flow.py
get_subflow
#
get_subflow(structure: list[str]) -> OpenMLFlow
Returns a subflow from the tree of dependencies.
| PARAMETER | DESCRIPTION |
|---|---|
structure
|
A list of strings, indicating the location of the subflow
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
OpenMLFlow
|
The OpenMLFlow that corresponds to the structure |
Source code in openml/flows/flow.py
open_in_browser
#
Opens the OpenML web page corresponding to this object in your default browser.
Source code in openml/base.py
publish
#
publish(raise_error_if_exists: bool = False) -> OpenMLFlow
Publish this flow to OpenML server.
Raises a PyOpenMLError if the flow exists on the server, but
self.flow_id does not match the server known flow id.
| PARAMETER | DESCRIPTION |
|---|---|
raise_error_if_exists
|
If True, raise PyOpenMLError if the flow exists on the server. If False, update the local flow to match the server flow.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
self
|
TYPE:
|
Source code in openml/flows/flow.py
push_tag
#
Annotates this entity with a tag on the server.
| PARAMETER | DESCRIPTION |
|---|---|
tag
|
Tag to attach to the flow.
TYPE:
|
remove_tag
#
Removes a tag from this entity on the server.
| PARAMETER | DESCRIPTION |
|---|---|
tag
|
Tag to attach to the flow.
TYPE:
|
to_filesystem
#
Write a flow to the filesystem as XML to output_directory.
Source code in openml/flows/flow.py
url_for_id
classmethod
#
Return the OpenML URL for the object of the class entity with the given id.
assert_flows_equal
#
assert_flows_equal(flow1: OpenMLFlow, flow2: OpenMLFlow, ignore_parameter_values_on_older_children: str | None = None, ignore_parameter_values: bool = False, ignore_custom_name_if_none: bool = False, check_description: bool = True) -> None
Check equality of two flows.
Two flows are equal if their all keys which are not set by the server are equal, as well as all their parameters and components.
| PARAMETER | DESCRIPTION |
|---|---|
flow1
|
TYPE:
|
flow2
|
TYPE:
|
ignore_parameter_values_on_older_children
|
If set to
TYPE:
|
ignore_parameter_values
|
Whether to ignore parameter values when comparing flows.
TYPE:
|
ignore_custom_name_if_none
|
Whether to ignore the custom name field if either flow has
TYPE:
|
check_description
|
Whether to ignore matching of flow descriptions.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
When either argument is not an :class: |
ValueError
|
When a relevant mismatch is found between the two flows. |
Examples:
>>> import openml
>>> f1 = openml.flows.get_flow(5)
>>> f2 = openml.flows.get_flow(5)
>>> openml.flows.assert_flows_equal(f1, f2)
>>> # If flows differ, a ValueError is raised
Source code in openml/flows/functions.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | |
delete_flow
#
Delete flow with id flow_id from the OpenML server.
You can only delete flows which you uploaded and which which are not linked to runs.
| PARAMETER | DESCRIPTION |
|---|---|
flow_id
|
OpenML id of the flow
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the deletion was successful. False otherwise. |
| RAISES | DESCRIPTION |
|---|---|
OpenMLServerException
|
If the server-side deletion fails due to permissions or other errors. |
Side Effects
- Removes the flow from the OpenML server (if permitted).
Examples:
>>> import openml
>>> # Deletes flow 23 if you are the uploader and it's not linked to runs
>>> openml.flows.delete_flow(23)
Source code in openml/flows/functions.py
flow_exists
#
Check whether a flow (name + external_version) exists on the server.
The OpenML server defines uniqueness of flows by the pair
(name, external_version). This helper queries the server and
returns the corresponding flow id when present.
| PARAMETER | DESCRIPTION |
|---|---|
name
|
Flow name (e.g.,
TYPE:
|
external_version
|
Version information associated with flow.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int or bool
|
The flow id if the flow exists on the server, otherwise |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If |
OpenMLServerException
|
When the API request fails. |
Examples:
Source code in openml/flows/functions.py
get_flow
#
get_flow(flow_id: int, reinstantiate: bool = False, strict_version: bool = True) -> OpenMLFlow
Fetch an OpenMLFlow by its server-assigned ID.
Queries the OpenML REST API for the flow metadata and returns an
:class:OpenMLFlow instance. If the flow is already cached locally,
the cached copy is returned. Optionally the flow can be re-instantiated
into a concrete model instance using the registered extension.
| PARAMETER | DESCRIPTION |
|---|---|
flow_id
|
The OpenML flow id.
TYPE:
|
reinstantiate
|
If True, convert the flow description into a concrete model instance
using the flow's extension (e.g., sklearn). If conversion fails and
TYPE:
|
strict_version
|
When
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
OpenMLFlow
|
The flow object with metadata; |
| RAISES | DESCRIPTION |
|---|---|
OpenMLCacheException
|
When cached flow files are corrupted or cannot be read. |
OpenMLServerException
|
When the REST API call fails. |
Side Effects
- Writes to
openml.config.cache_directory/flows/{flow_id}/flow.xmlwhen the flow is downloaded from the server.
Preconditions
- Network access to the OpenML server is required unless the flow is cached.
- For private flows,
openml.config.apikeymust be set.
Notes
Results are cached to speed up subsequent calls. When reinstantiate is
True and version mismatches occur, a new flow may be returned to reflect
the converted model (only when strict_version is False).
Examples:
Source code in openml/flows/functions.py
get_flow_id
#
get_flow_id(model: Any | None = None, name: str | None = None, exact_version: bool = True) -> int | bool | list[int]
Retrieve flow id(s) for a model instance or a flow name.
Provide either a concrete model (which will be converted to a flow by
the appropriate extension) or a flow name. Behavior depends on
exact_version:
model+exact_version=True: convertmodelto a flow and call :func:flow_existsto get a single flow id (or False).model+exact_version=False: convertmodelto a flow and return all server flow ids with the same flow name.name: ignoreexact_versionand return all server flow ids that matchname.
| PARAMETER | DESCRIPTION |
|---|---|
model
|
TYPE:
|
name
|
TYPE:
|
exact_version
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int or bool or list[int]
|
If |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If neither |
OpenMLServerException
|
If underlying API calls fail. |
Side Effects
- May call server APIs (
flow/exists,flow/list) and therefore depends on network access and API keys for private flows.
Examples:
>>> import openml
>>> # Lookup by flow name
>>> openml.flows.get_flow_id(name="weka.JRip")
>>> # Lookup by model instance (requires a registered extension)
>>> import sklearn
>>> import openml_sklearn
>>> clf = sklearn.tree.DecisionTreeClassifier()
>>> openml.flows.get_flow_id(model=clf)
Source code in openml/flows/functions.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
list_flows
#
list_flows(offset: int | None = None, size: int | None = None, tag: str | None = None, uploader: str | None = None) -> DataFrame
List flows available on the OpenML server.
This function supports paging and filtering and returns a pandas DataFrame with one row per flow and columns for id, name, version, external_version, full_name and uploader.
| PARAMETER | DESCRIPTION |
|---|---|
offset
|
Number of flows to skip, starting from the first (for paging).
TYPE:
|
size
|
Maximum number of flows to return.
TYPE:
|
tag
|
Only return flows having this tag.
TYPE:
|
uploader
|
Only return flows uploaded by this user.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
DataFrame
|
Rows correspond to flows. Columns include |
| RAISES | DESCRIPTION |
|---|---|
OpenMLServerException
|
When the API call fails. |
Side Effects
- None: results are fetched and returned; Read-only operation.
Preconditions
- Network access is required to list flows unless cached mechanisms are used by the underlying API helper.
Examples: