PennyLane
Next

To attempt this challenge, please switch to a larger screen size.

Beginner
Getting Started

PennyLane x unitaryHACK 2026 Challenge

Challenge statement

You are tasked with implementing a Greenberger-Horne-Zeilinger (GHZ) state. It is a maximally entangled state that is useful in quantum error correction and teleportation, to name a couple of applications.

The 3-qubit version is written as \frac{|000\rangle + |111\rangle}{\sqrt{2}}. This statevector is an 8-dimensional vector that has all zeros except for the first and last entries. Most generally, the n-qubit GHZ state is written as \frac{|0\rangle^{\otimes n} + |1\rangle^{\otimes n}}{\sqrt{2}}.

A GHZ state is created from the all-zero initial state by firstly establishing a uniform superposition on the first qubit with the Hadamard gate, creating the state \frac{1}{\sqrt{2}}(|0\rangle + |1\rangle) |0\rangle \dots |0\rangle . A CNOT gate, with the first qubit as the control and the second qubit as the target, creates an entangled copy: \frac{1}{\sqrt{2}}(|00\rangle + |11\rangle) |0\rangle \dots |0\rangle . Continued application of CNOT gates from the first qubit to all other qubits leads to a GHZ state. The circuit below implements the 3-qubit GHZ state as an example.

A circuit to construct a 3-qubit GHZ state

Input

The number of qubits is denoted as num_wires.

Output

The expected output of your circuit is the statevector of the n-qubit GHZ state.

Test cases

The following public test cases are available to you. Note that there are additional hidden test cases that we use to verify that your code is valid in full generality. Note that we take the real component of the output of the circuit behind the scenes. You don't need to do that.

test_input: "3" expected_output: '[0.7071067811865475, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7071067811865475]' test_input: "5" expected_output: '[0.7071067811865475, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7071067811865475]'

If your solution matches the correct one in check, the output will be "Success!" Otherwise, you will receive an "Incorrect" prompt.

Good luck!

Loading...