From 37f466323b2a33d92c62fd2cdc4b05ab564408fd Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Wed, 29 May 2024 15:37:43 -0700 Subject: [PATCH] Translation --- glue/crumble/README.md | 13 ++++++++++--- glue/crumble/main.js | 26 +++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/glue/crumble/README.md b/glue/crumble/README.md index d4673789..15ffbf32 100644 --- a/glue/crumble/README.md +++ b/glue/crumble/README.md @@ -119,10 +119,16 @@ button (now labelled "Hide Import/Export") again. - `ctrl+c`: Copy selection to clipboard (or entire layer if nothing selected). - `ctrl+v`: Past clipboard contents at current selection (or entire layer if nothing selected). - `ctrl+x`: Cut selection to clipboard (or entire layer if nothing selected). -- `t`: Rotate circuit 45 degrees clockwise. -- `shift+t`: Rotate circuit 45 degrees counter-clockwise. +- `f`: Flip qubit order of selected operations (e.g. flip the control-to-target direction of a CNOT). - `home`: Jump to the first layer of the circuit. - `end`: Jump to the last layer of the circuit. +- `t`: Rotate circuit 45 degrees clockwise. +- `shift+t`: Rotate circuit 45 degrees counter-clockwise. +- `v`: Translate circuit down one step. +- `^`: Translate circuit up one step. +- `>`: Translate circuit right one step. +- `<`: Translate circuit left one step. +- `.`: Translate circuit down and right by a half step. **Single Qubit Gates** @@ -143,10 +149,11 @@ Note: use `shift` to get the inverse of a gate. - `m+r+x`: Overwrite selection with `MRX` gate - `m+r+y`: Overwrite selection with `MRY` gate - `m+r`: Overwrite selection with `MR` gate -- `f`: Overwrite selection with `C_XYZ` gate +- `c+t`: Overwrite selection with `C_XYZ` gate - `j+x`: Overwrite selection with **j**ust a Pauli `X` gate - `j+y`: Overwrite selection with **j**ust a Pauli `Y` gate - `j+z`: Overwrite selection with **j**ust a Pauli `Z` gate +- `shift+c+t`: Overwrite selection with `C_ZYX` gate **Two Qubit Gates** diff --git a/glue/crumble/main.js b/glue/crumble/main.js index c6989c16..cb8cc52a 100644 --- a/glue/crumble/main.js +++ b/glue/crumble/main.js @@ -240,6 +240,30 @@ function makeChordHandlers() { res.set('m+p+x', preview => editorState.writeGateToFocus(preview, make_mpp_gate("X".repeat(editorState.focusedSet.size)), [])); res.set('m+p+y', preview => editorState.writeGateToFocus(preview, make_mpp_gate("Y".repeat(editorState.focusedSet.size)), [])); res.set('m+p+z', preview => editorState.writeGateToFocus(preview, make_mpp_gate("Z".repeat(editorState.focusedSet.size)), [])); + res.set('f', preview => { + let newCircuit = editorState.copyOfCurCircuit(); + let layer = newCircuit.layers[editorState.curLayer]; + let flipped_op_first_targets = new Set(); + for (let q of editorState.focusedSet.keys()) { + let op = layer.id_ops.get(newCircuit.coordToQubitMap().get(q)); + if (op !== undefined && ['CX', 'XCZ', 'CY', 'XCY', 'YCX', 'YCZ', 'CXSWAP', 'SWAPCX'].indexOf(op.gate.name) !== -1) { + flipped_op_first_targets.add(op.id_targets[0]); + } + } + for (let q of flipped_op_first_targets) { + layer.id_ops.get(q).id_targets.reverse(); + } + editorState.commit_or_preview(newCircuit, preview); + }); + res.set('shift+>', preview => editorState.applyCoordinateTransform((x, y) => [x + 1, y], preview)); + res.set('shift+<', preview => editorState.applyCoordinateTransform((x, y) => [x - 1, y], preview)); + res.set('shift+v', preview => editorState.applyCoordinateTransform((x, y) => [x, y + 1], preview)); + res.set('shift+^', preview => editorState.applyCoordinateTransform((x, y) => [x, y - 1], preview)); + res.set('>', preview => editorState.applyCoordinateTransform((x, y) => [x + 1, y], preview)); + res.set('<', preview => editorState.applyCoordinateTransform((x, y) => [x - 1, y], preview)); + res.set('v', preview => editorState.applyCoordinateTransform((x, y) => [x, y + 1], preview)); + res.set('^', preview => editorState.applyCoordinateTransform((x, y) => [x, y - 1], preview)); + res.set('.', preview => editorState.applyCoordinateTransform((x, y) => [x + 0.5, y + 0.5], preview)); /** * @param {!Array} chords @@ -292,7 +316,7 @@ function makeChordHandlers() { addGateChords(['c+w+z'], "CZSWAP", undefined); addGateChords(['c+w'], "CZSWAP", undefined); - addGateChords(['f'], "C_XYZ", "C_ZYX"); + addGateChords(['c+t'], "C_XYZ", "C_ZYX"); addGateChords(['c+s+x'], "SQRT_XX", "SQRT_XX_DAG"); addGateChords(['c+s+y'], "SQRT_YY", "SQRT_YY_DAG"); addGateChords(['c+s+z'], "SQRT_ZZ", "SQRT_ZZ_DAG");