SpookyQubits
Ghost Blocks

Ghost Blocks Reference

Look up each block as you build a circuit or simulate light in Scratch.

Download the Word guide (.docx)

Start building

  1. Open the Ghost Blocks Editor on a computer. Select Add Extension → Ghost Blocks.
  2. Stack commands under the green flag. Start with put away all ghost coins for a fresh circuit on every run. A ghost coin is a simulated qubit. Use the same name to refer to it and choose different names for different qubits. You can use up to eight.
  3. Drop rounded reporter blocks into say or set variable to to see their values. Brackets in this guide mark the places where you type or pick an input.

Qubits and gates

new ghost coin [coin]
Prepares the named qubit in state 0. Reusing a name measures and resets that qubit, which can change the state of qubits entangled with it.
ghost [coin]
Applies the Hadamard gate (H). On a fresh qubit it makes a superposition with equal 0 and 1 odds. A second H reverses the first if no other operation intervenes.
flip [coin]
Applies X, exchanging the 0 and 1 amplitudes of the qubit.
sign [coin]
Applies Z, reversing the sign of the 1 amplitude. The immediate Z-basis odds stay the same.
link [control] to [target]
Applies controlled-X (CNOT). The gate flips the target in components where the control is 1. It can entangle two qubits.
phase [coin] by [angle] degrees (P)
Turns the phase of the 1 amplitude. Use 90° for S or 45° for T.
rotate [coin] around [axis] by [angle] degrees
Rotates the qubit about X, Y, or Z on the Bloch sphere. A 90° Y rotation takes a fresh qubit from 0 to the positive X eigenstate.
controlled Z with [control] on [target]
Applies CZ, reversing the sign of the component where both qubits are 1.
swap [coin A] and [coin B] (SWAP)
Exchanges two qubits, including their correlations with other qubits.
flip [target] if [coin A] and [coin B] are 1 (CCX)
Applies Toffoli (CCX). It flips the target in components where both controls are 1. Use three distinct names.

Reading qubits

The chance % blocks preview odds for an existing qubit. Evaluating look or measure samples an outcome and updates the state. In the X and Y bases, outcome 0 labels the +1 eigenstate and outcome 1 labels the −1 eigenstate.

look at [coin]
Measures in the Z basis and returns one result, 0 or 1.
chance % that [coin] is 1
Reports the predicted percentage of 1 outcomes in the Z basis.
measure [coin] in [basis] basis
Measures along X, Y, or Z. A second measurement in the same basis gives the same result if no intervening operation changes the state.
chance % of [coin] outcome 1 in [basis] basis
Reports the predicted percentage of 1 outcomes in the selected basis.
all chips
Lists joint-state amplitudes in coin creation order. It shows signed chip counts when possible and rounded amplitudes such as +0.7071i for complex states.
put away all ghost coins
Clears the named qubits and their shared quantum state. Use it at the start of a run or each independent trial.

Turn a phase into a measurable change

Create a fresh coin. Apply ghost → phase 180° → ghost, then show its Z-basis chance of 1. Expect 100%. Start over with 90° and expect 50%.

Make a Bell pair

Start with fresh coins a and b. Apply ghost [a], then link [a] to [b]. Each coin has a 50% chance of 1 in Z. Use look at to read both and check that their results match. Rebuild the pair for each new trial.

Photons and arrows

Use the two-slit model to sample photon positions on a screen. Use arrows at a named spot to build your own example of amplitudes combining.

two slits: gap [gap] wave [wave] screen distance [distance]
Sets the slit separation, wavelength, and distance to the screen. Enter positive values in the same units.
watch the slits [off/on]
Switches the idealized path detectors. With detectors off, the paths interfere. With detectors on, the stripes disappear.
brightness % at x [x]
Reports the relative brightness at screen position x on a 0–100 scale.
shoot one photon: landing x
Samples one horizontal landing position. Repeat and plot the values to see the brightness pattern emerge.
add arrow turned [angle] to spot [name]
Adds a unit-length arrow pointing at the given angle in degrees to the named spot.
brightness of spot [name]
Reports the squared length of the sum of the arrows at that spot. Two aligned unit arrows give 4.
clear spot [name]
Removes all the arrows from that spot so you can start a fresh comparison.

Compare a bright and dark fringe

Set gap to 10, wave to 2, and screen distance to 300. With watching off, compare brightness % at x = 0 and x = 30. Expect 100% and 0%. Turn watching on and check both positions again.

Make two arrows cancel

Clear spot A. Add an arrow at 0° and one at 180°. Check that the brightness is 0. Clear the spot, try two arrows at 0°, and check that the brightness is 4.