Ullmann -- some more

This commit is contained in:
Théophile Bastian 2017-08-22 16:43:33 +02:00
parent 0bf014766a
commit 2dbaba6779

View file

@ -377,7 +377,7 @@ out to be still too slow in real-world cases --- which looks unlikely ---,
would be to try to multithread this computation.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Group equality}
\section{Group equality}\label{sec:group_equality}
Given two circuit group gates, the task of group equality is to determine
whether the two groups are structurally equivalent, as discussed above.
@ -517,17 +517,55 @@ The refining function is detailed in Figure~\ref{alg:ullmann_refine}.
\caption{Ullmann's refining function}\label{alg:ullmann_refine}
\end{figure}
\subsection{Ullmann for \emph{isomatch}}
\paragraph{Graph used.} Our circuit is not actually a graph just as-is: indeed,
a wire can be connected to multiple circuits (multiple gates' inputs, or even
multiple gates' outputs when using tristate circuits). This could be transposed
into a graph with $\frac{n(n-1)}{2}$ edges (the complete subgraph) for this
particular wire. Though, internally, a wire is better represented as a vertex
itself, with $n$ edges linking it to the connected gates. This representation
is also used in Ullmann's implementation, leading to a permutation matrix of
$\left(\card{\text{needle gates}} + \card{\text{needle wires}}\right) \times
\left(\card{\text{haystack gates}} + \card{\text{haystack wires}}\right)$.
\paragraph{Final result.} Once a result (\ie{} a correct permutation) is
obtained, we further need to check it is actually a solution of our problem.
Indeed, while the structure is guaranteed by the algorithm to be the same, we
still need to check that every circuit is equal to its matched one, through the
procedure described in Section~\ref{sec:group_equality}. So far, only the
equality of signatures was checked. We only need to check the circuits, as the
wires are necessarily actually matching.
\paragraph{Non-overlapping results.} We want our results to be non-overlapping
(because we won't be able to perform a search-and-replace if it is not the
case). Whenever two potential results are conflicting, an arbitrary one of the
two can be returned (a human user is operating the software and can make a
narrower search if needed).
To match this specification, we must keep track of the circuits that are
already included in a match. We also cannot include an ancestor of a circuit
that was included in a match in another match (though this is not possible,
because the needle can't be included in itself, but signature collisions could
occur).
\subsection{Implementation optimisations}
\paragraph{Initial permutation matrix.} The matrix is first filled according to
the signatures matches. It is then refined a bit more, by making sure that for
every match, every potentially matching gate has the same ``wire kinds''.
Indeed, a gate needle's wire must have at least the same inbound adjacent
signatures as its matching haystack wire, and same goes for outbound adjacent
signatures. Thus, two circuits cannot be matched if this condition is not
respected for each pair of corresponding wires of those circuits, and their
corresponding cell in the permutation matrix can be nulled.
The matrix is first filled according to the signatures matches. It is then
refined a bit more, by making sure that for every match, every potentially
matching gate has the same ``wire kinds''. Indeed, a gate needle's wire must
have at least the same inbound adjacent signatures as its matching haystack
wire, and same goes for outbound adjacent signatures. Thus, two circuits cannot
be matched if this condition is not respected for each pair of corresponding
wires of those circuits, and their corresponding cell in the permutation matrix
can be nulled.
\paragraph{Pre-check.} The needle will, in most cases, not be found at all in
a given hierarchy group of the haystack. To avoid wasting computation time, we
first check that every signature present in the needle is present at least as
many times in the haystack. This simple check saved a lot of time.
\todo{More stuff?}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Performance}