Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] quickrun result error inspection command #492

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions openfecli/commands/inspect_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import click
from openfecli import OFECommandPlugin

import json
import warnings

def unit_summary(unit_label, unit):
qualname = unit['__qualname__']
if qualname == "ProtocolUnitResult":
yield f"Unit {unit_label} ran successfully."
elif qualname == "ProtocolUnitFailure":
yield f"Unit {unit_label} failed with an error:"
yield f"{unit['exception'][0]}: {unit['exception'][1][0]}"
yield f"{unit['traceback']}"

Check warning on line 14 in openfecli/commands/inspect_result.py

View check run for this annotation

Codecov / codecov/patch

openfecli/commands/inspect_result.py#L8-L14

Added lines #L8 - L14 were not covered by tests
else:
warnings.warn(f"Unexpected result type '{aqualname}' from unit "

Check warning on line 16 in openfecli/commands/inspect_result.py

View check run for this annotation

Codecov / codecov/patch

openfecli/commands/inspect_result.py#L16

Added line #L16 was not covered by tests
f"{unit_label}")

def result_summary(result_dict):
import math

Check warning on line 20 in openfecli/commands/inspect_result.py

View check run for this annotation

Codecov / codecov/patch

openfecli/commands/inspect_result.py#L20

Added line #L20 was not covered by tests
# we were success or failurea
estimate = result_dict['estimate']['magnitude']
success = "FAILURE" if math.isnan(estimate) else "SUCCESS"
yield f"This edge was a {success}."
units = result_dict['unit_results']
yield f"This edge consists of {len(units)} units."
yield ""
for unit_label, unit in units.items():
yield from unit_summary(unit_label, unit)
yield ""

Check warning on line 30 in openfecli/commands/inspect_result.py

View check run for this annotation

Codecov / codecov/patch

openfecli/commands/inspect_result.py#L22-L30

Added lines #L22 - L30 were not covered by tests


@click.command(
'inspect-result',
short_help="Inspect result to show errors.",
)
@click.argument('result_json', type=click.Path(exists=True, readable=True))
def inspect_result(result_json):
with open(result_json, mode='r') as f:
result_dict = json.loads(f.read())

Check warning on line 40 in openfecli/commands/inspect_result.py

View check run for this annotation

Codecov / codecov/patch

openfecli/commands/inspect_result.py#L39-L40

Added lines #L39 - L40 were not covered by tests

for line in result_summary(result_dict):
print(line)

Check warning on line 43 in openfecli/commands/inspect_result.py

View check run for this annotation

Codecov / codecov/patch

openfecli/commands/inspect_result.py#L42-L43

Added lines #L42 - L43 were not covered by tests

PLUGIN = OFECommandPlugin(
command=inspect_result,
section="Quickrun Executor",
requires_ofe=(0, 10)
)

if __name__ == "__main__":
inspect_result()
Loading