From 1c3dbac5d3192e0d41c08f48987ecd69aee1f34a Mon Sep 17 00:00:00 2001 From: David Pomeroy Date: Sat, 12 Oct 2024 05:06:16 +0000 Subject: [PATCH] Address reviewer feedback Fixes minor issues, moves FomType and BetterDirection to new module --- lib/ramble/ramble/application.py | 5 +- lib/ramble/ramble/cmd/results.py | 2 +- lib/ramble/ramble/language/shared_language.py | 55 +---------------- lib/ramble/ramble/reports.py | 2 +- lib/ramble/ramble/util/foms.py | 60 +++++++++++++++++++ 5 files changed, 67 insertions(+), 57 deletions(-) create mode 100644 lib/ramble/ramble/util/foms.py diff --git a/lib/ramble/ramble/application.py b/lib/ramble/ramble/application.py index 62218a511..d19a5b652 100644 --- a/lib/ramble/ramble/application.py +++ b/lib/ramble/ramble/application.py @@ -48,6 +48,7 @@ import ramble.util.graph import ramble.util.class_attributes import ramble.util.lock as lk +from ramble.util.foms import FomType from ramble.util.logger import logger from ramble.util.shell_utils import source_str from ramble.util.naming import NS_SEPARATOR @@ -56,7 +57,7 @@ from ramble.experiment_result import ExperimentResult from ramble.language.application_language import ApplicationMeta -from ramble.language.shared_language import SharedMeta, FomType, register_builtin, register_phase +from ramble.language.shared_language import SharedMeta, register_builtin, register_phase from ramble.error import RambleError from ramble.util.output_capture import output_mapper @@ -1825,6 +1826,7 @@ def calculate_statistics(self, workspace): namespace. """ + # TODO: Think about if this should move to FomType class or new FOM class def is_numeric_fom(fom): """Returns true if a fom value is numeric, and of an applicable type""" @@ -2160,6 +2162,7 @@ def _analysis_dicts(self, criteria_list): "units": conf["units"], "origin": conf["origin"], "origin_type": conf["origin_type"], + # FIXME: this 'to_dict' is getting something strange passed into it and I'm not sure where it came from "fom_type": conf["fom_type"].to_dict(), } if conf["contexts"]: diff --git a/lib/ramble/ramble/cmd/results.py b/lib/ramble/ramble/cmd/results.py index 090fdce92..17d9cfd3b 100644 --- a/lib/ramble/ramble/cmd/results.py +++ b/lib/ramble/ramble/cmd/results.py @@ -141,7 +141,7 @@ def import_results_file(filename): logger.debug(filename) with open(filename) as imported_file: - logger.msg(f"Importing {filename}") + logger.msg(f"Importing results file: {filename}") ext = os.path.splitext(filename)[1] if ext.lower() == ".json": diff --git a/lib/ramble/ramble/language/shared_language.py b/lib/ramble/ramble/language/shared_language.py index 61dfca226..5ad2a0a6b 100644 --- a/lib/ramble/ramble/language/shared_language.py +++ b/lib/ramble/ramble/language/shared_language.py @@ -6,14 +6,11 @@ # option. This file may not be copied, modified, or distributed # except according to those terms. -import copy - -from enum import Enum - import ramble.language.language_base import ramble.language.language_helpers import ramble.success_criteria from ramble.util.logger import logger +from ramble.util.foms import FomType """This module contains directives directives that are shared between multiple object types @@ -81,56 +78,6 @@ def _execute_figure_of_merit_context(obj): return _execute_figure_of_merit_context -# For a FOM, the direction that is 'better' e.g., faster is better -class BetterDirection(Enum): - HIGHER = 1 - LOWER = 2 - INDETERMINATE = 3 # requires interpretation or FOM type not defined - INAPPLICABLE = 4 # non-numerical or no direction is 'better', like strings or categories - - @classmethod - def from_str(cls, string): - try: - return cls[string.upper()] - except KeyError: - return None - - -class FomType(Enum): - TIME = 1 - THROUGHPUT = 2 - MEASURE = 3 - CATEGORY = 4 - INFO = 5 - UNDEFINED = 6 - - def better_direction(self): - direction = { - FomType.TIME: BetterDirection.LOWER, - FomType.THROUGHPUT: BetterDirection.HIGHER, - FomType.MEASURE: BetterDirection.INDETERMINATE, - FomType.CATEGORY: BetterDirection.INAPPLICABLE, - FomType.INFO: BetterDirection.INAPPLICABLE, - FomType.UNDEFINED: BetterDirection.INDETERMINATE, - } - - return direction[self] - - def copy(self): - return copy.deepcopy(self) - - @classmethod - def from_str(cls, string): - try: - return cls[string.upper()] - except KeyError: - return None - - def to_dict(self): - """Converts the FomType enum member to a dictionary representation.""" - return {"name": self.name, "better_direction": self.better_direction().name} - - @shared_directive("figures_of_merit") def figure_of_merit( name, diff --git a/lib/ramble/ramble/reports.py b/lib/ramble/ramble/reports.py index abe9cbe02..dafdcf005 100644 --- a/lib/ramble/ramble/reports.py +++ b/lib/ramble/ramble/reports.py @@ -19,9 +19,9 @@ import ramble.config import ramble.filters from ramble.keywords import keywords -from ramble.language.shared_language import BetterDirection, FomType import ramble.pipeline import ramble.util.path +from ramble.util.foms import BetterDirection, FomType from ramble.util.logger import logger try: diff --git a/lib/ramble/ramble/util/foms.py b/lib/ramble/ramble/util/foms.py new file mode 100644 index 000000000..4e21d9be3 --- /dev/null +++ b/lib/ramble/ramble/util/foms.py @@ -0,0 +1,60 @@ +# Copyright 2022-2024 The Ramble Authors +# +# Licensed under the Apache License, Version 2.0 or the MIT license +# , at your +# option. This file may not be copied, modified, or distributed +# except according to those terms. + +import copy +from enum import Enum + + +# For a FOM, the direction that is 'better' e.g., faster is better +class BetterDirection(Enum): + HIGHER = 1 + LOWER = 2 + INDETERMINATE = 3 # requires interpretation or FOM type not defined + INAPPLICABLE = 4 # non-numerical or no direction is 'better', like strings or categories + + @classmethod + def from_str(cls, string): + try: + return cls[string.upper()] + except KeyError: + return None + + +class FomType(Enum): + TIME = 1 + THROUGHPUT = 2 + MEASURE = 3 + CATEGORY = 4 + INFO = 5 + UNDEFINED = 6 + + def better_direction(self): + direction = { + FomType.TIME: BetterDirection.LOWER, + FomType.THROUGHPUT: BetterDirection.HIGHER, + FomType.MEASURE: BetterDirection.INDETERMINATE, + FomType.CATEGORY: BetterDirection.INAPPLICABLE, + FomType.INFO: BetterDirection.INAPPLICABLE, + FomType.UNDEFINED: BetterDirection.INDETERMINATE, + } + + return direction[self] + + def copy(self): + return copy.deepcopy(self) + + @classmethod + def from_str(cls, string): + try: + return cls[string.upper()] + except KeyError: + return None + + def to_dict(self): + """Converts the FomType enum member to a dictionary representation.""" + return {"name": self.name, "better_direction": self.better_direction().name}