diff --git a/.github/workflows/zizmor.yml b/.github/workflows/zizmor.yml new file mode 100644 index 0000000..6b38282 --- /dev/null +++ b/.github/workflows/zizmor.yml @@ -0,0 +1,26 @@ +name: zizmor + +on: + push: + branches: ["develop"] + pull_request: + branches: ["**"] + +permissions: {} + +jobs: + zizmor: + name: Run zizmor + runs-on: ubuntu-latest + permissions: + security-events: write # Required for upload-sarif (used by zizmor-action) to upload SARIF files. + contents: read + actions: read + steps: + - name: Checkout repository + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + + - name: Run zizmor + uses: zizmorcore/zizmor-action@b1d7e1fb5de872772f31590499237e7cce841e8e # v0.5.3 diff --git a/docs/examples/complex-workflow-csv.md b/docs/examples/complex-workflow-csv.md index c939cba..def0a7c 100644 --- a/docs/examples/complex-workflow-csv.md +++ b/docs/examples/complex-workflow-csv.md @@ -118,14 +118,20 @@ class Workflow(FlowSpec): ): """Pick the best solution based on the result value.""" - results = nextroute_results + [vroom_result, ortools_result] + def get_value(idx: int, result: dict) -> float: + if k := next((k for k in ("statistics", "metrics") if k in result), None): + return result[k]["result"]["value"] + raise ValueError(f"Result at index {idx} does not contain 'statistics' or 'metrics'") + + """Aggregates the results.""" + results = results_nextroute + [result_ortools, result_pyvroom] best_solution_idx = min( range(len(results)), - key=lambda i: results[i].output["statistics"]["result"]["value"], + key=lambda i: get_value(i, results[i]), ) - for result in results: - log(f"{result.metadata.application_id}: " + f"{result.output['statistics']['result']['value']}") + for i, result in enumerate(results): + log(f"{result.metadata.application_id}: " + f"{get_value(i, result)}") return results[best_solution_idx].output diff --git a/docs/examples/complex-workflow.md b/docs/examples/complex-workflow.md index e8d1fa8..22e669e 100644 --- a/docs/examples/complex-workflow.md +++ b/docs/examples/complex-workflow.md @@ -90,13 +90,19 @@ class Workflow(FlowSpec): ): """Aggregates the results.""" + def get_value(idx: int, result: dict) -> float: + if k := next((k for k in ("statistics", "metrics") if k in result), None): + return result[k]["result"]["value"] + raise ValueError(f"Result at index {idx} does not contain 'statistics' or 'metrics'") + + """Aggregates the results.""" results = results_nextroute + [result_ortools, result_pyvroom] best_solution_idx = min( range(len(results)), - key=lambda i: results[i]["statistics"]["result"]["value"], + key=lambda i: get_value(i, results[i]), ) - values = [result["statistics"]["result"]["value"] for result in results] + values = [get_value(i, result) for i, result in enumerate(results)] values.sort() log(f"Values: {values}") diff --git a/docs/examples/ensemble-workflow.md b/docs/examples/ensemble-workflow.md index 8406c50..311e7d2 100644 --- a/docs/examples/ensemble-workflow.md +++ b/docs/examples/ensemble-workflow.md @@ -48,10 +48,15 @@ class Workflow(FlowSpec): def pick_best(results: list[dict[str, Any]]) -> dict[str, Any]: """Aggregates the results.""" - log(f"Values: {[result['statistics']['result']['value'] for result in results]}") + def get_value(idx: int, result: dict) -> float: + if k := next((k for k in ("statistics", "metrics") if k in result), None): + return result[k]["result"]["value"] + raise ValueError(f"Result at index {idx} does not contain 'statistics' or 'metrics'") + + log(f"Values: {[get_value(i, result) for i, result in enumerate(results)]}") best_solution_idx = min( range(len(results)), - key=lambda i: results[i]["statistics"]["result"]["value"], + key=lambda i: get_value(i, results[i]), ) return results[best_solution_idx] diff --git a/tests/pipelines/complex.py b/tests/pipelines/complex.py index 83ebc56..2ec3b70 100644 --- a/tests/pipelines/complex.py +++ b/tests/pipelines/complex.py @@ -41,14 +41,18 @@ def pick_best( result_ortools: dict, result_pyvroom: dict, ): - """Aggregates the results.""" + def get_value(idx: int, result: dict) -> float: + if k := next((k for k in ("statistics", "metrics") if k in result), None): + return result[k]["result"]["value"] + raise ValueError(f"Result at index {idx} does not contain 'statistics' or 'metrics'") + results = results_nextroute + [result_ortools, result_pyvroom] best_solution_idx = min( range(len(results)), - key=lambda i: results[i]["statistics"]["result"]["value"], + key=lambda i: get_value(i, results[i]), ) - values = [result["statistics"]["result"]["value"] for result in results] + values = [get_value(i, result) for i, result in enumerate(results)] values.sort() log(f"Values: {values}")