Пример #1
0
    def test_apply_basis_state(self, nr_wires, tol):
        """Tests that we correctly apply a `BasisState` operation for the |11...1> state"""
        dev = qml.device("default.mixed", wires=nr_wires)
        state = np.ones(nr_wires)
        dev.apply([BasisState(state, wires=range(nr_wires))])

        assert np.allclose(dev.state, basis_state(2 ** nr_wires - 1, nr_wires), atol=tol, rtol=0)
Пример #2
0
    def test_raise_order_error_basis_state(self):
        """Tests that an error is raised if a state is prepared after BasisState has been
        applied"""
        dev = qml.device("default.mixed", wires=1)
        state = np.array([0])
        ops = [PauliX(0), BasisState(state, wires=0)]

        with pytest.raises(DeviceError, match="Operation"):
            dev.apply(ops)