{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example from *Graph-theoretic Simplification of Quantum Circuits with the ZX-calculus*\n", "\n", "This notebook shows how the circuit that is used as a demonstration in the paper https://arxiv.org/abs/1902.03178 is generated and simplified." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First we need to important the standard things" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import sys; sys.path.append('..')\n", "import random\n", "import pyzx as zx\n", "%config InlineBackend.figure_format = 'svg'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we generate the circuit. " ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Circuit on 4 qubits with 350 gates.\n", " 4 is the T-count\n", " 346 Cliffords among which \n", " 109 2-qubit gates and 0 Hadamard gates.\n" ] } ], "source": [ "random.seed(1344) # Make sure the same circuit is generated\n", "g = zx.generate.cliffordT(4,350,p_t=0.010) # Generate the circuit as a ZX-diagram\n", "c = zx.Circuit.from_graph(g) # Convert it to a sequence-of-gates representation\n", "print(c.stats())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This circuit contains many more gates then the one used in the paper. This is because ``generate.clifordT`` generates a lot of single qubit gate strings that can trivially be simplified. Before processing it with our ZX-simplification routine, we therefore process it trough the ``optimize.basic_optimization`` routine to show that our simplification routine is actually doing non-trivial simplifications." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Circuit on 4 qubits with 195 gates.\n", " 4 is the T-count\n", " 191 Cliffords among which \n", " 86 2-qubit gates and 43 Hadamard gates.\n" ] } ], "source": [ "c2 = zx.optimize.basic_optimization(c.split_phase_gates())\n", "print(c2.stats())" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ], "text/plain": [ "