2

I am trying to implement small codes for quantum kernel estimation with Qiskit. In this challenge, I face the difficulty of implementing modular multiplication under a given prime number $p$. I have found some articles and a function in Qiskit to take modular multiplication under $N$, where $N = 2^n$ and $n$ is the number of qubits. However, I don't see a construction of modular multiplication under a given prime $p$. I know this is a big topic in quantum computing and many discussions about it must exist. But simply I could not find it.

Could anybody explain how to implement modular multiplication under a given prime $p$ to me or provide literature about it with me, please?

Thank you very much.

ksk S
  • 53
  • 5

1 Answers1

2

You can find an example construction in "Factoring with n+2 clean qubits and n-1 dirty qubits". It won't be the best one, but it has a diagram for every step.

The simplest decomposition chain I know is as follows (where each entry can be implemented using the next):

  1. Modular multiplication (q_x *= K (mod p))
  2. Modular fused-multiply-add (q_x += q_y * K (mod p))
  3. Controlled modular addition (if q_c: q_x += q_y (mod p))
  4. Controlled addition + comparisons (q_c = q_x < q_y) (if q_c: q_x += q_y (mod 2**n))
  5. Toffolis

This maybe gives a sense of why it's rare to find self-contained explanations of the implementation. Because any reasonable explanation is going to cover several pages of details.

Craig Gidney
  • 47,099
  • 1
  • 44
  • 119