Esempio n. 1
0
 def test_expand_vector_invalid_wires(self):
     """Test exception raised if unphysical subsystems provided."""
     with pytest.raises(
         ValueError,
         match="Invalid target subsystems provided in 'original_wires' argument",
     ):
         pu.expand_vector(TestExpand.VECTOR2, [-1, 5], 4)
Esempio n. 2
0
    def test_expand_vector_two_wires(self, original_wires, expanded_wires,
                                     expected, tol):
        """Test that expand_vector works with a single-wire vector."""

        res = pu.expand_vector(TestExpand.VECTOR2, original_wires,
                               expanded_wires)

        assert np.allclose(res, expected, atol=tol, rtol=0)
Esempio n. 3
0
    def vec_vec_product(self, phases, vec, wires):
        r"""Apply multiplication of a phase vector to subsystems of the quantum state.

        This represents the multiplication with diagonal gates in a more efficient manner.

        Args:
            phases (array): vector to multiply
            vec (array): state vector to multiply
            wires (Sequence[int]): target subsystems

        Returns:
            array: output vector after applying ``phases`` to input ``vec`` on specified subsystems
        """
        # TODO: use multi-index vectors/matrices to represent states/gates internally
        phases = expand_vector(phases, wires, list(range(self.num_wires)))
        return vec * phases
Esempio n. 4
0
 def test_expand_vector_invalid_vector(self):
     """Test exception raised if incorrect sized vector provided."""
     with pytest.raises(ValueError,
                        match="Vector parameter must be of length"):
         pu.expand_vector(TestExpand.VECTOR1, [0, 1], 4)