<jupyter_start><jupyter_text>Running Grover's algorithm on k4  Define the graphThe graph being searched is the following:The vertices will start at top left and go clockwise lexographically, i.e.```A    BD    C```<jupyter_code>edges = [('A', 'B'), ('B', 'C'), ('C', 'D'), ('D', 'A'), ('A', 'C'), ('B', 'D')]<jupyter_output><empty_output><jupyter_text>Grover Experiments!First, use the autowrapper, then break it down and see what's going on under the hood!<jupyter_code>from graph_utils import groversearch, evaluators<jupyter_output><empty_output><jupyter_text>Running it on k4<jupyter_code>groversearch.run_grovers(edges, plot=True)<jupyter_output>Grover's search on n = 4 vertices:
Time elapsed: 0.2667112350463867s

      ┌───┐┌────┐┌─┐         
 q_0: ┤ H ├┤0   ├┤M├─────────
      ├───┤│    │└╥┘┌─┐      
 q_1: ┤ H ├┤1   ├─╫─┤M├──────
      ├───┤│    │ ║ └╥┘┌─┐   
 q_2: ┤ H ├┤2   ├─╫──╫─┤M├───
      ├───┤│    │ ║  ║ └╥┘┌─┐
 q_3: ┤ H ├┤3 Q ├─╫──╫──╫─┤M├
      └───┘│    │ ║  ║  ║ └╥┘
 q_4: ─────┤4   ├─╫──╫──╫──╫─
           │    │ ║  ║  ║  ║ 
 q_5: ─────┤5   ├─╫──╫──╫──╫─
           │    │ ║  ║  ║  ║ 
 q_6: ─────┤6   ├─╫──╫──╫──╫─
           └────┘ ║  ║  ║  ║ 
c0: 4/════════════╩══╩══╩══╩═
                  0  1  2  3<jupyter_text>Under the Hood  Generate the Ground Truth Table<jupyter_code>evlr = evaluators.HamiltonianEvaluator(edges)
truth_table = evlr.generate_truth_table()
truth_table<jupyter_output><empty_output><jupyter_text>And all of the Hamiltonian cycles<jupyter_code>for edges, is_hamiltonian in truth_table.items():
    if is_hamiltonian:
        print(edges)<jupyter_output>(('A', 'B'), ('B', 'C'), ('C', 'D'), ('D', 'A'))
(('A', 'B'), ('C', 'D'), ('A', 'C'), ('B', 'D'))
(('B', 'C'), ('D', 'A'), ('A', 'C'), ('B', 'D'))<jupyter_text>Running Grover's Calculate the theoretical number of shots required:$O(\sqrt{\binom{E}{V}})$ vs. $O(2^E)$<jupyter_code>import math

truth_map = groversearch.get_truth_map(truth_table)
shots = math.ceil(math.sqrt(len(truth_map)))
shots
shots = 1024
result = groversearch.call_grover(truth_map, len(evlr.vertices),
                                  shots=shots)<jupyter_output>Grover's search on n = 4 vertices:
Time elapsed: 0.09552597999572754s<jupyter_text>Visualization<jupyter_code>from qiskit.tools.visualization import plot_histogram<jupyter_output><empty_output><jupyter_text>Plot the probabilities of all of the combinations<jupyter_code>plot_histogram(result['measurement'], title='Possible Hamiltonian Cycles')<jupyter_output><empty_output><jupyter_text>Create a quick helper function to convert enumerations into edge sets<jupyter_code>combinations_set = list(truth_table.keys())
enumeration_to_edges = lambda bin_combo: combinations_set[int(str(bin_combo), 2)]<jupyter_output><empty_output><jupyter_text>Interactive demo<jupyter_code>combo = input('Input the edge combination: ')
print(enumeration_to_edges(combo))<jupyter_output>Input the edge combination1101
(('B', 'C'), ('D', 'A'), ('A', 'C'), ('B', 'D'))
{'fraction_non_alphanumeric': 0.20959087860496312, 'fraction_numerical': 0.023138832997987926, 'mean_word_length': 4.883629191321499, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '409346', 'license': 'MIT', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1276, 'n_words': 264, 'path': 'grovers-k4.ipynb', 'repo_name': 'agupta231/ma3233-final-project', 'size': '2982'}