pyqpanda_alg.QLuoShu.VarModDou
¶
Module Contents¶
Functions¶
|
Quantum Circuit for Variant Modular Doubling for Odd Modulo. |
- pyqpanda_alg.QLuoShu.VarModDou.VarModDou(qvec, aux, N)¶
Quantum Circuit for Variant Modular Doubling for Odd Modulo.
- Parameters:
\(qvec\) :
qlist
holds the integer \(x\)
aux :
qubit
an auxiliary qubit to control constant modulo addition
\(N\) :
int
the constant modulo
- Return:
circuit :
VarModDou.QCircuit
The circuit is used to compute modular doubling that \(|x \rangle |0 \rangle \rightarrow |2x \mod N\rangle|0\rangle\). The modular doubling circuit for a constant odd integer modulus \(N\). There are two changes that make it more efficient than the addition circuit. First, it works in place on only one \(n\)-qubit input integer \(|x \rangle\), with \(n=\lceil \log_{2}N \rceil\). Therefore it uses only \(n+1\) qubits.
- Example:
If \(x =7, N=11\), putting \(x\) held in \(|qvec \rangle\). By the circuit, the result \(|0011 \rangle\) will be held in the \(|qvec \rangle\), i.e., \(2*7 \mod 11=3\).
from pyqpanda import * import math from pyqpanda_alg.QLuoShu import VarModDou if __name__ == "__main__": N = 11 x = 7 n = math.ceil(math.log(N, 2)) qvm = init_quantum_machine(QMachineType.CPU) prog = QProg() qvec = qvm.qAlloc_many(n) aux = qvm.qAlloc_many(1) prog << bind_nonnegative_data(x, qvec) \ << VarModDou.VarModDou(qvec, aux, N) result = prob_run_dict(prog, qvec, 1) for key in result: print(key + ":" + str(result[key])) c = int(key, 2) print("2*%d mod %d=%d" % (x, N, c))
0011:0.9999999999999982 2*7 mod 11=3
Note that: \(N\) is an odd integer.