Grover: factorize number
from typing import Tuple
from qlasskit import qlassf, Qint
from qlasskit.algorithms import Grover
@qlassf
def factorize(a: Tuple[Qint[2], Qint[2]]) -> bool:
return a[0] * a[1] == 9
q_algo = Grover(factorize)
from qiskit import QuantumCircuit, transpile
from qiskit.visualization import plot_histogram
from qiskit_aer import AerSimulator
qc = q_algo.export("qiskit")
qc.measure_all()
simulator = AerSimulator()
circ = transpile(qc, simulator)
result = simulator.run(circ).result()
counts = result.get_counts(circ)
counts_readable = q_algo.decode_counts(counts, discard_lower=5)
plot_histogram(counts_readable)
![_images/a8e68097f8738467945b57489cb75c8b58528f2d581316465ab6403de8225d56.png](_images/a8e68097f8738467945b57489cb75c8b58528f2d581316465ab6403de8225d56.png)
qc.draw("mpl")
![_images/a1154c255c589e0e4d1936fc4b97b314aad8947cab4b38c090c94fd12164d179.png](_images/a1154c255c589e0e4d1936fc4b97b314aad8947cab4b38c090c94fd12164d179.png)