liveBook · Manning

Weight register

As explained in Building Quantum Software with Python

A weight register is a quantum register that stores the weight associated with an encoded item selection.

A weight register is a quantum register that stores the total weight associated with each encoded item selection. In a knapsack circuit, it works alongside a key register for selections and a value register for total values. section 10.1.2 section 11.3.1

Build the register and encode the weight function with these implementation steps:

  • Choose the register size to represent the weights required by the algorithm; the example starts with three qubits and later uses four. section 10.1.2 section 11.3.2
  • Initialize the weight register in equal superposition with Hadamard gates, alongside the selection and value registers. section 11.3.1
  • Represent each weight contribution as a coefficient and the selection qubit controlling that contribution. section 10.1.2
  • Apply controlled phase rotations for each term, then apply the inverse quantum Fourier transform to convert the encoded phases into integer weights. section 10.1.2 section 11.3.1
  • Use the resulting register values to identify selections whose weights satisfy a constraint. section 11.3.2

Three-item knapsack

For item weights 3, 2, and 1, encode the terms [(3, [0]), (2, [1]), (1, [2])]. Selection 011 produces weight 5, while selection 101 produces weight 4. To enforce a capacity of 4, encode w′ = 4 − w; feasible selections then have nonnegative values in the adjusted weight register. section 10.1.2 section 11.3.2

Table 10.3 Each possible selection of items and the corresponding value and weight
Selection
Value
Weight
000
0
0
001
2
3
010
3
2
011
5
5
100
1
1
101
3
4
110
4
3
111
6
6

Compare every binary item selection with its corresponding total weight and value before applying search constraints. section 10.1.2

How Building Quantum Software with Python covers it

How deep it goes
Explains register sizing, initialization, controlled rotations, inverse quantum Fourier transforms, and adjusted weights, while deferring general sizing details.
Examples
Uses three items with weights 3, 2, and 1, enumerating binary selections and encoding their totals with Python circuit code.
What it assumes
Assumes basic quantum-circuit programming and binary item selections while teaching the register encoding procedure through a small knapsack example.
What you can do after
Build it from scratch using quantum registers, controlled phase rotations, inverse quantum Fourier transforms, and adjusted weight functions.
How it connects
Connects quantum registers with key registers, value registers, inverse quantum Fourier transforms, knapsack problems, and search oracles.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Quantum Software with Python. The section links point to the parts of the book it draws on.