utilities¶
PV_Circuit_Model.utilities
¶
Artifact
¶
Serializable artifact base class.
__init__(object_)
¶
Wrap an object as Artifact so that it can be saved via dump and loaded via load like pickle
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
object_
|
Optional[Any]
|
artifact payload. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Example
from PV_Circuit_Model.utilities import Artifact
art = Artifact({"a": 1})
clone(critical_fields_only=False)
¶
Clone this Artifact.
Returns:
| Name | Type | Description |
|---|---|---|
Artifact |
Artifact
|
Cloned instance. |
Example
from PV_Circuit_Model.utilities import Artifact
art = Artifact({"a": 1})
clone = art.clone()
dump(path, *, indent=2, critical_fields_only=False)
¶
Write serialized parameters to JSON or BSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Output file path. |
required |
indent
|
int
|
JSON indentation. |
2
|
critical_fields_only
|
bool
|
If True, only serialize critical fields. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Final path written. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If an unsupported file extension is used. |
Example
import tempfile
from PV_Circuit_Model.utilities import Artifact
art = Artifact({"a": 1})
with tempfile.TemporaryDirectory() as folder:
art.dump(Path(folder) / "artifact.json")
load(path)
staticmethod
¶
Load an Artifact or serialized object from JSON or BSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path]
|
Input file path. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Restored object. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If an unsupported file extension is used. |
Example
import tempfile
from PV_Circuit_Model.utilities import Artifact
art = Artifact({"a": 1})
with tempfile.TemporaryDirectory() as folder:
path = Path(folder) / "artifact.json"
art.dump(path)
Artifact.load(path)