예제 #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)
예제 #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)
예제 #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)
예제 #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)