Skip to content

Commit

Permalink
Address reviewer feedback
Browse files Browse the repository at this point in the history
Fixes minor issues, moves FomType and BetterDirection to new module
  • Loading branch information
dapomeroy committed Oct 12, 2024
1 parent ade3463 commit 1c3dbac
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 57 deletions.
5 changes: 4 additions & 1 deletion lib/ramble/ramble/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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"""

Expand Down Expand Up @@ -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"]:
Expand Down
2 changes: 1 addition & 1 deletion lib/ramble/ramble/cmd/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
55 changes: 1 addition & 54 deletions lib/ramble/ramble/language/shared_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/ramble/ramble/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
60 changes: 60 additions & 0 deletions lib/ramble/ramble/util/foms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2022-2024 The Ramble Authors
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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}

0 comments on commit 1c3dbac

Please sign in to comment.