.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/pattern_from_circuit.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_pattern_from_circuit.py: From Circuit to Executable Pattern ===================================== This example transpiles an MBQC-native circuit into GraphQOMB's compiler IRs, then lowers them to an executable pattern and validates it by simulation. .. GENERATED FROM PYTHON SOURCE LINES 9-20 .. code-block:: Python import numpy as np from graphqomb.circuit import MBQCCircuit, circuit2graph from graphqomb.pattern import print_pattern from graphqomb.qompiler import qompile from graphqomb.simulator import ( CircuitSimulator, PatternSimulator, SimulatorBackend, ) .. GENERATED FROM PYTHON SOURCE LINES 21-22 generate circuit .. GENERATED FROM PYTHON SOURCE LINES 22-31 .. code-block:: Python circuit = MBQCCircuit(3) circuit.j(0, 0.5 * np.pi) circuit.cz(0, 1) circuit.cz(0, 2) circuit.j(1, 0.75 * np.pi) circuit.j(2, 0.25 * np.pi) circuit.cz(0, 2) circuit.cz(1, 2) .. GENERATED FROM PYTHON SOURCE LINES 32-33 Convert the circuit into GraphQOMB's compiler IRs. .. GENERATED FROM PYTHON SOURCE LINES 33-46 .. code-block:: Python graphstate, xflow, scheduler = circuit2graph(circuit) print("graph nodes:", len(graphstate.physical_nodes)) print("graph edges:", len(graphstate.physical_edges)) print("feedforward entries:", len(xflow)) print("scheduled slices:", scheduler.num_slices()) # Lower the IRs into an executable pattern using the derived schedule. pattern = qompile(graphstate, xflow, scheduler=scheduler) print("pattern depth:", pattern.depth) print("pattern max space:", pattern.max_space) print("pattern active volume:", pattern.active_volume) print_pattern(pattern) .. rst-class:: sphx-glr-script-out .. code-block:: none graph nodes: 6 graph edges: 7 feedforward entries: 3 scheduled slices: 3 pattern depth: 3 pattern max space: 5 pattern active volume: 15 N: node=3 E: nodes=(2, 3) E: nodes=(0, 3) E: nodes=(1, 3) TICK N: node=4 N: node=5 E: nodes=(1, 4) E: nodes=(4, 5) E: nodes=(2, 5) E: nodes=(3, 5) M: node=0, plane=Plane.XY, angle=-1.5707963267948966 TICK M: node=1, plane=Plane.XY, angle=-2.356194490192345 M: node=2, plane=Plane.XY, angle=-0.7853981633974483 TICK X: node=3 Z: node=3 X: node=4 Z: node=4 X: node=5 Z: node=5 0 more commands truncated. Change lim argument of print_pattern() to show more .. GENERATED FROM PYTHON SOURCE LINES 47-48 simulate the pattern .. GENERATED FROM PYTHON SOURCE LINES 48-60 .. code-block:: Python simulator = PatternSimulator(pattern, SimulatorBackend.StateVector) simulator.simulate() state = simulator.state statevec = state.state() # check by comparing the circuit simulator circ_simulator = CircuitSimulator(circuit, SimulatorBackend.StateVector) circ_simulator.simulate() circ_state = circ_simulator.state.state() inner_product = np.vdot(statevec, circ_state) print("inner product:", np.abs(inner_product)) # should be 1 .. rst-class:: sphx-glr-script-out .. code-block:: none inner product: 0.9999999999999993 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.004 seconds) .. _sphx_glr_download_gallery_pattern_from_circuit.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: pattern_from_circuit.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: pattern_from_circuit.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: pattern_from_circuit.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_