From 4d586f16d7e2d5e1fca3348391d31cf6297fefdc Mon Sep 17 00:00:00 2001 From: TimWeaving Date: Wed, 9 Oct 2024 13:17:03 +0100 Subject: [PATCH 1/4] Fixes to subgraph isomorphism utils --- symmer/evolution/utils.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/symmer/evolution/utils.py b/symmer/evolution/utils.py index 42af29b8..d7ef5ba5 100644 --- a/symmer/evolution/utils.py +++ b/symmer/evolution/utils.py @@ -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 @@ -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 \ No newline at end of file + """ + """ + 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 + From 31ebf52331b451802a367a304c2c0caff0e36a62 Mon Sep 17 00:00:00 2001 From: TimWeaving Date: Wed, 9 Oct 2024 13:21:23 +0100 Subject: [PATCH 2/4] Changed default expectation_eval to sparse_array and derivative_eval to param_shift --- symmer/evolution/variational_optimization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symmer/evolution/variational_optimization.py b/symmer/evolution/variational_optimization.py index 304aad50..81f121ca 100644 --- a/symmer/evolution/variational_optimization.py +++ b/symmer/evolution/variational_optimization.py @@ -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 From 1b1a3e2dedceff8a0ef5e7d7d1d775fc39d4b7ab Mon Sep 17 00:00:00 2001 From: TimWeaving Date: Wed, 9 Oct 2024 13:21:36 +0100 Subject: [PATCH 3/4] derivative_eval -> param_shift --- symmer/evolution/variational_optimization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symmer/evolution/variational_optimization.py b/symmer/evolution/variational_optimization.py index 81f121ca..f5c3e9a9 100644 --- a/symmer/evolution/variational_optimization.py +++ b/symmer/evolution/variational_optimization.py @@ -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. From 530faad4f38d8ebfd15712526cca1b30f2112f02 Mon Sep 17 00:00:00 2001 From: TimWeaving Date: Wed, 9 Oct 2024 13:25:43 +0100 Subject: [PATCH 4/4] Not topology aware by default --- symmer/evolution/variational_optimization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symmer/evolution/variational_optimization.py b/symmer/evolution/variational_optimization.py index f5c3e9a9..e264a822 100644 --- a/symmer/evolution/variational_optimization.py +++ b/symmer/evolution/variational_optimization.py @@ -245,7 +245,7 @@ class ADAPT_VQE(VQE_Driver): # 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