Note
Go to the end to download the full example code.
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:
from __future__ import annotations
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)
100-qubit GHZ state generation
Transpile into pattern

Number of nodes: 399
Number of edges: 398
Calculate the amplitudes of |00...0> and |11...1> states.
tn = pattern.simulate_pattern(backend="tensornetwork")
print(f"The amplitude of |00...0>: {tn.basis_amplitude(0)}")
print(f"The amplitude of |11...1>: {tn.basis_amplitude(2**n - 1)}")
/home/docs/checkouts/readthedocs.org/user_builds/graphix/checkouts/v0.3.5/examples/ghz_with_tn.py:48: UserWarning: Default random-number generator is used. Results may not be reproducible.
tn = pattern.simulate_pattern(backend="tensornetwork")
The amplitude of |00...0>: 0.499999999999993
The amplitude of |11...1>: 0.499999999999993
Total running time of the script: (0 minutes 6.720 seconds)