Skip to content

Commit

Permalink
Draw T and S gates as "T" and "S" instead of "Z^1/2" etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc committed Jun 7, 2018
1 parent 1e14146 commit 48c57df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/circuit/Gate.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,16 @@ class Gate {
* @param {!Matrix} matrix
* @param {!string} name
* @param {!string} blurb
* @param {undefined|!string} serializedId
* @returns {!Gate}
*/
static fromKnownMatrix(symbol, matrix, name='', blurb='') {
static fromKnownMatrix(symbol, matrix, name='', blurb='', serializedId=undefined) {
if (!(matrix instanceof Matrix)) {
throw new DetailedError("Bad matrix.", {symbol, matrix, name, blurb});
}
let g = new Gate();
g.symbol = symbol;
g.serializedId = symbol;
g.serializedId = serializedId === undefined ? symbol : serializedId;
g.name = name;
g.blurb = blurb;
g._isDefinitelyUnitary = matrix.isUnitary(0.01);
Expand Down
10 changes: 6 additions & 4 deletions src/gates/QuarterTurnGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ QuarterTurnGates.SqrtYBackward = Gate.fromKnownMatrix(

/** @type {!Gate} */
QuarterTurnGates.SqrtZForward = Gate.fromKnownMatrix(
"Z^½",
"S",
Matrix.fromPauliRotation(0, 0, 0.25),
"√Z Gate",
"Principle square root of Z.\nAlso known as the 'S' gate.");
"Principle square root of Z.\nAlso known as the 'S' gate.",
"Z^½");

/** @type {!Gate} */
QuarterTurnGates.SqrtZBackward = Gate.fromKnownMatrix(
"Z^-½",
"S^-1",
Matrix.fromPauliRotation(0, 0, 0.75),
"Z^-½ Gate",
"Adjoint square root of Z.");
"Adjoint square root of Z.",
"Z^-½");

QuarterTurnGates.all = [
QuarterTurnGates.SqrtXForward,
Expand Down
10 changes: 6 additions & 4 deletions src/gates/VariousZGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ VariousZGates.Z3i = Gate.fromKnownMatrix(
"Z^-⅓ Gate",
"Adjoint third root of Z.");
VariousZGates.Z4 = Gate.fromKnownMatrix(
"Z^¼",
"T",
Matrix.fromPauliRotation(0, 0, 1 / 8),
"Z^¼ Gate",
"Principle fourth root of Z.\nAlso known as the 'T' gate.");
"Principle fourth root of Z.",
"Z^¼");
VariousZGates.Z4i = Gate.fromKnownMatrix(
"Z^-¼",
"T^-1",
Matrix.fromPauliRotation(0, 0, -1 / 8),
"Z^-¼ Gate",
"Adjoint fourth root of Z.");
"Adjoint fourth root of Z.",
"Z^-¼");
VariousZGates.Z8 = Gate.fromKnownMatrix(
"Z^⅛",
Matrix.fromPauliRotation(0, 0, 1 / 16),
Expand Down

0 comments on commit 48c57df

Please sign in to comment.