code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
controlledWireProbabilityJustAfter(wireIndex, colIndex) { return this.qubitDensityMatrix(colIndex, wireIndex).rawBuffer()[6]; }
Returns the probability that a wire would be on if it was measured just before a given column, but conditioned on wires with controls in that column matching their controls. A wire is never conditioned on itself; self-conditions are ignored when computing the probability. @param {int} wireIndex @param {int|Infinity} c...
controlledWireProbabilityJustAfter
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
static withNanDataFromCircuitAtTime(circuitDefinition, time) { return new CircuitStats( circuitDefinition, time, [1], [], Matrix.zero(1, 1 << circuitDefinition.numWires).times(NaN), new Map()); }
@param {!CircuitDefinition} circuitDefinition @param {!number} time @returns {!CircuitStats}
withNanDataFromCircuitAtTime
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
static fromCircuitAtTime(circuitDefinition, time) { try { return CircuitStats._fromCircuitAtTime_noFallback(circuitDefinition, time); } catch (ex) { notifyAboutRecoveryFromUnexpectedError( `Defaulted to NaN results. Computing circuit values failed.`, ...
@param {!CircuitDefinition} circuitDefinition @param {!number} time @returns {!CircuitStats}
fromCircuitAtTime
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
static decohereMeasuredBitsInDensityMatrix(densityMatrix, isMeasuredMask) { if (isMeasuredMask === 0) { return densityMatrix; } let buf = new Float32Array(densityMatrix.rawBuffer()); let n = densityMatrix.width(); for (let row = 0; row < n; row++) { for (...
Returns the same density matrix, but without any diagonal terms related to qubits that have been measured. @param {!Matrix} densityMatrix @param {!int} isMeasuredMask A bitmask where each 1 corresponds to a measured qubit position. @returns {!Matrix}
decohereMeasuredBitsInDensityMatrix
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
static scatterAndDecohereDensities(rawMatrices, numWires, qubitSpan, isMeasuredMask, hasDisplayMask) { let nanMatrix = Matrix.zero(1 << qubitSpan, 1 << qubitSpan).times(NaN); let used = 0; let result = []; for (let row = 0; row < numWires - qubitSpan + 1; row++) { if ((hasDis...
@param {!Array.<!Matrix>} rawMatrices @param {!int} numWires @param {!int} qubitSpan @param {!int} isMeasuredMask @param {!int} hasDisplayMask @returns {!Array.<!Matrix>}
scatterAndDecohereDensities
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
static _extractColumnQubitStatsFromPixelDatas(circuitDefinition, colQubitDensitiesPixelData) { let qubitDensityGrid = []; for (let col = 0; col < colQubitDensitiesPixelData.length; col++) { let dataHasStatsMask = col === circuitDefinition.columns.length ? -1 : // All wires ha...
@param {!CircuitDefinition} circuitDefinition @param {!Array.<!Float32Array>} colQubitDensitiesPixelData @returns {!Array.<!Array<!Matrix>>} @private
_extractColumnQubitStatsFromPixelDatas
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
static _extractColumnSurvivalRateStatsFromPixelDatas(normsPixelData) { let curSurvivalRate = 1; let survivalRates = []; for (let col = 0; col < normsPixelData.length; col++) { if (normsPixelData[col].length > 0) { curSurvivalRate = normsPixelData[col][0]; ...
@param {!Array.<!Float32Array>} normsPixelData @returns {!Array.<!number>} @private
_extractColumnSurvivalRateStatsFromPixelDatas
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
static _fromCircuitAtTime_noFallback(circuitDefinition, time) { circuitDefinition = circuitDefinition.withMinimumWireCount(); const numWires = circuitDefinition.numWires; // Advance state while collecting stats into textures. let stateTrader = new WglTextureTrader(CircuitShaders.classic...
@param {!CircuitDefinition} circuitDefinition @param {!number} time @returns {!CircuitStats}
_fromCircuitAtTime_noFallback
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
constructor(inclusionMask, desiredValueMask, parityMask=0) { if ((desiredValueMask & ~inclusionMask) !== 0) { throw new DetailedError("Desired un-included bits", {inclusionMask, desiredValueMask}); } if (parityMask !== 0 && Util.popcnt(inclusionMask & parityMask) !== 1) { ...
@param {!int} inclusionMask. @param {!int} desiredValueMask @param {!int=0} parityMask @property {!int} inclusionMask. @property {!int} desiredValueMask
constructor
javascript
Strilanc/Quirk
src/circuit/Controls.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Controls.js
Apache-2.0
static bit(bitIndex, desiredValue) { if (bitIndex < 0) { throw new DetailedError("Out of range", {bitIndex}) } return new Controls(1 << bitIndex, desiredValue ? (1 << bitIndex) : 0); }
@param {!int} bitIndex @param {!boolean} desiredValue @returns {!Controls}
bit
javascript
Strilanc/Quirk
src/circuit/Controls.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Controls.js
Apache-2.0
desiredValueFor(bitIndex) { if ((this.inclusionMask & (1 << bitIndex)) === 0) { return undefined; } return (this.desiredValueMask & (1 << bitIndex)) !== 0; }
@param {!int} bitIndex @returns {undefined|!boolean}
desiredValueFor
javascript
Strilanc/Quirk
src/circuit/Controls.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Controls.js
Apache-2.0
findGateWithSerializedId(id) { for (let g of this.gates) { if (g.serializedId === id) { return g; } } return undefined; }
@param {!String} id @returns {undefined|!Gate}
findGateWithSerializedId
javascript
Strilanc/Quirk
src/circuit/CustomGateSet.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CustomGateSet.js
Apache-2.0
constructor() { /** @type {!string} The text shown when drawing the gate. */ this.symbol = ''; /** @type {!string} The identifier text used for the gate when serializing/parsing JSON. */ this.serializedId = ''; /** @type {!string} The title text of gate tooltips. */ this....
Describes a quantum operation that may vary with time.
constructor
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
static fromKnownMatrix(symbol, matrix, name='', blurb='', serializedId=undefined, alternate=undefined) { if (!(matrix instanceof Matrix)) { throw new DetailedError("Bad matrix.", {symbol, matrix, name, blurb}); } let builder = new GateBuilder(). setSymbol(symbol). ...
@param {!string} symbol @param {!Matrix} matrix @param {!string} name @param {!string} blurb @param {undefined|!string} serializedId @param {undefined|!Gate=} alternate @returns {!Gate}
fromKnownMatrix
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
_copy() { let g = new Gate(); g.symbol = this.symbol; g.name = this.name; g.blurb = this.blurb; g.alternate = this.alternate; g.serializedId = this.serializedId; g.onClickGateFunc = this.onClickGateFunc; g.tag = this.tag; g.param = this.param; ...
Returns a copy of this gate which can be safely mutated. @private @returns {!Gate}
_copy
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
withParam(value) { let g = this._copy(); g.param = value; g._withParamRecomputeFunc(g); return g; }
Sets an arbitrary json value, saved and restored with the circuit, that the gate's custom functions may use. @param {undefined|!string|!number|!Array} value @returns {!Gate}
withParam
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
static buildFamily(minSize, maxSize, gateBuildFunc) { let gates = []; for (let span = minSize; span <= maxSize; span++) { let builder = new GateBuilder(); builder.setHeight(span); gateBuildFunc(span, builder); builder.gate.gateFamily = gates; g...
Creates size-variants of a gate that can be resized between. @param {!int} minSize @param {!int} maxSize @param {!function(span: !int, builder: !GateBuilder)} gateBuildFunc @returns {!{all: !Array.<!Gate>, ofSize: !function(!int) : !Gate}}
buildFamily
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
ofSize = h => { for (let g of gates) { if (g.height === h) { return g; } } return undefined; }
Creates size-variants of a gate that can be resized between. @param {!int} minSize @param {!int} maxSize @param {!function(span: !int, builder: !GateBuilder)} gateBuildFunc @returns {!{all: !Array.<!Gate>, ofSize: !function(!int) : !Gate}}
ofSize
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
ofSize = h => { for (let g of gates) { if (g.height === h) { return g; } } return undefined; }
Creates size-variants of a gate that can be resized between. @param {!int} minSize @param {!int} maxSize @param {!function(span: !int, builder: !GateBuilder)} gateBuildFunc @returns {!{all: !Array.<!Gate>, ofSize: !function(!int) : !Gate}}
ofSize
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
getUnmetContextKeys() { let result = new Set(this._requiredContextKeys); if (this.knownCircuit !== undefined) { for (let key of this.knownCircuit.getUnmetContextKeys()) { result.add(key); } } return result; }
Returns context keys required by this gate, including keys inherited from its custom circuit (if applicable). @returns {!Set.<!String>}
getUnmetContextKeys
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
knownMatrixAt(time) { return this._knownMatrix !== undefined ? this._knownMatrix : this._knownMatrixFunc !== undefined ? this._knownMatrixFunc(time, this.param) : undefined; }
@param {!number} time @returns {undefined|!Matrix}
knownMatrixAt
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setSymbol(symbol) { this.gate.symbol = symbol; return this; }
Sets the text shown inside the box when drawing the gate (unless a custom drawer is used). @param {!string} symbol @returns {!GateBuilder}
setSymbol
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setAlternateFromFamily(alternateFamily) { return this.setAlternate(alternateFamily.ofSize(this.gate.height)); }
@param {!{all: !Array.<!Gate>, ofSize: !function(!int) : !Gate}} alternateFamily @returns {!GateBuilder}
setAlternateFromFamily
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setSerializedId(serializedId) { this.gate.serializedId = serializedId; return this; }
Specifies the id to use when serializing/parsing this gate (instead of defaulting to the symbol). @param {!string} serializedId @returns {!GateBuilder}
setSerializedId
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setTitle(title) { this.gate.name = title; return this; }
Sets the gate's tooltip title. @param {!string} title A helpful human-readable name for the operation. @returns {!GateBuilder}
setTitle
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setBlurb(blurb) { this.gate.blurb = blurb; return this; }
Sets the detail text shown inside tooltips for the gate. @param {!string} blurb A helpful description of what the gate does. @returns {!GateBuilder}
setBlurb
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setHeight(height) { this.gate.height = height; return this; }
Sets the number of wires the gate spans. @param {!int} height @returns {!GateBuilder}
setHeight
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setWidth(width) { this.gate.width = width; return this; }
Sets the number of columns the gate spans. @param {!int} width @returns {!GateBuilder}
setWidth
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setDrawer(drawer) { this.gate.customDrawer = drawer; return this; }
Provides a custom drawing function for the gate (use undefined to use the default boxed-symbol drawer). @param {undefined|!function(!GateDrawParams) : void} drawer @returns {!GateBuilder}
setDrawer
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setOnClickGateFunc(gateFunc) { this.gate.onClickGateFunc = gateFunc; return this; }
@param {!function(!Gate) : !Gate} gateFunc @returns {!GateBuilder}
setOnClickGateFunc
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setKnownEffectToPermutation(permutationFunc) { this.gate.knownPermutationFuncTakingInputs = permutationFunc; this.gate._knownMatrixFunc = _ => Matrix.generateTransition(1 << this.gate.height, permutationFunc); this.gate._stableDuration = Infinity; this.gate._hasNoEffect = false; ...
Provides a permutation function asserted to be equivalent to the gate's effect. Determines various properties of the gate (e.g. unitarity) and also used by tests to check if the gate's shader's behavior is correct. @param {!function(val: !int) : !int} permutationFunc Returns the output state for each input state. @re...
setKnownEffectToPermutation
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setKnownEffectToBitPermutation(knownBitPermutationFunc) { this.gate.knownBitPermutationFunc = knownBitPermutationFunc; this.gate.knownBitPermutationGroupMasks = permutationGrouping(knownBitPermutationFunc, this.gate.height); this.gate._isDefinitelyUnitary = true; this.gate._stableDuratio...
Provides a function equivalent to how the gate rearranges wires, for checking in tests if the gate's behavior is correct. @param {!function(!int) : !int} knownBitPermutationFunc Returns the output of the permutation for a given input, assuming the gate is exactly sized to the overall circuit. @returns {!GateBuilder...
setKnownEffectToBitPermutation
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setKnownEffectToTimeVaryingPermutation(timeVaryingPermutationFunc) { let g = this.gate; g._stableDuration = 0; g._knownMatrixFunc = t => Matrix.generateTransition(1 << g.height, i => timeVaryingPermutationFunc(t, i)); g._hasNoEffect = false; g._effectPermutesStates = true; ...
Provides a permutation function asserted to be equivalent to the gate's effect. Determines various properties of the gate (e.g. unitarity) and also used by tests to check if the gate's shader's behavior is correct. @param {!function(time: !number, state: !int) : !int} timeVaryingPermutationFunc @returns {!GateBuilder...
setKnownEffectToTimeVaryingPermutation
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setKnownEffectToParametrizedPermutation(permutationFunc) { let g = this.gate; g.knownPermutationFuncTakingInputs = permutationFunc; g._knownMatrixFunc = undefined; g._stableDuration = Infinity; g._hasNoEffect = false; g._effectPermutesStates = true; g._effectCreat...
Provides a permutation function asserted to be equivalent to the gate's effect. Determines various properties of the gate (e.g. unitarity) and also used by tests to check if the gate's shader's behavior is correct. @param { !function(val: !int, a: !int) : !int | !function(val: !int, a: !int, b: !int) : !int...
setKnownEffectToParametrizedPermutation
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setKnownEffectToPhaser(phaseTurnsFunc) { this.gate._hasNoEffect = false; this.gate._effectPermutesStates = false; this.gate._effectCreatesSuperpositions = false; this.gate._isDefinitelyUnitary = true; this.gate._stableDuration = Infinity; this.gate.knownPhaseTurnsFunc = p...
Provides a phase-factor function asserted to be equivalent to the gate's effect. Determines various properties of the gate (e.g. unitarity) and also used by tests to check if the gate's shader's behavior is correct. @param {!function(state: !int) : !number} phaseTurnsFunc Determines how many turns each basis sta...
setKnownEffectToPhaser
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setTooltipMatrixFunc(matrixFunc) { this.gate._knownMatrixFunc = _ => matrixFunc(); this.gate._stableDuration = Infinity; return this; }
@param {!function() : !Matrix} matrixFunc @returns {GateBuilder}
setTooltipMatrixFunc
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setKnownEffectToCircuit(circuitDefinition) { this.gate.knownCircuit = circuitDefinition; this.gate.knownCircuitNested = circuitDefinition.withDisabledReasonsForEmbeddedContext(0, new Map()); this.gate._isDefinitelyUnitary = circuitDefinition.hasOnlyUnitaryGates(); this.gate._stableDurati...
Provides a circuit equivalent to the gate's effect, which can be used to simulate or analyze the gate. @param {!CircuitDefinition} circuitDefinition @returns {!GateBuilder}
setKnownEffectToCircuit
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setEffectToTimeVaryingMatrix(timeToMatrixFunc) { this.gate._stableDuration = 0; this.gate._knownMatrixFunc = timeToMatrixFunc; this.gate._hasNoEffect = false; return this; }
@param {!function(time : !number, gateParam: *) : !Matrix} timeToMatrixFunc @returns {!GateBuilder}
setEffectToTimeVaryingMatrix
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setWithParamPropertyRecomputeFunc(withParamRecomputeFunc) { this.gate._withParamRecomputeFunc = withParamRecomputeFunc; return this; }
A function called by `Gate.withParam` before returning its result. @param {!function(gate: !Gate): undefined} withParamRecomputeFunc @returns {!GateBuilder}
setWithParamPropertyRecomputeFunc
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setActualEffectToUpdateFunc(circuitUpdateFunc) { if (circuitUpdateFunc !== undefined && typeof circuitUpdateFunc !== "function") { throw new DetailedError("Bad customOperation", {circuitUpdateFunc}); } this.gate.customOperation = circuitUpdateFunc; return this; }
Sets a custom circuit-update function to run when simulating this gate. @param {undefined|!function(!CircuitEvalContext)} circuitUpdateFunc @returns {!GateBuilder}
setActualEffectToUpdateFunc
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setActualEffectToShaderProvider(shaderFunc) { return this.setActualEffectToUpdateFunc(ctx => ctx.applyOperation(shaderFunc)); }
Sets a shader as the custom circuit-update function to run when simulating this gate. @param {!function(!CircuitEvalContext) : !WglConfiguredShader} shaderFunc @returns {!GateBuilder}
setActualEffectToShaderProvider
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
promiseEffectOnlyPermutesAndPhases() { this.gate._hasNoEffect = false; this.gate._effectPermutesStates = true; this.gate._effectCreatesSuperpositions = false; this.gate._isDefinitelyUnitary = true; return this; }
Sets meta-properties to indicate the gate is safe for classical use and quantum use, but not safe for mixed used. @returns {!GateBuilder}
promiseEffectOnlyPermutesAndPhases
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
promiseEffectIsDiagonal() { this.gate._hasNoEffect = false; this.gate._effectPermutesStates = false; this.gate._effectCreatesSuperpositions = false; return this; }
Sets meta-properties to indicate the gate is equivalent to a matrix with diagonal entries, such as post-selection in the computational basis. @returns {!GateBuilder}
promiseEffectIsDiagonal
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
promiseEffectOnlyPhases() { this.gate._hasNoEffect = false; this.gate._effectPermutesStates = false; this.gate._effectCreatesSuperpositions = false; this.gate._isDefinitelyUnitary = true; return this; }
Sets meta-properties to indicate the gate is safe for classical, quantum, and mixed use. @returns {!GateBuilder}
promiseEffectOnlyPhases
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
promiseEffectIsStable() { this.gate._stableDuration = Infinity; return this; }
Sets meta-properties to indicate a gate doesn't change over time, and so doesn't force the circuit to constantly recompute. @returns {!GateBuilder}
promiseEffectIsStable
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
promiseHasNoNetEffectOnStateVector() { this.gate._stableDuration = Infinity; this.gate._hasNoEffect = true; this.gate._isDefinitelyUnitary = true; this.gate._effectPermutesStates = false; this.gate._effectCreatesSuperpositions = false; return this; }
Indicates that the gate can be skipped over when computing the system state. Note that Input gates and Z controls meet this definition, because their effects happen via other gates conditioning on them. X and Y controls don't meet the definition because they have to perform a temporary basis change which counts as a c...
promiseHasNoNetEffectOnStateVector
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
markAsNotInterestedInControls() { this.gate.interestedInControls = false; return this; }
Indicates that the gate isn't a control wire destination when drawing. @returns {!GateBuilder}
markAsNotInterestedInControls
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
markAsControlExpecting(bit, guaranteedClassical=false) { this.gate._controlBit = bit; this.gate.isControlWireSource = true; this.gate.interestedInControls = false; this.gate._isClassicalControl = guaranteedClassical; return this; }
Sets meta-properties to indicate a gate is a control. @param {!boolean|!string} bit: Whether gate is a control (True), anti-control (False), or parity control ("parity"). Use before/after operations for flexibility. @param {!boolean} guaranteedClassical Whether or not the control can be used to control permutations...
markAsControlExpecting
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
markAsReachingOtherWires() { this.gate._showAsReachesOtherWires = true; return this; }
Indicates that the effect of this gate can immediately affect gates or displays on wires other than the ones this gate is placed on. @returns {GateBuilder}
markAsReachingOtherWires
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
markAsDrawerNeedsSingleQubitDensityStats() { this.gate.isSingleQubitDisplay = true; return this; }
Sets meta-properties indicating a qubit density matrix needs to be computed wherever this gate is placed. @returns {!GateBuilder}
markAsDrawerNeedsSingleQubitDensityStats
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setRequiredContextKeys(...keys) { this.gate._requiredContextKeys = keys; return this; }
Specifies context values provided by other gates that this gate needs to be present in order to function. @param {...!String} keys @returns {!GateBuilder}
setRequiredContextKeys
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setContextProvider(customColumnContextProvider) { this.gate.customColumnContextProvider = customColumnContextProvider; this.gate.isContextTemporary = true; return this; }
Specifies a function for retrieving the context provided by a gate to other gates. @param {!function(qubit:!int,gate:!Gate):!Array.<!{key: !string, val: *}>} customColumnContextProvider @returns {!GateBuilder}
setContextProvider
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setStickyContextProvider(customColumnContextProvider) { this.gate.customColumnContextProvider = customColumnContextProvider; this.gate.isContextTemporary = false; return this; }
Specifies a function for retrieving the context provided by a gate to other gates. @param {!function(qubit:!int,gate:!Gate):!Array.<!{key: !string, val: *}>} customColumnContextProvider @returns {!GateBuilder}
setStickyContextProvider
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setSetupCleanupEffectsToShaderProviders(beforeColumnShaderFunc, afterColumnShaderFunc) { return this.setSetupCleanupEffectToUpdateFunc( beforeColumnShaderFunc === undefined ? undefined : ctx => ctx.applyOperation(beforeColumnShaderFunc), afterColumnShaderFunc === undefined ? undefined : ...
Sets a setup shader to unconditionally run before executing the operations in a column containing this gate. @param {undefined|!function(!CircuitEvalContext) : !WglConfiguredShader} beforeColumnShaderFunc @param {undefined|!function(!CircuitEvalContext) : !WglConfiguredShader} afterColumnShaderFunc @returns {!GateBuild...
setSetupCleanupEffectsToShaderProviders
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setSetupCleanupEffectToUpdateFunc(beforeColumnUpdateFunc, afterColumnUpdateFunc) { if (beforeColumnUpdateFunc !== undefined && typeof beforeColumnUpdateFunc !== "function") { throw new DetailedError("Bad beforeColumnUpdateFunc", {customOperation}); } if (afterColumnUpdateFunc !== und...
Sets a setup operation to unconditionally run before executing the operations in a column containing this gate. @param {undefined|!function(!CircuitEvalContext) : void} beforeColumnUpdateFunc @param {undefined|!function(!CircuitEvalContext) : void} afterColumnUpdateFunc @returns {!GateBuilder}
setSetupCleanupEffectToUpdateFunc
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setExtraDisableReasonFinder(customDisableReasonFinder) { this.gate.customDisableReasonFinder = customDisableReasonFinder; return this; }
Specifies a function for retrieving unusual reasons a gate is being misused and so must be disabled. @param {!function(!GateCheckArgs) : (undefined|!string)} customDisableReasonFinder @returns {!GateBuilder}
setExtraDisableReasonFinder
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setStatTexturesMaker(statTexturesMaker) { this.gate.customStatTexturesMaker = statTexturesMaker; return this; }
Specifies how to extract data that will be needed when drawing a display gate. @param {undefined|!function(!CircuitEvalContext) : (!WglTexture|!Array.<!WglTexture>)} statTexturesMaker @returns {!GateBuilder}
setStatTexturesMaker
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setStatPixelDataPostProcessor(pixelFunc) { this.gate.customStatPostProcesser = pixelFunc; return this; }
Specifies how to process raw pixel data from the custom stats texture maker into a more useful value. @param {undefined|!function(pixelData: !Float32Array | Array.<!Float32Array>, circuit: !CircuitDefinition, col:!int, row:!int)} pixelF...
setStatPixelDataPostProcessor
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
setProcessedStatsToJsonFunc(jsonFunc) { this.gate.processedStatsToJsonFunc = jsonFunc; return this; }
Specifies how to convert custom stats data into json when exporting. @param {undefined|!function(data: *) : *} jsonFunc @returns {!GateBuilder}
setProcessedStatsToJsonFunc
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
function permutationGrouping(knownBitPermutationFunc, height) { let seen = new Set(); let result = []; for (let i = 0; i < height; i++) { let mask = 0; let j = i; while (!seen.has(j)) { seen.add(j); mask |= 1 << j; j = knownBitPermutationFunc(j); ...
@param {!function(!int) : !int} knownBitPermutationFunc Returns the output of the permutation for a given input, assuming the gate is exactly sized to the overall circuit. @param {!int} height @returns {!Array.<!int>}
permutationGrouping
javascript
Strilanc/Quirk
src/circuit/Gate.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Gate.js
Apache-2.0
constructor(gate, innerColumn, outerRow, measuredMask, context, isNested) { /** @type {!Gate} */ this.gate = gate; /** @type {!GateColumn} */ this.innerColumn = innerColumn; /** @type {!int} */ ...
@param {!Gate} gate @param {!GateColumn} innerColumn @param {!int} outerRow @param {!int} measuredMask @param {!Map.<!string, *>} context @param {!boolean} isNested
constructor
javascript
Strilanc/Quirk
src/circuit/GateCheckArgs.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateCheckArgs.js
Apache-2.0
constructor(gates) { /** @type {!Array.<undefined|!Gate>} */ this.gates = gates; }
A column of gates in a circuit with many qubits. @param {!Array.<undefined|!Gate>} gates The list of gates to apply to each wire, with the i'th gate applying to the i'th wire. Wires without a gate in this column should use undefined instead.
constructor
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
hasControl(inputMeasureMask=0, ignoreMask=0) { return this.hasCoherentControl(inputMeasureMask | ignoreMask) || this.hasMeasuredControl(inputMeasureMask & ~ignoreMask); }
@param {!int} inputMeasureMask @param {!int} ignoreMask @returns {!boolean}
hasControl
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
_disabledReason(inputMeasureMask, row, outerRowOffset, context, isNested) { let g = this.gates[row]; if (g === undefined) { return undefined; } let args = new GateCheckArgs(g, this, outerRowOffset + row, inputMeasureMask, context, isNested); return g.customDisableRea...
@param {!int} inputMeasureMask @param {!int} row @param {!int} outerRowOffset @param {!Map<!string, *>} context @param {!boolean} isNested @returns {undefined|!string} @private
_disabledReason
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
_disabledReason_overlappingTags(outerRow, row) { let keys = new Set( this.gates[row].customColumnContextProvider(outerRow + row, this.gates[row]).map(e => e.key)); if (keys.length === 0) { return undefined; } for (let i = 0; i < row; i++) { let g = th...
@param {!int} outerRow @param {!int} row @returns {undefined|!string} @private
_disabledReason_overlappingTags
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
_disabledReason_remixing(row, inputMeasureMask) { // Measured qubits can't be re-superposed for implementation simplicity reasons. let g = this.gates[row]; let mask = ((1 << g.height) - 1) << row; let maskMeasured = mask & inputMeasureMask; if (maskMeasured !== 0 && g.knownBitPer...
@param {!int} row @param {!int} inputMeasureMask @returns {undefined|!string} @private
_disabledReason_remixing
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
hasGatesWithGlobalEffects() { for (let i = 0; i < this.gates.length; i++) { let gate = this.gates[i]; if (gate !== undefined && gate.shouldShowAsHavingGlobalEffect()) { return true; } } return false; }
@returns {boolean} Whether there is a gate with a global effect in the column or not.
hasGatesWithGlobalEffects
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
indexOfNonUnitaryGate() { for (let i = 0; i < this.gates.length; i++) { let gate = this.gates[i]; if (gate !== undefined && !gate.isDefinitelyUnitary()) { return i; } } return undefined; }
@returns {undefined|!int} The index of some non-unitary gate in the column, if any.
indexOfNonUnitaryGate
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
static _disabledReason_inputs(args) { let rangeVals = []; for (let key of args.gate.getUnmetContextKeys()) { if (key.startsWith("Input Range ") && args.context.has(key)) { rangeVals.push(args.context.get(key)); } } return GateColumn._disabledReaso...
@param {!GateCheckArgs} args @returns {undefined|!string} @private
_disabledReason_inputs
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
static _disabledReason_inputs_missing(args) { let missing = []; for (let key of args.gate.getUnmetContextKeys()) { let altKey = key. replace("Input Range ", "Input Default "). replace("Input NO_DEFAULT Range ", "Input Range "); if (!args.context.ha...
@param {!GateCheckArgs} args @returns {undefined|!string} @private
_disabledReason_inputs_missing
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
static _disabledReason_inputs_inside(args, rangeVals) { let row = args.outerRow; for (let {offset, length} of rangeVals) { //noinspection JSUnusedAssignment if (offset + length > row && row + args.gate.height > offset) { return "input\ninside"; } ...
@param {!GateCheckArgs} args @param {!Array.<!{offset: !int, length: !int}>} rangeVals @returns {undefined|!string} @private
_disabledReason_inputs_inside
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
static _disabledReason_inputs_coherenceMismatch(args, rangeVals) { let row = args.outerRow; if (args.gate.effectMightPermutesStates()) { let hasMeasuredOutputs = ((args.measuredMask >> row) & ((1 << args.gate.height) - 1)) !== 0; if (hasMeasuredOutputs) { for (let...
@param {!GateCheckArgs} args @param {!Array.<!{offset: !int, length: !int}>} rangeVals @returns {undefined|!string} @private
_disabledReason_inputs_coherenceMismatch
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
_disabledReason_controlInside(row) { let g = this.gates[row]; for (let j = 1; j < g.height && row + j < this.gates.length; j++) { if (this.gates[row + j] !== undefined && this.gates[row + j].isControl()) { return "control\ninside"; } } return undef...
@param {!int} row @returns {undefined|!string} @private
_disabledReason_controlInside
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
minimumRequiredWireCount() { let best = 0; for (let i = 0; i < this.gates.length; i++) { if (this.gates[i] !== undefined) { best = Math.max(best, this.gates[i].height + i); } } return best; }
@param {!int} row @returns {undefined|!string} @private
minimumRequiredWireCount
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
maximumGateWidth() { let best = -Infinity; for (let g of this.gates) { if (g !== undefined) { best = Math.max(best, g.width); } } return best; }
@param {!int} row @returns {undefined|!string} @private
maximumGateWidth
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
perRowDisabledReasons(inputMeasureMask, outerRowOffset, outerContext, prevStickyCtx, isNested) { let context = Util.mergeMaps(outerContext, prevStickyCtx); let stickyCtx = new Map(prevStickyCtx); for (let row = this.gates.length - 1; row >= 0; row--) { let g = this.gates[row]; ...
@param {!int} inputMeasureMask @param {!int} outerRowOffset @param {!Map.<!string, *>} outerContext @param {!Map.<!string, *>} prevStickyCtx @param {!boolean} isNested @returns {{allReasons: !Array.<undefined|!string>, stickyCtx: !Map<!string, *>}}
perRowDisabledReasons
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
_updateMeasureMask_gateStep(state, row, disabledReasons) { if (disabledReasons[row] !== undefined) { return; } let gate = this.gates[row]; if (gate === undefined) { return; } // The measurement gate measures. if (gate === Gates.Special.M...
@param {{measureMask: !int, earlierRowWithSwapGate: undefined|!int}} state @param row @param {!Array.<undefined|!string>} disabledReasons @returns {void} @private
_updateMeasureMask_gateStep
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
static _updateMeasureMask_swapGate(gate, state, row) { if (gate !== Gates.Special.SwapHalf) { return; } if (state.earlierRowWithSwapGate === undefined) { state.earlierRowWithSwapGate = row; return; } // Swap gate swaps measurement states. ...
@param {!Gate} gate @param {{measureMask: !int, earlierRowWithSwapGate: undefined|!int}} state @param row @returns {void} @private
_updateMeasureMask_swapGate
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
static _updateMeasureMask_customPermute(gate, state, row) { if (gate.knownBitPermutationFunc === undefined) { return; } let mask = ((1 << gate.height) - 1) << row; let prev = state.measureMask & mask; state.measureMask &= ~mask; for (let i = 0; i < gate.heigh...
@param {!Gate} gate @param {{measureMask: !int, earlierRowWithSwapGate: undefined|!int}} state @param row @returns {void} @private
_updateMeasureMask_customPermute
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
nextMeasureMask(inputMeasureMask, disabledReasons) { let state = {measureMask: inputMeasureMask, earlierRowWithSwapGate: undefined}; for (let row = 0; row < this.gates.length; row++) { this._updateMeasureMask_gateStep(state, row, disabledReasons); } return state.measureMask; ...
@param {!int} inputMeasureMask @param {!Array.<undefined|!string>} disabledReasons @returns {!int}
nextMeasureMask
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
withGatesAdded(startIndex, insertedCol) { if (!Number.isInteger(startIndex) || startIndex < 0 || startIndex > this.gates.length- insertedCol.gates.length) { throw new DetailedError("Bad start index", {baseCol: this, startIndex, insertedCol}); } let gates = this.gates....
@param {!int} startIndex @param {!GateColumn} insertedCol @returns {!GateColumn}
withGatesAdded
javascript
Strilanc/Quirk
src/circuit/GateColumn.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateColumn.js
Apache-2.0
function _applySingleQubitOperationFunc(ctx, matrix) { if (matrix.width() !== 2 || matrix.height() !== 2) { throw new DetailedError("Not a single-qubit operation.", {matrix}); } let [ar, ai, br, bi, cr, ci, dr, di] = matrix.rawBuffer(); ctx.applyOperation(CUSTOM_SINGLE_QUBIT_OPERATION_SHADER.wit...
Renders the result of applying a custom controlled single-qubit operation to a superposition. @param {!CircuitEvalContext} ctx @param {!Matrix} matrix
_applySingleQubitOperationFunc
javascript
Strilanc/Quirk
src/circuit/GateShaders.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateShaders.js
Apache-2.0
hugeQubitOperationMaker = qubitCount => ketShader( '', ` vec2 t = vec2(0.0, 0.0); for (int k = 0; k < ${1<<qubitCount}; k++) { t += cmul(inp(float(k)), read_coefs(out_id * ${1<<qubitCount}.0 + float(k))); } return t; `, qubitCount, [I...
Renders the result of applying a custom controlled single-qubit operation to a superposition. @param {!CircuitEvalContext} ctx @param {!Matrix} matrix
hugeQubitOperationMaker
javascript
Strilanc/Quirk
src/circuit/GateShaders.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateShaders.js
Apache-2.0
hugeQubitOperationMaker = qubitCount => ketShader( '', ` vec2 t = vec2(0.0, 0.0); for (int k = 0; k < ${1<<qubitCount}; k++) { t += cmul(inp(float(k)), read_coefs(out_id * ${1<<qubitCount}.0 + float(k))); } return t; `, qubitCount, [I...
Renders the result of applying a custom controlled single-qubit operation to a superposition. @param {!CircuitEvalContext} ctx @param {!Matrix} matrix
hugeQubitOperationMaker
javascript
Strilanc/Quirk
src/circuit/GateShaders.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateShaders.js
Apache-2.0
multiQubitOperationMaker = qubitCount => ketShader( `uniform vec4 coefs[${1<<(2*qubitCount-1)}];`, ` int row = int(out_id); vec2 t = vec2(0.0, 0.0); for (int d = 0; d < ${1<<qubitCount}; d++) { // Can't index by row, since it's not a constant, so we do a const brute force loo...
Renders the result of applying a custom controlled single-qubit operation to a superposition. @param {!CircuitEvalContext} ctx @param {!Matrix} matrix
multiQubitOperationMaker
javascript
Strilanc/Quirk
src/circuit/GateShaders.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateShaders.js
Apache-2.0
multiQubitOperationMaker = qubitCount => ketShader( `uniform vec4 coefs[${1<<(2*qubitCount-1)}];`, ` int row = int(out_id); vec2 t = vec2(0.0, 0.0); for (int d = 0; d < ${1<<qubitCount}; d++) { // Can't index by row, since it's not a constant, so we do a const brute force loo...
Renders the result of applying a custom controlled single-qubit operation to a superposition. @param {!CircuitEvalContext} ctx @param {!Matrix} matrix
multiQubitOperationMaker
javascript
Strilanc/Quirk
src/circuit/GateShaders.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/GateShaders.js
Apache-2.0
ketShader = (head, body, span=null, inputs=[]) => ({withArgs: makePseudoShaderWithInputsAndOutputAndCode( [ ...inputs, Inputs.vec2('ketgen_ket'), Inputs.bool('ketgen_control') ], Outputs.vec2(), ` uniform float _ketgen_step; ${span === null ? 'uniform float span;' : ''} ...
Creates a shader for a quantum gate based on a minimalist input like `return cmul(inp(0.0), vec2(0.0, 1.0));`. Available methods and values: - float out_id: The state for which we're computing an amplitude. Note that this state is relativized: when in a circuit with more qubits than the gate's spa...
ketShader
javascript
Strilanc/Quirk
src/circuit/KetShaderUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/KetShaderUtil.js
Apache-2.0
ketShader = (head, body, span=null, inputs=[]) => ({withArgs: makePseudoShaderWithInputsAndOutputAndCode( [ ...inputs, Inputs.vec2('ketgen_ket'), Inputs.bool('ketgen_control') ], Outputs.vec2(), ` uniform float _ketgen_step; ${span === null ? 'uniform float span;' : ''} ...
Creates a shader for a quantum gate based on a minimalist input like `return cmul(inp(0.0), vec2(0.0, 1.0));`. Available methods and values: - float out_id: The state for which we're computing an amplitude. Note that this state is relativized: when in a circuit with more qubits than the gate's spa...
ketShader
javascript
Strilanc/Quirk
src/circuit/KetShaderUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/KetShaderUtil.js
Apache-2.0
ketShaderPermute = (head, body, span=null) => ketShader( head + `float _ketgen_input_for(float out_id) { ${body} }`, 'return inp(_ketgen_input_for(out_id));', span)
@param {!String} head @param {!String} body @param {null|!int=null} span @return {!{withArgs: !function(args: ...!WglArg|!WglTexture) : !WglConfiguredShader}}
ketShaderPermute
javascript
Strilanc/Quirk
src/circuit/KetShaderUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/KetShaderUtil.js
Apache-2.0
ketShaderPermute = (head, body, span=null) => ketShader( head + `float _ketgen_input_for(float out_id) { ${body} }`, 'return inp(_ketgen_input_for(out_id));', span)
@param {!String} head @param {!String} body @param {null|!int=null} span @return {!{withArgs: !function(args: ...!WglArg|!WglTexture) : !WglConfiguredShader}}
ketShaderPermute
javascript
Strilanc/Quirk
src/circuit/KetShaderUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/KetShaderUtil.js
Apache-2.0
ketShaderPhase = (head, body, span=null) => ketShader( `${head} float _ketgen_phase_for(float out_id) { ${body} } `, ` float angle = _ketgen_phase_for(out_id); return cmul(amp, vec2(cos(angle), sin(angle))); `, span)
Returns a shader that multiplies each of the amplitudes in a superposition by computed phase factors. @param {!String} head Header code defining shader methods, uniforms, etc. @param {!String} body The body of a shader method returning the number of radians to phase by. @param {null|!int=null} span The number of qubit...
ketShaderPhase
javascript
Strilanc/Quirk
src/circuit/KetShaderUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/KetShaderUtil.js
Apache-2.0
ketShaderPhase = (head, body, span=null) => ketShader( `${head} float _ketgen_phase_for(float out_id) { ${body} } `, ` float angle = _ketgen_phase_for(out_id); return cmul(amp, vec2(cos(angle), sin(angle))); `, span)
Returns a shader that multiplies each of the amplitudes in a superposition by computed phase factors. @param {!String} head Header code defining shader methods, uniforms, etc. @param {!String} body The body of a shader method returning the number of radians to phase by. @param {null|!int=null} span The number of qubit...
ketShaderPhase
javascript
Strilanc/Quirk
src/circuit/KetShaderUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/KetShaderUtil.js
Apache-2.0
function ketArgs(ctx, span=undefined, input_letters=[]) { let result = [ ctx.stateTrader.currentTexture, ctx.controlsTexture, WglArg.float("_ketgen_step", 1 << ctx.row) ]; if (span !== undefined) { result.push(WglArg.float('span', 1 << span)); } for (let letter of inp...
Determines some arguments to give to a shader produced by one of the ketShader methods. @param {!CircuitEvalContext} ctx The context in which the ket shader is being applied. @param {undefined|!int=undefined} span The number of qubits this shader applies to (if wasn't known ahead of time). @param {undefined|!Array.<!s...
ketArgs
javascript
Strilanc/Quirk
src/circuit/KetShaderUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/KetShaderUtil.js
Apache-2.0
function ketInputGateArgs(ctx, letter) { let offset = 0; let length = -1; let defaultVal = ctx.customContextFromGates.get(`Input Default ${letter}`) || 0; let inputCtx = ctx.customContextFromGates.get(`Input Range ${letter}`); if (inputCtx !== undefined) { offset = inputCtx.offset; l...
@param {!CircuitEvalContext} ctx @param {!string} letter @returns {!Array.<!WglArg>}
ketInputGateArgs
javascript
Strilanc/Quirk
src/circuit/KetShaderUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/KetShaderUtil.js
Apache-2.0
function _superpositionTexToUnsummedQubitDensitiesTex(trader, keptBitMask) { if (keptBitMask === 0) { throw new DetailedError("keptBitMask === 0", {trader, keptBitMask}); } let startingQubitCount = currentShaderCoder().vec2.arrayPowerSizeOfTexture(trader.currentTexture); let remainingQubitCount ...
@param {!WglTextureTrader} trader @param {!int} keptBitMask
_superpositionTexToUnsummedQubitDensitiesTex
javascript
Strilanc/Quirk
src/circuit/KetTextureUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/KetTextureUtil.js
Apache-2.0
function _sumDownVec4(trader, outCount) { // When the number of kept qubits isn't a power of 2, we have some extra junk results interleaved to ignore. let outputSizePower = Util.ceilLg2(outCount); let curSizePower = currentShaderCoder().vec4.arrayPowerSizeOfTexture(trader.currentTexture); while (curSiz...
@param {!WglTextureTrader} trader @param {!int} outCount The number of interleaved slices being summed. The output will be a single row containing this many results (but padded up to a power of 2).
_sumDownVec4
javascript
Strilanc/Quirk
src/circuit/KetTextureUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/KetTextureUtil.js
Apache-2.0
function initSerializer(gateLabelDrawer, gateMatrixDrawer, gateCircuitDrawer, locationIndependentGateDrawer) { labelDrawer = gateLabelDrawer; matrixDrawer = gateMatrixDrawer; circuitDrawer = gateCircuitDrawer; locationIndependentDrawer = locationIndependentGateDrawer; }
@param {!function(!GateDrawParams)} gateLabelDrawer @param {!function(!GateDrawParams)} gateMatrixDrawer @param {!function(!GateDrawParams)} gateCircuitDrawer @param {!function(!GateDrawParams)} locationIndependentGateDrawer
initSerializer
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
static toJson(value, context=undefined) { //noinspection JSUnusedLocalSymbols for (let [type, toJ, _] of BINDINGS) { //noinspection JSUnusedAssignment if (value instanceof type) { //noinspection JSUnusedAssignment return toJ(value, context); ...
@param {*} value @param {*=undefined} context @returns {*}
toJson
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
static fromJson(expectedType, json, context=undefined) { //noinspection JSUnusedLocalSymbols for (let [type, _, fromJ] of BINDINGS) { //noinspection JSUnusedAssignment if (type === expectedType) { //noinspection JSUnusedAssignment return fromJ(json...
@param {*} expectedType @param {*} json @param {*=undefined} context @returns {*}
fromJson
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_Complex = json => { if (typeof json === "string") { return Complex.parse(json); } throw new Error("Not a packed complex string: " + json); }
@param {object} json @returns {!Complex} @throws {Error}
fromJson_Complex
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0