Skip to content
This repository was archived by the owner on Sep 6, 2025. It is now read-only.

Commit 03bd695

Browse files
FermiousFermious
authored andcommitted
Refactor QC playground layout structure
Simplify layout inheritance and fix rendering issues by using default layout instead of custom HTML structure.
1 parent 6b11e25 commit 03bd695

File tree

3 files changed

+218
-83
lines changed

3 files changed

+218
-83
lines changed

_layouts/qc-playground.html

Lines changed: 187 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
---
2-
# No parent layout to avoid HTML compression in production mode
2+
# No parent layout to avoid HTML compression breaking JavaScript
33
---
44

55
<!doctype html>
66

77
{% include origin-type.html %}
88
{% include lang.html %}
99

10-
<html lang="{{ site.data.locales[lang].name | default: lang }}"{% if lang == 'ko_KR' %} class="notranslate" translate="no"{% endif %}>
10+
{% if site.theme_mode %}
11+
{% capture prefer_mode %}data-mode="{{ site.theme_mode }}"{% endcapture %}
12+
{% endif %}
13+
14+
<html lang="{{ page.lang | default: site.alt_lang | default: site.lang }}" {{ prefer_mode }}>
1115
{% include head.html %}
16+
1217
<body>
1318
{% include sidebar.html lang=lang %}
14-
{% include topbar.html lang=lang %}
1519

1620
<div id="main-wrapper" class="d-flex justify-content-center">
1721
<div class="container d-flex flex-column px-xxl-5">
22+
{% include topbar.html lang=lang %}
23+
1824
<div class="row flex-grow-1">
19-
<main class="col-12 col-lg-11 col-xl-9 px-md-4">
25+
<main aria-label="Main Content" class="col-12 col-lg-11 col-xl-9 px-md-4">
2026

2127
<!-- Q.js Stylesheets -->
2228
<link rel="stylesheet" href="{{ '/assets/css/qjs/Q.css' | relative_url }}">
@@ -233,33 +239,75 @@
233239
</style>
234240

235241
<div class="qc-playground">
236-
<!-- Compact Sample Circuits -->
242+
<!-- Comprehensive Sample Circuits -->
237243
<div class="sample-circuits-compact">
238-
<h4><i class="fas fa-lightbulb me-2"></i>Quick Start - Sample Circuits</h4>
239-
<p class="mb-3">Click any circuit to load it instantly:</p>
244+
<h4><i class="fas fa-lightbulb me-2"></i>Sample Quantum Circuits</h4>
245+
<p class="mb-3">Click any circuit to load it instantly and explore quantum algorithms:</p>
246+
247+
<h5>Fundamentals</h5>
248+
<div class="circuits-row">
249+
<span class="circuit-pill" onclick="loadSampleCircuit('superposition')" title="Create equal superposition |0⟩+|1⟩">Superposition</span>
250+
<span class="circuit-pill" onclick="loadSampleCircuit('pauliX')" title="Pauli-X gate (quantum NOT)">Pauli X</span>
251+
<span class="circuit-pill" onclick="loadSampleCircuit('pauliY')" title="Pauli-Y gate">Pauli Y</span>
252+
<span class="circuit-pill" onclick="loadSampleCircuit('pauliZ')" title="Pauli-Z gate (phase flip)">Pauli Z</span>
253+
<span class="circuit-pill" onclick="loadSampleCircuit('phaseGate')" title="Phase gate">Phase P</span>
254+
<span class="circuit-pill" onclick="loadSampleCircuit('tGate')" title="T gate (π/8 rotation)">T Gate</span>
255+
<span class="circuit-pill" onclick="loadSampleCircuit('sGate')" title="S gate (π/4 rotation)">S Gate</span>
256+
</div>
240257

241-
<h5>Basic</h5>
258+
<h5>Bell States & Entanglement</h5>
242259
<div class="circuits-row">
243-
<span class="circuit-pill" onclick="loadSampleCircuit('superposition')">Superposition</span>
244-
<span class="circuit-pill" onclick="loadSampleCircuit('bell')">Bell State</span>
245-
<span class="circuit-pill" onclick="loadSampleCircuit('bellModified')">Bell + X</span>
260+
<span class="circuit-pill" onclick="loadSampleCircuit('bellPhiPlus')" title="Bell state |Φ+⟩ = (|00⟩+|11⟩)/√2">|Φ+⟩ Bell</span>
261+
<span class="circuit-pill" onclick="loadSampleCircuit('bellPhiMinus')" title="Bell state |Φ-⟩ = (|00⟩-|11⟩)/√2">|Φ-⟩ Bell</span>
262+
<span class="circuit-pill" onclick="loadSampleCircuit('bellPsiPlus')" title="Bell state |Ψ+⟩ = (|01⟩+|10⟩)/√2">|Ψ+⟩ Bell</span>
263+
<span class="circuit-pill" onclick="loadSampleCircuit('bellPsiMinus')" title="Bell state |Ψ-⟩ = (|01⟩-|10⟩)/√2">|Ψ-⟩ Bell</span>
264+
<span class="circuit-pill" onclick="loadSampleCircuit('ghz3')" title="3-qubit GHZ state (|000⟩+|111⟩)/√2">GHZ State</span>
265+
<span class="circuit-pill" onclick="loadSampleCircuit('w3')" title="3-qubit W state (|001⟩+|010⟩+|100⟩)/√3">W State</span>
246266
</div>
247267

248-
<h5>Intermediate</h5>
268+
<h5>Multi-Qubit Gates</h5>
249269
<div class="circuits-row">
250-
<span class="circuit-pill" onclick="loadSampleCircuit('deutsch')">Deutsch Algorithm</span>
251-
<span class="circuit-pill" onclick="loadSampleCircuit('toffoli')">Toffoli Gate</span>
252-
<span class="circuit-pill" onclick="loadSampleCircuit('ghz')">GHZ State</span>
253-
<span class="circuit-pill" onclick="loadSampleCircuit('swapTest')">Swap Test</span>
270+
<span class="circuit-pill" onclick="loadSampleCircuit('cnot')" title="Controlled-NOT (CNOT) gate">CNOT</span>
271+
<span class="circuit-pill" onclick="loadSampleCircuit('ccnot')" title="Controlled-Controlled-NOT (Toffoli) gate">Toffoli</span>
272+
<span class="circuit-pill" onclick="loadSampleCircuit('fredkinGate')" title="Controlled-SWAP (Fredkin) gate">Fredkin</span>
254273
</div>
255274

256-
<h5>Advanced</h5>
275+
<h5>Quantum Algorithms</h5>
257276
<div class="circuits-row">
258-
<span class="circuit-pill" onclick="loadSampleCircuit('qft2')">2-Qubit QFT</span>
259-
<span class="circuit-pill" onclick="loadSampleCircuit('teleportation')">Teleportation</span>
260-
<span class="circuit-pill" onclick="loadSampleCircuit('grover2')">Grover Search</span>
261-
<span class="circuit-pill" onclick="loadSampleCircuit('phaseKickback')">Phase Kickback</span>
262-
<span class="circuit-pill" onclick="loadSampleCircuit('catState')">Cat State</span>
277+
<span class="circuit-pill" onclick="loadSampleCircuit('deutsch')" title="Deutsch algorithm for function evaluation">Deutsch</span>
278+
<span class="circuit-pill" onclick="loadSampleCircuit('deutschJozsa')" title="Deutsch-Jozsa algorithm">Deutsch-Jozsa</span>
279+
<span class="circuit-pill" onclick="loadSampleCircuit('bernsteinVazirani')" title="Bernstein-Vazirani hidden string algorithm">Bernstein-Vazirani</span>
280+
<span class="circuit-pill" onclick="loadSampleCircuit('grover2')" title="Grover's search algorithm (2-qubit)">Grover Search</span>
281+
<span class="circuit-pill" onclick="loadSampleCircuit('amplitudeAmplification')" title="Amplitude amplification technique">Amplitude Amplification</span>
282+
</div>
283+
284+
<h5>Quantum Fourier Transform</h5>
285+
<div class="circuits-row">
286+
<span class="circuit-pill" onclick="loadSampleCircuit('qft2')" title="2-qubit Quantum Fourier Transform">2-Qubit QFT</span>
287+
<span class="circuit-pill" onclick="loadSampleCircuit('qft3')" title="3-qubit Quantum Fourier Transform">3-Qubit QFT</span>
288+
<span class="circuit-pill" onclick="loadSampleCircuit('phaseEstimation')" title="Quantum Phase Estimation">Phase Estimation</span>
289+
</div>
290+
291+
<h5>Error Correction</h5>
292+
<div class="circuits-row">
293+
<span class="circuit-pill" onclick="loadSampleCircuit('bitFlipCode')" title="3-qubit bit flip error correction">Bit Flip Code</span>
294+
<span class="circuit-pill" onclick="loadSampleCircuit('phaseFlipCode')" title="3-qubit phase flip error correction">Phase Flip Code</span>
295+
</div>
296+
297+
<h5>Quantum Communication</h5>
298+
<div class="circuits-row">
299+
<span class="circuit-pill" onclick="loadSampleCircuit('teleportation')" title="Quantum teleportation protocol">Teleportation</span>
300+
<span class="circuit-pill" onclick="loadSampleCircuit('denseCoding')" title="Dense coding protocol">Dense Coding</span>
301+
<span class="circuit-pill" onclick="loadSampleCircuit('swapTest')" title="SWAP test for state comparison">SWAP Test</span>
302+
</div>
303+
304+
<h5>Applications</h5>
305+
<div class="circuits-row">
306+
<span class="circuit-pill" onclick="loadSampleCircuit('randomNumber')" title="Quantum random number generator">Random Numbers</span>
307+
<span class="circuit-pill" onclick="loadSampleCircuit('coinFlip')" title="Quantum coin flip">Coin Flip</span>
308+
<span class="circuit-pill" onclick="loadSampleCircuit('catState4')" title="4-qubit cat state">Cat State</span>
309+
<span class="circuit-pill" onclick="loadSampleCircuit('phaseKickback')" title="Phase kickback demonstration">Phase Kickback</span>
310+
<span class="circuit-pill" onclick="loadSampleCircuit('quantumWalk')" title="Quantum walk example">Quantum Walk</span>
263311
</div>
264312
</div>
265313

@@ -326,42 +374,106 @@ <h4><i class="fab fa-latex me-2"></i>LaTeX Export</h4>
326374
let currentCircuit = null;
327375
let playgroundInputText = '';
328376

329-
// Sample circuits data organized by difficulty
377+
// Sample circuits organized by category and educational value
330378
const sampleCircuits = {
331-
// Basic Circuits
379+
// Fundamentals
332380
superposition: `H`,
333-
bell: `H-X#0
381+
pauliX: `X`,
382+
pauliY: `Y`,
383+
pauliZ: `Z`,
384+
phaseGate: `P`,
385+
tGate: `T`,
386+
sGate: `S`,
387+
388+
// Bell States (Entanglement)
389+
bellPhiPlus: `H-X#0
334390
I-X#1`,
335-
bellModified: `H-X#0-X
391+
bellPhiMinus: `H-X#0-Z
392+
I-X#1-I`,
393+
bellPsiPlus: `H-X#0-I
336394
I-X#1-X`,
395+
bellPsiMinus: `H-X#0-Z
396+
I-X#1-X`,
397+
398+
// Basic Algorithms
399+
deutsch: `H-H-I-H-I
400+
I-H-X-H-I`,
401+
deutschJozsa: `H-H-H-I-I-H-H-H
402+
I-I-H-X-I-I-I-H`,
403+
bernsteinVazirani: `H-H-H-I-I-H-H-H
404+
I-I-H-Z-I-I-I-H`,
337405

338-
// Intermediate Circuits
339-
deutsch: `H-I-H-I
340-
H-X-I-H`,
341-
toffoli: `I-I-X#2
342-
I-I-X#2
343-
X-X-X#2`,
344-
ghz: `H-X#1-X#2
406+
// Multi-Qubit Gates
407+
cnot: `H-X#0
408+
I-X#1`,
409+
ccnot: `H-I-X#2
410+
I-H-X#2
411+
I-I-X#2`,
412+
fredkinGate: `H-I-S#2
413+
I-H-S#2
414+
I-I-S#2`,
415+
416+
// Entangled States
417+
ghz3: `H-X#1-X#2
345418
I-X#1-I
346419
I-I---X#2`,
347-
swapTest: `H-I---I-H
348-
I-X#2-X-I
349-
I-X#2-I-I`,
420+
w3: `H-X#1-I
421+
I-I---H
422+
I-I---X#0`,
350423

351-
// Advanced Circuits
352-
qft2: `I-H-S#1-H
353-
H-I-I---I`,
354-
teleportation: `I---I-H-I-X#1-Z#2
355-
I---I-I-I-I---I
424+
// Quantum Fourier Transform
425+
qft2: `I-H-S#1-H-S#0
426+
H-I-I---I-I`,
427+
qft3: `I-I-H-S#2-T#2-H-S#1-H
428+
I-H-I-I---I---I-I---I
429+
H-I-I-I---I---I-I---I`,
430+
431+
// Search Algorithms
432+
grover2: `H-H-X-X-H-Z#1-H-X-X-H-H
433+
H-H-X-X-H-Z#0-H-X-X-H-H`,
434+
amplitudeAmplification: `H-H-I-X-H-Z#1-H-X-I-H-H
435+
H-H-X-I-H-Z#0-H-I-X-H-H`,
436+
437+
// Error Correction
438+
bitFlipCode: `I-X#1-X#2-I-I-I
439+
H-X#1-I---I-I-I
440+
I-I---X#2-I-I-I`,
441+
phaseFlipCode: `H-X#1-X#2-H-H-H
442+
I-X#1-I---I-I-I
443+
I-I---X#2-I-I-I`,
444+
445+
// Applications
446+
teleportation: `I-I-H-I-X#0-Z#0
447+
I-I-I-I-I---I
356448
H-X#0-I-H-I---I`,
357-
grover2: `H-X-H-X-H
358-
H-X-H-X-H`,
449+
denseCoding: `H-X#0-I-I-H-I
450+
I-X#1-H-X-I-X`,
451+
randomNumber: `H-I-I-I
452+
H-I-I-I
453+
H-I-I-I
454+
H-I-I-I`,
455+
coinFlip: `H-I
456+
I-I`,
457+
458+
// Advanced Protocols
459+
swapTest: `H-I---I-H
460+
I-S#2-S-I
461+
I-S#2-I-I`,
359462
phaseKickback: `H-I-I-Z#0-I-H
360463
I-H-Z-Z#0-H-I`,
361-
catState: `H-X#1-X#2-X#3
464+
quantumWalk: `H-I-S-H-S-H
465+
I-S-I-I-I-I`,
466+
467+
// Cat States
468+
catState4: `H-X#1-X#2-X#3
362469
I-X#1-I---I
363470
I-I---X#2-I
364-
I-I---I---X#3`
471+
I-I---I---X#3`,
472+
473+
// Phase Estimation
474+
phaseEstimation: `H-I-I-P#2-H
475+
I-H-I-I---I
476+
I-I-H-I---I`
365477
};
366478

367479
// Load a sample circuit into the editor
@@ -577,17 +689,41 @@ <h4><i class="fab fa-latex me-2"></i>LaTeX Export</h4>
577689
});
578690
</script>
579691

580-
</main>
692+
</main>
693+
694+
<!-- panel -->
695+
<aside aria-label="Panel" id="panel-wrapper" class="col-xl-3 ps-2 text-muted">
696+
<div class="access">
697+
{% include_cached update-list.html lang=lang %}
698+
{% include_cached trending-tags.html lang=lang %}
699+
</div>
700+
</aside>
701+
</div>
702+
703+
<div class="row">
704+
<!-- tail -->
705+
<div id="tail-wrapper" class="col-12 col-lg-11 col-xl-9 px-md-4">
706+
{% include_cached footer.html lang=lang %}
581707
</div>
582708
</div>
709+
710+
{% include_cached search-results.html lang=lang %}
583711
</div>
584712

585-
{% include footer.html lang=lang %}
713+
<aside aria-label="Scroll to Top">
714+
<button id="back-to-top" type="button" class="btn btn-lg btn-box-shadow">
715+
<i class="fas fa-angle-up"></i>
716+
</button>
717+
</aside>
718+
</div>
586719

587-
<div id="mask"></div>
720+
<div id="mask" class="d-none position-fixed w-100 h-100 z-1"></div>
588721

589-
{% include search-results.html lang=lang %}
590-
{% include js-selector.html %}
722+
{% if site.pwa.enabled %}
723+
{% include_cached notification.html lang=lang %}
724+
{% endif %}
591725

726+
{% include_cached search-loader.html lang=lang %}
592727
</body>
593-
</html>
728+
</html>
729+

_tabs/qc-playground.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: qc-playground
33
icon: fas fa-microchip
4-
order: 4
4+
order: 3
55
title: QC Playground
66
---
77

@@ -24,10 +24,4 @@ Interactive quantum circuit simulator powered by [Q.js](https://quantumjavascrip
2424
3. Experiment with the sample circuits provided
2525
4. Export your circuits for use in documentation or presentations
2626

27-
Start with something simple like a Bell state:
28-
```
29-
H-X#0
30-
I-X#1
31-
```
32-
3327
Or try the loaded example circuit to see how entanglement works!

assets/js/qjs/Q-Circuit-Editor.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -587,31 +587,36 @@ Q.Circuit.Editor.set = function( circuitEl, operation ){
587587
return registerIndex !== siblingRegisterIndex
588588
})
589589
)
590-
operation.registerIndices.forEach( function( registerIndex, i ){
591-
592-
if( i < operation.registerIndices.length - 1 ){
593-
594-
const
595-
siblingRegisterIndex = operation.registerIndices[ i + 1 ],
596-
registerDelta = Math.abs( siblingRegisterIndex - registerIndex ),
597-
start = Math.min( registerIndex, siblingRegisterIndex ),
598-
end = Math.max( registerIndex, siblingRegisterIndex ),
599-
containerEl = document.createElement( 'div' ),
600-
linkEl = document.createElement( 'div' )
601-
602-
backgroundEl.appendChild( containerEl )
603-
containerEl.setAttribute( 'moment-index', operation.momentIndex )
604-
containerEl.setAttribute( 'register-index', registerIndex )
605-
containerEl.classList.add( 'Q-circuit-operation-link-container' )
606-
containerEl.style.gridRowStart = Q.Circuit.Editor.registerIndexToGridRow( start )
607-
containerEl.style.gridRowEnd = Q.Circuit.Editor.registerIndexToGridRow( end + 1 )
608-
containerEl.style.gridColumn = Q.Circuit.Editor.momentIndexToGridColumn( operation.momentIndex )
609-
610-
containerEl.appendChild( linkEl )
611-
linkEl.classList.add( 'Q-circuit-operation-link' )
612-
if( registerDelta > 1 ) linkEl.classList.add( 'Q-circuit-operation-link-curved' )
613-
}
614-
})
590+
591+
// Create the connecting lines only once per multi-qubit operation
592+
// (when processing the first register index)
593+
if( i === 0 ){
594+
operation.registerIndices.forEach( function( regIndex, j ){
595+
596+
if( j < operation.registerIndices.length - 1 ){
597+
598+
const
599+
siblingRegisterIndex = operation.registerIndices[ j + 1 ],
600+
registerDelta = Math.abs( siblingRegisterIndex - regIndex ),
601+
start = Math.min( regIndex, siblingRegisterIndex ),
602+
end = Math.max( regIndex, siblingRegisterIndex ),
603+
containerEl = document.createElement( 'div' ),
604+
linkEl = document.createElement( 'div' )
605+
606+
backgroundEl.appendChild( containerEl )
607+
containerEl.setAttribute( 'moment-index', operation.momentIndex )
608+
containerEl.setAttribute( 'register-index', regIndex )
609+
containerEl.classList.add( 'Q-circuit-operation-link-container' )
610+
containerEl.style.gridRowStart = Q.Circuit.Editor.registerIndexToGridRow( start )
611+
containerEl.style.gridRowEnd = Q.Circuit.Editor.registerIndexToGridRow( end + 1 )
612+
containerEl.style.gridColumn = Q.Circuit.Editor.momentIndexToGridColumn( operation.momentIndex )
613+
614+
containerEl.appendChild( linkEl )
615+
linkEl.classList.add( 'Q-circuit-operation-link' )
616+
if( registerDelta > 1 ) linkEl.classList.add( 'Q-circuit-operation-link-curved' )
617+
}
618+
})
619+
}
615620
if( operation.isControlled && i === 0 ){
616621

617622
operationEl.classList.add( 'Q-circuit-operation-control' )

0 commit comments

Comments
 (0)