Beispiel #1
0
    def test_append_grid_by_layers(self):
        """Test appending a grid to another by layers."""
        raw_grid_transpose1 = [[0, 3], [1, 4], [2, 5]]
        raw_grid_transpose2 = [[6, 7], [8, 9]]

        grid1 = Grid(_transpose(raw_grid_transpose1))
        grid2 = Grid(_transpose(raw_grid_transpose2))

        grid1.append_grid_by_layers(grid2)

        assert np.array_equal(grid1.raw_grid.T, [[0, 3], [1, 4], [2, 5], [6, 7], [8, 9]])
        assert np.array_equal(grid1.raw_grid, _transpose([[0, 3], [1, 4], [2, 5], [6, 7], [8, 9]]))
Beispiel #2
0
    def test_insert_wire(self, idx, expected_grid):
        """Test that wire insertion works properly."""

        raw_grid = [[0, 3], [1, 4], [2, 5]]
        grid = Grid(raw_grid)

        grid.insert_wire(idx, [6, 7])

        assert np.array_equal(grid.raw_grid, expected_grid)
        assert np.array_equal(grid.raw_grid.T, _transpose(expected_grid))
Beispiel #3
0
    def test_replace_layer(self, idx, expected_transposed_grid):
        """Test that layer replacement works properly."""

        raw_grid = [[0, 3], [1, 4], [2, 5]]
        grid = Grid(raw_grid)

        grid.replace_layer(idx, [6, 7, 8])

        assert np.array_equal(grid.raw_grid.T, expected_transposed_grid)
        assert np.array_equal(grid.raw_grid, _transpose(expected_transposed_grid))
def to_grid(layer_list, num_wires):
    """Convert the given list of operations per layer to a Grid.

    Args:
        layer_list (list[list[~.Operation]]): List of layers in terms of Operations
        num_wires (int): Number of wires in the system

    Returns:
        ~.Grid: The corresponding Operation grid
    """
    grid = Grid(_transpose([to_layer(layer_list[0], num_wires)]))

    for i in range(1, len(layer_list)):
        grid.append_layer(to_layer(layer_list[i], num_wires))

    return grid
Beispiel #5
0
 def test_transpose_squared(self, input):
     """Test that transpose transposes a list of list."""
     assert _transpose(_transpose(input)) == input
Beispiel #6
0
 def test_transpose(self, input, expected_output):
     """Test that transpose transposes a list of list."""
     assert _transpose(input) == expected_output
Beispiel #7
0
    def test_layer(self, raw_transposed_grid):
        """Test that layer returns the correct layer."""
        grid = Grid(_transpose(raw_transposed_grid))

        for idx, layer in enumerate(raw_transposed_grid):
            assert np.array_equal(grid.layer(idx), layer)