.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/qft_with_tn.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_qft_with_tn.py: Large-scale simulations with tensor network simulator ===================================================== In this example, we demonstrate simulation of MBQC involving 10k+ nodes. You can also run this code on your browser with `mybinder.org `_ - click the badge below. .. image:: https://mybinder.org/badge_logo.svg :target: https://mybinder.org/v2/gh/TeamGraphix/graphix-examples/HEAD?labpath=qft_with_tn.ipynb Firstly, let us import relevant modules and define the circuit: .. GENERATED FROM PYTHON SOURCE LINES 16-47 .. code-block:: default import numpy as np from graphix import Circuit def cp(circuit, theta, control, target): circuit.rz(control, theta / 2) circuit.rz(target, theta / 2) circuit.cnot(control, target) circuit.rz(target, -1 * theta / 2) circuit.cnot(control, target) def qft_rotations(circuit, n): circuit.h(n) for qubit in range(n + 1, circuit.width): cp(circuit, np.pi / 2 ** (qubit - n), qubit, n) def swap_registers(circuit, n): for qubit in range(n // 2): circuit.swap(qubit, n - qubit - 1) return circuit def qft(circuit, n): for i in range(n): qft_rotations(circuit, i) swap_registers(circuit, n) .. GENERATED FROM PYTHON SOURCE LINES 48-49 We will simulate 55-qubit QFT, which requires graph states with more than 10000 nodes. .. GENERATED FROM PYTHON SOURCE LINES 49-66 .. code-block:: default n = 55 print(f"{n}-qubit QFT") circuit = Circuit(n) for i in range(n): circuit.h(i) qft(circuit, n) # standardize pattern pattern = circuit.transpile(opt=True).pattern pattern.standardize() pattern.shift_signals() nodes, edges = pattern.get_graph() print(f"Number of nodes: {len(nodes)}") print(f"Number of edges: {len(edges)}") .. rst-class:: sphx-glr-script-out .. code-block:: none 55-qubit QFT Number of nodes: 10560 Number of edges: 13475 .. GENERATED FROM PYTHON SOURCE LINES 67-69 Using efficient graph state simulator `graphix.GraphSim`, we can classically preprocess Pauli measurements. We are currently improving the speed of this process by using rust-based graph manipulation backend. .. GENERATED FROM PYTHON SOURCE LINES 69-72 .. code-block:: default pattern.perform_pauli_measurements(use_rustworkx=True) .. GENERATED FROM PYTHON SOURCE LINES 73-75 To specify TN backend of the simulation, simply provide as a keyword argument. here we do a very basic check that one of the statevector amplitudes is what it is expected to be: .. GENERATED FROM PYTHON SOURCE LINES 75-86 .. code-block:: default import time t1 = time.time() tn = pattern.simulate_pattern(backend="tensornetwork") value = tn.get_basis_amplitude(0) t2 = time.time() print("amplitude of |00...0> is ", value) print("1/2^n (true answer) is", 1 / 2**n) print("approximate execution time in seconds: ", t2 - t1) .. rst-class:: sphx-glr-script-out .. code-block:: none amplitude of |00...0> is 2.775557561562938e-17 1/2^n (true answer) is 2.7755575615628914e-17 approximate execution time in seconds: 25.010623931884766 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 59.125 seconds) .. _sphx_glr_download_gallery_qft_with_tn.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: qft_with_tn.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: qft_with_tn.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_