Skip to content

Add animated detector slice diagrams - #1103

Open
ShallIBE wants to merge 2 commits into
quantumlib:mainfrom
ShallIBE:animated-detslice-with-ops
Open

Add animated detector slice diagrams#1103
ShallIBE wants to merge 2 commits into
quantumlib:mainfrom
ShallIBE:animated-detslice-with-ops

Conversation

@ShallIBE

@ShallIBE ShallIBE commented Aug 20, 2026

Copy link
Copy Markdown

Adds animated-detslice-with-ops to stim.Circuit.diagram and stim diagram.

The result is a self-contained HTML animation of Stim’s existing detslice-with-ops-svg output. Integer ticks use exact Stim SVG frames, while detector regions interpolate smoothly between ticks.

Supports tick ranges and coordinate filtering. No external dependencies.

Add a self-contained animation for detector slices with operations. Preserve exact Stim SVG frames at integer ticks and interpolate detector regions between ticks.
@ShallIBE
ShallIBE marked this pull request as ready for review August 20, 2026 09:46
}
};

DetectorSliceSvgPath parse_shape(std::string_view tag) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why is this code doing any parsing? It should be generating images, not parsing images.

Is it consuming images produced elsewhere in the code and editing them? That is far too brittle.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed the SVG parsing. Detector geometry and style are now collected directly while the existing detector-slice renderer writes the SVG.

std::map<uint64_t, DetectorRegion> detector_regions;
};

struct StringBuffer : std::streambuf {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not just std::stringstream?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Changed to std::stringstream.

function fillOpacity(group){for(const e of group.querySelectorAll('path,circle'))if(e.getAttribute('stroke')==='none'&&e.getAttribute('fill')!=='none'){const value=Number(e.getAttribute('fill-opacity')||1);if(Number.isFinite(value))return value}return 1}
function decodePoints(text){const raw=atob(text),bytes=new Uint8Array(raw.length);for(let k=0;k<raw.length;k++)bytes[k]=raw.charCodeAt(k);return new Float32Array(bytes.buffer)}
function pathData(a,b,t){let d='M';for(let k=0;k<a.length/2;k++){if(k)d+='L';d+=(a[2*k]+(b[2*k]-a[2*k])*t).toFixed(4)+','+(a[2*k+1]+(b[2*k+1]-a[2*k+1])*t).toFixed(4)}return d+'Z'}
function replaceShape(element){if(!element)return null;const path=document.createElementNS(NS,'path');for(const attr of element.attributes){if(attr.name!=='d'&&attr.name!=='cx'&&attr.name!=='cy'&&attr.name!=='r')path.setAttribute(attr.name,attr.value)}element.replaceWith(path);return path}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why does is this all mushed together?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Expanded the embedded JavaScript into readable functions

StringBuffer buffer(capacity);
std::ostream out(&buffer);
write_animation_frames(std::move(frames), tick_slice_start, out);
return std::move(buffer.data);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Needs unit tests.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added focused unit tests covering exact frame generation and detector transition behavior.

@ShallIBE
ShallIBE marked this pull request as draft August 24, 2026 22:43
Remove SVG parsing by collecting detector geometry during rendering.
Use std::stringstream, format the embedded player, and add focused tests.
@ShallIBE
ShallIBE force-pushed the animated-detslice-with-ops branch from f44d7d0 to 1524b11 Compare August 25, 2026 01:12
@ShallIBE
ShallIBE requested a review from Strilanc August 25, 2026 01:40
@ShallIBE
ShallIBE marked this pull request as ready for review August 25, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants