GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: Add opt-in check-redundancy meta-check DETECTORs for CSS memory circuits by ashmitjsg · Pull Request #7 · Deltakit/deltakit-explorer

Conversation

@ashmitjsg

@ashmitjsg ashmitjsg commented Aug 12, 2026

Copy link
Copy Markdown

🔗 Closed Issues

Closes Deltakit/deltakit#312


📝 Description

css_code_memory_circuit on bivariate-bicycle and other CSS codes with redundant check rows emits DETECTOR annotations that span every deterministic measurement parity except the first-round dependency products on the random-basis syndrome side (e.g. six missing parities on [[72,12,6]] Z-memory: rank deficit of the 36 X-check rows). Those products are deterministic, payload-independent, and useful for single-shot decoding and syndrome-validation workflows, but were not previously exposed in the emitted circuit artifact.

This PR adds opt-in support for those meta-checks:

  • include_check_redundancies=False (default) on css_code_memory_circuit, behaviour unchanged.
  • include_check_redundancies=True, appends extra DETECTORs tagged check_redundancy, one per independent GF(2) left-nullspace dependency of the random-basis check matrix, using first-round syndrome MeasurementRecords.
  • StabiliserCode.check_redundancy_record_sets(...), accessor returning the same redundancy basis as frozensets of measurement records, for consumers that prefer to attach parities outside the default detector stream.

Side selection (per issue discussion): Z-memory -> H_x / X-ancilla (random side); X-memory -> H_z / Z-ancilla.

Scope limits:

  • Local circuit generation only (client=None); cloud path raises NotImplementedError if the flag is set.
  • Default emission deliberately unchanged: dense meta-check rows (fan-in 16–18 on BB codes) can regress stock circuit-level BP+OSD at small round counts when injected into the default stream.

Implementation: new module _check_redundancies.py with GF(2) nullspace computation, matrix/side selection, detector construction, and test helpers (detector_parity_matrix, detector_annotation_rank, etc.).
Tests cover [[72,12,6]], [[90,8,10]], [[108,8,10]] across Z/X memory and multiple round counts; rank/span accounting; correct matrix side vs regression guards; planar code unchanged; Stim DEM compilation; accessor consistency.


🚦 Status

  • Opt-in flag and accessor implemented
  • Unit tests added and passing locally
  • Default circuit output unchanged when flag is False

🛠️ Future Work

  • Cloud circuit generation support for include_check_redundancies=True ([#312 follow-up}(https://github.com/request: Add opt-in emission of the check-redundancy (meta-check) parities to css_code_memory_circuit deltakit#312), out of scope here).
  • User-facing note in docs/guide/circuit_generation.md describing when and why to enable meta-checks.
  • Extend beyond BivariateBicycleCode / CSSCode if other StabiliserCode subclasses need the same path (currently raises NotImplementedError for unsupported types).
  • Optional integration examples for decoders that consume meta-check record sets directly.

➕️ Additional Information

Meta-check DETECTORs are appended after the standard memory pipeline stages; they do not alter the underlying measurement schedule. Codes with full-rank check matrices (e.g. rotated planar surface code) produce no extra detectors even when the flag is True.

Tagged detectors (tag="check_redundancy") can be filtered by downstream tooling without parsing parity structure.


🧾 Release Note

Add opt-in check-redundancy meta-check DETECTORs for CSS memory circuits (include_check_redundancies on css_code_memory_circuit; check_redundancy_record_sets on StabiliserCode). Default behaviour unchanged.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ashmitjsg
Add opt-in check-redundancy meta-check DETECTORs for CSS memory circu…
e9e5210
…its.

Expose include_check_redundancies on css_code_memory_circuit and check_redundancy_record_sets on StabiliserCode for GF(2) dependency parities on the random-basis syndrome side. Default behaviour unchanged; meta-checks remain opt-in for BP+OSD compatibility.
This was referenced Aug 12, 2026
Add opt-in check-redundancy meta-check DETECTORs for CSS memory circuits Deltakit/deltakit#334
Closed
request: Decoder calibration scoring (Brier score / reliability diagrams) in deltakit_analyse Deltakit/deltakit#321
Open
@nelimee nelimee assigned ashmitjsg Aug 18, 2026
@nelimee nelimee added the enhancement New feature or request label Aug 18, 2026
nelimee
nelimee reviewed Aug 18, 2026
View reviewed changes

@nelimee nelimee left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an initial review that is not on the implementation itself.

Just a comment: this is not flagged as a prioritised issue, and potential reviewers for that PR have several deadlines coming up internally, so a full review might take time, sorry in advance for that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/deltakit_explorer/codes/_css/_stabiliser_code.py Outdated
Comment on lines +174 to +175
One record set per independent check redundancy on the
random-basis syndrome side.

@nelimee nelimee Aug 18, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
One record set per independent check redundancy on the
random-basis syndrome side.
One record set per independent check redundancy on the random-basis syndrome side.

probably fits on the line length?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ashmitjsg reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread src/deltakit_explorer/codes/_css/_stabiliser_code.py Outdated
Comment on lines +160 to +163
self,
circuit: Circuit,
logical_basis: PauliBasis,
num_rounds: int,

@nelimee nelimee Aug 18, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self,
circuit: Circuit,
logical_basis: PauliBasis,
num_rounds: int,
self, circuit: Circuit, logical_basis: PauliBasis, num_rounds: int

probably fits on the line length

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ashmitjsg reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread tests/circuit_generation/test_circuit_generation.py Outdated
Comment on lines +37 to +50
def _count_check_redundancy_detectors(circuit) -> int:
return sum(
1
for detector in circuit.detectors(include_nested=True)
if detector.tag == "check_redundancy"
)


def _meta_check_detectors(circuit):
return [
detector
for detector in circuit.detectors(include_nested=True)
if detector.tag == "check_redundancy"
]

@nelimee nelimee Aug 18, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can re-use:

Suggested change
def _count_check_redundancy_detectors(circuit) -> int:
return sum(
1
for detector in circuit.detectors(include_nested=True)
if detector.tag == "check_redundancy"
)
def _meta_check_detectors(circuit):
return [
detector
for detector in circuit.detectors(include_nested=True)
if detector.tag == "check_redundancy"
]
def _count_check_redundancy_detectors(circuit) -> int:
return len(_meta_check_detectors(circuit))
def _meta_check_detectors(circuit):
return [
detector
for detector in circuit.detectors(include_nested=True)
if detector.tag == "check_redundancy"
]

also, please add typing information, that's not required per-se, but that helps everyone.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ashmitjsg reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread src/deltakit_explorer/codes/_css/_check_redundancies.py Outdated
"""
Row basis of the left nullspace of ``H`` over GF(2).

Each returned row ``╬╗`` satisfies ``╬╗ @ H = 0 (mod 2)``.

@nelimee nelimee Aug 18, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about that symbol.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ashmitjsg reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@ashmitjsg ashmitjsg Aug 25, 2026

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the lambda symbol (λ), which somehow got corrupted when I was generating the docstring. Fixed it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ashmitjsg and others added 2 commits August 25, 2026 21:21
@ashmitjsg
Merge branch 'main' into feature/312-check-redundancy-parities
bc7846d
@ashmitjsg
fix: address review feedback on check-redundancy and its tests
6b01fad
@ashmitjsg

ashmitjsg commented Aug 25, 2026

Copy link
Copy Markdown
Author

Hi @nelimee, I have resolved all review suggestions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ashmitjsg
ashmitjsg requested a review from nelimee August 25, 2026 17:33
@nelimee

nelimee commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Hey! I'll try to check the maths, but I have quite a few deadlines until mid next week, so it might take a little bit more time. I apologise for the delay in answers, I was 100% on the release of https://github.com/deltakit/deltakit-compile.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@YaegakiY

YaegakiY commented Sep 9, 2026

Copy link
Copy Markdown

Hi @ashmitjsg, apologies for the slow response to the review request in Deltakit/deltakit#312.
Independent check of 6b01fadd with the oracle behind the issue (the deterministic-parity space from stim's flow generators compared over GF(2) with the span of the emitted DETECTORs and OBSERVABLEs), run as two processes: circuits generated under this branch (deltakit-core/circuit/decode 0.9.1, deltakit-stim 0.2.3), verdicts computed in a stim-only process (stim 1.16.0) from the emitted text.

instance, basis, rounds k/2 missing parities, flag off / on annotation rank, flag off / on appended detectors, fan-in first-round random-side records payload-independent detectors accessor
[[72,12,6]] Z, r=1 6 6 / 0 78 / 84 6, 16 to 18 yes, 36 of 36 used 84 of 84 equal
[[72,12,6]] Z, r=2 6 6 / 0 150 / 156 6, 16 to 18 yes 156 of 156 equal
[[72,12,6]] Z, r=3 6 6 / 0 222 / 228 6, 16 to 18 yes 228 of 228 equal
[[72,12,6]] X, r=1 6 6 / 0 78 / 84 6, 16 to 18 yes 84 of 84 equal
[[72,12,6]] X, r=2 6 6 / 0 150 / 156 6, 16 to 18 yes 156 of 156 equal
[[72,12,6]] X, r=3 6 6 / 0 222 / 228 6, 16 to 18 yes 228 of 228 equal
[[90,8,10]] Z, r=1 4 4 / 0 94 / 98 4, 20 yes, 45 of 45 98 of 98 equal
[[108,8,10]] Z, r=1 4 4 / 0 112 / 116 4, 24 yes, 54 of 54 116 of 116 equal
[[144,12,12]] Z, r=1 6 6 / 0 150 / 156 6, 32 to 36 yes, 72 of 72 156 of 156 equal

With the flag on, the annotation rank equals the rank of the deterministic-parity space on every config, so the gap reported in Deltakit/deltakit#312 is closed, and the growth is exactly k/2, which is the test that separates this implementation from an H_z-side one (that variant also appends k/2 deterministic detectors but leaves the rank unchanged; measured on the five r=1 configs: k/2 detectors, a compiling DEM, k/2 parities still missing, annotation rank unchanged). The appended parities use only first-round records on the random side (identified from the circuit: first-round records emitted as singleton DETECTORs are the deterministic side, and every appended record lies outside that set), all carry the check_redundancy tag, the flag-on detector error model compiles, and check_redundancy_record_sets returns the same record sets. Under logical insertions at the preparation boundary (all X-bar generators for a Z memory, Z-bar for X), no detector in the flag-on circuits flips and the observables' quotient classes stay independent, so the appended detectors do not read the encoded state and cannot inflate a distance verdict.

Default emission: within one process the flag-on text is the flag-off text plus the k/2 DETECTOR lines on every config. Against released 0.9.2 the flag-off circuits agree on operations, measurement order, detector coordinates, observables and detector record sets after relabeling qubits by coordinate and sorting targets inside instructions. Byte identity across processes does not hold for 0.9.2 against itself (qubit labels and target order vary between two runs with the same PYTHONHASHSEED), so the existing single-process planar test is the right shape and a two-process text comparison would be flaky.

cc @nelimee

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rolandriver
rolandriver self-requested a review September 29, 2026 16:50
@rolandriver rolandriver changed the title Add opt-in check-redundancy meta-check DETECTORs for CSS memory circuits request: Add opt-in check-redundancy meta-check DETECTORs for CSS memory circuits Sep 29, 2026
@rolandriver rolandriver changed the title request: Add opt-in check-redundancy meta-check DETECTORs for CSS memory circuits feat: Add opt-in check-redundancy meta-check DETECTORs for CSS memory circuits Sep 29, 2026
rolandriver
rolandriver reviewed Sep 30, 2026
View reviewed changes

@rolandriver rolandriver left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ashmitjsg for this. A general comment, it feels like everywhere a NDArray[np.uint8] is used can be replaced with galois.GF2. So it'd be good to avoid as much as possible to do back and forth between the two. Ideally, only galois.GF2 should be used. Can you please investigate if this is possible ?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/deltakit_explorer/codes/_css/_check_redundancies.py
parity_matrix = detector_parity_matrix(detectors, len(circuit.measurement_gates))
if parity_matrix.size == 0:
return 0
return int(np.linalg.matrix_rank(galois.GF2(parity_matrix)))

@rolandriver rolandriver Sep 30, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use the functionality provided by galois itself to compute the rank over GF(2) directly instead of relying on np.linalg.matrix_rank which uses floating point linear algebra.

import galois

GF2 = galois.GF(2)
A = GF2(parity_matrix)

rank = galois.linalg.rank(A)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/deltakit_explorer/codes/_css/_check_redundancies.py
for row_index, detector in enumerate(detectors):
for record in detector.measurements:
rows[row_index, measurement_gate_index(num_measurements, record)] = 1
return rows

@rolandriver rolandriver Sep 30, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would return a galois.GF2 here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/deltakit_explorer/codes/_css/_check_redundancies.py
)
if check_matrix.size == 0:
return 0
rank = int(np.linalg.matrix_rank(galois.GF2(check_matrix)))

@rolandriver rolandriver Sep 30, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/deltakit_explorer/codes/_css/_check_redundancies.py
Returns:
``num_check_rows - rank(H)`` over GF(2).
"""
check_matrix = check_matrix_for_memory_basis(

@rolandriver rolandriver Sep 30, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to return a galois.GF2 here, see comment below.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/deltakit_explorer/codes/_css/_check_redundancies.py
if check_matrix.size == 0:
return 0
rank = int(np.linalg.matrix_rank(galois.GF2(check_matrix)))
return check_matrix.shape[0] - rank

@rolandriver rolandriver Sep 30, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If everything is galois.GF2 you can simplify the rank-nullity theorem computation as:

null_space = galois.linalg.null_space(H)

nullity = null_space.shape[0]

and return nullity.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/deltakit_explorer/codes/_css/_check_redundancies.py
import numpy as np
from deltakit_circuit import Circuit, Detector, MeasurementRecord, PauliX, PauliZ
from deltakit_circuit.gates import PauliBasis
from numpy.typing import NDArray

@rolandriver rolandriver Sep 30, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from numpy.typing import NDArray
import numpy.typing as npt

and then replace NDArray with npt.NDArray.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/deltakit_explorer/codes/_css/_check_redundancies.py
if H.size == 0:
return np.zeros((0, H.shape[0]), dtype=np.uint8)
H_gf2 = galois.GF2(H)
rank = int(np.linalg.matrix_rank(H_gf2))

@rolandriver rolandriver Sep 30, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use functionality from galois.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rolandriver

rolandriver commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Hi @ashmitjsg could you please provide insight on whether you'll be able to work on this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rolandriver

rolandriver commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Hi @ashmitjsg I will close this PR now. If you want to resume the work, please reopen it. Thank you.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rolandriver rolandriver closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rolandriver rolandriver rolandriver left review comments
@nelimee nelimee Awaiting requested review from nelimee

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@ashmitjsg ashmitjsg

Labels

enhancement New feature or request

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

request: Add opt-in emission of the check-redundancy (meta-check) parities to css_code_memory_circuit

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@ashmitjsg @nelimee @YaegakiY @rolandriver
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.