Implementation of the algorithm introduced in
Joonas Ilmavirta, Matti Lassas, Jinpeng Lu, Lauri Oksanen, Lauri Ylinen. Quantum computing algorithms for inverse problems on graphs and an NP-complete inverse problem. https://arxiv.org/abs/2306.05253
Given an incidence matrix
We begin by computing the shortest paths in the graph. These are encoded by
We set
Test 1.
Method c_paths
in classical.py computes Paths
in circuits.py. The classical and quantum implementations both use the method paths_test1_vars
that sets up variables so that the above Test 1 can be performed using ANDs and ORs.
In practice, we will use a minimal number of indices to encode the edges, rather than the incidence matrix.
In paths_test1_vars
, the variable paths[i]
with index i = ix.path(d, j, k)
corresponds to paths
. The duplication is avoided by using the function prev(p)
to choose a value either from paths
or from edges
where the latter corresponds to
The distances are checked by
Test 2.
This is implemented by c_dis_check
in classical.py for testing purposes, and the corresponding quantum circuit is Dist_check
in circuits.py. The classical and quantum implementations both use the method dist_check_test2_flags
that sets up flag variables so that the above Test 2 can be performed using ANDs and NOTs.
The method c_dist_check_groups
calls c_dist_check
several times. With the grouping given by dmat2ds_groups
in expected.py, its quantum analogue Dist_check_groups
can be used to implement the algorithm for which the number of qubits scales as Dist_check
directly without grouping yields the complexity
Bitflip2Phaseflip
is a generic circuit that converts a bit flip oracle to a phase flip oracle. After this conversion, Dist_check
and Dist_check_groups
can be used as oracles in Grover's algorithm, implemented in grover.py.
Example driver routines running Grover's algorithm are given in driver.ipynb. Notebook simulation.ipynb reproduces the plots in Figure 3 in Appendix A of Quantum computing algorithms for inverse problems on graphs and an NP-complete inverse problem.
Tests that attempt to verify correctness of the oracle are implemented in test_circuits.py. The tests are designed to be run using pytest framework.