From 472b5111e878ea2f341c13f60899cf52c6251156 Mon Sep 17 00:00:00 2001 From: Sebastian Echeverria Date: Tue, 3 Oct 2023 15:01:04 -0400 Subject: [PATCH 1/4] Simplified derived Property constructors --- mlte/property/costs/storage_cost.py | 12 ++++-------- mlte/property/costs/training_compute_cost.py | 12 ++++-------- mlte/property/costs/training_memory_cost.py | 12 ++++-------- mlte/property/functionality/task_efficacy.py | 12 ++++-------- mlte/property/property.py | 13 ++++++------- test/spec/extended_property.py | 12 ++++-------- 6 files changed, 26 insertions(+), 47 deletions(-) diff --git a/mlte/property/costs/storage_cost.py b/mlte/property/costs/storage_cost.py index dc1597cb..37698c02 100644 --- a/mlte/property/costs/storage_cost.py +++ b/mlte/property/costs/storage_cost.py @@ -4,7 +4,6 @@ StorageCost property definition. """ -from mlte._private.text import cleantext from mlte.property.property import Property @@ -16,15 +15,12 @@ class StorageCost(Property): def __init__(self, rationale: str): """Initialize a StorageCost instance.""" super().__init__( - self.__class__.__name__, - cleantext( - """ + instance=self, + description=""" The StorageCost property assesses the storage requirements of a model. These requirements may be expressed in a variety of ways, including the physical size of the model when it is persisted to stable storage, or the number of parameters it contains. - """ - ), - rationale, - __name__, + """, + rationale=rationale, ) diff --git a/mlte/property/costs/training_compute_cost.py b/mlte/property/costs/training_compute_cost.py index f7d1a82f..e652b88e 100644 --- a/mlte/property/costs/training_compute_cost.py +++ b/mlte/property/costs/training_compute_cost.py @@ -4,7 +4,6 @@ TrainingComputeCost property definition. """ -from mlte._private.text import cleantext from mlte.property.property import Property @@ -19,17 +18,14 @@ def __init__(self, rationale: str): Initialize a TrainingComputeCost instance. """ super().__init__( - self.__class__.__name__, - cleantext( - """ + instance=self, + description=""" The TrainingComputeCost property assesses the computational requirements of model training. This might be measured in terms of CPU utilization for training processes that run locally, or the cost of compute resources required for training processes that run on on-demand cloud infrastructure. - """ - ), - rationale, - __name__, + """, + rationale=rationale, ) diff --git a/mlte/property/costs/training_memory_cost.py b/mlte/property/costs/training_memory_cost.py index ec54d55f..8336ea2f 100644 --- a/mlte/property/costs/training_memory_cost.py +++ b/mlte/property/costs/training_memory_cost.py @@ -4,7 +4,6 @@ TrainingMemoryCost property definition. """ -from mlte._private.text import cleantext from mlte.property.property import Property @@ -19,17 +18,14 @@ def __init__(self, rationale: str): Initialize a TrainingMemoryCost instance. """ super().__init__( - self.__class__.__name__, - cleantext( - """ + instance=self, + description=""" The TrainingMemoryCost property assesses the memory requirements of model training. This might be measured by the memory requirements of training processes that run locally, or the cost of memory resources required for training processes that run on on-demand cloud infrastructure. - """ - ), - rationale, - __name__, + """, + rationale=rationale, ) diff --git a/mlte/property/functionality/task_efficacy.py b/mlte/property/functionality/task_efficacy.py index 51e04ac7..3a065f48 100644 --- a/mlte/property/functionality/task_efficacy.py +++ b/mlte/property/functionality/task_efficacy.py @@ -4,7 +4,6 @@ TaskEfficacy property definition. """ -from mlte._private.text import cleantext from mlte.property.property import Property @@ -17,16 +16,13 @@ class TaskEfficacy(Property): def __init__(self, rationale: str): """Initialize a TaskEfficacy instance.""" super().__init__( - self.__class__.__name__, - cleantext( - """ + instance=self, + description=""" The TaskEfficacy property assesses a model's ability to correctly perform instances of its task. The means of measurement for this property will vary by both domain and task. Examples include accuracy, error rate, and average precision, but many others are possible. - """ - ), - rationale, - __name__, + """, + rationale=rationale, ) diff --git a/mlte/property/property.py b/mlte/property/property.py index 81433b64..63081cfc 100644 --- a/mlte/property/property.py +++ b/mlte/property/property.py @@ -11,6 +11,7 @@ from typing import Type import mlte._private.meta as meta +from mlte._private.text import cleantext from mlte.spec.model import PropertyModel @@ -22,26 +23,24 @@ def __subclasshook__(cls, subclass): """Define the interface for all concrete properties.""" return meta.has_callables(subclass, "__init__") - def __init__( - self, name: str, description: str, rationale: str, module: str - ): + def __init__(self, instance: Property, description: str, rationale: str): """ Initialize a Property instance. - :param name: The name of the property + :param instance: The derived Property we are creating from. :param description: The description of the property :param rationale: The rationale for using the property """ - self.name: str = name + self.name: str = instance.__class__.__name__ """The name of the property.""" - self.description: str = description + self.description: str = cleantext(description) """The description of the property.""" self.rationale: str = rationale """The rationale for using the property.""" - self.module: str = module + self.module: str = instance.__module__ """The name of the module the property is defined in.""" def to_model(self) -> PropertyModel: diff --git a/test/spec/extended_property.py b/test/spec/extended_property.py index 0a58e46a..9c779cb2 100644 --- a/test/spec/extended_property.py +++ b/test/spec/extended_property.py @@ -4,7 +4,6 @@ ExtendedProperty definition, for testing purposes. """ -from mlte._private.text import cleantext from mlte.property.property import Property @@ -16,12 +15,9 @@ class ExtendedProperty(Property): def __init__(self, rationale: str): """Initialize a ExtendedProperty instance.""" super().__init__( - self.__class__.__name__, - cleantext( - """ + instance=self, + description=""" The ExtendedProperty property is just for testing purposes. - """ - ), - rationale, - __name__, + """, + rationale=rationale, ) From a94fd164727d822f849b51fd9c3b772f83801124 Mon Sep 17 00:00:00 2001 From: Sebastian Echeverria Date: Tue, 3 Oct 2023 17:47:53 -0400 Subject: [PATCH 2/4] Renaming to address #265 --- mlte/property/{property.py => base.py} | 4 ++-- mlte/property/costs/storage_cost.py | 2 +- mlte/property/costs/training_compute_cost.py | 2 +- mlte/property/costs/training_memory_cost.py | 2 +- mlte/property/functionality/task_efficacy.py | 2 +- mlte/spec/spec.py | 2 +- mlte/validation/validated_spec.py | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) rename mlte/property/{property.py => base.py} (96%) diff --git a/mlte/property/property.py b/mlte/property/base.py similarity index 96% rename from mlte/property/property.py rename to mlte/property/base.py index 63081cfc..3b08c7cb 100644 --- a/mlte/property/property.py +++ b/mlte/property/base.py @@ -1,5 +1,5 @@ """ -mlte/property/property.py +mlte/property/base.py The superclass for all model properties. """ @@ -27,7 +27,7 @@ def __init__(self, instance: Property, description: str, rationale: str): """ Initialize a Property instance. - :param instance: The derived Property we are creating from. + :param instance: The derived Property we are constructing from. :param description: The description of the property :param rationale: The rationale for using the property """ diff --git a/mlte/property/costs/storage_cost.py b/mlte/property/costs/storage_cost.py index 37698c02..87048195 100644 --- a/mlte/property/costs/storage_cost.py +++ b/mlte/property/costs/storage_cost.py @@ -4,7 +4,7 @@ StorageCost property definition. """ -from mlte.property.property import Property +from mlte.property.base import Property class StorageCost(Property): diff --git a/mlte/property/costs/training_compute_cost.py b/mlte/property/costs/training_compute_cost.py index e652b88e..2b1331a7 100644 --- a/mlte/property/costs/training_compute_cost.py +++ b/mlte/property/costs/training_compute_cost.py @@ -4,7 +4,7 @@ TrainingComputeCost property definition. """ -from mlte.property.property import Property +from mlte.property.base import Property class TrainingComputeCost(Property): diff --git a/mlte/property/costs/training_memory_cost.py b/mlte/property/costs/training_memory_cost.py index 8336ea2f..698aa556 100644 --- a/mlte/property/costs/training_memory_cost.py +++ b/mlte/property/costs/training_memory_cost.py @@ -4,7 +4,7 @@ TrainingMemoryCost property definition. """ -from mlte.property.property import Property +from mlte.property.base import Property class TrainingMemoryCost(Property): diff --git a/mlte/property/functionality/task_efficacy.py b/mlte/property/functionality/task_efficacy.py index 3a065f48..43a32c1e 100644 --- a/mlte/property/functionality/task_efficacy.py +++ b/mlte/property/functionality/task_efficacy.py @@ -4,7 +4,7 @@ TaskEfficacy property definition. """ -from mlte.property.property import Property +from mlte.property.base import Property class TaskEfficacy(Property): diff --git a/mlte/spec/spec.py b/mlte/spec/spec.py index c9996974..1a3cb681 100644 --- a/mlte/spec/spec.py +++ b/mlte/spec/spec.py @@ -12,7 +12,7 @@ from mlte.artifact.artifact import Artifact from mlte.artifact.model import ArtifactModel from mlte.artifact.type import ArtifactType -from mlte.property.property import Property +from mlte.property.base import Property from mlte.spec.condition import Condition from mlte.spec.model import PropertyModel, SpecModel diff --git a/mlte/validation/validated_spec.py b/mlte/validation/validated_spec.py index 938b881d..25e3d666 100644 --- a/mlte/validation/validated_spec.py +++ b/mlte/validation/validated_spec.py @@ -12,7 +12,7 @@ from mlte.artifact.artifact import Artifact from mlte.artifact.model import ArtifactModel from mlte.artifact.type import ArtifactType -from mlte.property.property import Property +from mlte.property.base import Property from mlte.spec.condition import Condition from mlte.spec.model import SpecModel from mlte.spec.spec import Spec From 953e5cfcd33c4dbc2c690f2239bcbad1106ee6e1 Mon Sep 17 00:00:00 2001 From: Sebastian Echeverria Date: Tue, 3 Oct 2023 17:54:02 -0400 Subject: [PATCH 3/4] Missing renaming --- test/spec/extended_property.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/extended_property.py b/test/spec/extended_property.py index 9c779cb2..ed01ae42 100644 --- a/test/spec/extended_property.py +++ b/test/spec/extended_property.py @@ -4,7 +4,7 @@ ExtendedProperty definition, for testing purposes. """ -from mlte.property.property import Property +from mlte.property.base import Property class ExtendedProperty(Property): From 2d03bf6ac385c994f961d107d73485914892b84b Mon Sep 17 00:00:00 2001 From: Sebastian Echeverria Date: Tue, 3 Oct 2023 17:57:31 -0400 Subject: [PATCH 4/4] Comment fix --- test/spec/extended_property.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/extended_property.py b/test/spec/extended_property.py index ed01ae42..0a7de7a1 100644 --- a/test/spec/extended_property.py +++ b/test/spec/extended_property.py @@ -1,5 +1,5 @@ """ -test/spec/test_model.py +test/spec/extended_property.py ExtendedProperty definition, for testing purposes. """