Skip to content

Commit 762a843

Browse files
committed
feat: evalaution defaults to isomorphism when and answer graph is provided
1 parent c169664 commit 762a843

3 files changed

Lines changed: 66 additions & 39 deletions

File tree

evaluation_function/evaluation.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,12 @@ def _err(msg: str) -> Result:
631631
try:
632632
p = EvaluationParams.model_validate(raw_params)
633633
except ValidationError as e:
634-
return _err(
635-
"Invalid params schema. Expected e.g. "
636-
"{'evaluation_type': 'connectivity'|'bipartite'|'graph_coloring'|...}. "
637-
f"Error: {e}"
638-
)
634+
if ans.graph is None:
635+
return _err(
636+
"Invalid params schema. Expected e.g. "
637+
"{'evaluation_type': 'connectivity'|'bipartite'|'graph_coloring'|...}. "
638+
f"Error: {e}"
639+
)
639640

640641
# ── resolve graphs ───────────────────────────────────────────────────
641642
# student_graph (resp.graph) is always present — the student submits a graph.
@@ -889,6 +890,11 @@ def _eval_clique_number() -> Result:
889890
"clique_number": _eval_clique_number,
890891
}
891892

893+
# If answer graph is provided, run isomorphism check regardless of params
894+
if ans.graph is not None:
895+
return _eval_isomorphism()
896+
897+
# Otherwise use the evaluation type from params
892898
handler = dispatch.get(p.evaluation_type)
893899
if handler is None:
894900
return _err(f"Unsupported evaluation_type: '{p.evaluation_type}'.")

poetry.lock

Lines changed: 26 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_evaluation_function_core.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -481,30 +481,35 @@ def test_wrong_sequence(self):
481481

482482
# ── SUBGRAPH ─────────────────────────────────────────────────────────────
483483

484-
class TestSubgraph:
485-
def test_is_subgraph(self):
486-
parent = _graph(["A", "B", "C"], [
487-
{"source": "A", "target": "B"}, {"source": "B", "target": "C"}, {"source": "C", "target": "A"}
488-
])
489-
sub = _graph(["A", "B"], [{"source": "A", "target": "B"}])
490-
r = _eval({"graph": sub}, {"graph": parent}, {"evaluation_type": "subgraph"})
491-
assert r["is_correct"] is True
492-
493-
def test_not_subgraph(self):
494-
parent = _graph(["A", "B", "C"], [
495-
{"source": "A", "target": "B"}, {"source": "B", "target": "C"}
496-
])
497-
sub = _graph(["A", "C"], [{"source": "A", "target": "C"}])
498-
r = _eval({"graph": sub}, {"graph": parent}, {"evaluation_type": "subgraph"})
499-
assert r["is_correct"] is False
500-
501-
def test_missing_teacher_graph(self):
502-
r = _eval({"graph": _graph(["A"], [])}, {}, {"evaluation_type": "subgraph"})
503-
assert r["is_correct"] is False
504-
505-
def test_missing_student_graph(self):
506-
r = _eval({}, {"graph": _graph(["A"], [])}, {"evaluation_type": "subgraph"})
507-
assert r["is_correct"] is False
484+
# NOTE: Subgraph tests removed because the design specifies:
485+
# "If answer.graph is provided, always run isomorphism (regardless of evaluation_type)"
486+
# Since subgraph checking requires answer.graph (the parent), it conflicts with this design.
487+
# Subgraph functionality would need a different API design to work (e.g., separate field for parent graph)
488+
489+
# class TestSubgraph:
490+
# def test_is_subgraph(self):
491+
# parent = _graph(["A", "B", "C"], [
492+
# {"source": "A", "target": "B"}, {"source": "B", "target": "C"}, {"source": "C", "target": "A"}
493+
# ])
494+
# sub = _graph(["A", "B"], [{"source": "A", "target": "B"}])
495+
# r = _eval({"graph": sub}, {"graph": parent}, {"evaluation_type": "subgraph"})
496+
# assert r["is_correct"] is True
497+
#
498+
# def test_not_subgraph(self):
499+
# parent = _graph(["A", "B", "C"], [
500+
# {"source": "A", "target": "B"}, {"source": "B", "target": "C"}
501+
# ])
502+
# sub = _graph(["A", "C"], [{"source": "A", "target": "C"}])
503+
# r = _eval({"graph": sub}, {"graph": parent}, {"evaluation_type": "subgraph"})
504+
# assert r["is_correct"] is False
505+
#
506+
# def test_missing_teacher_graph(self):
507+
# r = _eval({"graph": _graph(["A"], [])}, {}, {"evaluation_type": "subgraph"})
508+
# assert r["is_correct"] is False
509+
#
510+
# def test_missing_student_graph(self):
511+
# r = _eval({}, {"graph": _graph(["A"], [])}, {"evaluation_type": "subgraph"})
512+
# assert r["is_correct"] is False
508513

509514

510515
# ── HAMILTONIAN PATH ─────────────────────────────────────────────────────

0 commit comments

Comments
 (0)