Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
validation_scaffold.py
Go to the documentation of this file.
1 """Shared helpers for density-matrix evidence validation slice modules."""
2 
3 from __future__ import annotations
4 
5 import argparse
6 from collections.abc import Callable
7 from pathlib import Path
8 from typing import Any
9 
10 
12  bundle: dict[str, Any],
13  fields: tuple[str, ...],
14  label: str,
15 ) -> None:
16  missing = [field for field in fields if field not in bundle]
17  if missing:
18  raise ValueError(
19  "{} missing required fields: {}".format(label, ", ".join(missing))
20  )
21 
22 
24  argv: list[str] | None,
25  *,
26  build_cases: Callable[[], list[dict[str, Any]]],
27  build_artifact_bundle: Callable[[list[dict[str, Any]]], dict[str, Any]],
28  artifact_filename: str,
29  default_output_dir: Path,
30  description: str,
31  output_dir_help: str,
32  quiet_report: Callable[[dict[str, Any]], None] | None = None,
33 ) -> int:
34  """CLI for slices that follow build_cases → build_artifact_bundle(cases) → write."""
35  from benchmarks.density_matrix.evidence_io import write_artifact_bundle
36 
37  parser = argparse.ArgumentParser(description=description)
38  parser.add_argument(
39  "--output-dir",
40  type=Path,
41  default=default_output_dir,
42  help=output_dir_help,
43  )
44  parser.add_argument(
45  "--quiet",
46  action="store_true",
47  help="Suppress per-case console output.",
48  )
49  args = parser.parse_args(argv)
50 
51  cases = build_cases()
52  bundle = build_artifact_bundle(cases)
53  output_path = write_artifact_bundle(bundle, args.output_dir, artifact_filename)
54 
55  if not args.quiet:
56  if quiet_report is not None:
57  quiet_report(bundle)
58  print("Wrote {}".format(output_path))
59 
60  return 0 if bundle["status"] == "pass" else 1
def build_artifact_bundle(results)