PennyLane

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

Beginner
Resource Estimation

Introduction to Resource Estimation

Background

Skip to Challenge statement if you are already familiar with resource estimation methods in PennyLane.

Resource estimation is a critical task for evaluating the feasibility of a quantum program, especially for fault-tolerant quantum computing (FTQC). It can also be a helpful tool to identify where and how to make quantum programs more efficient.

The quantum resource estimation module supports resource estimation of quantum algorithms at an industrial scale in PennyLane. You can read how this module has already enabled cutting-edge quantum algorithms research.

Resource estimation can be as simple and as quick as invoking qre.estimate on that circuit. For example,

import pennylane.estimator as qre import time t1 = time.time() resources_exec = qre.estimate(circuit)(input) t2 = time.time() print(f"Processing time: {(t2 - t1):.3g} seconds") print(resources_exec)

Might give an output like:

Processing time: 0.000962 seconds --- Resources: --- Total wires: 2.000E+4 algorithmic wires: 20000 allocated wires: 0 zero state: 0 any state: 0 Total gates : 7.151E+8 'T': 6.556E+8, 'CNOT': 2.980E+7, 'Z': 9.900E+6, 'S': 1.980E+7, 'Hadamard': 2.000E+4

You can see the default gate set is {'Toffoli', 'T', 'CNOT', 'X', 'Y', 'Z', 'S', 'Hadamard'}. The module makes it easy to change the gate set to whichever you prefer with gate_set={...} as an input to qre.estimate. A common universal gate set is {H, S, CNOT, T}.

Notice that these gate sets do not contain rotation gates with arbitrary angular precision such as RZ(θ). In these cases, rotations are decomposed in terms of the gates in the gate set. If you want a rotation to many significant figures, then you generally need to execute many gates. By contrast, if you are happy with a lower precision (e.g., 3.14 rather than 3.141592653), then fewer gates are usually needed. You can set the rotation precision to be used in qre.estimate with a Resource config object.

Challenge statement

You are tasked with estimating the resource cost of quantum Fourier transform (QFT) for a number of wires. The

In particular, you will need to:

  • Print out the resource estimates for this circuit,
  • Change the gate set to {Hadamard, S, CNOT, T} instead of the default,
  • Change the precision of RZ rotations to 1e-15 instead of the default.

Your method should work even if the number of wires changes.

Challenge code

Here are some helpful resources:

  • Estimating with qre.estimate
  • Setting precision with a ResourceConfig

Note that we have wrapped a function around the circuit whose input is num_wires and output is resource_estimate to evaluate your solution to this challenge. When you use this code in practice, you do not need the wrapper.

Output

The expected output is an object that contains the resource estimate of the quantum Fourier transform in terms of the gates in the gateset like:

Resources for QFT --- Resources: --- Total wires: 10 algorithmic wires: 10 allocated wires: 0 zero state: 0 any state: 0 Total gates : 9.025E+3 'T': 8.910E+3, 'CNOT': 105, 'Hadamard': 10

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.

test_input: 3 expected_output: {'Hadamard': 3, 'CNOT': 9, 'T': 594} test_input: 8 expected_output: {'Hadamard': 8, 'CNOT': 68, 'T': 5544}

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

Good luck!

Loading...