def test_empty(self): """Tests creating a grid with empty operations and no wire map""" grid = drawable_grid([]) assert grid == [[]] Grid_obj = Grid(grid) assert Grid_obj.raw_grid.shape == (1, 0)
def test_all_wires_measurement(self, measurement): """Test measurements that act on all wires also block on all available wires.""" ops = [qml.PauliX(0), measurement, qml.PauliY(1)] grid = drawable_grid(ops, wire_map={0: 0, 1: 1, 2: 2}) assert grid[0] == [ops[0], ops[1], None] assert grid[1] == [None, ops[1], ops[2]] assert grid[2] == [None, ops[1], None]
def test_empty_wire_map(self): """Test creating a grid when no operations are present but there is a wire map""" wire_map = {1: 1, 2: 2} grid = drawable_grid([], wire_map) assert grid == [[], []] Grid_obj = Grid(grid) assert Grid_obj.raw_grid.shape == (2, 0)
def test_single_wires_blocking(self): """Test where single wire gates block each other""" ops = [qml.PauliX(0), qml.PauliX(0), qml.PauliX(0)] grid = drawable_grid(ops) assert grid == [ops] Grid_obj = Grid(grid) assert Grid_obj.raw_grid.shape == (1, 3)
def test_single_wires_no_blocking(self): """Test where nothing blocks each other""" ops = [qml.PauliX(0), qml.PauliX(1), qml.PauliX(2)] grid = drawable_grid(ops) assert grid == [[ops[0]], [ops[1]], [ops[2]]] Grid_obj = Grid(grid) assert Grid_obj.raw_grid.shape == (3, 1)
def test_multiwire_blocking(self): """Test multi-wire gate blocks on unused wire.""" wire_map = {0: 0, 1: 1, 2: 2} ops = [qml.PauliZ(1), qml.CNOT(wires=(0, 2)), qml.PauliX(1)] grid = drawable_grid(ops, wire_map) assert grid[0] == [None, ops[1], None] assert grid[1] == [ops[0], None, ops[2]] assert grid[2] == [None, ops[1], None] Grid_obj = Grid(grid) assert Grid_obj.raw_grid.shape == (3, 3)