Skip to content

Commit

Permalink
Merge branch 'main' of ssh://github.com/UCL-CCS/symmer into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisRalli committed Oct 9, 2024
2 parents ba290d2 + b842ec6 commit 2a314cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 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

6 changes: 3 additions & 3 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,12 +240,12 @@ 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.
TETRIS = False
topology_aware = True
topology_aware = False
topology_bias = 1
topology = None
subgraph_match_depth = 3
Expand Down

0 comments on commit 2a314cf

Please sign in to comment.