Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions glue/crumble/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ clipboard, pasting over the contents of the textbox, and hitting the
"↓ Import from Stim Circuit ↓" button below the textbox.
The import/export text box can be hidden by clicking the "Show Import/Export"
button (now labelled "Hide Import/Export") again.
- **Removing detectors**: Click the "Remove Detectors" button to delete every
`DETECTOR` declaration while preserving the rest of the circuit. This action
can be undone and redone using the normal editor controls.

<a name="keyboard-commands"></a>
## Keyboard Controls
Expand Down
1 change: 1 addition & 0 deletions glue/crumble/crumble.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<div class="btn-group">
<button id="btnShowHideImportExport">Show Import/Export</button>
<button id="clear">Clear All</button>
<button id="btnRemoveDetectors">Remove Detectors</button>
</div>
<div class="btn-group">
<button id="btnClearMarkers">Clear All Pauli Marks</button>
Expand Down
8 changes: 8 additions & 0 deletions glue/crumble/editor/editor_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,14 @@ class EditorState {
this.commit(c);
}

removeDetectors() {
let c = this.copyOfCurCircuit();
for (let layer of c.layers) {
layer.markers = layer.markers.filter(e => e.gate.name !== 'DETECTOR');
}
this.commit(c);
}

/**
* @param {!boolean} parityLock
* @returns {!Array<![!int, !int]>}
Expand Down
38 changes: 38 additions & 0 deletions glue/crumble/editor/editor_state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,44 @@ test("editor_state.writeGateToFocus", () => {
`));
});

test("editor_state.removeDetectors", () => {
let state = new EditorState(undefined);
state.commit(Circuit.fromStimCircuit(`
QUBIT_COORDS(0, 0) 0
QUBIT_COORDS(1, 0) 1
R 0 1
#!pragma MARKZ(2) 1
TICK
M 0
DETECTOR(1, 2, 3) rec[-1]
TICK
M 1
DETECTOR(4, 5, 6) rec[-1] rec[-2]
OBSERVABLE_INCLUDE(0) rec[-1]
#!pragma MARKZ(2) 1
`));
let before = state.copyOfCurCircuit();
let after = Circuit.fromStimCircuit(`
QUBIT_COORDS(0, 0) 0
QUBIT_COORDS(1, 0) 1
R 0 1
#!pragma MARKZ(2) 1
TICK
M 0
TICK
M 1
OBSERVABLE_INCLUDE(0) rec[-1]
#!pragma MARKZ(2) 1
`);

state.removeDetectors();
assertThat(state.copyOfCurCircuit()).isEqualTo(after);
state.undo();
assertThat(state.copyOfCurCircuit()).isEqualTo(before);
state.redo();
assertThat(state.copyOfCurCircuit()).isEqualTo(after);
});

test('editor_state.writeMarkerToDetector', () => {
let state = new EditorState(undefined);
state.commit(Circuit.fromStimCircuit(`
Expand Down
5 changes: 5 additions & 0 deletions glue/crumble/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const btnRotate45Counter = /** @type{!HTMLButtonElement} */ document.getElementB
const btnExport = /** @type {!HTMLButtonElement} */ document.getElementById('btnExport');
const btnImport = /** @type {!HTMLButtonElement} */ document.getElementById('btnImport');
const btnClear = /** @type {!HTMLButtonElement} */ document.getElementById('clear');
const btnRemoveDetectors = /** @type {!HTMLButtonElement} */ document.getElementById('btnRemoveDetectors');
const txtStimCircuit = /** @type {!HTMLTextAreaElement} */ document.getElementById('txtStimCircuit');
const btnTimelineFocus = /** @type{!HTMLButtonElement} */ document.getElementById('btnTimelineFocus');
const btnClearTimelineFocus = /** @type{!HTMLButtonElement} */ document.getElementById('btnClearTimelineFocus');
Expand Down Expand Up @@ -77,6 +78,10 @@ btnClear.addEventListener('click', _ev => {
editorState.clearCircuit();
});

btnRemoveDetectors.addEventListener('click', _ev => {
editorState.removeDetectors();
});

btnUndo.addEventListener('click', _ev => {
editorState.undo();
});
Expand Down
Loading