-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3D circuit visualization using Typescript dev environment #4334
Merged
+1,905
−32
Merged
Changes from all commits
Commits
Show all changes
224 commits
Select commit
Hold shift + click to select a range
4648e65
add node_modules to .gitignore, add three.js to package-lock
seunomonije 621b729
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije 8832853
initial refactoring
seunomonije 5516b55
move package-lock into the web subdirectory
seunomonije 7a2aacd
readme, slight refactor
seunomonije bbf8af2
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije 490a8b2
add live-server
seunomonije a08a196
added more to readme file
seunomonije b3a3a7e
prettier
seunomonije 2c66c8a
small changes to readme
seunomonije bb015e0
typescript
seunomonije eb1a435
small change to readme
seunomonije 724a9da
hacking endpoint from friday
seunomonije 86199a6
refactor/progress dump
seunomonije 1f52ac8
post gts lint. The extra interface files might not stay.
seunomonije 391258d
rename to cirq-web
seunomonije 2650381
refactor and additional files
seunomonije 064de3f
refactor again
seunomonije be5564c
updated setup
seunomonije 6d8b533
init file
seunomonije eddb58f
refactor, split cirq-web into its own package
seunomonije 8015fac
update versions to match
seunomonije 1557b52
add cirq-web autopkg to script
seunomonije ee9f890
moved python init
seunomonije 09127f8
small test changes cuz colab is being difficult
seunomonije df2e359
new bundle to upload
seunomonije 03e8bd0
lowercase cirq
seunomonije f574154
fix dev browser environment
seunomonije c24ffe3
pre presentation
seunomonije e78d85d
post presentation state
seunomonije 21343fb
very very very rough bloch sphere
seunomonije 37f1218
rough vector support end to end
seunomonije 6351f77
updated with working HTML hot reloading and example bloch_sphere in j…
seunomonije 29ec82f
progress dump
seunomonije cf9b435
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije 807b4ff
refactored Bloch Sphere organization
seunomonije 731d194
new directory structure, standalone HTML files, Python integration, n…
seunomonije 5ab03c5
small changes for webpack continuity and organization
seunomonije 51ea689
added comments to ts components
seunomonije c7cf8c9
rename cirq_python to cirq_web
seunomonije ab8febe
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije b33eb1e
added first test
seunomonije 3fedccd
added preliminary testing to cirq_web
seunomonije b4ecff1
recommit
seunomonije 12bc26b
testing covg, updated readmes, documentation, other
seunomonije e6723da
todo readme
seunomonije 416b126
move gitignore
seunomonije c07c561
fix gitignore
seunomonije 57df8aa
cleanup
seunomonije fce0580
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije f2eec63
remove bloch sphere
seunomonije 918f77e
remove files.js
seunomonije bd5d1b4
add dist for path issues, may need to refactor to keep out later
seunomonije 39ab966
adding support for cirq-web dependencies in the pytest-minimal test
seunomonije 44d62b6
quick fix to pytest-minimal
seunomonije 10bd505
explicit utf-8 encoding for windows systems
seunomonije 08e48a5
quick addition
seunomonije 8300306
add final explicit encoding
seunomonije 83297ef
deciding to use mocha for testing
seunomonije 802f9d2
testing framework setup with simple test run
seunomonije c431503
Update cirq-web/cirq_web/bloch_sphere/cirq_bloch_sphere.py
seunomonije 0107a58
Update cirq-web/cirq_ts/_version.py
seunomonije bbc844e
Update cirq-web/cirq_ts/src/bloch_sphere/components/Axes.class.d.ts
seunomonije 0ccdb90
Update cirq-web/cirq_ts/src/bloch_sphere/components/Axes.class.ts
seunomonije 6f5597f
Update cirq-web/cirq_ts/src/bloch_sphere/components/Meridians.class.ts
seunomonije cd1c7a0
Update cirq-web/cirq_web/bloch_sphere/cirq_bloch_sphere.py
seunomonije b3d297d
Update cirq-web/setup.py
seunomonije af02537
Update cirq-web/cirq_ts/src/bloch_sphere/components/Meridians.class.ts
seunomonije b2045e9
Update cirq-web/cirq_ts/src/bloch_sphere/components/Meridians.class.ts
seunomonije efcdac1
Update cirq-web/cirq_ts/src/bloch_sphere/components/Meridians.class.ts
seunomonije d489643
Update cirq-web/cirq_ts/src/bloch_sphere/components/Vector.class.ts
seunomonije a758965
small changes
seunomonije 2f0c502
Merge branch 'master' of https://github.com/seunomonije/Cirq
seunomonije a343878
small fixes commit
seunomonije bc4d3de
first round of comment resolutions, added tiny visualization testing …
seunomonije 227b56f
cirq_ts readme PR comment fixes
seunomonije 0a46d3f
PR comment fixes BlochSphere.ts
seunomonije bc97a60
PR comment fixes meridians
seunomonije 576031b
PR comment fixes scene
seunomonije 54b2e1b
PR comment fixes vector and test
seunomonije 28467fb
double check fixes from PR comments
seunomonije 0a5f6bc
rename files, work on text.ts
seunomonije 845a944
temp change of bs symbols, quick/dirty but working e2e image check te…
seunomonije 2c80848
ran the linter, fixed .eslintrc.json so that it reports no errors
seunomonije 7657584
add preliminary CI
seunomonije 70887eb
CI for unit testing
seunomonije b80007b
fix rename for ts-test
seunomonije 8ad3ef4
rename library to CirqTS
seunomonije 2527c57
can configure div id of the bloch sphere
seunomonije 7bce91e
add vector type
seunomonije 250ea94
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije 3a6acd6
update bundle and jupyter notebook
seunomonije 6aabc66
small refactor of python, added more to README
seunomonije 71ff76d
pylint
seunomonije a803e11
removed IPython as a requirement
seunomonije 3c3bafc
added TS testing frameworks, rough TS viz and unit testing, small rea…
seunomonije f6e48bb
restart ci
seunomonije a49fcbc
test ci
seunomonije 3451a3a
add back coverage testing
seunomonije 20b314c
fixed merge conflicts
seunomonije d3fdd5a
make check/ts-coverage an executable
seunomonije 4bb2242
rough text changes, fix ipython fails on CI
seunomonije b512c9f
move _version.py to the correct spot
seunomonije 8769ffc
quick updates
seunomonije b8d5926
fix space in file
seunomonije e7ba83f
updated ts testing framework, fixed labels
seunomonije cbb6930
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije 278c911
linting and merge w upstream
seunomonije 3b5a513
add copyrights, small PR comment changes
seunomonije bdc7955
fix naming of divId
seunomonije 16ec03a
ts e2e testing writes to temp file
seunomonije 9bdbc47
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije 3e1054d
exclude utility functions from testing
seunomonije 599a8bd
updated testing portion of ts README
seunomonije 8820d39
updated README, example notebook, fixed bloch sphere vector point, sm…
seunomonije b41057c
linting and cleanup changes
seunomonije 4d6bffc
deleting bloch sphere due to ci issues
seunomonije 2914c0d
redo expected png
seunomonije b259678
add utf-8 encoding to test
seunomonije 4b0da2d
second attempt to fix image diff issue
seunomonije e48596f
fix test to account for unicode diff threshold
seunomonije 2fe2377
update cirq-web readme
seunomonije 625659e
add utf-8 charset for readme
seunomonije d2e37ea
add cirq_ts to setup.py
seunomonije 9f403bf
change setup.py for new packaging structure
seunomonije e314d19
add ts distribution files to the python package
seunomonije 045fbc3
more clarity to package searching
seunomonije 1976d8c
add .js extension
seunomonije 3a6e0a6
add manifest file to help get the bundles
seunomonije cc23aee
change to setup.py
seunomonije 6a619dd
reset setup.py
seunomonije 44a9521
include package data tag for manifest to work
seunomonije eb0d7a4
testing removal of cirq_ts from packagin, we don't need it to have an…
seunomonije bae0b7c
adding cirq_ts back, we need it
seunomonije ede563f
formatting fix
seunomonije 12fdbc7
remove packaging from readme
seunomonije 22ed261
Merge branch 'master' into master
seunomonije c187c49
typescript PR fixes
seunomonije 6e2e549
pr fixes for python
seunomonije 969d236
change fixes
seunomonije 618ff01
missed fixes
seunomonije 7f9536e
progress on new testing
seunomonije 5469659
another refactor of the testing framework
seunomonije 7ff32f7
update meridians test
seunomonije 27ed7cb
major typescript code and testing refactor, implemented PR comments
seunomonije b30dd9b
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije d59d56a
lint fixes
seunomonije 8998701
PR comment resolutions, additional misc cleanup and fixes
seunomonije da0c436
Merge branch 'master' into master
seunomonije e041212
add IPython back for CI
seunomonije 4deb927
pr comment fixes and bug fixes
seunomonije 95e6fa1
added uuids to bloch spheres, cleaned up example notebook
seunomonije 72ee0e8
update testing statements, general pr fixes
seunomonije d32510c
fix axes
seunomonije 936ca9a
initial circuits structure
seunomonije 16ae383
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije 553dde8
removed json middleman, added more check scripts, general cleanup
seunomonije 59511c6
removed MANIFEST.in and included bundle in package_data
seunomonije 60cc765
changes to pass CI, delete determine_env from widget (YAGNI)
seunomonije 9eb7f29
fix changes after quick scroll through
seunomonije 629519e
Merge branch 'master' of https://github.com/seunomonije/Cirq into 3d-…
seunomonije 07c6c50
PR comment resolutions, adding CI for end to end tests, other refacto…
seunomonije 1ab1b76
pr resolutions
seunomonije b1bd2d7
stashing
seunomonije f56bdd3
pr changes
seunomonije 28187c7
revert .gitignore
seunomonije 44bb800
rename MockWidget to FakeWidget and format widget.py
seunomonije 9026f65
Merge branch 'master' into master
balopat 2f2282f
stashing changes
seunomonije a5a9cd9
Merge branch 'master' of https://github.com/seunomonije/Cirq into 3d-…
seunomonije 4b8e08e
progress dump
seunomonije 675b725
fix merge conflicts
seunomonije f290bc6
updated cirq-web README
seunomonije d8f698a
progress dump
seunomonije 4568181
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije 818d6c2
resolve PR comments
seunomonije b7f89cc
start of cleanup
seunomonije 3c1ae4e
ugly push before computer restart
seunomonije dd2eb3e
added copyright, very scarce testing
seunomonije bf83842
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije 3044f5b
Merge branch 'master' of https://github.com/seunomonije/Cirq into 3d-…
seunomonije 84f640e
added a small amount of testing
seunomonije 915b8dc
remove example notebook trash
seunomonije 1802686
add docstrings
seunomonije 326ca2b
little cleanup of docstrings
seunomonije a14fa33
check fixes
seunomonije 975ac29
last config
seunomonije f93c1e7
initial PR changes
seunomonije 9428578
refactor progress dump
seunomonije 9f7c0d2
rough push before review
seunomonije b30d6e1
changes
seunomonije ec57933
stashing
seunomonije 7b77cad
fix camera
seunomonije fa3e149
notebook stash
seunomonije ddbdfab
dirty push, but allows configuration of blocks via Python, and center…
seunomonije d0bec90
small cleanup of ts
seunomonije ffe157e
added initial typescript testing, ran some linting on both python and…
seunomonije c0af8e1
quick fix on error message change in test
seunomonije 2113f9b
ugly dev index structure
seunomonije 6eece7f
change in test structure
seunomonije e10e956
full python coverage with simple tests
seunomonije 492690d
lint
seunomonije 6a4c9fc
cut notebook output
seunomonije 2a78fc6
added the padding_factor
seunomonije 7fcf3a1
fix testing and jupyter notebook links
seunomonije 474e9d9
added python comments
seunomonije 63ba8f0
add test for GridQubit public method
seunomonije 7b1ac75
CI cleanup
seunomonije a196db4
cleanup
seunomonije 89104e3
add X mesh in the middle of the X gate
seunomonije d443365
Merge branch 'master' into 3d-circuits
seunomonije dfe8eb0
more cleanup, and added e2e tests
seunomonije cfefaa4
fix documentation error
seunomonije e7c0cf2
fix lint in e2e test
seunomonije 10d9f37
90% through changes
seunomonije fb80334
refactor code to build GridCircuit objects from gates
seunomonije 49e6025
rename circuit to qubit_map
seunomonije bb0c24f
Merge branch 'master' of https://github.com/quantumlib/Cirq into 3d-c…
seunomonije 90ab7ba
apply padding_factor to the time direction
seunomonije 137fca7
convert map type
seunomonije 188d8f9
Merge branch 'master' of https://github.com/quantumlib/Cirq into 3d-c…
seunomonije 4158e80
updated circuit bundle
seunomonije 690b268
add test for coverage
seunomonije 8ccfac3
Merge branch 'master' of https://github.com/quantumlib/Cirq into 3d-c…
seunomonije File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "737bce11", | ||
"metadata": {}, | ||
"source": [ | ||
"#### Copyright 2021 The Cirq Developers" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "6db8c987", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n", | ||
"# you may not use this file except in compliance with the License.\n", | ||
"# You may obtain a copy of the License at\n", | ||
"#\n", | ||
"# https://www.apache.org/licenses/LICENSE-2.0\n", | ||
"#\n", | ||
"# Unless required by applicable law or agreed to in writing, software\n", | ||
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n", | ||
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", | ||
"# See the License for the specific language governing permissions and\n", | ||
"# limitations under the License." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "88f3b242", | ||
"metadata": {}, | ||
"source": [ | ||
"### Cirq-web 3D circuit visualization" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "9f4089af", | ||
"metadata": {}, | ||
"source": [ | ||
"\n", | ||
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n", | ||
" <td>\n", | ||
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/quantumlib/Cirq/blob/master/master/cirq-web/circuit-example.ipynb\"><img src=\"https://quantumai.google/site-assets/images/buttons/colab_logo_1x.png\" />Run in Google Colab</a>\n", | ||
" </td>\n", | ||
" <td>\n", | ||
" <a target=\"_blank\" href=\"https://github.com/quantumlib/Cirq/blob/master/cirq-web/circuit-example.ipynb\"><img src=\"https://quantumai.google/site-assets/images/buttons/github_logo_1x.png\" />View source on GitHub</a>\n", | ||
" </td>\n", | ||
"</table>" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "99172e40", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!pip install --quiet cirq --pre" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "ebc22e4d", | ||
"metadata": {}, | ||
"source": [ | ||
"Note: this notebook relies on unreleased Cirq features. If you want to try these features, make sure you install cirq via `pip install cirq --pre`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "e4bd9946", | ||
"metadata": { | ||
"scrolled": true | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"!pip install cirq-web" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "fe0d0e69", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import cirq\n", | ||
"qubits = [cirq.GridQubit(x, y) for x in range(10) for y in range(10)]\n", | ||
"\n", | ||
"import cirq.testing\n", | ||
"from cirq.protocols import circuit_diagram_info\n", | ||
"circuit = cirq.testing.random_circuit(cirq.GridQubit.square(10), n_moments=5, op_density=.7)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "81689b3f", | ||
"metadata": { | ||
"scrolled": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"\"\"\"\n", | ||
"This cell builds a 3D circuit diagram using a big list of operations provided TS Circuit class.\n", | ||
"\"\"\"\n", | ||
"import cirq_web\n", | ||
"from typing import Optional\n", | ||
"from cirq_web.circuits.symbols import SymbolInfo\n", | ||
"\n", | ||
"class FunkyHadamard(cirq_web.circuits.symbols.SymbolResolver):\n", | ||
" def resolve(self, operation: cirq.Operation) -> Optional[SymbolInfo]:\n", | ||
" if isinstance(operation.gate, cirq.HPowGate):\n", | ||
" return SymbolInfo(['Hello!'], ['yellow'])\n", | ||
" else:\n", | ||
" return None\n", | ||
" \n", | ||
"resolvers = list(cirq_web.circuits.symbols.DEFAULT_SYMBOL_RESOLVERS) + [\n", | ||
" FunkyHadamard()\n", | ||
"]\n", | ||
"\n", | ||
"from cirq_web import Circuit3D\n", | ||
"c3d = Circuit3D(circuit, resolvers, 2.5)\n", | ||
"display(c3d)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "139acc3d", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.7.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* @license | ||
* Copyright 2010-2021 Three.js Authors | ||
* SPDX-License-Identifier: MIT | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<title>Cirq Web Development page</title> | ||
</head> | ||
<body> | ||
<div id="container"></div> | ||
<script src="/bloch_sphere.bundle.js"></script> | ||
<script> | ||
renderBlochSphere('container', 5) | ||
.addVector(1, 0, 0); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<html lang="en"> | ||
<head> | ||
<title>Cirq Web Development Page -- 3D circuits</title> | ||
</head> | ||
<body> | ||
<button id="camera-reset">Reset Camera</button> | ||
<button id="camera-toggle">Toggle Camera Type</button> | ||
<div id="mycircuitdiv"></div> | ||
<script src="/circuit.bundle.js"></script> | ||
<script> | ||
const circuit = createGridCircuit( | ||
[ | ||
{'wire_symbols': ['Z'], 'location_info': [{'row': 2, 'col': 3}], 'color_info': ['cyan'], 'moment': 0}, | ||
{'wire_symbols': ['X'], 'location_info': [{'row': 2, 'col': 3}], 'color_info': ['black'], 'moment': 1}, | ||
{'wire_symbols': ['@', 'X'], 'location_info': [{'row': 3, 'col': 0}, {'row': 0, 'col': 0}], 'color_info': ['black', 'black'], 'moment': 0}, | ||
], 5, 'mycircuitdiv', 1); | ||
|
||
// Event listener for reset press | ||
document.getElementById("camera-reset").addEventListener('click', () => { | ||
circuit.scene.setCameraAndControls(circuit.circuit); | ||
}); | ||
|
||
// Event listener for camera change | ||
document.getElementById("camera-toggle").addEventListener('click', () => { | ||
circuit.scene.toggleCamera(circuit.circuit); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright 2021 The Cirq Developers | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import puppeteer from 'puppeteer'; | ||
import {expect} from 'chai'; | ||
import {readFileSync} from 'fs'; | ||
import pixelmatch from 'pixelmatch'; | ||
import * as PNG from 'pngjs'; | ||
import * as temp from 'temp'; | ||
import * as path from 'path'; | ||
|
||
/** | ||
* Generates an HTML script with the current repository bundle | ||
* that we will use to compare. | ||
*/ | ||
|
||
// Due to the path, reading the file will only work by running this file in the same directory | ||
// as the package.json file. | ||
const bundleString = readFileSync('dist/circuit.bundle.js'); | ||
function htmlContent(clientCode: string) { | ||
return ` | ||
<!doctype html> | ||
<meta charset="UTF-8"> | ||
<html lang="en"> | ||
<head> | ||
<title>Cirq Web Development page</title> | ||
</head> | ||
<body> | ||
<div id="mycircuitdiv"></div> | ||
<script>${bundleString}</script> | ||
<script>${clientCode}</script> | ||
</body> | ||
</html> | ||
`; | ||
} | ||
|
||
// Automatically track and cleanup files on exit | ||
temp.track(); | ||
|
||
describe('Circuit', () => { | ||
temp.mkdir('tmp', (err, dirPath) => { | ||
const outputPath = path.join(dirPath, 'circuit.png'); | ||
|
||
before(async () => { | ||
const browser = await puppeteer.launch({args: ['--app']}); | ||
const page = await browser.newPage(); | ||
|
||
// Take a screenshot of the first image | ||
await page.setContent( | ||
htmlContent(` | ||
const circuit = createGridCircuit( | ||
[ | ||
{ | ||
'wire_symbols': ['Z'], | ||
'location_info': [{'row': 2, 'col': 3}], | ||
'color_info': ['cyan'], | ||
'moment': 0 | ||
}, | ||
{ | ||
'wire_symbols': ['X'], | ||
'location_info': [{'row': 2, 'col': 3}], | ||
'color_info': ['black'], | ||
'moment': 1 | ||
}, | ||
{ | ||
'wire_symbols': ['@', 'X'], | ||
'location_info': [{'row': 3, 'col': 0}, {'row': 0, 'col': 0}], | ||
'color_info': ['black', 'black'], | ||
'moment': 0 | ||
}, | ||
], 5, 'mycircuitdiv' | ||
); | ||
`) | ||
); | ||
await page.screenshot({path: outputPath}); | ||
await browser.close(); | ||
}); | ||
|
||
it('with limited gates matches the gold copy', () => { | ||
const expected = PNG.PNG.sync.read( | ||
readFileSync('e2e/circuit/circuit_expected.png') | ||
); | ||
const actual = PNG.PNG.sync.read(readFileSync(outputPath)); | ||
const {width, height} = expected; | ||
const diff = new PNG.PNG({width, height}); | ||
|
||
const pixels = pixelmatch( | ||
expected.data, | ||
actual.data, | ||
diff.data, | ||
width, | ||
height, | ||
{threshold: 0.1} | ||
); | ||
|
||
expect(pixels).to.equal(0); | ||
}); | ||
}); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These links are still useful even in Github view. Let's remove the open on Quantum AI button. Also the download can point to the Github raw URL. Also we should point to this ipynb file not the circuits ipynb (copy pasta! 🍝 )