コード例 #1
0
ファイル: test_grid.py プロジェクト: rahul1704/pennylane
    def test_replace_error_message(self):
        """Test that an exception is raised when replacing layers in
        an uninitialized Grid is attempted."""
        grid = Grid()

        with pytest.raises(AttributeError, match="Can't replace layer. The Grid has not yet been initialized."):
            grid.replace_layer(1, [1, 2, 3])
コード例 #2
0
ファイル: test_grid.py プロジェクト: rahul1704/pennylane
    def test_append_layer(self):
        """Test that layer appending works properly."""

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

        grid.append_layer([6, 7, 8])

        assert np.array_equal(grid.raw_grid, [[0, 3, 6], [1, 4, 7], [2, 5, 8]])
        assert np.array_equal(grid.raw_grid.T, [[0, 1, 2], [3, 4, 5], [6, 7, 8]])
コード例 #3
0
ファイル: test_grid.py プロジェクト: rahul1704/pennylane
    def test_insert_layer(self, idx, expected_transposed_grid):
        """Test that layer insertion works properly."""

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

        grid.insert_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))
コード例 #4
0
ファイル: test_grid.py プロジェクト: rahul1704/pennylane
    def test_append_wire(self):
        """Test that wire appending works properly."""

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

        grid.append_wire([6, 7])

        assert np.array_equal(grid.raw_grid, [[0, 3], [1, 4], [2, 5], [6, 7]])
        assert np.array_equal(grid.raw_grid.T, [[0, 1, 2, 6], [3, 4, 5, 7]])
コード例 #5
0
ファイル: test_grid.py プロジェクト: rahul1704/pennylane
    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]]))
コード例 #6
0
ファイル: test_grid.py プロジェクト: rahul1704/pennylane
    def test_copy(self):
        """Test that copy copies the grid."""
        raw_grid = [[0, 3], [1, 4], [2, 5]]
        grid = Grid(raw_grid)

        other_grid = grid.copy()

        # Assert that everything is indeed copied
        assert other_grid is not grid
        assert other_grid.raw_grid is not grid.raw_grid

        # Assert the copy is correct
        assert np.array_equal(other_grid.raw_grid, grid.raw_grid)
コード例 #7
0
ファイル: test_grid.py プロジェクト: rahul1704/pennylane
    def test_empty_init(self):
        """Test that the Grid class is initialized correctly when no raw_grid is given."""
        grid = Grid()

        assert grid.num_layers == 0
        assert grid.num_wires == 0
        assert grid.raw_grid is None
コード例 #8
0
ファイル: test_grid.py プロジェクト: rahul1704/pennylane
    def test_init(self):
        """Test that the Grid class is initialized correctly."""

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

        assert np.array_equal(grid.raw_grid, raw_grid)
        assert np.array_equal(grid.raw_grid.T, [[0, 1, 2], [3, 4, 5]])
コード例 #9
0
    def test_error_init_with_wrong_grid_shape(self, raw_grid):
        """Test that the Grid class is initialized correctly."""

        with pytest.raises(
                ValueError,
                match=
                "The entered raw grid was not parsed as two-dimensional array"
        ):
            grid = Grid(raw_grid)
コード例 #10
0
ファイル: test_grid.py プロジェクト: rahul1704/pennylane
    def test_str(self):
        """Test string rendering of Grid."""
        raw_grid = [[0, 3], [1, 4], [2, 5]]
        grid = Grid(raw_grid)

        assert str(grid) == "[0 3]\n[1 4]\n[2 5]\n"
コード例 #11
0
ファイル: test_grid.py プロジェクト: rahul1704/pennylane
    def test_wire(self, raw_grid):
        """Test that wire returns the correct wire."""
        grid = Grid(raw_grid)

        for idx, wire in enumerate(raw_grid):
            assert np.array_equal(grid.wire(idx), wire)
コード例 #12
0
ファイル: test_grid.py プロジェクト: rahul1704/pennylane
    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)
コード例 #13
0
ファイル: test_grid.py プロジェクト: rahul1704/pennylane
    def test_num_wires(self, raw_grid, expected_num_wires):
        """Test that num_layers returns the correct number of wires."""
        grid = Grid(raw_grid)

        assert grid.num_wires == expected_num_wires