Skip to content

Commit

Permalink
Added matrix display to dynamic phase gradient gates
Browse files Browse the repository at this point in the history
- Also adjusted their cycle indicator to have it origin rightward instead of downward
  • Loading branch information
Strilanc committed Nov 25, 2017
1 parent afbc6a0 commit 82851d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/draw/GatePainting.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,10 @@ GatePainting.MATRIX_DRAWER = args => {
* @param {!number=} xScale
* @param {!number=} yScale
* @param {!number=} tScale
* @param {!number=} zeroAngle
* @returns {!function(!GateDrawParams) : *}
*/
GatePainting.makeCycleDrawer = (xScale=1, yScale=1, tScale=1) => args => {
GatePainting.makeCycleDrawer = (xScale=1, yScale=1, tScale=1, zeroAngle=0) => args => {
GatePainting.MAKE_HIGHLIGHTED_DRAWER(Config.TIME_DEPENDENT_HIGHLIGHT_COLOR)(args);

if (args.isInToolbox && !args.isHighlighted) {
Expand All @@ -377,6 +378,7 @@ GatePainting.makeCycleDrawer = (xScale=1, yScale=1, tScale=1) => args => {

args.painter.ctx.translate(c.x, c.y);
args.painter.ctx.scale(-xScale, -yScale);
args.painter.ctx.rotate(zeroAngle);
args.painter.ctx.strokeStyle = 'black';
args.painter.ctx.fillStyle = 'yellow';
args.painter.ctx.globalAlpha *= 0.4;
Expand Down
12 changes: 10 additions & 2 deletions src/gates/PhaseGradientGates.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {GatePainting} from "src/draw/GatePainting.js"
import {ketArgs, ketShaderPhase} from "src/circuit/KetShaderUtil.js"
import {MUL_STEP} from "src/gates/MultiplyAccumulateGates.js"
import {WglArg} from "src/webgl/WglArg.js"
import {Matrix} from "src/math/Matrix.js";
import {Complex} from "src/math/Complex.js";

const PHASE_GRADIENT_SHADER = ketShaderPhase(
`
Expand Down Expand Up @@ -70,8 +72,11 @@ PhaseGradientGates.DynamicPhaseGradientFamily = Gate.buildFamily(1, 16, (span, b
setActualEffectToShaderProvider(ctx => PHASE_GRADIENT_SHADER.withArgs(
...ketArgs(ctx, span),
WglArg.float("factor", ctx.time * Math.PI * 2))).
setEffectToTimeVaryingMatrix(t => Matrix.generateDiagonal(
1 << span,
k => Complex.polar(1, t * 2 * Math.PI * k))).
promiseEffectOnlyPhases().
setDrawer(GatePainting.makeCycleDrawer(-1, -1)));
setDrawer(GatePainting.makeCycleDrawer(-1, -1, 1, -Math.PI / 2)));

PhaseGradientGates.DynamicPhaseDegradientFamily = Gate.buildFamily(1, 16, (span, builder) => builder.
setSerializedId("grad^-t" + span).
Expand All @@ -81,8 +86,11 @@ PhaseGradientGates.DynamicPhaseDegradientFamily = Gate.buildFamily(1, 16, (span,
setActualEffectToShaderProvider(ctx => PHASE_GRADIENT_SHADER.withArgs(
...ketArgs(ctx, span),
WglArg.float("factor", -ctx.time * Math.PI * 2))).
setEffectToTimeVaryingMatrix(t => Matrix.generateDiagonal(
1 << span,
k => Complex.polar(1, t * 2 * Math.PI * -k))).
promiseEffectOnlyPhases().
setDrawer(GatePainting.makeCycleDrawer(1, -1)));
setDrawer(GatePainting.makeCycleDrawer(1, -1, 1, Math.PI / 2)));

PhaseGradientGates.all = [
...PhaseGradientGates.PhaseGradientFamily.all,
Expand Down

0 comments on commit 82851d1

Please sign in to comment.