Visualizing Collisionless circuits#

[1]:
# Import the required packages from the qlbm framework
from qlbm.components import (
    CQLBM,
    CollisionlessStreamingOperator,
    ControlledIncrementer,
    SpecularReflectionOperator,
    SpeedSensitivePhaseShift,
)
from qlbm.lattice import CollisionlessLattice
[2]:
# Define an example which uses 4 velocity qubits and the qubits with speed 2 will stream
speed_shift_primitive = SpeedSensitivePhaseShift(4, 2, True)
[3]:
# You can draw circuits in Qiskit's ASCII art format
speed_shift_primitive.draw("text")
[3]:
     ┌────────┐
q_0: ┤ P(π/4) ├
     ├────────┤
q_1: ┤ P(π/2) ├
     └┬──────┬┘
q_2: ─┤ P(π) ├─
      ├──────┤
q_3: ─┤ P(0) ├─
      └──────┘ 
[4]:
# Also through Qiskit's Matplotlib interface
speed_shift_primitive.draw("mpl")
[4]:
../../_images/examples_notebooks_collisionless_vis_4_0.png
[5]:
# Can also export directly to Latex source
speed_shift_primitive.draw("latex_source")
[5]:
'\\documentclass[border=2px]{standalone}\n\n\\usepackage[braket, qm]{qcircuit}\n\\usepackage{graphicx}\n\n\\begin{document}\n\\scalebox{1.0}{\n\\Qcircuit @C=1.0em @R=0.2em @!R { \\\\\n\t \t\\nghost{{q}_{0} :  } & \\lstick{{q}_{0} :  } & \\gate{\\mathrm{P}\\,(\\mathrm{\\frac{\\pi}{4}})} & \\qw & \\qw\\\\\n\t \t\\nghost{{q}_{1} :  } & \\lstick{{q}_{1} :  } & \\gate{\\mathrm{P}\\,(\\mathrm{\\frac{\\pi}{2}})} & \\qw & \\qw\\\\\n\t \t\\nghost{{q}_{2} :  } & \\lstick{{q}_{2} :  } & \\gate{\\mathrm{P}\\,(\\mathrm{\\pi})} & \\qw & \\qw\\\\\n\t \t\\nghost{{q}_{3} :  } & \\lstick{{q}_{3} :  } & \\gate{\\mathrm{P}\\,(\\mathrm{0})} & \\qw & \\qw\\\\\n\\\\ }}\n\\end{document}'
[6]:
# Define a lattice based on which we can construct
# Operators and algorithms
example_lattice = CollisionlessLattice(
    {
        "lattice": {"dim": {"x": 8, "y": 8}, "velocities": {"x": 4, "y": 4}},
        "geometry": [
            {"shape": "cuboid", "x": [5, 6], "y": [1, 2], "boundary": "specular"}
        ],
    }
)
[7]:
# All primitives can be drawn to the same interface
ControlledIncrementer(example_lattice, reflection=False).draw("mpl")
[7]:
../../_images/examples_notebooks_collisionless_vis_7_0.png
[8]:
# All operators can be drawn the same way
CollisionlessStreamingOperator(example_lattice, [0, 2, 3]).draw("mpl")
[8]:
../../_images/examples_notebooks_collisionless_vis_8_0.png
[9]:
SpecularReflectionOperator(example_lattice, example_lattice.blocks["bounceback"]).draw(
    "mpl"
)
[9]:
../../_images/examples_notebooks_collisionless_vis_9_0.png
[10]:
# As can entire algorithms
CQLBM(example_lattice).draw("mpl")
[10]:
../../_images/examples_notebooks_collisionless_vis_10_0.png
[ ]: