Skip to content

Commit

Permalink
Merge pull request #191 from UCL-CCS/adapt_bugfix
Browse files Browse the repository at this point in the history
Fixes to subgraph isomorphism utils
  • Loading branch information
TimWeaving authored Oct 9, 2024
2 parents 810243e + 1b1a3e2 commit fa575b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 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

4 changes: 2 additions & 2 deletions symmer/evolution/variational_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class VQE_Driver:
expectation_eval (str): expectation value method. Its default value is 'symbolic_direct'.
verbose (bool): If True, prints out useful information during computation. By default it is set to 'True'.
"""
expectation_eval = 'symbolic_direct'
expectation_eval = 'sparse_array'
# prints out useful information during computation:
verbose = True

Expand Down Expand Up @@ -240,7 +240,7 @@ class ADAPT_VQE(VQE_Driver):
# method by which to calculate the operator pool derivatives, either
# commutators: compute the commutator of the observable with each pool element
# param_shift: use the parameter shift rule, requiring two expectation values per derivative
derivative_eval = 'commutators'
derivative_eval = 'param_shift'
# we have alost implemented TETRIS-ADAPT-VQE as per https://doi.org/10.48550/arXiv.2209.10562
# that aims to reduce circuit-depth in the ADAPT routine by adding multiple excitation terms
# per cycle that are supported on distinct qubit positions.
Expand Down

0 comments on commit fa575b1

Please sign in to comment.