Skip to content
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
merged 224 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from 214 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 May 11, 2021
621b729
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije May 11, 2021
8832853
initial refactoring
seunomonije May 12, 2021
5516b55
move package-lock into the web subdirectory
seunomonije May 12, 2021
7a2aacd
readme, slight refactor
seunomonije May 14, 2021
bbf8af2
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije May 14, 2021
490a8b2
add live-server
seunomonije May 14, 2021
a08a196
added more to readme file
seunomonije May 14, 2021
b3a3a7e
prettier
seunomonije May 14, 2021
2c66c8a
small changes to readme
seunomonije May 14, 2021
bb015e0
typescript
seunomonije May 14, 2021
eb1a435
small change to readme
seunomonije May 14, 2021
724a9da
hacking endpoint from friday
seunomonije May 17, 2021
86199a6
refactor/progress dump
seunomonije May 19, 2021
1f52ac8
post gts lint. The extra interface files might not stay.
seunomonije May 19, 2021
391258d
rename to cirq-web
seunomonije May 21, 2021
2650381
refactor and additional files
seunomonije May 21, 2021
064de3f
refactor again
seunomonije May 21, 2021
be5564c
updated setup
seunomonije May 21, 2021
6d8b533
init file
seunomonije May 21, 2021
eddb58f
refactor, split cirq-web into its own package
seunomonije May 21, 2021
8015fac
update versions to match
seunomonije May 21, 2021
1557b52
add cirq-web autopkg to script
seunomonije May 21, 2021
ee9f890
moved python init
seunomonije May 21, 2021
09127f8
small test changes cuz colab is being difficult
seunomonije May 21, 2021
df2e359
new bundle to upload
seunomonije May 21, 2021
03e8bd0
lowercase cirq
seunomonije May 21, 2021
f574154
fix dev browser environment
seunomonije May 21, 2021
c24ffe3
pre presentation
seunomonije May 26, 2021
e78d85d
post presentation state
seunomonije May 26, 2021
21343fb
very very very rough bloch sphere
seunomonije May 27, 2021
37f1218
rough vector support end to end
seunomonije May 27, 2021
6351f77
updated with working HTML hot reloading and example bloch_sphere in j…
seunomonije May 27, 2021
29ec82f
progress dump
seunomonije Jun 3, 2021
cf9b435
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije Jun 3, 2021
807b4ff
refactored Bloch Sphere organization
seunomonije Jun 3, 2021
731d194
new directory structure, standalone HTML files, Python integration, n…
seunomonije Jun 4, 2021
5ab03c5
small changes for webpack continuity and organization
seunomonije Jun 4, 2021
51ea689
added comments to ts components
seunomonije Jun 4, 2021
c7cf8c9
rename cirq_python to cirq_web
seunomonije Jun 4, 2021
ab8febe
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije Jun 4, 2021
b33eb1e
added first test
seunomonije Jun 4, 2021
3fedccd
added preliminary testing to cirq_web
seunomonije Jun 4, 2021
b4ecff1
recommit
seunomonije Jun 4, 2021
12bc26b
testing covg, updated readmes, documentation, other
seunomonije Jun 7, 2021
e6723da
todo readme
seunomonije Jun 8, 2021
416b126
move gitignore
seunomonije Jun 8, 2021
c07c561
fix gitignore
seunomonije Jun 8, 2021
57df8aa
cleanup
seunomonije Jun 8, 2021
fce0580
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije Jun 8, 2021
f2eec63
remove bloch sphere
seunomonije Jun 8, 2021
918f77e
remove files.js
seunomonije Jun 8, 2021
bd5d1b4
add dist for path issues, may need to refactor to keep out later
seunomonije Jun 8, 2021
39ab966
adding support for cirq-web dependencies in the pytest-minimal test
seunomonije Jun 8, 2021
44d62b6
quick fix to pytest-minimal
seunomonije Jun 8, 2021
10bd505
explicit utf-8 encoding for windows systems
seunomonije Jun 8, 2021
08e48a5
quick addition
seunomonije Jun 8, 2021
8300306
add final explicit encoding
seunomonije Jun 8, 2021
83297ef
deciding to use mocha for testing
seunomonije Jun 8, 2021
802f9d2
testing framework setup with simple test run
seunomonije Jun 8, 2021
c431503
Update cirq-web/cirq_web/bloch_sphere/cirq_bloch_sphere.py
seunomonije Jun 8, 2021
0107a58
Update cirq-web/cirq_ts/_version.py
seunomonije Jun 8, 2021
bbc844e
Update cirq-web/cirq_ts/src/bloch_sphere/components/Axes.class.d.ts
seunomonije Jun 8, 2021
0ccdb90
Update cirq-web/cirq_ts/src/bloch_sphere/components/Axes.class.ts
seunomonije Jun 8, 2021
6f5597f
Update cirq-web/cirq_ts/src/bloch_sphere/components/Meridians.class.ts
seunomonije Jun 8, 2021
cd1c7a0
Update cirq-web/cirq_web/bloch_sphere/cirq_bloch_sphere.py
seunomonije Jun 8, 2021
b3d297d
Update cirq-web/setup.py
seunomonije Jun 8, 2021
af02537
Update cirq-web/cirq_ts/src/bloch_sphere/components/Meridians.class.ts
seunomonije Jun 8, 2021
b2045e9
Update cirq-web/cirq_ts/src/bloch_sphere/components/Meridians.class.ts
seunomonije Jun 8, 2021
efcdac1
Update cirq-web/cirq_ts/src/bloch_sphere/components/Meridians.class.ts
seunomonije Jun 8, 2021
d489643
Update cirq-web/cirq_ts/src/bloch_sphere/components/Vector.class.ts
seunomonije Jun 8, 2021
a758965
small changes
seunomonije Jun 8, 2021
2f0c502
Merge branch 'master' of https://github.com/seunomonije/Cirq
seunomonije Jun 8, 2021
a343878
small fixes commit
seunomonije Jun 8, 2021
bc4d3de
first round of comment resolutions, added tiny visualization testing …
seunomonije Jun 9, 2021
227b56f
cirq_ts readme PR comment fixes
seunomonije Jun 9, 2021
0a46d3f
PR comment fixes BlochSphere.ts
seunomonije Jun 9, 2021
bc97a60
PR comment fixes meridians
seunomonije Jun 9, 2021
576031b
PR comment fixes scene
seunomonije Jun 9, 2021
54b2e1b
PR comment fixes vector and test
seunomonije Jun 9, 2021
28467fb
double check fixes from PR comments
seunomonije Jun 9, 2021
0a5f6bc
rename files, work on text.ts
seunomonije Jun 9, 2021
845a944
temp change of bs symbols, quick/dirty but working e2e image check te…
seunomonije Jun 10, 2021
2c80848
ran the linter, fixed .eslintrc.json so that it reports no errors
seunomonije Jun 10, 2021
7657584
add preliminary CI
seunomonije Jun 10, 2021
70887eb
CI for unit testing
seunomonije Jun 10, 2021
b80007b
fix rename for ts-test
seunomonije Jun 10, 2021
8ad3ef4
rename library to CirqTS
seunomonije Jun 10, 2021
2527c57
can configure div id of the bloch sphere
seunomonije Jun 10, 2021
7bce91e
add vector type
seunomonije Jun 10, 2021
250ea94
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije Jun 10, 2021
3a6acd6
update bundle and jupyter notebook
seunomonije Jun 10, 2021
6aabc66
small refactor of python, added more to README
seunomonije Jun 10, 2021
71ff76d
pylint
seunomonije Jun 10, 2021
a803e11
removed IPython as a requirement
seunomonije Jun 11, 2021
3c3bafc
added TS testing frameworks, rough TS viz and unit testing, small rea…
seunomonije Jun 14, 2021
f6e48bb
restart ci
seunomonije Jun 14, 2021
a49fcbc
test ci
seunomonije Jun 14, 2021
3451a3a
add back coverage testing
seunomonije Jun 14, 2021
20b314c
fixed merge conflicts
seunomonije Jun 14, 2021
d3fdd5a
make check/ts-coverage an executable
seunomonije Jun 14, 2021
4bb2242
rough text changes, fix ipython fails on CI
seunomonije Jun 14, 2021
b512c9f
move _version.py to the correct spot
seunomonije Jun 14, 2021
8769ffc
quick updates
seunomonije Jun 14, 2021
b8d5926
fix space in file
seunomonije Jun 15, 2021
e7ba83f
updated ts testing framework, fixed labels
seunomonije Jun 15, 2021
cbb6930
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije Jun 15, 2021
278c911
linting and merge w upstream
seunomonije Jun 15, 2021
3b5a513
add copyrights, small PR comment changes
seunomonije Jun 15, 2021
bdc7955
fix naming of divId
seunomonije Jun 15, 2021
16ec03a
ts e2e testing writes to temp file
seunomonije Jun 15, 2021
9bdbc47
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije Jun 15, 2021
3e1054d
exclude utility functions from testing
seunomonije Jun 15, 2021
599a8bd
updated testing portion of ts README
seunomonije Jun 15, 2021
8820d39
updated README, example notebook, fixed bloch sphere vector point, sm…
seunomonije Jun 16, 2021
b41057c
linting and cleanup changes
seunomonije Jun 16, 2021
4d6bffc
deleting bloch sphere due to ci issues
seunomonije Jun 16, 2021
2914c0d
redo expected png
seunomonije Jun 16, 2021
b259678
add utf-8 encoding to test
seunomonije Jun 16, 2021
4b0da2d
second attempt to fix image diff issue
seunomonije Jun 16, 2021
e48596f
fix test to account for unicode diff threshold
seunomonije Jun 16, 2021
2fe2377
update cirq-web readme
seunomonije Jun 16, 2021
625659e
add utf-8 charset for readme
seunomonije Jun 16, 2021
d2e37ea
add cirq_ts to setup.py
seunomonije Jun 16, 2021
9f403bf
change setup.py for new packaging structure
seunomonije Jun 16, 2021
e314d19
add ts distribution files to the python package
seunomonije Jun 16, 2021
045fbc3
more clarity to package searching
seunomonije Jun 16, 2021
1976d8c
add .js extension
seunomonije Jun 16, 2021
3a6e0a6
add manifest file to help get the bundles
seunomonije Jun 16, 2021
cc23aee
change to setup.py
seunomonije Jun 16, 2021
6a619dd
reset setup.py
seunomonije Jun 16, 2021
44a9521
include package data tag for manifest to work
seunomonije Jun 16, 2021
eb0d7a4
testing removal of cirq_ts from packagin, we don't need it to have an…
seunomonije Jun 16, 2021
bae0b7c
adding cirq_ts back, we need it
seunomonije Jun 16, 2021
ede563f
formatting fix
seunomonije Jun 16, 2021
12fdbc7
remove packaging from readme
seunomonije Jun 17, 2021
22ed261
Merge branch 'master' into master
seunomonije Jun 17, 2021
c187c49
typescript PR fixes
seunomonije Jun 17, 2021
6e2e549
pr fixes for python
seunomonije Jun 17, 2021
969d236
change fixes
seunomonije Jun 17, 2021
618ff01
missed fixes
seunomonije Jun 17, 2021
7f9536e
progress on new testing
seunomonije Jun 21, 2021
5469659
another refactor of the testing framework
seunomonije Jun 21, 2021
7ff32f7
update meridians test
seunomonije Jun 21, 2021
27ed7cb
major typescript code and testing refactor, implemented PR comments
seunomonije Jun 22, 2021
b30dd9b
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije Jun 22, 2021
d59d56a
lint fixes
seunomonije Jun 22, 2021
8998701
PR comment resolutions, additional misc cleanup and fixes
seunomonije Jun 24, 2021
da0c436
Merge branch 'master' into master
seunomonije Jun 24, 2021
e041212
add IPython back for CI
seunomonije Jun 24, 2021
4deb927
pr comment fixes and bug fixes
seunomonije Jun 25, 2021
95e6fa1
added uuids to bloch spheres, cleaned up example notebook
seunomonije Jun 25, 2021
72ee0e8
update testing statements, general pr fixes
seunomonije Jun 28, 2021
d32510c
fix axes
seunomonije Jun 28, 2021
936ca9a
initial circuits structure
seunomonije Jun 28, 2021
16ae383
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije Jul 1, 2021
553dde8
removed json middleman, added more check scripts, general cleanup
seunomonije Jul 1, 2021
59511c6
removed MANIFEST.in and included bundle in package_data
seunomonije Jul 1, 2021
60cc765
changes to pass CI, delete determine_env from widget (YAGNI)
seunomonije Jul 1, 2021
9eb7f29
fix changes after quick scroll through
seunomonije Jul 1, 2021
629519e
Merge branch 'master' of https://github.com/seunomonije/Cirq into 3d-…
seunomonije Jul 1, 2021
07c6c50
PR comment resolutions, adding CI for end to end tests, other refacto…
seunomonije Jul 1, 2021
1ab1b76
pr resolutions
seunomonije Jul 2, 2021
b1bd2d7
stashing
seunomonije Jul 2, 2021
f56bdd3
pr changes
seunomonije Jul 2, 2021
28187c7
revert .gitignore
seunomonije Jul 2, 2021
44bb800
rename MockWidget to FakeWidget and format widget.py
seunomonije Jul 2, 2021
9026f65
Merge branch 'master' into master
balopat Jul 2, 2021
2f2282f
stashing changes
seunomonije Jul 7, 2021
a5a9cd9
Merge branch 'master' of https://github.com/seunomonije/Cirq into 3d-…
seunomonije Jul 7, 2021
4b8e08e
progress dump
seunomonije Jul 12, 2021
675b725
fix merge conflicts
seunomonije Jul 12, 2021
f290bc6
updated cirq-web README
seunomonije Jul 12, 2021
d8f698a
progress dump
seunomonije Jul 15, 2021
4568181
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije Jul 15, 2021
818d6c2
resolve PR comments
seunomonije Jul 15, 2021
b7f89cc
start of cleanup
seunomonije Jul 15, 2021
3c1ae4e
ugly push before computer restart
seunomonije Jul 16, 2021
dd2eb3e
added copyright, very scarce testing
seunomonije Jul 16, 2021
bf83842
Merge branch 'master' of https://github.com/quantumlib/Cirq
seunomonije Jul 16, 2021
3044f5b
Merge branch 'master' of https://github.com/seunomonije/Cirq into 3d-…
seunomonije Jul 16, 2021
84f640e
added a small amount of testing
seunomonije Jul 19, 2021
915b8dc
remove example notebook trash
seunomonije Jul 19, 2021
1802686
add docstrings
seunomonije Jul 19, 2021
326ca2b
little cleanup of docstrings
seunomonije Jul 19, 2021
a14fa33
check fixes
seunomonije Jul 19, 2021
975ac29
last config
seunomonije Jul 19, 2021
f93c1e7
initial PR changes
seunomonije Jul 23, 2021
9428578
refactor progress dump
seunomonije Jul 27, 2021
9f7c0d2
rough push before review
seunomonije Jul 27, 2021
b30d6e1
changes
seunomonije Jul 28, 2021
ec57933
stashing
seunomonije Jul 28, 2021
7b77cad
fix camera
seunomonije Jul 28, 2021
fa3e149
notebook stash
seunomonije Jul 28, 2021
ddbdfab
dirty push, but allows configuration of blocks via Python, and center…
seunomonije Jul 30, 2021
d0bec90
small cleanup of ts
seunomonije Aug 2, 2021
ffe157e
added initial typescript testing, ran some linting on both python and…
seunomonije Aug 3, 2021
c0af8e1
quick fix on error message change in test
seunomonije Aug 3, 2021
2113f9b
ugly dev index structure
seunomonije Aug 3, 2021
6eece7f
change in test structure
seunomonije Aug 4, 2021
e10e956
full python coverage with simple tests
seunomonije Aug 4, 2021
492690d
lint
seunomonije Aug 4, 2021
6a4c9fc
cut notebook output
seunomonije Aug 4, 2021
2a78fc6
added the padding_factor
seunomonije Aug 5, 2021
7fcf3a1
fix testing and jupyter notebook links
seunomonije Aug 5, 2021
474e9d9
added python comments
seunomonije Aug 5, 2021
63ba8f0
add test for GridQubit public method
seunomonije Aug 5, 2021
7b1ac75
CI cleanup
seunomonije Aug 9, 2021
a196db4
cleanup
seunomonije Aug 9, 2021
89104e3
add X mesh in the middle of the X gate
seunomonije Aug 9, 2021
d443365
Merge branch 'master' into 3d-circuits
seunomonije Aug 9, 2021
dfe8eb0
more cleanup, and added e2e tests
seunomonije Aug 9, 2021
cfefaa4
fix documentation error
seunomonije Aug 9, 2021
e7c0cf2
fix lint in e2e test
seunomonije Aug 9, 2021
10d9f37
90% through changes
seunomonije Aug 10, 2021
fb80334
refactor code to build GridCircuit objects from gates
seunomonije Aug 10, 2021
49e6025
rename circuit to qubit_map
seunomonije Aug 10, 2021
bb0c24f
Merge branch 'master' of https://github.com/quantumlib/Cirq into 3d-c…
seunomonije Aug 10, 2021
90ab7ba
apply padding_factor to the time direction
seunomonije Aug 10, 2021
137fca7
convert map type
seunomonije Aug 10, 2021
188d8f9
Merge branch 'master' of https://github.com/quantumlib/Cirq into 3d-c…
seunomonije Aug 10, 2021
4158e80
updated circuit bundle
seunomonije Aug 10, 2021
690b268
add test for coverage
seunomonije Aug 11, 2021
8ccfac3
Merge branch 'master' of https://github.com/quantumlib/Cirq into 3d-c…
seunomonije Aug 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 1 addition & 22 deletions cirq-web/example.ipynb → cirq-web/bloch_sphere_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,7 @@
"id": "fbf7b67d",
"metadata": {},
"source": [
"### Cirq-web visualization"
]
},
{
"cell_type": "markdown",
"id": "e4bf9c7d",
"metadata": {},
"source": [
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
Copy link
Contributor

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! 🍝 )

" <a target=\"_blank\" href=\"https://quantumai.google/cirq/circuits\"><img src=\"https://quantumai.google/site-assets/images/buttons/quantumai_logo_1x.png\" />View on QuantumAI</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/quantumlib/Cirq/blob/master/docs/circuits.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/docs/circuits.ipynb\"><img src=\"https://quantumai.google/site-assets/images/buttons/github_logo_1x.png\" />View source on GitHub</a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://storage.googleapis.com/tensorflow_docs/Cirq/docs/circuits.ipynb\"><img src=\"https://quantumai.google/site-assets/images/buttons/download_icon_1x.png\" />Download notebook</a>\n",
" </td>\n",
"</table>"
"### Cirq-web Bloch sphere visualization"
]
},
{
Expand Down
229 changes: 229 additions & 0 deletions cirq-web/circuit_example.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cirq-web/cirq_ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ We take the following steps for visualization testing in our development environ
3. We take a screenshot of the HTML output in the "browser" (Using Puppeteer)
4. We compare the result of the screenshot with a pre-generated PNG file.

The screenshot of the HTML browser output must live in a temporary directory; we use the [temp](https://github.com/bruce/node-temp) package to handle that for us. Reference the test at `e2e/bloch_sphere/test_bloch_sphere.ts` to see how to easily generate the screenshot in a temporary directory.
The screenshot of the HTML browser output must live in a temporary directory; we use the [temp](https://github.com/bruce/node-temp) package to handle that for us. Reference the test at `e2e/bloch_sphere/bloch_sphere_e2e_test.ts` to see how to easily generate the screenshot in a temporary directory.

The pre-generated PNG file is a screenshot of the developer's choice that represents what the visualization should look like. Each visualization is required to have at least one expected PNG screenshot. For more complex visualizations, multiple screenshots may be needed.
2 changes: 2 additions & 0 deletions cirq-web/cirq_ts/dist/circuit.bundle.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions cirq-web/cirq_ts/dist/circuit.bundle.js.LICENSE.txt
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
*/
14 changes: 14 additions & 0 deletions cirq-web/cirq_ts/dist/html/bloch_sphere.html
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>
39 changes: 39 additions & 0 deletions cirq-web/cirq_ts/dist/html/circuit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<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(
[
{row: 0, col: 0},
{row: 0, col: 1},
{row: 1, col: 0},
{row: 2, col: 3},
{row: 3, col: 2},
{row: 3, col: 0},
], 5, 'mycircuitdiv');
circuit.circuit.addSymbolsFromList(
[
{'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},
]
);

// 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>
12 changes: 6 additions & 6 deletions cirq-web/cirq_ts/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<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>
<div id="bloch-sphere">
<a href="/html/bloch_sphere.html">Bloch sphere dev environment</a>
</div>
<div id="circuit">
<a href="/html/circuit.html">Circuit dev environment</a>
</div>
</body>
</html>
119 changes: 119 additions & 0 deletions cirq-web/cirq_ts/e2e/circuit/circuit_e2e_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// 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(
[
{row: 0, col: 0},
{row: 0, col: 1},
{row: 1, col: 0},
{row: 2, col: 3},
{row: 3, col: 2},
{row: 3, col: 0},
], 5, 'mycircuitdiv');
circuit.circuit.addSymbolsFromList(
[
{
'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
},
]
);
`)
);
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);
});
});
});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions cirq-web/cirq_ts/src/circuit/components/grid_qubit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 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 {Group, Vector3} from 'three';
import {QubitLine, QubitLabel} from './meshes';
import {Symbol3D} from './types';

/**
* Class that represents a GridQubit.
* A GridQubit consists of a three.js line, a sprite
* with location information, and three.js mesh objects
* representing the gates, if applicable.
*/
export class GridQubit extends Group {
readonly row: number;
readonly col: number;

/**
* Class constructor.
* @param row The row of the GridQubit
* @param col The column of the GridQubit
* @param moments The number of moments of the entire circuit. This
seunomonije marked this conversation as resolved.
Show resolved Hide resolved
* determines the length of the three.js line representing the GridQubit
*/
constructor(row: number, col: number, moments: number, padding_factor = 1) {
super();

this.row = row;
this.col = col;
this.add(this.createLine(moments, padding_factor));
this.add(this.addLocationLabel(padding_factor));
}

/**
* Adds a designated symbol to the qubit. Location information,
* including the moment at which it occurs, is included in the
* symbol itself.
* @param symbol A Symbol3D object to add to the qubit.
*/
addSymbol(symbol: Symbol3D) {
this.add(symbol);
}

private createLine(moments: number, padding_factor: number): QubitLine {
const coords = [
new Vector3(this.row * padding_factor, 0, this.col * padding_factor),
new Vector3(
this.row * padding_factor,
moments,
this.col * padding_factor
),
];
return new QubitLine(coords[0], coords[1]);
}

private addLocationLabel(padding_factor: number): QubitLabel {
const sprite = new QubitLabel(`(${this.row}, ${this.col})`);
sprite.position.copy(
new Vector3(this.row * padding_factor, -0.6, this.col * padding_factor)
);
return sprite;
}
}
60 changes: 60 additions & 0 deletions cirq-web/cirq_ts/src/circuit/components/grid_qubit_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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 {expect} from 'chai';
import {Line} from 'three';
import {GridQubit} from './grid_qubit';
import {QubitLabel} from './meshes';
import {Symbol3D, SymbolInformation} from './types';

describe('GridQubit', () => {
balopat marked this conversation as resolved.
Show resolved Hide resolved
seunomonije marked this conversation as resolved.
Show resolved Hide resolved
const DEFAULT_ROW = 0;
const DEFAULT_COL = 0;
const DEFAULT_MOMENTS = 5;
const gridQubit = new GridQubit(DEFAULT_ROW, DEFAULT_COL, DEFAULT_MOMENTS);
const children = gridQubit.children;

it('is a three.js line object with length 5', () => {
const line = children.find(child => child.type === 'Line') as Line;
line.computeLineDistances();
const distancePoints = line.geometry.attributes.lineDistance.array;

expect(distancePoints[0]).to.equal(0);
expect(distancePoints[1]).to.equal(DEFAULT_MOMENTS);
});

it('has a three.js sprite label', () => {
const sprite = children.find(
child => child.type === 'Sprite'
) as QubitLabel;
expect(sprite.text).to.equal(`(${DEFAULT_ROW}, ${DEFAULT_COL})`);
});

it('handles adding a basic Symbol3D object', () => {
const symbolInfo: SymbolInformation = {
wire_symbols: ['X'],
location_info: [{row: 0, col: 0}],
color_info: ['black'],
moment: 1,
};

const symbol = new Symbol3D(symbolInfo);
gridQubit.addSymbol(symbol);

const symbol3D = children.find(
child => child.constructor.name === 'Symbol3D'
)!;
expect(symbol3D.children[0].constructor.name).to.equal('X3DSymbol');
});
});