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
2 changes: 1 addition & 1 deletion glue/crumble/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ button (now labelled "Hide Import/Export") again.
- `y+#`: Put a Y-type Pauli propagation marker at the current selection for the indexed Pauli product.
- `z+#`: Put a Z-type Pauli propagation marker at the current selection for the indexed Pauli product.
- `d+#`: Converts the indexed Pauli product into a circuit `DETECTOR` declaration.
- `o+#`: Converts the indexed Pauli product into a circuit `OBSERVABLE_INCLUDE` declaration.
- `o+#`: Converts the indexed Pauli product into a circuit `OBSERVABLE_INCLUDE` declaration, using the smallest nonnegative observable index not already present in the circuit.
- `j+#`: Picks a `DETECTOR` or `OBSERVABLE_INCLUDE` declaration touching the current selection and converts it into a tracked Pauli product.
- `k+#`: Add a marker to any dissipative gate that the indexed Pauli product overlaps in the current layer.

Expand Down
9 changes: 8 additions & 1 deletion glue/crumble/editor/editor_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,14 @@ class EditorState {

_writeMarkerToDetOrObs(preview, marker_index, isDet) {
let newCircuit = this.copyOfCurCircuit();
let argIndex = isDet ? newCircuit.collectDetectorsAndObservables(false).dets.length : marker_index;
let {dets, obs} = newCircuit.collectDetectorsAndObservables(false);
let argIndex = dets.length;
if (!isDet) {
argIndex = 0;
while (obs.has(argIndex)) {
argIndex += 1;
}
}
let prop = PropagatedPauliFrames.fromCircuit(newCircuit, marker_index);

for (let k = 0; k < newCircuit.layers.length; k++) {
Expand Down
75 changes: 69 additions & 6 deletions glue/crumble/editor/editor_state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,24 +313,24 @@ test('editor_state.writeMarkerToDetector_mxx', () => {
`));
});

test('editor_state.writeMarkerToObservable_mxx', () => {
test('editor_state.writeMarkerToObservable_no_existing_observables_multiple_terms', () => {
let state = new EditorState(undefined);
state.commit(Circuit.fromStimCircuit(`
QUBIT_COORDS(1, 1) 0
QUBIT_COORDS(1, 2) 1
QUBIT_COORDS(2, 1) 2
QUBIT_COORDS(2, 2) 3
R 0 1 2 3
#!pragma MARKZ(0) 0 1 2 3
#!pragma MARKZ(7) 0 1 2 3
TICK
MXX 0 2 1 3
#!pragma MARKX(0) 0 2 3 1
#!pragma MARKX(7) 0 2 3 1
TICK
MYY 3 2 1 0
#!pragma MARKY(0) 1 0 3 2
#!pragma MARKY(7) 1 0 3 2
`));
state.writeMarkerToObservable(false, 0);
assertThat(state.copyOfCurCircuit()).isEqualTo(Circuit.fromStimCircuit(`
let before = state.copyOfCurCircuit();
let after = Circuit.fromStimCircuit(`
QUBIT_COORDS(1, 1) 0
QUBIT_COORDS(1, 2) 1
QUBIT_COORDS(2, 1) 2
Expand All @@ -341,6 +341,69 @@ test('editor_state.writeMarkerToObservable_mxx', () => {
TICK
MYY 3 2 1 0
OBSERVABLE_INCLUDE(0) rec[-1] rec[-2] rec[-3] rec[-4]
`);

state.writeMarkerToObservable(true, 7);
assertThat(state.obs_val_draw_state.get().circuit).isEqualTo(after);
assertThat(state.copyOfCurCircuit()).isEqualTo(before);

state.writeMarkerToObservable(false, 7);
assertThat(state.copyOfCurCircuit()).isEqualTo(after);
state.undo();
assertThat(state.copyOfCurCircuit()).isEqualTo(before);
state.redo();
assertThat(state.copyOfCurCircuit()).isEqualTo(after);
});

test('editor_state.writeMarkerToObservable_id_collision', () => {
let state = new EditorState(undefined);
state.commit(Circuit.fromStimCircuit(`
QUBIT_COORDS(0, 0) 0
QUBIT_COORDS(1, 0) 1
R 0 1
#!pragma MARKZ(0) 1
TICK
M 0 1
OBSERVABLE_INCLUDE(0) rec[-2]
#!pragma MARKZ(0) 1
`));
state.writeMarkerToObservable(false, 0);
assertThat(state.copyOfCurCircuit()).isEqualTo(Circuit.fromStimCircuit(`
QUBIT_COORDS(0, 0) 0
QUBIT_COORDS(1, 0) 1
R 0 1
TICK
M 0 1
OBSERVABLE_INCLUDE(0) rec[-2]
OBSERVABLE_INCLUDE(1) rec[-1]
`));
});

test('editor_state.writeMarkerToObservable_sparse_ids', () => {
let state = new EditorState(undefined);
state.commit(Circuit.fromStimCircuit(`
QUBIT_COORDS(0, 0) 0
QUBIT_COORDS(1, 0) 1
QUBIT_COORDS(2, 0) 2
R 0 1 2
#!pragma MARKZ(9) 2
TICK
M 0 1 2
OBSERVABLE_INCLUDE(0) rec[-3]
OBSERVABLE_INCLUDE(2) rec[-2]
#!pragma MARKZ(9) 2
`));
state.writeMarkerToObservable(false, 9);
assertThat(state.copyOfCurCircuit()).isEqualTo(Circuit.fromStimCircuit(`
QUBIT_COORDS(0, 0) 0
QUBIT_COORDS(1, 0) 1
QUBIT_COORDS(2, 0) 2
R 0 1 2
TICK
M 0 1 2
OBSERVABLE_INCLUDE(0) rec[-3]
OBSERVABLE_INCLUDE(2) rec[-2]
OBSERVABLE_INCLUDE(1) rec[-1]
`));
});

Expand Down
Loading