diff --git a/benchmarking.py b/benchmarking.py index 9628ec38..d564292d 100644 --- a/benchmarking.py +++ b/benchmarking.py @@ -345,13 +345,14 @@ def table_style(styler: plt.style , cols: List[Tuple[str]]) -> plt.style: if any('Gates' in col for col in cols): border_col = 'Gates' elif any('2Q Count' in col for col in cols): border_col = '2Q Count' elif any('T Count' in col for col in cols): border_col = 'T Count' + elif any('t_opt' in col for col in cols): border_col = 't_opt' styler.set_table_styles(dict.fromkeys([col for col in cols if border_col in col or ('Original' in col and 'Qubits' in col)], [{'selector': 'th', 'props': 'border-left: 1px solid white !important'}, {'selector': 'td', 'props': 'border-left: 1px solid white !important'}]), overwrite=False, axis=0) styler.apply(lambda s: np.where(s==np.nanmin(s.values),'color:green',''), axis=1, subset=[col for col in cols if 'Gates' in col]) styler.apply(lambda s: np.where(s==np.nanmin(s.values),'color:green',''), axis=1, subset=[col for col in cols if '2Q Count' in col]) styler.apply(lambda s: np.where(s==np.nanmin(s.values),'color:green',''), axis=1, subset=[col for col in cols if 'T Count' in col]) - styler.format(subset=[col for col in cols if 't_opt' or 't_simp' in col],precision=2, na_rep='-', thousands=",") - styler.format(subset=[col for col in cols if 't_opt' not in col and 't_simp' not in col],precision=0, na_rep='-', thousands=",") + styler.format(subset=[col for col in cols if 't_opt' in col],precision=2, na_rep='-', thousands=",") + styler.format(subset=[col for col in cols if 't_opt' not in col],precision=0, na_rep='-', thousands=",") return(styler) def df(self, groups: List[str] = ['all'], routines: List[str] = ['all'], funcs: List[str] = ['all'], atts: List[str] = ['all']) -> pd.DataFrame: diff --git a/demos/circuit_optimisation/benchmarking.ipynb b/demos/Circuit Optimisation/benchmarking_demo.ipynb similarity index 58% rename from demos/circuit_optimisation/benchmarking.ipynb rename to demos/Circuit Optimisation/benchmarking_demo.ipynb index 498e111f..d121c80c 100644 --- a/demos/circuit_optimisation/benchmarking.ipynb +++ b/demos/Circuit Optimisation/benchmarking_demo.ipynb @@ -16,9 +16,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "To use the benchmarking class, we first create our benchmark object. \n", + "The ``Benchmark`` class provides a convenient wrapper in order to compare different circuit optimisation methods. To use it, we first create our benchmark object. \n", "\n", - "If a previous object has been saved (using ``b.save('dirpath')``), we can load this directly from the directory." + "If a previous object has been saved (using ``Benchmark.save('dirpath')``), we can load this directly from the directory." ] }, { @@ -28,7 +28,7 @@ "outputs": [], "source": [ "b = Benchmark()\n", - "# b = Benchmark(dirpath='benchmark')" + "# b = Benchmark(dirpath='benchmarking_demo_results')" ] }, { @@ -39,7 +39,10 @@ "\n", "If we have a set of already optimised circuits via a different routine, we can also load these. \n", "\n", - "Here we load a set of optimised circuits using the routine from [Nam, Ross, Su, Childs, Maslov - Automated optimization of large quantum circuits with continuous parameters](https://www.nature.com/articles/s41534-018-0072-4)." + "Here we load sets of optimised circuits by the following two routines:\n", + "\n", + "* NRSCM - [Nam, Ross, Su, Childs, Maslov - Automated optimization of large quantum circuits with continuous parameters](https://www.nature.com/articles/s41534-018-0072-4).\n", + "* TPar - [Amy, Maslov, Mosca - Polynomial-time T-depth Optimization of Clifford+T circuits via Matroid Partitioning](https://arxiv.org/abs/1303.2042)" ] }, { @@ -53,7 +56,7 @@ "text": [ "Circuit attributes: ['Qubits', 'Gates', '2Q Count', 'T Count', 't_opt']\n", "No loaded functions\n", - "Loaded routines: ['NRSCM']\n", + "Loaded routines: ['TPar', 'NRSCM']\n", "Loaded circuit groups: ['fast']\n" ] }, @@ -80,6 +83,7 @@ " \n", " Original\n", " NRSCM\n", + " TPar\n", " \n", " \n", " \n", @@ -87,14 +91,15 @@ " fast\n", " Y\n", " Y\n", + " Y\n", " \n", " \n", "\n", "" ], "text/plain": [ - " Original NRSCM\n", - "fast Y Y" + " Original NRSCM TPar\n", + "fast Y Y Y" ] }, "metadata": {}, @@ -104,6 +109,7 @@ "source": [ "b.load_circuits(dirname=os.path.join('..', '..', 'circuits', 'benchmarking_circuits', 'Fast', 'before'), group_name='fast')\n", "b.load_circuits(dirname=os.path.join('..', '..', 'circuits', 'benchmarking_circuits', 'Fast', 'nrscm'), group_name='fast', simp_strategy='NRSCM')\n", + "b.load_circuits(dirname=os.path.join('..', '..', 'circuits', 'benchmarking_circuits', 'Fast', 'tpar'), group_name='fast', simp_strategy='TPar')\n", "b.show_attributes()" ] }, @@ -126,18 +132,24 @@ " if c2.twoqubitcount() < c1.twoqubitcount(): return c2 # As this optimisation algorithm is targetted at reducting H-gates, we use the circuit with the smaller 2-qubit gate count here, either using SWAP rules or not.\n", " return c1\n", "\n", + "def clifford_simp(c):\n", + " g = c.to_graph()\n", + " zx.clifford_simp(g, quiet=True)\n", + " c2 = zx.extract_circuit(g).to_basic_gates()\n", + " return basic_optimise(c2)\n", + "\n", "def full_reduce(c):\n", " g = c.to_graph()\n", - " zx.full_reduce(g,quiet=True)\n", - " c2 = zx.extract_circuit(g,up_to_perm=False).to_basic_gates()\n", + " zx.full_reduce(g, quiet=True)\n", + " c2 = zx.extract_circuit(g).to_basic_gates()\n", " return basic_optimise(c2)\n", "\n", "def flow_opt(c):\n", " g = c.to_graph()\n", " zx.teleport_reduce(g)\n", - " zx.to_graph_like(g, assert_bound_connections=False)\n", - " zx.flow_2Q_simp(g, cFlow=True, rewrites=['id_fuse','lcomp','pivot'], max_lc_unfusions=2, max_p_unfusions=2)\n", - " c2 = zx.extract_simple(g, up_to_perm=False).to_basic_gates()\n", + " zx.to_graph_like(g)\n", + " zx.flow_2Q_simp(g)\n", + " c2 = zx.extract_simple(g).to_basic_gates()\n", " return basic_optimise(c2)" ] }, @@ -168,8 +180,9 @@ "name": "stderr", "output_type": "stream", "text": [ - "Processing full-reduce on qft_4 : 100%|██████████| 31/31 [00:17<00:00, 1.74it/s]\n", - "Processing flow-opt-c2 on qft_4 : 100%|██████████| 31/31 [00:23<00:00, 1.31it/s]" + "Processing full-reduce on qft_4 : 100%|██████████| 31/31 [00:17<00:00, 1.73it/s]\n", + "Processing cliff-simp on qft_4 : 100%|██████████| 31/31 [00:08<00:00, 3.55it/s]\n", + "Processing flow-opt on qft_4 : 100%|██████████| 31/31 [00:28<00:00, 1.07it/s]" ] }, { @@ -177,8 +190,8 @@ "output_type": "stream", "text": [ "Circuit attributes: ['Qubits', 'Gates', '2Q Count', 'T Count', 't_opt']\n", - "Loaded functions: ['full-reduce', 'flow-opt-c2']\n", - "Loaded routines: ['NRSCM']\n", + "Loaded functions: ['full-reduce', 'cliff-simp', 'flow-opt']\n", + "Loaded routines: ['TPar', 'NRSCM']\n", "Loaded circuit groups: ['fast']\n" ] }, @@ -212,7 +225,9 @@ " \n", " Original\n", " NRSCM\n", - " flow-opt-c2\n", + " TPar\n", + " cliff-simp\n", + " flow-opt\n", " full-reduce\n", " \n", " \n", @@ -223,14 +238,16 @@ " Y\n", " Y\n", " Y\n", + " Y\n", + " Y\n", " \n", " \n", "\n", "" ], "text/plain": [ - " Original NRSCM flow-opt-c2 full-reduce\n", - "fast Y Y Y Y" + " Original NRSCM TPar cliff-simp flow-opt full-reduce\n", + "fast Y Y Y Y Y Y" ] }, "metadata": {}, @@ -239,9 +256,10 @@ ], "source": [ "b.add_simplification_func(func=full_reduce, name='full-reduce', groups_to_run=['fast'], verify=True, rerun=False)\n", + "b.add_simplification_func(func=clifford_simp, name='cliff-simp', groups_to_run=['fast'], verify=True, rerun=False)\n", "\n", - "b.add_simplification_func(func=flow_opt, name='flow-opt-c2', groups_to_run=None)\n", - "b.run(funcs_to_run=['flow-opt-c2'], groups_to_run=['fast'], verify=True, rerun=False)\n", + "b.add_simplification_func(func=flow_opt, name='flow-opt', groups_to_run=None)\n", + "b.run(funcs_to_run=['flow-opt'], groups_to_run=['fast'], verify=True, rerun=False)\n", "\n", "b.show_attributes()" ] @@ -262,95 +280,114 @@ "data": { "text/html": [ "\n", - "\n", + "
\n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", @@ -365,448 +402,608 @@ " \n", " \n", " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", "
 OriginalNRSCMflow-opt-c2full-reduceOriginalNRSCMTParcliff-simpflow-optfull-reduce
 Qubits2Q CountT Count2Q CountT Count2Q CountT Countt_opt2Q CountT Countt_optQubits2Q CountT Count2Q CountT Count2Q CountT Count2Q CountT Countt_opt2Q CountT Countt_opt2Q CountT Countt_opt
Circuits        
Adder8232432669456111561.25160560.41Adder8232432669456--2882280.21112561.47160560.39
QFT885684564256420.1678420.02QFT8856845642--72530.0256420.1978420.02
QFTAdd8161842521841121751120.572631120.10QFTAdd816184252184112--2211740.121751120.752631120.10
adder_8244093992912152761734.034281730.79adder_8244093992912158852155203510.432771734.134281730.79
barenco_tof_10191922241301001461000.372011000.29barenco_tof_10191922241301003281002281920.161461000.582011000.29
barenco_tof_352428181620160.0124160.01barenco_tof_3524281816541639240.0120160.0224160.01
barenco_tof_474856342837280.0357280.02barenco_tof_4748563428902867480.0137280.0657280.02
barenco_tof_597284504055400.0774400.03barenco_tof_59728450401324093720.0255400.1374400.03
csla_mux_3_original158070706473620.04164620.04csla_mux_3_original1580707064--124640.0373620.05164620.04
csum_mux_9_corrected3016819614084140840.35313840.18csum_mux_9_corrected3016819614084--1891680.12140840.40313840.21
gf2^4_mult1299112996894680.07341680.06gf2^4_mult1299112996832468112960.0394680.16341680.07
gf2^5_mult151541751541151461150.135461150.10gf2^5_mult151541751541155351111701550.061461150.285461150.10
gf2^6_mult182212522211502091500.251,0171500.23gf2^6_mult182212522211506491502462160.112091500.721,0171500.23
gf2^7_mult213003433002172832170.461,4372170.38gf2^7_mult213003433002179922173293010.192832171.311,4372170.35
gf2^8_mult244054484052643832640.812,0672640.65gf2^8_mult244054484052641,2562644483840.283832642.771,9622640.61
grover_59288336--2231661.262841660.17grover_59288336--317523322900.132231661.352841660.17
ham15-low17236161--214972.43342970.19ham15-low17236161----3841470.13214973.22342970.18
hwb67116105--101750.27140750.05hwb67116105----142950.03101750.29140750.05
mod5_45282828162080.022780.00mod5_4528282816481633220.012180.032780.01
mod_mult_5594849403540350.0493350.02mod_mult_559484940351613765430.0140350.0493350.02
mod_red_2111105119777383730.22159730.06mod_red_21111051197773290731431070.0483730.30159730.06
qcla_adder_10362332381831621821620.453621620.53qcla_adder_10362332381831627371622932120.391821620.533621620.49
qcla_com_72418620313295133950.78251950.59qcla_com_72418620313295496952361690.22133950.79251950.55
qcla_mod_7263824132922352962373.116232372.94qcla_mod_7263824132922351,1502495093510.602962373.286232372.92
qft_454669--44670.0353670.02qft_454669----58670.0244670.0353670.02
rc_adder_6149377714771470.11122470.04rc_adder_6149377714723063126550.0471470.11122470.05
tof_1019102119707178710.14137710.08tof_10191021197071232711561030.0778710.17137710.07
tof_351821141515150.0121150.01tof_3518211415351525190.0015150.0121150.01
tof_473035222324230.0246230.01tof_4730352223632348310.0124230.0246230.01
tof_594249303133310.0355310.02tof_5942493031943166430.0133310.0555310.01
vbe_adder_3107070502440240.1970240.02vbe_adder_310707050241142481560.0239240.1670240.02
\n" ], "text/plain": [ - "" + "" ] }, "metadata": {}, @@ -826,21 +1023,14 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - " 0%| | 0/11 [00:00\n", " \n", " \n", - " 2023-12-04T15:50:58.522289\n", + " 2024-01-17T21:37:10.001497\n", " image/svg+xml\n", " \n", " \n", @@ -890,7 +1080,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -941,7 +1131,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -985,7 +1175,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1023,7 +1213,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1075,7 +1265,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1134,7 +1324,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1165,7 +1355,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1182,7 +1372,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1256,7 +1446,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1272,7 +1462,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1315,7 +1505,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1331,7 +1521,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1347,7 +1537,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1398,7 +1588,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1414,7 +1604,7 @@ " \n", " \n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1693,9 +1883,9 @@ "L 1133.999248 19.8 \n", "L 1165.330799 19.8 \n", "L 1196.66235 19.8 \n", - "\" clip-path=\"url(#p68fbeb6eb1)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #1f77b4; stroke-width: 1.5\"/>\n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #1f77b4; stroke-width: 1.5\"/>\n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", @@ -1733,9 +1923,9 @@ "L 1133.999248 159.473186 \n", "L 1165.330799 154.70347 \n", "L 1196.66235 150.052997 \n", - "\" clip-path=\"url(#p68fbeb6eb1)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #ff7f0e; stroke-width: 1.5\"/>\n", + "\" clip-path=\"url(#p9b506aef86)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #ff7f0e; stroke-width: 1.5\"/>\n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", - " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", @@ -1836,7 +2026,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1853,7 +2043,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1870,7 +2060,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1887,7 +2077,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1904,7 +2094,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1921,7 +2111,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1938,7 +2128,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1955,7 +2145,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1981,7 +2171,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -1996,7 +2186,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2011,7 +2201,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2027,7 +2217,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2043,7 +2233,7 @@ " \n", " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2171,19 +2361,19 @@ "L 306.846307 97.235407 \n", "L 338.177858 97.235407 \n", "L 369.509408 97.235407 \n", - "\" clip-path=\"url(#pe822177b3f)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #1f77b4; stroke-width: 1.5\"/>\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #1f77b4; stroke-width: 1.5\"/>\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", @@ -2198,46 +2388,46 @@ "L 306.846307 33.866986 \n", "L 338.177858 22.077512 \n", "L 369.509408 19.8 \n", - "\" clip-path=\"url(#pe822177b3f)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #ff7f0e; stroke-width: 1.5\"/>\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #ff7f0e; stroke-width: 1.5\"/>\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + "L 181.520104 135.417225 \n", + "L 212.851654 135.819139 \n", + "L 244.183205 135.819139 \n", + "L 275.514756 135.149282 \n", + "L 306.846307 136.756938 \n", + "L 338.177858 134.345455 \n", + "L 369.509408 133.273684 \n", + "\" clip-path=\"url(#p1d05ab1cf1)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #2ca02c; stroke-width: 1.5\"/>\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", @@ -2275,7 +2465,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2292,7 +2482,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2309,7 +2499,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2326,7 +2516,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2343,7 +2533,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2360,7 +2550,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2377,7 +2567,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2394,7 +2584,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2420,7 +2610,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2434,7 +2624,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2449,7 +2639,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2464,7 +2654,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2479,7 +2669,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2494,7 +2684,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2509,7 +2699,7 @@ " \n", " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke: #eeeeee; stroke-width: 0.8; stroke-linecap: round\"/>\n", " \n", " \n", " \n", @@ -2550,19 +2740,19 @@ "L 720.422777 71.288372 \n", "L 751.754328 46.590698 \n", "L 783.085879 19.8 \n", - "\" clip-path=\"url(#p0c73dd8933)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #1f77b4; stroke-width: 1.5\"/>\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #1f77b4; stroke-width: 1.5\"/>\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", @@ -2577,19 +2767,19 @@ "L 720.422777 139.311628 \n", "L 751.754328 131.776744 \n", "L 783.085879 122.776744 \n", - "\" clip-path=\"url(#p0c73dd8933)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #ff7f0e; stroke-width: 1.5\"/>\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #ff7f0e; stroke-width: 1.5\"/>\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", @@ -2604,19 +2794,19 @@ "L 720.422777 133.24186 \n", "L 751.754328 123.613953 \n", "L 783.085879 115.451163 \n", - "\" clip-path=\"url(#p0c73dd8933)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #2ca02c; stroke-width: 1.5\"/>\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + "\" clip-path=\"url(#pf853ef52bc)\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #2ca02c; stroke-width: 1.5\"/>\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", " \n", " \n", @@ -2646,7 +2836,7 @@ "L 46.848125 377.795312 \n", "\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #1f77b4; stroke-width: 1.5\"/>\n", " \n", - " \n", + " \n", " \n", " \n", " \n", @@ -2746,7 +2936,7 @@ "L 131.52625 377.795312 \n", "\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #ff7f0e; stroke-width: 1.5\"/>\n", " \n", - " \n", + " \n", " \n", " \n", " \n", @@ -2844,11 +3034,11 @@ "L 226.212187 377.795312 \n", "\" style=\"fill: none; stroke-dasharray: 1.5,2.475; stroke-dashoffset: 0; stroke: #2ca02c; stroke-width: 1.5\"/>\n", " \n", - " \n", + " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", " \n", " \n", - " \n", - " \n", - " \n", " \n", " \n", " \n", " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", - " \n", + " \n", " \n", " \n", " \n", @@ -2939,16 +3126,16 @@ } ], "source": [ - "fig = b.Pt_graphs(funcs=['full-reduce', 'flow-opt-c2'], qubits=8, depth=400, cnot_prob=0.3, t_probs=[0.015*i for i in range(11)], ys=['2Q Count', 'T Count', 'Gates'], reps=20, overwrite=True, random_seed=42)" + "fig = b.Pt_graphs(funcs=['full-reduce', 'flow-opt'], qubits=8, depth=400, cnot_prob=0.3, t_probs=[0.015*i for i in range(11)], ys=['2Q Count', 'T Count', 'Gates'], reps=20, overwrite=True, random_seed=42)" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ - "# b.save('benchmark')" + "# b.save('benchmarking_demo_results')" ] } ], diff --git a/demos/circuit_optimisation/benchmark/circuit_groups.pkl b/demos/Circuit Optimisation/benchmarking_demo_results/circuit_groups.pkl similarity index 100% rename from demos/circuit_optimisation/benchmark/circuit_groups.pkl rename to demos/Circuit Optimisation/benchmarking_demo_results/circuit_groups.pkl diff --git a/demos/Circuit Optimisation/benchmarking_demo_results/circuits.pkl b/demos/Circuit Optimisation/benchmarking_demo_results/circuits.pkl new file mode 100644 index 00000000..fe83d163 Binary files /dev/null and b/demos/Circuit Optimisation/benchmarking_demo_results/circuits.pkl differ diff --git a/demos/Circuit Optimisation/benchmarking_demo_results/funcs.pkl b/demos/Circuit Optimisation/benchmarking_demo_results/funcs.pkl new file mode 100644 index 00000000..e4e8ce61 Binary files /dev/null and b/demos/Circuit Optimisation/benchmarking_demo_results/funcs.pkl differ diff --git a/demos/Circuit Optimisation/benchmarking_demo_results/rand_data.pkl b/demos/Circuit Optimisation/benchmarking_demo_results/rand_data.pkl new file mode 100644 index 00000000..c9f5743d Binary files /dev/null and b/demos/Circuit Optimisation/benchmarking_demo_results/rand_data.pkl differ diff --git a/demos/Circuit Optimisation/benchmarking_demo_results/routines.pkl b/demos/Circuit Optimisation/benchmarking_demo_results/routines.pkl new file mode 100644 index 00000000..7cb0e902 Binary files /dev/null and b/demos/Circuit Optimisation/benchmarking_demo_results/routines.pkl differ diff --git a/demos/Circuit Optimisation/flow_opt_benchmarking.ipynb b/demos/Circuit Optimisation/flow_opt_benchmarking.ipynb new file mode 100644 index 00000000..c5837b68 --- /dev/null +++ b/demos/Circuit Optimisation/flow_opt_benchmarking.ipynb @@ -0,0 +1,1615 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import sys, os, time\n", + "sys.path.append('../..')\n", + "import pyzx as zx\n", + "from benchmarking import Benchmark" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This notebook demonstrates the results from [Causal flow preserving optimisation of quantum circuits in the ZX-calculus](https://arxiv.org/abs/2312.02793)." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "# b = Benchmark()\n", + "b = Benchmark(dirpath='flow_opt_results')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Circuit metrics are benchmarked against those of Nam, Ross, Su, Childs, Maslov (NRSCM) in [Automated optimization of large quantum circuits with continuous parameters](https://www.nature.com/articles/s41534-018-0072-4)." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Circuit attributes: ['Qubits', 'Gates', '2Q Count', 'T Count', 't_opt']\n", + "Loaded functions: ['flow-opt-g0', 'flow-opt-c0', 'flow-opt-c1', 'flow-opt-c2', 'flow-opt-c3', 'flow-opt-c4', 'flow-opt-c5']\n", + "Loaded routines: ['NRSCM']\n", + "Loaded circuit groups: ['fast']\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
OriginalNRSCMflow-opt-c0flow-opt-c1flow-opt-c2flow-opt-c3flow-opt-c4flow-opt-c5flow-opt-g0
fastYYYYYYYYY
\n", + "
" + ], + "text/plain": [ + " Original NRSCM flow-opt-c0 flow-opt-c1 flow-opt-c2 flow-opt-c3 \\\n", + "fast Y Y Y Y Y Y \n", + "\n", + " flow-opt-c4 flow-opt-c5 flow-opt-g0 \n", + "fast Y Y Y " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "b.load_circuits(dirname=os.path.join('..', '..', 'circuits', 'benchmarking_circuits', 'Fast', 'before'), group_name='fast')\n", + "b.load_circuits(dirname=os.path.join('..', '..', 'circuits', 'benchmarking_circuits', 'Fast', 'nrscm'), group_name='fast', simp_strategy='NRSCM')\n", + "b.show_attributes()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "100%|██████████| 31/31 [00:00<00:00, 100326.72it/s]\n", + "100%|██████████| 31/31 [00:00<00:00, 677205.33it/s]\n", + "100%|██████████| 31/31 [00:00<00:00, 673696.50it/s]\n", + "100%|██████████| 31/31 [00:00<00:00, 274890.96it/s]\n", + "100%|██████████| 31/31 [00:00<00:00, 812646.40it/s]\n", + "100%|██████████| 31/31 [00:00<00:00, 935420.32it/s]\n", + "100%|██████████| 31/31 [00:00<00:00, 333393.39it/s]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Circuit attributes: ['Qubits', 'Gates', '2Q Count', 'T Count', 't_opt']\n", + "Loaded functions: ['flow-opt-g0', 'flow-opt-c0', 'flow-opt-c1', 'flow-opt-c2', 'flow-opt-c3', 'flow-opt-c4', 'flow-opt-c5']\n", + "Loaded routines: ['NRSCM']\n", + "Loaded circuit groups: ['fast']\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
OriginalNRSCMflow-opt-c0flow-opt-c1flow-opt-c2flow-opt-c3flow-opt-c4flow-opt-c5flow-opt-g0
fastYYYYYYYYY
\n", + "
" + ], + "text/plain": [ + " Original NRSCM flow-opt-c0 flow-opt-c1 flow-opt-c2 flow-opt-c3 \\\n", + "fast Y Y Y Y Y Y \n", + "\n", + " flow-opt-c4 flow-opt-c5 flow-opt-g0 \n", + "fast Y Y Y " + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "def basic_optimise(c):\n", + " c1 = zx.basic_optimization(c.copy(), do_swaps=False).to_basic_gates()\n", + " c2 = zx.basic_optimization(c.copy(), do_swaps=True).to_basic_gates()\n", + " if c2.twoqubitcount() < c1.twoqubitcount(): return c2 # As this optimisation algorithm is targetted at reducting H-gates, we use the circuit with the smaller 2-qubit gate count here, either using SWAP rules or not.\n", + " return c1\n", + "\n", + "for flow,smax in [('g',0), ('c',0), ('c',1), ('c',2), ('c',3), ('c',4), ('c',5)]:\n", + " def flow_opt(c):\n", + " g = c.to_graph()\n", + " zx.teleport_reduce(g)\n", + " zx.to_graph_like(g)\n", + " zx.flow_2Q_simp(g, cFlow=flow=='c', max_lc_unfusions=smax, max_p_unfusions=smax)\n", + " if flow == 'c': c2 = zx.extract_simple(g).to_basic_gates()\n", + " else: c2 = zx.extract_circuit(g).to_basic_gates()\n", + " return basic_optimise(c2)\n", + " \n", + " b.add_simplification_func(func=flow_opt, name=f'flow-opt-{flow}{smax}', groups_to_run=['fast'], verify=True, rerun=False)\n", + "\n", + "b.show_attributes()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 OriginalNRSCMflow-opt-c0flow-opt-c1flow-opt-c2flow-opt-c3flow-opt-c4flow-opt-c5flow-opt-g0
 Qubits2Q CountT Count2Q CountT Count2Q CountT Count2Q CountT Count2Q CountT Count2Q CountT Count2Q CountT Count2Q CountT Count2Q CountT Count
Circuits                   
Adder823243266945612456115561125610856108561085612456
QFT88568456425642564256425642484245424242
QFTAdd816184252184112176112176112175112174112149112135112165112
adder_824409399291215295173284173277173269173267173268173296173
barenco_tof_1019192224130100159100151100146100146100146100146100159100
barenco_tof_35242818162116211620162016201620162116
barenco_tof_47485634284228372837283728372837284228
barenco_tof_59728450406340574055405540554055406340
csla_mux_3_original15807070647462736273627362736273627462
csum_mux_9_corrected301681961408415284150841408414084140841408415184
gf2^4_mult129911299689968996894689468946894689868
gf2^5_mult15154175154115154115154115146115146115146115146115153115
gf2^6_mult18221252221150221150221150209150209150209150209150217150
gf2^7_mult21300343300217300217300217283217283217283217283217293217
gf2^8_mult24405448405264405264405264383264383264383264383264395264
grover_59288336--228166228166223166219166220166212166228166
ham15-low17236161--23097224972149720897212972139723097
hwb67116105--987510275101759875987598759775
mod5_4528282816258238218218218218238
mod_mult_559484940354035403540354035403540354035
mod_red_211110511977738773867383738373837383738573
qcla_adder_1036233238183162200162189162182162180162174162175162200162
qcla_com_7241862031329513695134951339513395131951319513695
qcla_mod_726382413292235312237310237296237293237293237292237312237
qft_454669--4567446744674467446744674567
rc_adder_614937771477147714771477147714771477147
tof_101910211970717871787178717871787178717871
tof_35182114151515151515151515151515151515
tof_47303522232423242324232423242324232423
tof_59424930313331333133313331333133313331
vbe_adder_310707050244624442439244024362436244624
\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "df = b.df(groups=['fast'], routines=['all'], funcs=['all'], atts=['Qubits','2Q Count','T Count'])" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
 Originalflow-opt-c0flow-opt-c1flow-opt-c2flow-opt-c3flow-opt-c4flow-opt-c5flow-opt-g0
 Qubitst_optt_optt_optt_optt_optt_optt_opt
Circuits        
Adder8230.440.651.495.1613.0530.530.28
QFT880.020.030.161.5217.2470.570.02
QFTAdd8160.140.180.794.9718.8447.900.12
adder_8240.571.034.2020.0772.87207.770.46
barenco_tof_10190.200.290.622.147.5921.570.18
barenco_tof_350.010.010.020.030.050.080.01
barenco_tof_470.020.030.060.180.651.920.02
barenco_tof_590.040.060.130.481.744.960.03
csla_mux_3_original150.030.040.050.100.290.730.03
csum_mux_9_corrected300.160.220.410.600.800.950.15
gf2^4_mult120.050.070.130.512.277.930.05
gf2^5_mult150.090.120.291.8210.3247.290.08
gf2^6_mult180.160.220.756.1742.76227.310.14
gf2^7_mult210.270.361.3613.59106.82686.690.23
gf2^8_mult240.470.622.7933.13309.612,343.700.40
grover_590.430.561.333.175.988.150.30
ham15-low170.200.463.2817.7854.04579.600.17
hwb670.060.130.300.922.043.900.09
mod5_450.010.020.030.050.080.160.01
mod_mult_5590.020.020.040.060.140.160.02
mod_red_21110.070.120.310.812.666.460.06
qcla_adder_10360.160.240.542.058.6011.860.17
qcla_com_7240.150.230.822.898.0117.260.13
qcla_mod_7260.460.703.2323.73223.861,463.860.36
qft_450.020.020.040.090.070.110.02
rc_adder_6140.040.060.110.260.390.470.04
tof_10190.060.080.170.461.001.400.07
tof_350.010.010.010.020.020.030.01
tof_470.010.010.020.080.080.110.02
tof_590.020.020.050.130.270.400.02
vbe_adder_3100.030.060.200.430.630.820.03
\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "df = b.df(groups=['fast'], routines=['all'], funcs=['all'], atts=['Qubits','t_opt'])" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "b.save('flow_opt_results')" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "pyzx", + "language": "python", + "name": "pyzx" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/demos/Circuit Optimisation/flow_opt_results/circuit_groups.pkl b/demos/Circuit Optimisation/flow_opt_results/circuit_groups.pkl new file mode 100644 index 00000000..92aa2a5c Binary files /dev/null and b/demos/Circuit Optimisation/flow_opt_results/circuit_groups.pkl differ diff --git a/demos/Circuit Optimisation/flow_opt_results/circuits.pkl b/demos/Circuit Optimisation/flow_opt_results/circuits.pkl new file mode 100644 index 00000000..225c9f6c Binary files /dev/null and b/demos/Circuit Optimisation/flow_opt_results/circuits.pkl differ diff --git a/demos/Circuit Optimisation/flow_opt_results/funcs.pkl b/demos/Circuit Optimisation/flow_opt_results/funcs.pkl new file mode 100644 index 00000000..10607bca Binary files /dev/null and b/demos/Circuit Optimisation/flow_opt_results/funcs.pkl differ diff --git a/demos/Circuit Optimisation/flow_opt_results/rand_data.pkl b/demos/Circuit Optimisation/flow_opt_results/rand_data.pkl new file mode 100644 index 00000000..e2ecf720 --- /dev/null +++ b/demos/Circuit Optimisation/flow_opt_results/rand_data.pkl @@ -0,0 +1 @@ +€}”. \ No newline at end of file diff --git a/demos/circuit_optimisation/benchmark/routines.pkl b/demos/Circuit Optimisation/flow_opt_results/routines.pkl similarity index 100% rename from demos/circuit_optimisation/benchmark/routines.pkl rename to demos/Circuit Optimisation/flow_opt_results/routines.pkl diff --git a/demos/circuit_optimisation/qft-opt.ipynb b/demos/Circuit Optimisation/qft-opt.ipynb similarity index 96% rename from demos/circuit_optimisation/qft-opt.ipynb rename to demos/Circuit Optimisation/qft-opt.ipynb index 3d0fb56a..5026d18f 100644 --- a/demos/circuit_optimisation/qft-opt.ipynb +++ b/demos/Circuit Optimisation/qft-opt.ipynb @@ -12,6 +12,13 @@ "import numpy as np" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This notebook demonstrates a particularly effective method for optimising QFT circuits, as noted in [https://arxiv.org/abs/2312.02793](https://arxiv.org/abs/2312.02793)." + ] + }, { "cell_type": "code", "execution_count": 2, @@ -20,7 +27,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" @@ -362,7 +392,7 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" @@ -705,6 +758,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ + "This results in exactly one non-Clifford gate per two-qubit gate.\n", + "\n", "These two circuits are equal as evidenced by equal matrices. Note that the way the matrices are calculated introduces some rounding errors (e.g. see the 0,0 element below)." ] }, diff --git a/demos/circuit_optimisation/benchmark/circuits.pkl b/demos/circuit_optimisation/benchmark/circuits.pkl deleted file mode 100644 index 981f54e1..00000000 Binary files a/demos/circuit_optimisation/benchmark/circuits.pkl and /dev/null differ diff --git a/demos/circuit_optimisation/benchmark/funcs.pkl b/demos/circuit_optimisation/benchmark/funcs.pkl deleted file mode 100644 index 7e02d3a0..00000000 Binary files a/demos/circuit_optimisation/benchmark/funcs.pkl and /dev/null differ diff --git a/demos/circuit_optimisation/benchmark/rand_data.pkl b/demos/circuit_optimisation/benchmark/rand_data.pkl deleted file mode 100644 index 482081e0..00000000 Binary files a/demos/circuit_optimisation/benchmark/rand_data.pkl and /dev/null differ diff --git a/demos/CNOT-Benchmark.ipynb b/scratchpads/CNOT-Benchmark.ipynb similarity index 100% rename from demos/CNOT-Benchmark.ipynb rename to scratchpads/CNOT-Benchmark.ipynb diff --git a/demos/T-count Benchmark.ipynb b/scratchpads/T-count Benchmark.ipynb similarity index 100% rename from demos/T-count Benchmark.ipynb rename to scratchpads/T-count Benchmark.ipynb