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
padded(minCount, paddingItem=undefined) { if (minCount < 0) { throw new Error("needed minCount >= 0"); } let seq = this._iterable; return Seq.fromGenerator(function*() { let remaining = minCount; for (let e of seq) { yield e; ...
Returns a sequence starting with the same items, but padded up to the given length with the given item. If the sequence already exceeds the given length, no items are added. @param {!int} minCount @param {A=} paddingItem @returns {!Seq.<T|A>} @template T, A
padded
javascript
Strilanc/Quirk
src/base/Seq.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Seq.js
Apache-2.0
sorted() { return seq(this.toArray().sort()); }
Returns a sequence containing the same items, but in ascending order. @returns {!Seq.<T>} @template T
sorted
javascript
Strilanc/Quirk
src/base/Seq.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Seq.js
Apache-2.0
sortedBy(keySelector) { return seq(this.toArray().sort((e1, e2) => { let out1 = keySelector(e1); let out2 = keySelector(e2); return out1 < out2 ? -1 : out1 > out2 ? +1 : 0; })); }
Returns a sequence containing the same items, but in ascending order of outputs from the given function. @returns {!Seq.<T>} @template T
sortedBy
javascript
Strilanc/Quirk
src/base/Seq.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Seq.js
Apache-2.0
ifThen(condition, sequenceTransformation) { return condition ? new Seq(sequenceTransformation(this)) : this; }
Conditionally applies a transformation to the sequence. If the given condition is false, the original sequence is returned. If the given condition is true, the sequence is run through the given transformation and the result is returned. This method mainly exists for syntactic convenience, so a dotted pipeline can be d...
ifThen
javascript
Strilanc/Quirk
src/base/Seq.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Seq.js
Apache-2.0
toMap(keySelector, valueSelector) { let map = new Map(); for (let item of this._iterable) { let key = keySelector(item); let val = valueSelector(item); if (map.has(key)) { throw new Error(`Duplicate key <${key}>. Came from item <${item}>.`); ...
Returns a map containing the key/value pairs created by projecting each of the items in the sequence through key and value selector functions. If any duplicate keys are generated, an exception is thrown. @param {!function(T): K} keySelector @param {!function(T): V} valueSelector @returns {!Map.<K, V>} @template T, K,...
toMap
javascript
Strilanc/Quirk
src/base/Seq.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Seq.js
Apache-2.0
keyedBy(keySelector) { return this.toMap(keySelector, e => e); }
Returns a map where the items from the sequence are indexed by the result of running them through the given key selector function. If any duplicate keys are generated, an exception is thrown. @param {!function(T): K} keySelector @returns {!Map.<K, V>} @template T, K, V
keyedBy
javascript
Strilanc/Quirk
src/base/Seq.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Seq.js
Apache-2.0
groupBy(keySelector) { let map = new Map(); for (let item of this._iterable) { let key = keySelector(item); if (!map.has(key)) { map.set(key, []); } map.get(key).push(item); } return map; }
Returns a map, with keys generated by passing the sequence's items through the given key selector, where each key maps to an array of the items (from the sequence) that mapped to said key. @param {!function(T): K} keySelector @returns {!Map.<K, !(T[])>} @template T, K
groupBy
javascript
Strilanc/Quirk
src/base/Seq.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Seq.js
Apache-2.0
partitioned(partitionSize) { if (partitionSize <= 0) { throw new Error("need partitionSize > 0"); } let seq = this; return Seq.fromGenerator(function*() { let buffer = []; for (let item of seq) { buffer.push(item); if (b...
Groups elements into arrays of the given size (except for the last partition, which may be smaller) and yields the groups instead of individual items. @param {!int} partitionSize @returns {!Seq.<!(T[])>} @template T
partitioned
javascript
Strilanc/Quirk
src/base/Seq.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Seq.js
Apache-2.0
stride(stepSize) { return this.filterWithIndex((e, i) => i % stepSize === 0); }
Iterates the elements in the subsequence that are at indices congruent to 0 modulo the given step size. @param stepSize
stride
javascript
Strilanc/Quirk
src/base/Seq.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Seq.js
Apache-2.0
breadthFirstSearch(neighborSelector, keySelector = e => e) { let seq = this; return Seq.fromGenerator(function*() { let visited = new Set(); let schedule = seq.toArray(); for (let i = 0; i < schedule.length; i++) { let e = schedule[i]; ...
Iterates elements reachable by starting from the given sequence and applying the given neighbor yielding function to known nodes. @param {!function(T) : !(T[])} neighborSelector @param {!function(T) : K} keySelector @returns {!Seq.<T>} @template T, K
breadthFirstSearch
javascript
Strilanc/Quirk
src/base/Seq.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Seq.js
Apache-2.0
static need(expression, message, args) { if (expression !== true) { let argDesc = args === undefined ? "(not provided)" : `[${ Array.prototype.slice.call(args).join(", ") }]` ; let msgDesc = message === undefined ? "(not provided)" : message; l...
Checks a precondition, throwing an exception containing the given message in the case of failure. @param {!boolean|*} expression @param {=string} message @param {=Array} args
need
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static numberOfSetBits(i) { if (i < 0) { throw new Error("i < 0"); } if (!Number.isInteger(i)) { throw new Error("!Number.isInteger(i)"); } if (i > 0xFFFFFFFF) { throw new Error("i > 0xFFFFFFFF"); } // Start with each bit representing its own pop count. // Merge adjacent 1-bit p...
Checks a precondition, throwing an exception containing the given message in the case of failure. @param {!boolean|*} expression @param {=string} message @param {=Array} args
numberOfSetBits
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static bin(number, fixedLen) { return ("0".repeat(fixedLen) + number.toString(2)).slice(-fixedLen).split("").join(""); }
Returns a big-endian binary representation of the given number, zero-padded and truncated to the given length. @param {!number|!int} number @param {!int} fixedLen @returns {!string}
bin
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static notNull(v) { Util.need(v !== null, "notNull"); //noinspection JSValidateTypes return v; }
Forced cast from nullable to non-nullable, throwing an exception on failure. @param {?T} v @returns {!T} @template T
notNull
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static isPowerOf2(i) { return i > 0 && ((i - 1) & i) === 0; }
Determines if there is an integer p such that 2^p equals the given integer. @param {!int} i @returns {!boolean}
isPowerOf2
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static bitSize(n) { Util.need(n >= 0, "bitSize: n >= 0"); if (n === 0) { return 0; } return Util.floorLg2(n) + 1; }
Returns the number of bits needed to uniquely encode all integers up to and including the given value. A discrete off-by-one version of log_2(n). @param {!int} n @returns {!int}
bitSize
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static ceilingPowerOf2(n) { if (n <= 1) { return 1; } return 1 << Util.ceilLg2(n); }
Returns the smallest power of 2 that is equal to or larger than the given integer. @param {!int} n @returns {!int}
ceilingPowerOf2
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static ceilLg2(n) { if (n <= 1) { return 0; } let p = Math.ceil(Math.log2(n)); if (1<<p < n) { return p + 1; } if (n <= 1<<(p-1)) { return p - 1; } return p; }
@param {!int} n @returns {!int} A value p such that 2**(p-1) < n <= 2**p.
ceilLg2
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static floorLg2(n) { if (n <= 1) { return 0; } let p = Math.floor(Math.log2(n)); if (1<<(p+1) <= n) { return p + 1; } if (n < 1<<p) { return p - 1; } return p; }
@param {!int} n @returns {!int} A value p such that 2**p <= n < 2**(p+1).
floorLg2
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static popcnt(i) { if (i < 0) { return Math.POSITIVE_INFINITY; } let t = 0; while (i > 0) { i &= i - 1; t++; } return t; }
Counts the number of set bits in an integer. @param {!int} i @returns {!int}
popcnt
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static powerOfTwoness(i, zeroResult=Math.POSITIVE_INFINITY) { if (i === 0) { return zeroResult; } if (i < 0) { return Util.powerOfTwoness(-i, zeroResult); } return Math.round(Math.log2(i & ~(i - 1))); }
Determines how multiply-even a number is; how many times you can divide it by 2 before getting an odd result. Odd numbers have 0 power-of-two-ness, multiples of 2 that aren't multiples of 4 have 1 power-of-two-ness, multiples of 4 that aren't multiples of 8 have 3 power-of-two-ness, and so forth. Note that zero has in...
powerOfTwoness
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static reverseGroupMap(groupMap, includeGroupsForOriginalKeysEvenIfEmpty = false) { let result = new Map(); if (includeGroupsForOriginalKeysEvenIfEmpty) { for (let e of groupMap.keys()) { result.set(e, []); } } for (let [k, g] of groupMap) { ...
Converts from Map.<K, V[]> to Map.<V, K[]> in the "obvious" way, by having each value map to the group of keys that mapped to a group containing said value in the original map. @param {!Map.<K, !(V[])>} groupMap @param {!boolean=} includeGroupsForOriginalKeysEvenIfEmpty @returns {!Map.<V, !(K[])>} @template K, V
reverseGroupMap
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static binarySearchForTransitionFromTrueToFalse(max, argIsBeforeTransitionFunc) { let min = 0; while (max > min) { let med = min + Math.floor((max - min) / 2); if (argIsBeforeTransitionFunc(med)) { min = med + 1; } else { max = med; ...
Performs a binary search, looking for the first index to return false under the constraint that the given function returns true for all arguments less than some index and false afterwards. @param {!int} max Determines the range to search over. Valid inputs to the query function are non-negative integers up to this max...
binarySearchForTransitionFromTrueToFalse
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static breakLine(text, maxWidth, measureWidth) { if (text === "") { return [""]; } let lines = []; let p = 0; while (p < text.length) { // How many characters will fit on this line? let maxKeepLength = Util.binarySearchForTransitionFromTrueToFa...
Breaks a single line of characters into several lines, when forced to by a width boundary. @param {!string} text A single unbroken line of text, without any newline characters. @param {!number} maxWidth The maximum width that lines can grow to before they must be broken. @param {!function(!string) : !number} measureWid...
breakLine
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static decomposeObjectValues(object) { let result = []; let decomposeValueOrArray; decomposeValueOrArray = val => { if (Array.isArray(val)) { for (let item of val) { decomposeValueOrArray(item); } } else { ...
Enumerates the fields of an object, stashing their values into an array. Array fields are flattened into the result array. @param {*} object @returns {!Array.<*>}
decomposeObjectValues
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static recomposedObjectValues(originalObject, newFieldValues) { let result = {}; let i = 0; let recomposeValueOrArray; recomposeValueOrArray = originalVal => { if (Array.isArray(originalVal)) { let arr = []; for (let item of originalVal) { ...
@param {*} originalObject @param {!Array.<*>} newFieldValues @returns {!object}
recomposedObjectValues
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static objectifyArrayFunc(func) { return arg => Util.recomposedObjectValues(arg, func(Util.decomposeObjectValues(arg))); }
@param {!function(!Array.<*>) : !Array.<*>} func @returns {!function(!object) : !object}
objectifyArrayFunc
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static properMod(numerator, denominator) { if (denominator <= 0) { throw new DetailedError("denominator <= 0", {numerator, denominator}); } let result = numerator % denominator; return result + (result < 0 ? denominator : 0); }
Returns the math-style remainder, which is guaranteed to be in the range [0, denominator) even when the numerator is negative. @param {!number} numerator @param {!number} denominator @returns {!number}
properMod
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static modular_multiplicative_inverse(value, modulus) { let {x, gcd} = Util.extended_gcd(value, modulus); if (gcd !== 1) { return undefined; } x %= modulus; if (x < 0) { x += modulus; } return x; }
@param {!int} value @param {!int} modulus @returns {!int} A value r in [0, modulus) such that r*value = 1 (mod modulus).
modular_multiplicative_inverse
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
static extended_gcd(a, b) { let s = 0; let t = 1; let r = b; let old_s = 1; let old_t = 0; let old_r = a; while (r !== 0) { let q = Math.floor(old_r / r); [old_r, r] = [r, old_r - q * r]; [old_s, s] = [s, old_s - q * s]; ...
@param {!int} a @param {!int} b @returns {!{x: !int, y: !int, gcd: !int}} Such that x*a + y*b = gcd = GCD(a, b)
extended_gcd
javascript
Strilanc/Quirk
src/base/Util.js
https://github.com/Strilanc/Quirk/blob/master/src/base/Util.js
Apache-2.0
function textEditObservable(textBox) { return Observable.of( Observable.elementEvent(textBox, 'change'), Observable.elementEvent(textBox, 'keyup'), Observable.elementEvent(textBox, 'click'), Observable.elementEvent(textBox, 'paste'), Observable.elementEvent(textBox, 'input') ...
@param {!HTMLInputElement} textBox @returns {!Observable.<!String>}
textEditObservable
javascript
Strilanc/Quirk
src/browser/EventUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/EventUtil.js
Apache-2.0
constructor() { /** * @type {!boolean} * @private */ this._historyActionsNotWorking = false; /** * @type {undefined|*} * @private */ this._currentMemorableStateObj = undefined; }
Manages interactions with the browser's history as the app's state changes and frequently updates the URL.
constructor
javascript
Strilanc/Quirk
src/browser/HistoryPusher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/HistoryPusher.js
Apache-2.0
currentStateIsMemorableButUnknown() { this._currentMemorableStateObj = {wont_equal_this: true}; }
Indicates that the current state should be preserved in the browser history if the user transitions away from it. Because the state isn't known, any transition will trigger the preservation (possibly creating a duplicate history entry).
currentStateIsMemorableButUnknown
javascript
Strilanc/Quirk
src/browser/HistoryPusher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/HistoryPusher.js
Apache-2.0
currentStateIsMemorableAndEqualTo(stateObj) { this._currentMemorableStateObj = stateObj; }
Indicates that the current state should be preserved in the browser history if the user transitions away from it. @param {*} stateObj An ===-able object representing the current state, for identifying spurious transitions.
currentStateIsMemorableAndEqualTo
javascript
Strilanc/Quirk
src/browser/HistoryPusher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/HistoryPusher.js
Apache-2.0
currentStateIsNotMemorable() { this._currentMemorableStateObj = undefined; }
Indicates that the current state should not be preserved in the browser history if the user transitions away. States are not-memorable by default.
currentStateIsNotMemorable
javascript
Strilanc/Quirk
src/browser/HistoryPusher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/HistoryPusher.js
Apache-2.0
stateChange(stateObj, stateUrlHash) { if (!stateUrlHash.startsWith('#')) { throw new DetailedError("Expected a hash URL.", {stateObj, stateUrlHash}); } if (this._currentMemorableStateObj === stateObj) { return; } if (this._historyActionsNotWorking) { ...
@param {*} stateObj An equatable (by ===) object representing the latest state. @param {!string} stateUrlHash A document.location.hash value that will lead to the latest state.
stateChange
javascript
Strilanc/Quirk
src/browser/HistoryPusher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/HistoryPusher.js
Apache-2.0
function eventPosRelativeTo(ev, element) { let b = element.getBoundingClientRect(); return new Point(ev.clientX - b.left, ev.clientY - b.top); }
@param {!MouseEvent|!Touch} ev @param {!HTMLElement} element @returns {!Point}
eventPosRelativeTo
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
function watchDrags(element, grabHandler, cancelHandler, dragHandler, dropHandler) { return new DragWatcher(element, grabHandler, cancelHandler, dragHandler, dropHandler) .addListenersUntilResultInvoked(); }
@param {!HTMLElement} element @param {!function(!Point, !MouseEvent|!TouchEvent) : void} grabHandler @param {!function(!MouseEvent|!TouchEvent) : void} cancelHandler @param {!function(undefined|!Point, !MouseEvent|!TouchEvent) : void} dragHandler @param {!function(undefined|!Point, !MouseEvent|!TouchEvent) : void} drop...
watchDrags
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
addListenerUntilResultInvoked = (target, type, listener) => { target.addEventListener(type, listener); return () => target.removeEventListener(type, listener); }
@param {!EventTarget} target @param {!string} type @param {!EventListener|!Function} listener @returns {!function() : void}
addListenerUntilResultInvoked
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
addListenerUntilResultInvoked = (target, type, listener) => { target.addEventListener(type, listener); return () => target.removeEventListener(type, listener); }
@param {!EventTarget} target @param {!string} type @param {!EventListener|!Function} listener @returns {!function() : void}
addListenerUntilResultInvoked
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
constructor(element, grabHandler, cancelHandler, dragHandler, dropHandler) { /** @type {!HTMLElement} */ this._element = element; /** @type {!function(!Point, !MouseEvent|!TouchEvent) : void} */ this._grabHandler = grabHandler; /** @type {!function(!MouseEvent|!TouchEvent) : void...
@param {!HTMLElement} element @param {!function(!Point, !MouseEvent|!TouchEvent) : void} grabHandler @param {!function(!MouseEvent|!TouchEvent) : void} cancelHandler @param {!function(undefined|!Point, !MouseEvent|!TouchEvent) : void} dragHandler @param {!function(undefined|!Point, !MouseEvent|!TouchEvent) : void} drop...
constructor
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
onDown(pt, id, ev) { if (!isLeftClicking(ev)) { return; } if (this._grabPointerId !== undefined) { if (!this.canRegrab()) { return; } this._dropHandler(this._lastPos, this._lastEv); } this._grabPointerId = id; ...
@param {!Point} pt @param {*} id @param {!MouseEvent|!TouchEvent} ev
onDown
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
onMove(pt, id, ev) { if (this._grabPointerId !== id) { return; } if (!isLeftClicking(ev)) { // Dropped on another window with browser out of focus. this._lastPos = undefined; this._lastEv = undefined; this._grabPointerId = undefined; ...
@param {!Point} pt @param {*} id @param {!MouseEvent|!TouchEvent} ev
onMove
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
onCancel(pt, id, ev) { if (this._grabPointerId !== id) { return; } this._lastPos = undefined; this._lastEv = undefined; this._grabPointerId = undefined; this._cancelHandler(ev); }
@param {!Point} pt @param {*} id @param {!MouseEvent|!TouchEvent} ev
onCancel
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
onUp(pt, id, ev) { if (!isLeftClicking(ev) || this._grabPointerId !== id) { return; } this._lastPos = undefined; this._lastEv = undefined; this._grabPointerId = undefined; this._dropHandler(pt, ev); }
@param {!Point} pt @param {*} id @param {!MouseEvent|!TouchEvent} ev
onUp
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
onLeave(pt, id, ev) { if (!isLeftClicking(ev) || this._grabPointerId !== id) { return; } this._grabActivityTime = window.performance.now(); this._lastPos = undefined; this._lastEv = ev; this._dragHandler(undefined, ev); }
@param {!Point} pt @param {*} id @param {!MouseEvent|!TouchEvent} ev
onLeave
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
onEnter(pt, id, ev) { if (isLeftClicking(ev) || this._grabPointerId !== id) { return; } this._lastPos = undefined; this._lastEv = undefined; this._grabPointerId = undefined; this._dropHandler(undefined, ev); }
@param {!Point} pt @param {*} id @param {!MouseEvent|!TouchEvent} ev
onEnter
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
relativeEventPos(ev) { return eventPosRelativeTo(ev, this._element); }
@param {!MouseEvent|!Touch} ev @returns {!Point}
relativeEventPos
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
handleTouchEventWith(ev, handler) { for (let i = 0; i < ev.changedTouches.length; i++) { let touch = ev.changedTouches[i]; handler.call(this, this.relativeEventPos(touch), touch.identifier, ev); } }
@param {!TouchEvent} ev @param {!function(!Point, *, !MouseEvent|!TouchEvent) : void} handler
handleTouchEventWith
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
handleMouseEventWith(ev, handler) { handler.call(this, this.relativeEventPos(ev), MOUSE_ID, ev); }
@param {!MouseEvent} ev @param {!function(!Point, *, !MouseEvent|!TouchEvent) : void} handler
handleMouseEventWith
javascript
Strilanc/Quirk
src/browser/MouseWatcher.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/MouseWatcher.js
Apache-2.0
function saveFile(name, content) { //noinspection JSUnresolvedVariable if (navigator.msSaveBlob) { //noinspection JSUnresolvedFunction navigator.msSaveBlob(new Blob([content], {type: 'text/html;charset=UTF-8'}), name); return; } let anchor = document.createElement("a"); //no...
@param {!string} name @param {!string} content
saveFile
javascript
Strilanc/Quirk
src/browser/SaveFile.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/SaveFile.js
Apache-2.0
setBlockers(desiredBlockers, overrideCursorStyle) { while (this._curBlockers.length < desiredBlockers.length) { let blockerDiv = document.createElement('div'); blockerDiv.style.touchAction = 'none'; blockerDiv.style.position = 'absolute'; blockerDiv.style.opacity ...
@param {!Array.<!{rect: !Rect, cursor: undefined|!string}>} desiredBlockers @param {undefined|!string} overrideCursorStyle
setBlockers
javascript
Strilanc/Quirk
src/browser/TouchScrollBlocker.js
https://github.com/Strilanc/Quirk/blob/master/src/browser/TouchScrollBlocker.js
Apache-2.0
function setGateBuilderEffectToCircuit(builder, circuitDefinition) { return builder. setActualEffectToUpdateFunc(ctx => advanceStateWithCircuit( ctx, circuitDefinition.withDisabledReasonsForEmbeddedContext(ctx.row, ctx.customContextFromGates), false)). setKnownEff...
@param {!GateBuilder} builder @param {!CircuitDefinition} circuitDefinition @returns {!GateBuilder}
setGateBuilderEffectToCircuit
javascript
Strilanc/Quirk
src/circuit/CircuitComputeUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitComputeUtil.js
Apache-2.0
function advanceStateWithCircuit(ctx, circuitDefinition, collectStats) { // Prep stats collection. let colQubitDensities = []; let customStats = []; let colNorms = []; let customStatsMap = []; let statsCallback = col => statArgs => { if (!collectStats) { return; } ...
@param {!CircuitEvalContext} ctx @param {!CircuitDefinition} circuitDefinition @param {!boolean} collectStats @returns {!{ colQubitDensities: !Array.<!WglTexture>, colNorms: !Array.<!WglTexture>, customStats: !Array.<*>, customStatsMap: !Array.<*> }}
advanceStateWithCircuit
javascript
Strilanc/Quirk
src/circuit/CircuitComputeUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitComputeUtil.js
Apache-2.0
statsCallback = col => statArgs => { if (!collectStats) { return; } let {qubitDensities, norm, customGateStats} = _extractStateStatsNeededByCircuitColumn( statArgs, circuitDefinition, col); colQubitDensities.push(qubitDensities); c...
@param {!CircuitEvalContext} ctx @param {!CircuitDefinition} circuitDefinition @param {!boolean} collectStats @returns {!{ colQubitDensities: !Array.<!WglTexture>, colNorms: !Array.<!WglTexture>, customStats: !Array.<*>, customStatsMap: !Array.<*> }}
statsCallback
javascript
Strilanc/Quirk
src/circuit/CircuitComputeUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitComputeUtil.js
Apache-2.0
statsCallback = col => statArgs => { if (!collectStats) { return; } let {qubitDensities, norm, customGateStats} = _extractStateStatsNeededByCircuitColumn( statArgs, circuitDefinition, col); colQubitDensities.push(qubitDensities); c...
@param {!CircuitEvalContext} ctx @param {!CircuitDefinition} circuitDefinition @param {!boolean} collectStats @returns {!{ colQubitDensities: !Array.<!WglTexture>, colNorms: !Array.<!WglTexture>, customStats: !Array.<*>, customStatsMap: !Array.<*> }}
statsCallback
javascript
Strilanc/Quirk
src/circuit/CircuitComputeUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitComputeUtil.js
Apache-2.0
function _extractStateStatsNeededByCircuitColumn( ctx, circuitDefinition, col) { // Compute custom stats used by display gates. let customGateStats = []; for (let row of circuitDefinition.customStatRowsInCol(col)) { let statCtx = new CircuitEvalContext( ctx.time, ...
@param {!CircuitEvalContext} ctx @param {!CircuitDefinition} circuitDefinition @param {!int} col @private @returns {!{ qubitDensities: !WglTexture, norm: !WglTexture, customGateStats: !Array.<!{row: !int, stat: !WglTexture}> }}
_extractStateStatsNeededByCircuitColumn
javascript
Strilanc/Quirk
src/circuit/CircuitComputeUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitComputeUtil.js
Apache-2.0
function _advanceStateWithCircuitDefinitionColumn( ctx, circuitDefinition, col, statsCallback) { let controls = ctx.controls.and(circuitDefinition.colControls(col).shift(ctx.row)); let controlTex = CircuitShaders.controlMask(controls).toBoolTexture(ctx.wireCount); let colCo...
Advances the state trader inside of the given CircuitEvalContext. @param {!CircuitEvalContext} ctx Evaluation arguments, including the row this column starts at (for when the circuit we're applying is actually a gate embedded inside an outer circuit). @param {!CircuitDefinition} circui...
_advanceStateWithCircuitDefinitionColumn
javascript
Strilanc/Quirk
src/circuit/CircuitComputeUtil.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitComputeUtil.js
Apache-2.0
constructor(numWires, columns, outerRowOffset=0, outerContext=new Map(), customGateSet=new CustomGateSet(), isNested=false, customInitialValues=new Map()) { if (numWires < 0) { throw new DetailedError("Ba...
@param {!int} numWires @param {!Array.<!GateColumn>} columns @param {undefined|!int=} outerRowOffset @param {undefined|!Map.<!string, *>=} outerContext @param {!CustomGateSet} customGateSet @param {!boolean} isNested @param {!Map.<!int, !string>} customInitialValues
constructor
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
withSwitchedInitialStateOn(wire, newStateIndex=undefined) { let m = new Map([...this.customInitialValues.entries()]); let v = m.get(wire); let cycle = [...INITIAL_STATES_TO_GATES.keys()]; let newVal = cycle[(cycle.indexOf(v) + 1) % cycle.length]; if (newStateIndex !== undefined) ...
@param {!int} wire @param {!int=} newStateIndex= @returns {!CircuitDefinition}
withSwitchedInitialStateOn
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
withInitialStates(map) { return new CircuitDefinition( this.numWires, this.columns, this.outerRowOffset, this.outerContext, this.customGateSet, this.isNested, map); }
@param {!Map.<!int, *>} map @returns {!CircuitDefinition}
withInitialStates
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
withDisabledReasonsForEmbeddedContext(outerRowOffset, outerContext) { return new CircuitDefinition( this.numWires, this.columns, outerRowOffset, outerContext, this.customGateSet, true, this.customInitialValues); }
@param {!int} outerRowOffset @param {!Map.<!string, *>} outerContext @returns {!CircuitDefinition}
withDisabledReasonsForEmbeddedContext
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
_computeGateSlotCoverMap() { let result = new Map(); for (let col = 0; col < this.columns.length; col++) { for (let row = 0; row < this.numWires; row++) { let gate = this.columns[col].gates[row]; if (gate !== undefined) { for (let i = 0; i ...
@returns {!Map.<!string, !{col: !int, row: !int, gate: !Gate}>} @private
_computeGateSlotCoverMap
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
static fromTextDiagram(gateMap, diagram) { let lines = seq(diagram.split('\n')).map(e => e.trim()).filter(e => e !== '').toArray(); if (seq(lines.map(e => e.length)).distinct().count() > 1) { throw new DetailedError("Uneven diagram", {diagram}); } let rowCount = lines.length...
This mainly exists for writing tests that are understandable. @param {!string} diagram @param {!Map.<!string, !Gate|!{ofSize: !function(!int) : !Gate}>} gateMap @returns {!CircuitDefinition}
fromTextDiagram
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
spanAt = (col, row) => { for (let d = 1; row + d < lines.length; d++) { if (gateMap.get(lines[row + d][col]) !== null) { return d; } } return lines.length - row; }
This mainly exists for writing tests that are understandable. @param {!string} diagram @param {!Map.<!string, !Gate|!{ofSize: !function(!int) : !Gate}>} gateMap @returns {!CircuitDefinition}
spanAt
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
spanAt = (col, row) => { for (let d = 1; row + d < lines.length; d++) { if (gateMap.get(lines[row + d][col]) !== null) { return d; } } return lines.length - row; }
This mainly exists for writing tests that are understandable. @param {!string} diagram @param {!Map.<!string, !Gate|!{ofSize: !function(!int) : !Gate}>} gateMap @returns {!CircuitDefinition}
spanAt
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
withColumns(cols) { return new CircuitDefinition( this.numWires, cols, this.outerRowOffset, this.outerContext, this.customGateSet, false, this.customInitialValues); }
@param {!Array.<!GateColumn>} cols @returns {!CircuitDefinition}
withColumns
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
_findWidthWiseOverlapInRect(col, row, width, height) { for (let i = 1; i < width && col + i < this.columns.length; i++) { for (let j = 0; j < height; j++) { let otherGate = this.findGateCoveringSlot(col+i, row+j); if (otherGate === undefined || otherGate.col === col) ...
@param {!int} col @param {!int} row @param {!int} width @param {!int} height @returns {undefined|!{col: !int, row: !int}} @private
_findWidthWiseOverlapInRect
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
_findHeightWiseOverlapsInCol(col) { let pushedGates = new Set(); let h = 0; for (let row = 0; row < this.numWires; row++) { h -= 1; let gate = this.gateInSlot(col, row); if (gate !== undefined) { if (h > 0) { pushedGates.add...
@param {!int} col @returns {!Set.<!int>} @private
_findHeightWiseOverlapsInCol
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
minimumRequiredWireCount() { let best = 1; for (let c of this.columns) { best = Math.max(best, c.minimumRequiredWireCount()); } for (let usedWire of this.customInitialValues.keys()) { best = Math.max(best, usedWire + 1); } return best; }
@returns {!int} The minimum number of wires needed to hold the gates in the circuit, accounting for their height and assuming the gate positions are fixed (i.e. wires can only be added or removed from the bottom).
minimumRequiredWireCount
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
minimumRequiredColCount() { let best = 0; for (let col = 0; col < this.columns.length; col++) { best = Math.max(best, this.columns[col].maximumGateWidth() + col); } return best; }
@returns {!int} The minimum number of columns needed to hold the gates in the circuit, accounting for their width and assuming the gate positions are fixed (i.e. columns can only be added or removed from the right).
minimumRequiredColCount
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
colCustomContextFromGates(col, outerRowOffset) { if (col < 0 || col >= this.columns.length) { return new Map(); } let key = "" + outerRowOffset; let result = this._cachedColumnContexts.get(key); if (result === undefined) { result = this._uncached_customCon...
@param {!int} col @param {!int} outerRowOffset @returns {!Map.<!string, *>}
colCustomContextFromGates
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
_uncached_customContextFromGates(outerRowOffset) { let results = []; let stickyCtx = new Map(); for (let col = 0; col < this.columns.length; col++) { let ctx = new Map(stickyCtx); let c = this.columns[col]; for (let row = 0; row < c.gates.length; row++) { ...
@param {!int} outerRowOffset @returns {!Array.<!Map.<!string, *>>}
_uncached_customContextFromGates
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
locClassifyMeasuredIncludingGateExtension(pt) { let row = pt.y; if (row < 0 || row >= this.numWires) { return false; } let gate = this.columns[pt.x].gates[row]; let h = gate === undefined ? 1 : gate.height; let r = (this.colIsMeasuredMask(pt.x) >> row) & ((1 <...
@param {!Point} pt @returns {undefined|boolean}
locClassifyMeasuredIncludingGateExtension
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
gateInSlot(col, row) { if (col < 0 || col >= this.columns.length || row < 0 || row >= this.numWires) { return undefined; } let gate = this.columns[col].gates[row]; return gate === undefined ? undefined : gate; }
A gate is only "in" the slot at its top left. It "covers" any other slots underneath it. @param {!int} col @param {!int} row @returns {undefined|!Gate}
gateInSlot
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
findGateCoveringSlot(col, row) { let key = col+":"+row; if (!this._gateSlotCoverMap.has(key)) { return undefined; } return this._gateSlotCoverMap.get(key); }
A slot is covered when a gate is in it or extends over it. @param {!int} col @param {!int} row @returns {undefined|!{col: !int, row: !int, gate: !Gate}}
findGateCoveringSlot
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
colGetEnabledSwapGate(col) { if (col < 0 || col >= this.columns.length) { return undefined; } let locs = []; for (let row = 0; row < this.numWires; row++) { if (this.gateInSlot(col, row) === Gates.Special.SwapHalf) { if (this.gateAtLocIsDisabledRea...
@param {int} col @returns {undefined|![!int, !int]}
colGetEnabledSwapGate
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
locProvidesStat(pt, key) { let g = this.gateInSlot(pt.x, pt.y); return g !== undefined && !g.customColumnContextProvider(0, g).every(e => e.key !== key); }
@param {!Point} pt @param {!string} key @returns {!boolean}
locProvidesStat
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
locNeedsStat(pt, key) { let g = this.gateInSlot(pt.x, pt.y); return g !== undefined && g.getUnmetContextKeys().has(key); }
@param {!Point} pt @param {!string} key @returns {!boolean}
locNeedsStat
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
gateAtLocIsDisabledReason(col, row) { if (col < 0 || row < 0 || col >= this._colRowDisabledReason.length || row >= this.numWires) { return undefined; } return this._colRowDisabledReason[col][row]; }
@param {!int} col @param {!int} row @returns {undefined|!string}
gateAtLocIsDisabledReason
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
applyMainOperationsInCol(colIndex, ctx) { if (colIndex < 0 || colIndex >= this.columns.length) { return; } this._applyOpsInCol(colIndex, ctx, gate => { if (gate.definitelyHasNoEffect() || gate === Gates.Special.SwapHalf) { return undefined; } ...
@param {!int} colIndex @param {!CircuitEvalContext} ctx @return {void}
applyMainOperationsInCol
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
applyBeforeOperationsInCol(colIndex, ctx) { this._applyOpsInCol(colIndex, ctx, g => g.customBeforeOperation); }
@param {!int} colIndex @param {!CircuitEvalContext} ctx @return {void}
applyBeforeOperationsInCol
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
applyAfterOperationsInCol(colIndex, ctx) { this._applyOpsInCol(colIndex, ctx, g => g.customAfterOperation); }
@param {!int} colIndex @param {!CircuitEvalContext} ctx @return {void}
applyAfterOperationsInCol
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
_applyOpsInCol(colIndex, ctx, opGetter) { if (colIndex < 0 || colIndex >= this.columns.length) { return; } let col = this.columns[colIndex]; for (let row = 0; row < this.numWires; row++) { let gate = col.gates[row]; if (gate === undefined || this.gate...
@param {!int} colIndex @param {!CircuitEvalContext} ctx @param {!function(!Gate) : !function(!CircuitEvalContext)} opGetter @private
_applyOpsInCol
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
customStatRowsInCol(colIndex) { if (colIndex < 0 || colIndex >= this.columns.length) { return []; } let col = this.columns[colIndex]; let result = []; for (let row = 0; row < col.gates.length; row++) { if (col.gates[row] !== undefined && ...
@param {!int} colIndex @returns {!Array.<!int>}
customStatRowsInCol
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
isSlotRectCoveredByGateInSameColumn(col, row, height) { for (let j = 0; j < height; j++) { let f = this.findGateCoveringSlot(col, row+j); if (f !== undefined && f.col === col) { return true; } } return false; }
@param {!int} col @param {!int} row @param {!int} height @returns {!boolean}
isSlotRectCoveredByGateInSameColumn
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
controlLinesRanges(columnIndex) { let col = this.columns[columnIndex]; let n = col.gates.length; let swapRows = this.colGetEnabledSwapGate(columnIndex); let pt = i => new Point(columnIndex, i); let hasControllable = i => this.locHasControllableGate(pt(i)); let hasCohere...
@param {!int} columnIndex @returns {!Array.<!{first: !int, last: !int, measured: !boolean}>}
controlLinesRanges
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
function srcDstMatchInRange(rangeLen, srcPredicate, dstPredicate, measured) { let [src1, src2] = firstLastMatchInRange(rangeLen, srcPredicate); let [dst1, dst2] = firstLastMatchInRange(rangeLen, dstPredicate); if (dst1 === undefined || src1 === undefined) { return undefined; } return { ...
@param {!int} rangeLen @param {!function(!int) : !boolean} srcPredicate @param {!function(!int) : !boolean} dstPredicate @param {!boolean} measured @returns {undefined|!{first:!int, last:!int, measured:!boolean}} @private
srcDstMatchInRange
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
function firstLastMatchInRange(rangeLen, predicate){ let first = undefined; let last = undefined; for (let i = 0; i < rangeLen; i++) { if (predicate(i)) { if (first === undefined) { first = i; } last = i; } } return [first, last]; }
@param {!int} rangeLen @param {!function(!int): !boolean} predicate @returns {!Array.<undefined|!int>}
firstLastMatchInRange
javascript
Strilanc/Quirk
src/circuit/CircuitDefinition.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitDefinition.js
Apache-2.0
constructor(time, qubitRow, wireCount, controls, controlsTexture, rawControls, stateTrader, customContextFromGates) { /** @type {!number} */ this.time = time; /** * The top-le...
@param {!number} time @param {undefined|!int} qubitRow @param {!int} wireCount @param {!Controls} controls @param {!WglTexture} controlsTexture @param {!Controls} rawControls The controls of the gate column, made available so that before/after operations can use this information (even though they are not themselves...
constructor
javascript
Strilanc/Quirk
src/circuit/CircuitEvalContext.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitEvalContext.js
Apache-2.0
applyOperation(operation) { let configuredShader = operation instanceof WglConfiguredShader ? operation : operation(this); this.stateTrader.shadeAndTrade(configuredShader); }
@param {!WglConfiguredShader|!function(!CircuitEvalContext) : !WglConfiguredShader} operation @return {void}
applyOperation
javascript
Strilanc/Quirk
src/circuit/CircuitEvalContext.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitEvalContext.js
Apache-2.0
withInputSetToRange(letter, offset, length) { let r = this._clone(); r.customContextFromGates = new Map(r.customContextFromGates); r.customContextFromGates.set(`Input Range ${letter}`, {offset, length}); return r; }
@param {!string} letter @param {!int} offset @param {!int} length @returns {!CircuitEvalContext}
withInputSetToRange
javascript
Strilanc/Quirk
src/circuit/CircuitEvalContext.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitEvalContext.js
Apache-2.0
withInputSetToConstant(letter, value) { let r = this._clone(); r.customContextFromGates = new Map(r.customContextFromGates); r.customContextFromGates.delete(`Input Range ${letter}`); r.customContextFromGates.set(`Input Default ${letter}`, value); return r; }
@param {!string} letter @param {!int} value @returns {!CircuitEvalContext}
withInputSetToConstant
javascript
Strilanc/Quirk
src/circuit/CircuitEvalContext.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitEvalContext.js
Apache-2.0
withInputSetToOtherInput(letter, other) { let r = this._clone(); r.customContextFromGates = new Map(r.customContextFromGates); for (let key of ['Range', 'Default']) { let otherVal = r.customContextFromGates.get(`Input ${key} ${other}`); if (otherVal !== undefined) { ...
@param {!string} letter @param {!string} other @returns {!CircuitEvalContext}
withInputSetToOtherInput
javascript
Strilanc/Quirk
src/circuit/CircuitEvalContext.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitEvalContext.js
Apache-2.0
constructor(circuitDefinition, time, survivalRates, singleQubitDensities, finalState, customStatsProcessed) { /** * The circuit that these stats apply to. * @type {!CircuitDefinition} */ this.circu...
@param {!CircuitDefinition} circuitDefinition @param {!number} time @param {!Array.<!number>} survivalRates @param {!Array.<!Array.<!Matrix>>} singleQubitDensities @param {!Matrix} finalState @param {!Map<!string, *>} customStatsProcessed
constructor
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
qubitDensityMatrix(colIndex, wireIndex) { if (wireIndex < 0) { throw new DetailedError("Bad wireIndex", {wireIndex, colIndex}); } // The initial state is all-qubits-off. if (colIndex < 0 || wireIndex >= this.circuitDefinition.numWires) { if (wireIndex >= this.cir...
Returns the density matrix of a qubit at a particular point in the circuit. Note: only available if there was a corresponding display gate at that position. Otherwise result is NaN. @param {!int} colIndex @param {!int} wireIndex @returns {!Matrix}
qubitDensityMatrix
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
toReadableJson(includeOutputAmplitudes=true) { let result = { time_parameter: this.time, circuit: Serializer.toJson(this.circuitDefinition), chance_of_surviving_to_each_column: this._survivalRates, computed_bloch_vectors_by_column_then_wire: this._qubitDensities.m...
Converts the circuit stats into an exportable JSON object. @param {!boolean} includeOutputAmplitudes @returns {!object}
toReadableJson
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
_customStatsToReadableJson() { let result = []; for (let [key, data] of this._customStatsProcessed.entries()) { let [col, row] = key.split(':'); row = parseInt(row); col = parseInt(col); let gate = this.circuitDefinition.columns[col].gates[row]; ...
Converts the circuit stats into an exportable JSON object. @param {!boolean} includeOutputAmplitudes @returns {!object}
_customStatsToReadableJson
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
survivalRate(colIndex) { colIndex = Math.min(colIndex, this._survivalRates.length - 1); return colIndex < 0 ? 1 : this._survivalRates[colIndex]; }
Determines how often the circuit evaluation survives to the given column, without being post-selected out. Note that over-unitary gates will increase this number, so perhaps 'survival rate' isn't quite the best name. @param {!int} colIndex @returns {!number}
survivalRate
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0
customStatsForSlot(col, row) { let key = col+":"+row; return this._customStatsProcessed.has(key) ? this._customStatsProcessed.get(key) : undefined; }
@param {!int} col @param {!int} row @returns {undefined|*}
customStatsForSlot
javascript
Strilanc/Quirk
src/circuit/CircuitStats.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/CircuitStats.js
Apache-2.0