Пример #1
0
    def test_qubit_state_vector_on_wires_subset(self, init_state, device_wires,
                                                op_wires, tol):
        """Test QubitStateVector application on a subset of device wires"""
        dev = QulacsDevice(device_wires)
        state = init_state(len(op_wires))

        op = qml.QubitStateVector(state, wires=op_wires)
        dev.apply([op])
        dev._obs_queue = []

        res = dev.state
        expected = dev._expand_state(state, op_wires)

        assert np.allclose(res, expected, tol)
Пример #2
0
    def test_basis_state_on_wires_subset(self, state, device_wires, op_wires,
                                         tol):
        """Test basis state initialization on a subset of device wires"""
        dev = QulacsDevice(device_wires)

        op = qml.BasisState(state, wires=op_wires)
        dev.apply([op])
        dev._obs_queue = []

        res = np.abs(dev.state)**2
        # compute expected probabilities
        expected = np.zeros([2**len(op_wires)])
        expected[np.ravel_multi_index(state, [2] * len(op_wires))] = 1

        expected = dev._expand_state(expected, op_wires)
        assert np.allclose(res, expected, tol)
Пример #3
0
def test_expand_state(state, op_wires, device_wires, expected, tol):
    """Test that the expand_state method works as expected."""
    dev = QulacsDevice(device_wires)
    res = dev._expand_state(state, op_wires)

    assert np.allclose(res, expected, tol)