Beispiel #1
0
def gen_barrier(barrier: types.Barrier,
                formatter: Dict[str, Any]) -> List[drawings.LineData]:
    """Generate barrier line.

    Stylesheet:
        - `barrier` style is applied.

    Args:
        barrier: Barrier instruction.
        formatter: Dictionary of stylesheet settings.

    Returns:
        List of `LineData` drawings.
    """
    styles = {
        "alpha": formatter["alpha.barrier"],
        "zorder": formatter["layer.barrier"],
        "linewidth": formatter["line_width.barrier"],
        "linestyle": formatter["line_style.barrier"],
        "color": formatter["color.barrier"],
    }

    drawing = drawings.LineData(
        data_type=types.LineType.BARRIER,
        xvals=[barrier.t0, barrier.t0],
        yvals=[-0.5, 0.5],
        bit=barrier.bits[barrier.bit_position],
        styles=styles,
    )

    return [drawing]
    def test_line_data_equivalent_abstract_coord(self):
        """Test LineData equivalent check with abstract coordinate."""
        xs = [types.AbstractCoordinate.LEFT, types.AbstractCoordinate.RIGHT]
        ys = [types.AbstractCoordinate.BOTTOM, types.AbstractCoordinate.TOP]

        obj1 = drawings.LineData(data_type=types.LineType.BARRIER,
                                 bit=self.qubits[0],
                                 xvals=xs,
                                 yvals=ys,
                                 meta=self.meta1,
                                 styles=self.style1)

        obj2 = drawings.LineData(data_type=types.LineType.BARRIER,
                                 bit=self.qubits[0],
                                 xvals=xs,
                                 yvals=ys,
                                 meta=self.meta2,
                                 styles=self.style2)

        self.assertEqual(obj1, obj2)
    def test_line_data_equivalent(self):
        """Test LineData equivalent check."""
        xs = list(np.arange(10))
        ys = list(np.ones(10))

        obj1 = drawings.LineData(data_type=types.LineType.BARRIER,
                                 bit=self.qubits[0],
                                 xvals=xs,
                                 yvals=ys,
                                 meta=self.meta1,
                                 styles=self.style1)

        obj2 = drawings.LineData(data_type=types.LineType.BARRIER,
                                 bit=self.qubits[0],
                                 xvals=xs,
                                 yvals=ys,
                                 meta=self.meta2,
                                 styles=self.style2)

        self.assertEqual(obj1, obj2)