Skip to content

Commit

Permalink
Add option to omit amplitudes from simulator export output
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc committed Mar 24, 2019
1 parent 32efb93 commit f2e4e8b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
6 changes: 4 additions & 2 deletions html/export.partial.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
<br>
<strong>Simulation Data JSON</strong> - Output amplitudes, detector results, display data, etc.
<div style="margin: 10px 0 0 20px;">
<button tabindex="103" id="export-amplitudes-button">Generate and Copy to Clipboard</button>&nbsp;<span id="export-amplitudes-result"></span>
<button tabindex="105" id="export-amplitudes-button">Generate and Copy to Clipboard</button>&nbsp;<span id="export-amplitudes-result"></span>
<input type="checkbox" tabindex="106" id="export-amplitudes-use-amps" style="float: right; margin-right: 10px;">
<label style="float: right" for="export-amplitudes-use-amps">Skip output amplitudes</label>
<br>
<pre tabindex="105" id="export-amplitudes-pre" style="overflow:auto; max-width:600px; max-height:60px; border: 1px solid black; padding:5px; margin:2px;"></pre>
<pre tabindex="107" id="export-amplitudes-pre" style="overflow:auto; max-width:600px; max-height:60px; border: 1px solid black; padding:5px; margin:2px;"></pre>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion html/forge.partial.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<td></td>
<td>
<style scoped>
input[type="checkbox"]:not(:checked) + label {
input[id="gate-forge-matrix-fix"]:not(:checked) + label {
font-weight: bold;
background-color: pink;
}
Expand Down
10 changes: 7 additions & 3 deletions src/circuit/CircuitStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ class CircuitStats {

/**
* Converts the circuit stats into an exportable JSON object.
* @param {!boolean} includeOutputAmplitudes
* @returns {!object}
*/
toReadableJson() {
return {
output_amplitudes: complexVectorToReadableJson(this.finalState.getColumn(0)),
toReadableJson(includeOutputAmplitudes=true) {
let result = {
time_parameter: this.time,
circuit: Serializer.toJson(this.circuitDefinition),
chance_of_surviving_to_each_column: this._survivalRates,
Expand All @@ -123,6 +123,10 @@ class CircuitStats {
),
displays: this._customStatsToReadableJson()
};
if (includeOutputAmplitudes) {
result['output_amplitudes'] = complexVectorToReadableJson(this.finalState.getColumn(0));
}
return result;
}

_customStatsToReadableJson() {
Expand Down
7 changes: 5 additions & 2 deletions src/ui/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,15 @@ function initExports(revision, mostRecentStats, obsIsAnyOverlayShowing) {
const outputTextElement = /** @type {HTMLPreElement} */ document.getElementById('export-amplitudes-pre');
const copyButton = /** @type {HTMLButtonElement} */ document.getElementById('export-amplitudes-button');
const copyResultElement = /** @type {HTMLElement} */ document.getElementById('export-amplitudes-result');
obsIsAnyOverlayShowing.subscribe(_ => { outputTextElement.innerText = '[not generated yet]'; });
const excludeAmps = /** @type {HTMLInputElement} */ document.getElementById('export-amplitudes-use-amps');
obsIsAnyOverlayShowing.subscribe(_ => {
outputTextElement.innerText = '[not generated yet]';
});
setupButtonElementCopyToClipboard(
copyButton,
outputTextElement,
copyResultElement,
() => JSON.stringify(mostRecentStats.get().toReadableJson(), null, ' '));
() => JSON.stringify(mostRecentStats.get().toReadableJson(!excludeAmps.checked), null, ' '));
})();

// Export offline copy.
Expand Down

0 comments on commit f2e4e8b

Please sign in to comment.