Skip to content

Commit

Permalink
Fixes to subgraph isomorphism utils
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWeaving committed Oct 9, 2024
1 parent 0f42360 commit 4d586f1
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions symmer/evolution/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def get_CNOT_connectivity_graph(evolution_obj:Union[PauliwordOp,QuantumCircuit],
return G

def _subgraph_isomorphism_distance(G, target, depth=0):

"""
"""
if depth == 0:
if GraphMatcher(target, G).subgraph_is_isomorphic():
return 0
Expand All @@ -56,17 +57,28 @@ def _subgraph_isomorphism_distance(G, target, depth=0):
return None

def subgraph_isomorphism_distance(G, target, max_depth=3):
"""
"""
depth = 0
for depth in range(max_depth):
dist = _subgraph_isomorphism_distance(G, target, depth)
if dist is not None:
return depth * dist
return dist
else:
depth += 1
return None

def topology_match_score(ansatz_operator, topology, max_depth=3):
entangling_graph = get_CNOT_connectivity_graph(ansatz_operator)
subgraph_cost = subgraph_isomorphism_distance(entangling_graph, topology, max_depth=max_depth)
n_entangling_gates = np.count_nonzero(ansatz_operator.X_block | ansatz_operator.Z_block)
return 1-subgraph_cost/n_entangling_gates
"""
"""
n_entangling_gates = 2*(np.count_nonzero(ansatz_operator.X_block | ansatz_operator.Z_block)-ansatz_operator.n_terms)
if n_entangling_gates == 0:
return 1
else:
entangling_graph = get_CNOT_connectivity_graph(ansatz_operator)
subgraph_cost = subgraph_isomorphism_distance(entangling_graph, topology, max_depth=max_depth)
if subgraph_cost is None:
return 0
else:
return 1-subgraph_cost/n_entangling_gates

0 comments on commit 4d586f1

Please sign in to comment.