arkas.exporter¶
arkas.exporter ¶
Contain output exporters.
arkas.exporter.BaseExporter ¶
Bases: ABC
Define the base class to export an output object.
Example usage:
>>> import tempfile
>>> from pathlib import Path
>>> import numpy as np
>>> from arkas.output import AccuracyOutput
>>> from arkas.state import AccuracyState
>>> from arkas.exporter import MetricExporter
>>> output = AccuracyOutput(
... state=AccuracyState(
... y_true=np.array([1, 0, 0, 1, 1]),
... y_pred=np.array([1, 0, 0, 1, 1]),
... y_true_name="target",
... y_pred_name="pred",
... )
... )
>>> with tempfile.TemporaryDirectory() as tmpdir:
... exporter = MetricExporter(path=Path(tmpdir).joinpath("metrics.pkl"))
... print(exporter)
... exporter.export(output)
...
MetricExporter(
(path): .../metrics.pkl
(saver): PickleSaver()
(exist_ok): False
(show_metrics): False
)
arkas.exporter.BaseExporter.equal
abstractmethod
¶
equal(other: Any, equal_nan: bool = False) -> bool
Indicate if two exporters are equal or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Any
|
The other exporter to compare. |
required |
equal_nan
|
bool
|
Whether to compare NaN's as equal. If |
False
|
Returns:
Type | Description |
---|---|
bool
|
|
Example usage:
>>> from arkas.exporter import MetricExporter
>>> exporter1 = MetricExporter(path="/data/metrics.pkl")
>>> exporter2 = MetricExporter(path="/data/metrics.pkl")
>>> exporter3 = MetricExporter(path="/data/metrics.pkl", exist_ok=True)
>>> exporter1.equal(exporter2)
True
>>> exporter1.equal(exporter3)
False
arkas.exporter.BaseExporter.export
abstractmethod
¶
export(output: BaseOutput) -> None
Export an output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output
|
BaseOutput
|
The output object to export. |
required |
Example usage:
>>> import tempfile
>>> from pathlib import Path
>>> import numpy as np
>>> from arkas.output import AccuracyOutput
>>> from arkas.state import AccuracyState
>>> from arkas.exporter import MetricExporter
>>> output = AccuracyOutput(
... state=AccuracyState(
... y_true=np.array([1, 0, 0, 1, 1]),
... y_pred=np.array([1, 0, 0, 1, 1]),
... y_true_name="target",
... y_pred_name="pred",
... )
... )
>>> with tempfile.TemporaryDirectory() as tmpdir:
... exporter = MetricExporter(path=Path(tmpdir).joinpath("metrics.pkl"))
... exporter.export(output)
...
arkas.exporter.MetricExporter ¶
Bases: BaseExporter
Implement a simple metric exporter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path | str
|
The path where to save the metrics. |
required |
saver
|
BaseSaver | dict | None
|
The metric saver or its configuration. |
None
|
exist_ok
|
bool
|
If |
False
|
show_metrics
|
bool
|
If |
False
|
Example usage:
>>> import tempfile
>>> from pathlib import Path
>>> import numpy as np
>>> from arkas.output import AccuracyOutput
>>> from arkas.state import AccuracyState
>>> from arkas.exporter import MetricExporter
>>> output = AccuracyOutput(
... state=AccuracyState(
... y_true=np.array([1, 0, 0, 1, 1]),
... y_pred=np.array([1, 0, 0, 1, 1]),
... y_true_name="target",
... y_pred_name="pred",
... )
... )
>>> with tempfile.TemporaryDirectory() as tmpdir:
... exporter = MetricExporter(path=Path(tmpdir).joinpath("metrics.pkl"))
... exporter.export(output)
...
arkas.exporter.ReportExporter ¶
Bases: BaseExporter
Implement a simple report exporter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path | str
|
The path where to save the reports. |
required |
saver
|
BaseSaver | dict | None
|
The report saver or its configuration. |
None
|
exist_ok
|
bool
|
If |
False
|
max_toc_depth
|
int
|
The maximum level to show in the table of content. |
6
|
Example usage:
>>> import tempfile
>>> from pathlib import Path
>>> import numpy as np
>>> from arkas.output import AccuracyOutput
>>> from arkas.state import AccuracyState
>>> from arkas.exporter import ReportExporter
>>> output = AccuracyOutput(
... state=AccuracyState(
... y_true=np.array([1, 0, 0, 1, 1]),
... y_pred=np.array([1, 0, 0, 1, 1]),
... y_true_name="target",
... y_pred_name="pred",
... )
... )
>>> with tempfile.TemporaryDirectory() as tmpdir:
... exporter = ReportExporter(path=Path(tmpdir).joinpath("report.html"))
... exporter.export(output)
...
arkas.exporter.SequentialExporter ¶
Bases: BaseExporter
Implement an exporter that sequentially calls several exporters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exporters
|
Sequence[BaseExporter | dict]
|
The sequence of exporters. |
required |
Example usage:
>>> import tempfile
>>> from pathlib import Path
>>> import numpy as np
>>> from arkas.output import AccuracyOutput
>>> from arkas.state import AccuracyState
>>> from arkas.exporter import (
... SequentialExporter,
... ReportExporter,
... MetricExporter,
... )
>>> output = AccuracyOutput(
... state=AccuracyState(
... y_true=np.array([1, 0, 0, 1, 1]),
... y_pred=np.array([1, 0, 0, 1, 1]),
... y_true_name="target",
... y_pred_name="pred",
... )
... )
>>> with tempfile.TemporaryDirectory() as tmpdir:
... path = Path(tmpdir)
... exporter = SequentialExporter(
... [
... MetricExporter(path.joinpath("metrics.pkl")),
... ReportExporter(path.joinpath("report.html")),
... ]
... )
... print(exporter)
... exporter.export(output)
...
SequentialExporter(
(0): MetricExporter(
(path): .../metrics.pkl
(saver): PickleSaver()
(exist_ok): False
(show_metrics): False
)
(1): ReportExporter(
(path): .../report.html
(saver): TextSaver()
(exist_ok): False
(max_toc_depth): 6
)
)
arkas.exporter.is_exporter_config ¶
is_exporter_config(config: dict) -> bool
Indicate if the input configuration is a configuration for a
BaseExporter
.
This function only checks if the value of the key _target_
is valid. It does not check the other values. If _target_
indicates a function, the returned type hint is used to check
the class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
The configuration to check. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
|
Example usage:
>>> from arkas.exporter import is_exporter_config
>>> is_exporter_config(
... {
... "_target_": "arkas.exporter.MetricExporter",
... "path": "/path/to/data.csv",
... }
... )
True
arkas.exporter.setup_exporter ¶
setup_exporter(
exporter: BaseExporter | dict,
) -> BaseExporter
Set up a exporter.
The exporter is instantiated from its configuration
by using the BaseExporter
factory function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exporter
|
BaseExporter | dict
|
A exporter or its configuration. |
required |
Returns:
Type | Description |
---|---|
BaseExporter
|
An instantiated exporter. |
Example usage:
>>> from arkas.exporter import setup_exporter
>>> exporter = setup_exporter(
... {
... "_target_": "arkas.exporter.MetricExporter",
... "path": "/path/to/data.csv",
... }
... )
>>> exporter
MetricExporter(
(path): /path/to/data.csv
(saver): PickleSaver()
(exist_ok): False
(show_metrics): False
)