This repository contains Python scripts to simulate the evolution of quantum operators under random quantum circuits and analyze the growth of spatial entanglement entropy. The simulation uses a tensor-based representation for quantum operators, leveraging PyTorch for efficient computations. See details at arXiv:2505.09512.
The project investigates the relationship between the "magic" of a quantum circuit (i.e., the presence of non-Clifford gates like T, CCX, and H) and the growth of entanglement. It does so by evolving an initial quantum operator (represented as a tensor) through layers of randomized quantum gates and then measuring the change in spatial entanglement entropy across a bipartition of the qubits.
Two main experiments are conducted:
- Phase Diagram Analysis: Explores how entanglement growth depends on the probabilities of applying H and CCX gates for various initial operators.
- Functional Dependence Analysis: Examines how the final entanglement depends on the initial entanglement of the operator for different classes of circuits (Clifford, Clifford+H, Clifford+T/Toffoli).
-
Operator as a Tensor: A quantum operator on
$N$ qubits, which is a$2^N \times 2^N$ matrix, is represented as a tensor with$2N$ indices, each of dimension 2. This allows for efficient local gate operations using tensor contractions. -
Gate Application: Single and multi-qubit gates are applied to the operator tensor using
torch.einsum. This corresponds to the transformation$O \to U O U^\dagger$ . -
Spatial Entanglement Entropy (
$H_{SE}$ ): To measure the entanglement of the operator, the system is bipartitioned. The operator tensor is reshaped into a matrix corresponding to this split, and a Singular Value Decomposition (SVD) is performed. The von Neumann entropy of the normalized singular values is then calculated, providing a measure of entanglement across the boundary.
This is the main simulation script that runs the quantum circuit simulations and saves the results.
Functionality:
- Defines the
QuantumOpclass to handle the tensor representation of quantum operators and the application of quantum gates. - Implements the
run_parallel_circuitfunction to execute a layered random quantum circuit simulation. -
Experiment 1 (Phase Diagram):
- Iterates over a 2D grid of probabilities for applying Hadamard gates (
h_rate) and CCX gates (t_rate). - Runs simulations for several different initial operators (e.g.,
XXXXXX,XXXX00,000000). - Calculates and stores the mean, variance, and maximum entanglement entropy generated over multiple shots.
- Saves the aggregated results to
data_results/color_results.pkl.
- Iterates over a 2D grid of probabilities for applying Hadamard gates (
-
Experiment 2 (Functional Dependence):
- Investigates initial operators of the form
$X^{\otimes s} \otimes {|0\rangle!\langle0|}^{\otimes (N-s)}$ . - Runs simulations for three distinct circuit types:
- Clifford Circuit: Only CNOT and S gates.
-
H-magic Circuit (
$\mathcal{F}_{BBC}$ ): Clifford gates + H gates. -
T/Toffoli-magic Circuit (
$\mathcal{F}_{CBC}$ ): Clifford gates + T or Toffoli gates.
- Calculates and stores the resulting entanglement entropy as a function of
$s$ . - Saves the aggregated results to
data_results/func_results.pkl.
- Investigates initial operators of the form
This script is used for visualizing the data generated by phase_diag.py.
Functionality:
- Loads the simulation results from
data_results/color_results.pklanddata_results/func_results.pkl. - Generates two main figures:
-
phase_res_final2.pdf: A multi-panel figure containing:-
(a) Heatmaps (phase diagrams) showing the maximum entanglement entropy as a function of
$p_H$ and$p_{CCX}$ for different initial operators. - (b) A line plot showing the average entanglement entropy as a function of the number of Pauli-X operators in the initial state for the three circuit families, using Toffoli gates as the source of magic.
-
(a) Heatmaps (phase diagrams) showing the maximum entanglement entropy as a function of
-
appdix_plot.pdf: A supplementary plot showing the functional dependence of entanglement for circuits with T-gates.
-
You need to have Python installed along with the following libraries:
numpytorchmatplotlib
You can install them using pip:
pip install numpy torch matplotlib1. Run the Simulation: Execute the phase_diag.py script from your terminal. This will perform all the simulations. It can be time-consuming depending on the parameters (qubit_num, shot_number, etc.).
python phase_diag.pyThis will create a directory named data_results and populate it with color_results.pkl and func_results.pkl. 2. Generate the Plots: After the simulation is complete and the data files are generated, run the Plot.py script.
python Plot.pyThis will read the pickle files and generate the figures phase_res_final2.pdf and appdix_plot.pdf in the root directory.