Ejemplo n.º 1
0
 def test_invalid_n_samples(self, tmsv):
     """Test if function raises a ``ValueError`` when a number of samples less than one is
     requested."""
     with pytest.raises(ValueError,
                        match="Number of samples must be at least one"):
         r, t, U, w, ns = tmsv
         dynamics.sample_tmsv(r, t, U, w, 0)
Ejemplo n.º 2
0
 def test_complex_unitary(self, tmsv):
     """Test if function raises a ``ValueError`` when a complex unitary is given."""
     with pytest.raises(
             ValueError,
             match=
             "The normal mode to local mode transformation matrix must be real"
     ):
         r, t, U, w, ns = tmsv
         dynamics.sample_tmsv(r, t, 1.0j * U, w, ns)
Ejemplo n.º 3
0
 def test_invalid_mode(self, tmsv):
     """Test if function raises a ``ValueError`` when the number of modes in the input state and
     the normal-to-local transformation matrix are different."""
     with pytest.raises(
             ValueError,
             match=
             "Number of squeezing parameters and the number of modes in the normal-to-local",
     ):
         r, t, U, w, ns = tmsv
         dynamics.sample_tmsv(r + [[0, 0]], t, U, w, ns)
Ejemplo n.º 4
0
    def test_op_order(self, monkeypatch, tmsv):
        """Test if function correctly applies the operations."""
        if len(tmsv[0]) == 2:
            mock_eng_run = mock.MagicMock()

            with monkeypatch.context() as m:
                m.setattr(sf.LocalEngine, "run", mock_eng_run)
                dynamics.sample_tmsv(*tmsv)
                p_func = mock_eng_run.call_args[0][0]

            assert isinstance(p_func.circuit[0].op, sf.ops.S2gate)
            assert isinstance(p_func.circuit[1].op, sf.ops.S2gate)
            assert isinstance(p_func.circuit[2].op, sf.ops.Interferometer)
            assert isinstance(p_func.circuit[3].op, sf.ops.Rgate)
            assert isinstance(p_func.circuit[4].op, sf.ops.Rgate)
            assert isinstance(p_func.circuit[5].op, sf.ops.Interferometer)
            assert isinstance(p_func.circuit[6].op, sf.ops.MeasureFock)