nickh007 commited on
Commit
8900b7c
·
verified ·
1 Parent(s): 326c447

Add a browsable index so the Hub viewer can render the corpus

Browse files
Files changed (4) hide show
  1. README.md +7 -1
  2. build_index.py +52 -0
  3. data/index.jsonl +11 -0
  4. tests/test_conformance.py +26 -0
README.md CHANGED
@@ -14,11 +14,14 @@ tags:
14
  pretty_name: S-Parameter Physical Conformance Corpus
15
  size_categories:
16
  - n<1K
 
 
 
17
  ---
18
 
19
  # sparam-conformance
20
 
21
- ![CI](https://github.com/nickharris808/sparam-conformance/actions/workflows/ci.yml/badge.svg) ![Licence](https://img.shields.io/badge/data-CC--BY--4.0-green) ![Cases](https://img.shields.io/badge/cases-11%20labelled-blue) ![Tests](https://img.shields.io/badge/tests-46%20passing-brightgreen)
22
 
23
  **A labelled corpus of S-parameter networks with ground-truth physical verdicts —
24
  and a scorer that grades any checker against it.**
@@ -164,6 +167,9 @@ score.py scorer + adapter contract
164
  sparam_lint_adapter.py reference adapter (5 lines)
165
  data/*.s2p, *.s4p the corpus
166
  data/manifest.json labels, tags, SHA-256 digests
 
 
 
167
  tests/ label verification + scorer tests
168
  ```
169
 
 
14
  pretty_name: S-Parameter Physical Conformance Corpus
15
  size_categories:
16
  - n<1K
17
+ configs:
18
+ - config_name: index
19
+ data_files: data/index.jsonl
20
  ---
21
 
22
  # sparam-conformance
23
 
24
+ ![CI](https://github.com/nickharris808/sparam-conformance/actions/workflows/ci.yml/badge.svg) ![Licence](https://img.shields.io/badge/data-CC--BY--4.0-green) ![Cases](https://img.shields.io/badge/cases-11%20labelled-blue) ![Tests](https://img.shields.io/badge/tests-47%20passing-brightgreen)
25
 
26
  **A labelled corpus of S-parameter networks with ground-truth physical verdicts —
27
  and a scorer that grades any checker against it.**
 
167
  sparam_lint_adapter.py reference adapter (5 lines)
168
  data/*.s2p, *.s4p the corpus
169
  data/manifest.json labels, tags, SHA-256 digests
170
+ data/index.jsonl the manifest flattened one-row-per-case, so the
171
+ Hub viewer can render it (generated by build_index.py)
172
+ build_index.py regenerates index.jsonl from the manifest
173
  tests/ label verification + scorer tests
174
  ```
175
 
build_index.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Flatten the manifest into a tabular index the Hub dataset viewer can render.
3
+
4
+ The corpus itself is Touchstone text, which no dataset viewer parses, so a
5
+ reader landing on the Hub page would otherwise see nothing at all. This emits
6
+ one row per case -- labels, expected failures, digest -- so the contents are
7
+ browsable in the page without downloading anything.
8
+
9
+ The .sNp files remain the data; this is a view of the manifest, generated from
10
+ it, never edited by hand.
11
+ """
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ import pathlib
16
+
17
+ HERE = pathlib.Path(__file__).resolve().parent
18
+ DATA = HERE / "data"
19
+
20
+
21
+ def build() -> list[dict]:
22
+ m = json.loads((DATA / "manifest.json").read_text())
23
+ rows = []
24
+ for c in m["cases"]:
25
+ expect = c["expect"]
26
+ rows.append({
27
+ "name": c["name"],
28
+ "file": c["file"],
29
+ "n_ports": c["n_ports"],
30
+ "z0_ohm": c["z0_ohm"],
31
+ "physically_realizable": c["physical"],
32
+ "expected_to_pass_all_laws": c["expect_all_pass"],
33
+ "expected_failures": sorted(k for k, v in expect.items() if not v),
34
+ "tags": c.get("tags", []),
35
+ "note": c.get("note", ""),
36
+ "sha256": c.get("sha256", ""),
37
+ })
38
+ return rows
39
+
40
+
41
+ def main() -> int:
42
+ rows = build()
43
+ out = DATA / "index.jsonl"
44
+ with out.open("w") as fh:
45
+ for r in rows:
46
+ fh.write(json.dumps(r, sort_keys=True) + "\n")
47
+ print(f"{out.relative_to(HERE)}: {len(rows)} rows")
48
+ return 0
49
+
50
+
51
+ if __name__ == "__main__":
52
+ raise SystemExit(main())
data/index.jsonl ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"expected_failures": [], "expected_to_pass_all_laws": true, "file": "passive_line.s2p", "n_ports": 2, "name": "passive_line", "note": "Lossy 20 ps delay line, 0.5 dB insertion loss. The baseline sane case.", "physically_realizable": true, "sha256": "74d631c14f5c18e9e9cf06bde2579628ff15820fc4b652035cd09d2809f4166d", "tags": ["passive", "2port"], "z0_ohm": 50.0}
2
+ {"expected_failures": [], "expected_to_pass_all_laws": true, "file": "passive_resonator.s2p", "n_ports": 2, "name": "passive_resonator", "note": "Shunt resonator, Q=30 at 20 GHz. Sharp phase slope near resonance -- the case where a group-delay check without phase unwrapping fails.", "physically_realizable": true, "sha256": "1a4b1e2f9f873fcdc03327dababdccce6fc3d6ab0a0968ac70b2f03a803c3f39", "tags": ["passive", "2port", "sharp_phase"], "z0_ohm": 50.0}
3
+ {"expected_failures": [], "expected_to_pass_all_laws": true, "file": "passive_attenuator.s2p", "n_ports": 2, "name": "passive_attenuator", "note": "Ideal 10 dB matched attenuator.", "physically_realizable": true, "sha256": "ee4b89263c942825af357be7f0273716d62ea984da5d441bcaf204c70f59963d", "tags": ["passive", "2port"], "z0_ohm": 50.0}
4
+ {"expected_failures": [], "expected_to_pass_all_laws": true, "file": "matched_load.s2p", "n_ports": 2, "name": "matched_load", "note": "All-zero S: perfectly matched, fully absorbing. A degenerate but legal network; checkers that divide by |S| must not blow up.", "physically_realizable": true, "sha256": "7a60bff097406dfcb7cab59bcc837935353727634161806c53eae99ba865470b", "tags": ["passive", "2port", "degenerate"], "z0_ohm": 50.0}
5
+ {"expected_failures": [], "expected_to_pass_all_laws": true, "file": "marginal_lossless.s2p", "n_ports": 2, "name": "marginal_lossless", "note": "Lossless line with sigma_max = 1 - 1e-12. Sits on the passivity boundary; a checker with a too-tight tolerance false-alarms here.", "physically_realizable": true, "sha256": "2dc0808d30a664b78cc263f06a9a46b48f7920bb3e9a132d56dfe4364d9179b4", "tags": ["passive", "2port", "boundary"], "z0_ohm": 50.0}
6
+ {"expected_failures": [], "expected_to_pass_all_laws": true, "file": "passive_4port.s4p", "n_ports": 4, "name": "passive_4port", "note": "Four-port with two independent thru paths. Exercises N>2 handling.", "physically_realizable": true, "sha256": "1c24a1157c72806fa771c2e592eb8751724c8ba5cae446dc7b798dd8b0302f17", "tags": ["passive", "4port"], "z0_ohm": 50.0}
7
+ {"expected_failures": ["energy_conservation", "passivity"], "expected_to_pass_all_laws": false, "file": "active_gain.s2p", "n_ports": 2, "name": "active_gain", "note": "Delay line with 3x through-path gain. Creates energy: fails both the spectral-norm and the row-power tests.", "physically_realizable": false, "sha256": "3f78dfcd6598f6734633a65a37e30edc8c4486c89d0c2e29cc52720780f22c32", "tags": ["nonphysical", "2port"], "z0_ohm": 50.0}
8
+ {"expected_failures": ["energy_conservation", "passivity"], "expected_to_pass_all_laws": false, "file": "energy_row_violation.s2p", "n_ports": 2, "name": "energy_row_violation", "note": "Row power > 1 when port 1 is driven.", "physically_realizable": false, "sha256": "05e30904110032dc75777b11b96dbde5398ae9e922ab64a89704f9675db7ae83", "tags": ["nonphysical", "2port"], "z0_ohm": 50.0}
9
+ {"expected_failures": ["energy_conservation", "passivity", "positive_real_z0"], "expected_to_pass_all_laws": false, "file": "negative_resistance.s2p", "n_ports": 2, "name": "negative_resistance", "note": "|S11| > 1 gives Re(Z_in) < 0: negative resistance at the port. It unavoidably breaks energy conservation too -- a reflection coefficient above unity returns more power than arrives -- so this case cannot isolate a single law, and the label says so.", "physically_realizable": false, "sha256": "2eb111856d1bfcdfb53e93f873704073f21af7926cb2ed18f5b2ef5b3114fdcc", "tags": ["nonphysical", "2port"], "z0_ohm": 50.0}
10
+ {"expected_failures": ["group_delay_nonneg"], "expected_to_pass_all_laws": false, "file": "noncausal_advance.s2p", "n_ports": 2, "name": "noncausal_advance", "note": "Phase advances with frequency: the output precedes the input. Passive and reciprocal, so ONLY the causality check should fire.", "physically_realizable": false, "sha256": "ede95a08f616205688b97eac8c7665b2491ce4a038767614ebc69ad0730ffe5c", "tags": ["nonphysical", "2port", "isolates_one_law"], "z0_ohm": 50.0}
11
+ {"expected_failures": ["reciprocity"], "expected_to_pass_all_laws": false, "file": "ferrite_isolator.s2p", "n_ports": 2, "name": "ferrite_isolator", "note": "A ferrite isolator. NON-RECIPROCAL BY DESIGN and entirely realizable -- the medium is not reciprocal. The reciprocity check correctly fires, and that is a true positive for the law but NOT a defect in the device. Any tool reporting this must let the user say so.", "physically_realizable": true, "sha256": "574d727015c7c3bb436bf1f9723098ac12a73e0392d3e2045a1b356c53e57f30", "tags": ["physical", "2port", "expected_law_failure"], "z0_ohm": 50.0}
tests/test_conformance.py CHANGED
@@ -187,3 +187,29 @@ def test_reference_adapter_conforms():
187
  assert r["checker_errors"] == 0
188
  assert r["false_pass"] == 0, f"sparam-lint false passes: {r['per_case']}"
189
  assert r["passed"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  assert r["checker_errors"] == 0
188
  assert r["false_pass"] == 0, f"sparam-lint false passes: {r['per_case']}"
189
  assert r["passed"]
190
+
191
+
192
+ # ------------------------------------------------------- viewer index
193
+
194
+ def test_index_matches_the_manifest_exactly():
195
+ """The browsable index is a view of the manifest, never a second source."""
196
+ import json as _json
197
+ import subprocess
198
+ import sys as _sys
199
+ here = Path(__file__).resolve().parents[1]
200
+ idx = here / "data" / "index.jsonl"
201
+ assert idx.exists(), "index.jsonl missing -- run build_index.py"
202
+ rows = [_json.loads(x) for x in idx.read_text().splitlines() if x.strip()]
203
+ man = _json.loads((here / "data" / "manifest.json").read_text())
204
+ assert len(rows) == len(man["cases"]) == man["n_cases"]
205
+ by_name = {r["name"]: r for r in rows}
206
+ for c in man["cases"]:
207
+ r = by_name[c["name"]]
208
+ assert r["physically_realizable"] == c["physical"]
209
+ assert r["expected_failures"] == sorted(
210
+ k for k, v in c["expect"].items() if not v)
211
+ # and it must regenerate identically
212
+ before = idx.read_bytes()
213
+ subprocess.run([_sys.executable, str(here / "build_index.py")],
214
+ capture_output=True, check=True)
215
+ assert idx.read_bytes() == before, "index.jsonl is stale vs the manifest"