.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/ghz_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_ghz_with_tn.py: Using Tensor Network simulator ============================== In this example, we simulate a circuit to create Greenberger-Horne-Zeilinger(GHZ) state with a tensor network simulator. We will simulate the generation of 100-qubit GHZ state. Firstly, let us import relevant modules: .. GENERATED FROM PYTHON SOURCE LINES 12-31 .. code-block:: default import matplotlib.pyplot as plt import networkx as nx from graphix import Circuit n = 100 print(f"{n}-qubit GHZ state generation") circuit = Circuit(n) # initialize to ``|0>`` state. for i in range(n): circuit.h(i) # GHZ generation circuit.h(0) for i in range(1, n): circuit.cnot(i - 1, i) .. rst-class:: sphx-glr-script-out .. code-block:: none 100-qubit GHZ state generation .. GENERATED FROM PYTHON SOURCE LINES 32-33 Transpile into pattern .. GENERATED FROM PYTHON SOURCE LINES 33-47 .. code-block:: default pattern = circuit.transpile().pattern pattern.standardize() nodes, edges = pattern.get_graph() g = nx.Graph() g.add_nodes_from(nodes) g.add_edges_from(edges) print(f"Number of nodes: {len(nodes)}") print(f"Number of edges: {len(edges)}") pos = nx.spring_layout(g) nx.draw(g, pos=pos, node_size=15) plt.show() .. image-sg:: /gallery/images/sphx_glr_ghz_with_tn_001.png :alt: ghz with tn :srcset: /gallery/images/sphx_glr_ghz_with_tn_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Number of nodes: 399 Number of edges: 398 .. GENERATED FROM PYTHON SOURCE LINES 48-49 Calculate the amplitudes of ``|00...0>`` and ``|11...1>`` states. .. GENERATED FROM PYTHON SOURCE LINES 49-54 .. code-block:: default tn = pattern.simulate_pattern(backend="tensornetwork") print(f"The amplitude of |00...0>: {tn.get_basis_amplitude(0)}") print(f"The amplitude of |11...1>: {tn.get_basis_amplitude(2**n - 1)}") .. rst-class:: sphx-glr-script-out .. code-block:: none The amplitude of |00...0>: 0.49999999999999317 The amplitude of |11...1>: 0.49999999999999317 .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 7.466 seconds) .. _sphx_glr_download_gallery_ghz_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: ghz_with_tn.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ghz_with_tn.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_