Skip to content

Commit

Permalink
added enums for verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
Julia Putko committed Feb 12, 2024
1 parent 4108181 commit 10d7f89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions smartsim/_core/control/previewrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import typing as t
from enum import Enum

import jinja2

Expand All @@ -38,13 +39,18 @@
from smartsim import Experiment

_OutputFormatString = t.Optional[t.Literal["plain_text"]]
_VerbosityLevelString = t.Literal["info", "debug", "developer"]


class Verbosity(str, Enum):
INFO = "info"
DEBUG = "debug"
DEVELOPER = "developer"


def render(
exp: "Experiment",
manifest: t.Optional[Manifest] = None,
verbosity_level: _VerbosityLevelString = "info",
verbosity_level: Verbosity = Verbosity.INFO,
output_format: _OutputFormatString = "plain_text",
) -> str:
"""
Expand All @@ -54,7 +60,7 @@ def render(
:param manifest: the manifest to be previewed.
:type manifest: Manifest
:param verbosity_level: the verbosity level
:type verbosity_level: _VerbosityLevelString
:type verbosity_level: Verbosity
:param output_format: the output format.
:type output_format: _OutputFormatString
"""
Expand Down Expand Up @@ -102,18 +108,15 @@ def _check_output_format(output_format: _OutputFormatString) -> None:


def _check_verbosity_level(
verbosity_level: _VerbosityLevelString,
) -> _VerbosityLevelString:
verbosity_level: Verbosity,
) -> Verbosity:
"""
Check that the given verbosity level is valid.
"""
if verbosity_level not in ["info", "debug", "developer"]:
raise ValueError("The only valid verbosity level currently available is info")

if verbosity_level in ("debug", "developer"):
if verbosity_level not in (Verbosity.INFO, Verbosity.DEBUG, Verbosity.DEVELOPER):
logger.warning(

Check warning on line 117 in smartsim/_core/control/previewrenderer.py

View check run for this annotation

Codecov / codecov/patch

smartsim/_core/control/previewrenderer.py#L116-L117

Added lines #L116 - L117 were not covered by tests
f"'{verbosity_level}' is an unsupported verbosity level requested.\
Setting verbosity to: info"
Setting verbosity to: {Verbosity.INFO}"
)
return "info"
return "info"
return Verbosity.INFO
return verbosity_level

Check warning on line 122 in smartsim/_core/control/previewrenderer.py

View check run for this annotation

Codecov / codecov/patch

smartsim/_core/control/previewrenderer.py#L121-L122

Added lines #L121 - L122 were not covered by tests
2 changes: 1 addition & 1 deletion smartsim/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def preview(
self,
*args: t.Any,
output_format: previewrenderer._OutputFormatString = "plain_text",
verbosity_level: previewrenderer._VerbosityLevelString = "info",
verbosity_level: previewrenderer.Verbosity = previewrenderer.Verbosity.INFO,
output_filename: t.Optional[str] = None,
) -> None:
"""Preview entity information prior to launch. This method
Expand Down

0 comments on commit 10d7f89

Please sign in to comment.