Ejemplo n.º 1
0
def integration_formatted(savefile="example_formatted.png"):

    wire_options = {"color": "indigo", "linewidth": 4}
    drawer = MPLDrawer(n_wires=2, n_layers=4, wire_options=wire_options)

    label_options = {"fontsize": "x-large", "color": "indigo"}
    drawer.label(["0", "a"], text_options=label_options)

    box_options = {"facecolor": "lightcoral", "edgecolor": "maroon", "linewidth": 5}
    text_options = {"fontsize": "xx-large", "color": "maroon"}
    drawer.box_gate(layer=0, wires=0, text="Z", box_options=box_options, text_options=text_options)

    swap_options = {"linewidth": 4, "color": "darkgreen"}
    drawer.SWAP(layer=1, wires=(0, 1), options=swap_options)

    ctrl_options = {"linewidth": 4, "color": "teal"}
    drawer.CNOT(layer=2, wires=(0, 1), options=ctrl_options)
    drawer.ctrl(layer=3, wires=(0, 1), options=ctrl_options)

    measure_box = {"facecolor": "white", "edgecolor": "indigo"}
    measure_lines = {"edgecolor": "indigo", "facecolor": "plum", "linewidth": 2}
    for wire in range(2):
        drawer.measure(layer=4, wires=wire, box_options=measure_box, lines_options=measure_lines)

    drawer.fig.suptitle("My Circuit", fontsize="xx-large")

    plt.savefig(folder / savefile)
    plt.close()
Ejemplo n.º 2
0
    def test_measure_formatted(self):
        """Tests you can color the measure box"""

        drawer = MPLDrawer(1, 1)
        rgba_red = (1.0, 0, 0, 1.0)
        rgba_green = (0, 1, 0, 1)
        box_options = {"facecolor": rgba_red, "edgecolor": rgba_green}
        lines_options = {"color": rgba_green, "linewidth": 0.5}
        drawer.measure(0,
                       0,
                       box_options=box_options,
                       lines_options=lines_options)

        box = drawer.ax.patches[0]
        assert box.get_facecolor() == rgba_red
        assert box.get_edgecolor() == rgba_green

        arc = drawer.ax.patches[1]
        assert arc.get_edgecolor() == rgba_green
        assert arc.get_linewidth() == 0.5

        arrow = drawer.ax.patches[2]
        assert arrow.get_edgecolor() == rgba_green
        assert arrow.get_linewidth() == 0.5

        plt.close()
Ejemplo n.º 3
0
def integration_rcParams(savefile="example_rcParams.png"):
    plt.rcParams["patch.facecolor"] = "white"
    plt.rcParams["patch.edgecolor"] = "black"
    plt.rcParams["patch.linewidth"] = 2
    plt.rcParams["patch.force_edgecolor"] = True

    plt.rcParams["lines.color"] = "black"

    drawer = MPLDrawer(n_wires=5, n_layers=5)

    drawer.label(["0", "a", r"$|\Psi\rangle$", r"$|\theta\rangle$", "aux"])

    drawer.box_gate(0, [0, 1, 2, 3, 4], "Entangling Layers", text_options={"rotation": "vertical"})
    drawer.box_gate(1, [0, 1], "U(θ)")

    drawer.box_gate(1, 4, "Z")

    drawer.SWAP(1, (2, 3))
    drawer.CNOT(2, (0, 2))

    drawer.ctrl(3, [1, 3], control_values=[True, False])
    drawer.box_gate(
        layer=3, wires=2, text="H", box_options={"zorder": 4}, text_options={"zorder": 5}
    )

    drawer.ctrl(4, [1, 2])

    drawer.measure(5, 0)

    drawer.fig.suptitle("My Circuit", fontsize="xx-large")

    plt.savefig(folder / savefile)
    plt.style.use("default")
    plt.close()
Ejemplo n.º 4
0
def integration(style="default", savefile="example_basic.png"):
    plt.style.use(style)
    drawer = MPLDrawer(n_wires=5, n_layers=5)

    drawer.label(["0", "a", r"$|\Psi\rangle$", r"$|\theta\rangle$", "aux"])

    drawer.box_gate(0, [0, 1, 2, 3, 4], "Entangling Layers", text_options={"rotation": "vertical"})
    drawer.box_gate(1, [0, 1], "U(θ)")

    drawer.box_gate(1, 4, "Z")

    drawer.SWAP(1, (2, 3))
    drawer.CNOT(2, (0, 2))

    drawer.ctrl(3, [1, 3], control_values=[True, False])
    drawer.box_gate(
        layer=3, wires=2, text="H", box_options={"zorder": 4}, text_options={"zorder": 5}
    )

    drawer.ctrl(4, [1, 2])

    drawer.measure(5, 0)

    drawer.fig.suptitle("My Circuit", fontsize="xx-large")
    plt.savefig(folder / savefile)
    plt.style.use("default")
    plt.close()
Ejemplo n.º 5
0
def measure_formatted(savefile="measure_formatted.png"):
    drawer = MPLDrawer(n_wires=1, n_layers=1)

    measure_box = {"facecolor": "white", "edgecolor": "indigo"}
    measure_lines = {"edgecolor": "indigo", "facecolor": "plum", "linewidth": 2}
    drawer.measure(0, 0, box_options=measure_box, lines_options=measure_lines)
    plt.savefig(folder / savefile)
    plt.close()
Ejemplo n.º 6
0
    def test_measure(self):
        """Tests the measure method."""

        drawer = MPLDrawer(1, 1)
        drawer.measure(0, 0)

        box = drawer.ax.patches[0]
        assert box.get_xy() == (-0.4, -0.4)
        assert box.get_width() == 0.8
        assert box.get_height() == 0.8

        arc = drawer.ax.patches[1]
        assert arc.center == (0, 0.05)
        assert arc.theta1 == 180
        assert arc.theta2 == 0
        assert allclose(arc.height, 0.44)
        assert arc.width == 0.48

        arrow = drawer.ax.patches[2]
        assert isinstance(arrow, FancyArrow)

        plt.close()
Ejemplo n.º 7
0
def measure(savefile="measure.png"):
    drawer = MPLDrawer(n_wires=1, n_layers=1)

    drawer.measure(0, 0)
    plt.savefig(folder / savefile)
    plt.close()