Исправлены замечания ревью Workers
This commit is contained in:
@@ -23,12 +23,21 @@ class SciMeshRunner:
|
||||
command = [sys.executable, "-m", "scimesh.cli", task.workload, str(input_path)]
|
||||
params = task.parameters
|
||||
if task.workload == "similarity-search":
|
||||
query_id = self._string(params, "query_id")
|
||||
self._reject_unknown(params, {"query_id", "query_smiles", "top_k", "threshold", "threshold_direction", "max_rows", "progress_every"})
|
||||
query_id, query_smiles = params.get("query_id"), params.get("query_smiles")
|
||||
if (query_id is None) == (query_smiles is None):
|
||||
raise ValueError("exactly one of query_id or query_smiles is required")
|
||||
top_k = self._positive_int(params, "top_k", default=20)
|
||||
command += ["--query-id", query_id, "--top-k", str(top_k)]
|
||||
command += ["--query-id", self._string(params, "query_id")] if query_id is not None else ["--query-smiles", self._string(params, "query_smiles")]
|
||||
command += ["--top-k", str(top_k)]
|
||||
self._append_common_options(command, params)
|
||||
elif task.workload == "similarity-graph":
|
||||
self._reject_unknown(params, {"threshold", "threshold_direction", "block_size", "max_rows", "progress_every"})
|
||||
threshold = self._number(params, "threshold")
|
||||
command += ["--threshold", str(threshold)]
|
||||
self._append_common_options(command, params, include_threshold=False)
|
||||
if "block_size" in params:
|
||||
command += ["--block-size", str(self._positive_int(params, "block_size", default=1_000))]
|
||||
else:
|
||||
raise ValueError(f"unsupported workload: {task.workload}")
|
||||
command += ["--output", str(output_path)]
|
||||
@@ -38,6 +47,25 @@ class SciMeshRunner:
|
||||
processed_rows = max(sum(1 for _ in output_path.open(encoding="utf-8")) - 1, 0)
|
||||
return RunResult((ProducedArtifact(output_path, "text/csv"),), {"processed_rows": processed_rows})
|
||||
|
||||
def _append_common_options(self, command: list[str], params: dict[str, object], *, include_threshold: bool = True) -> None:
|
||||
if include_threshold and "threshold" in params:
|
||||
command += ["--threshold", str(self._number(params, "threshold"))]
|
||||
if "threshold_direction" in params:
|
||||
direction = params["threshold_direction"]
|
||||
if direction not in ("greater", "less"):
|
||||
raise ValueError("threshold_direction must be 'greater' or 'less'")
|
||||
command += ["--threshold-direction", str(direction)]
|
||||
if "max_rows" in params:
|
||||
command += ["--max-rows", str(self._positive_int(params, "max_rows", default=1))]
|
||||
if "progress_every" in params:
|
||||
command += ["--progress-every", str(self._nonnegative_int(params, "progress_every"))]
|
||||
|
||||
@staticmethod
|
||||
def _reject_unknown(params: dict[str, object], allowed: set[str]) -> None:
|
||||
unknown = set(params) - allowed
|
||||
if unknown:
|
||||
raise ValueError(f"unsupported parameters: {', '.join(sorted(unknown))}")
|
||||
|
||||
@staticmethod
|
||||
def _string(params: dict[str, object], name: str) -> str:
|
||||
value = params.get(name)
|
||||
@@ -52,6 +80,13 @@ class SciMeshRunner:
|
||||
raise ValueError(f"{name} must be a positive integer")
|
||||
return value
|
||||
|
||||
@staticmethod
|
||||
def _nonnegative_int(params: dict[str, object], name: str) -> int:
|
||||
value = params[name]
|
||||
if isinstance(value, bool) or not isinstance(value, int) or value < 0:
|
||||
raise ValueError(f"{name} must be a non-negative integer")
|
||||
return value
|
||||
|
||||
@staticmethod
|
||||
def _number(params: dict[str, object], name: str) -> float:
|
||||
value = params.get(name)
|
||||
|
||||
Reference in New Issue
Block a user