예제 #1
0
 def test_invalid_n_samples(self, c):
     """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"):
         alpha, t, U, w, ns = c
         dynamics.sample_coherent(alpha, t, U, w, 0)
예제 #2
0
 def test_complex_unitary(self, c):
     """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"
     ):
         alpha, t, U, w, ns = c
         dynamics.sample_coherent(alpha, t, 1.0j * U, w, ns)
예제 #3
0
 def test_invalid_mode(self, c):
     """Test if function raises a ``ValueError`` when the number of displacement parameters and the
     number of modes in the normal-to-local transformation matrix are different."""
     with pytest.raises(
             ValueError,
             match=
             "Number of displacement parameters and the number of modes in the normal-to-local",
     ):
         alpha, t, U, w, ns = c
         dynamics.sample_coherent(alpha + [0], t, U, w, ns)
예제 #4
0
    def test_op_order(self, monkeypatch, c):
        """Test if function correctly applies the operations."""
        if len(c[0]) == 2:
            mock_eng_run = mock.MagicMock()

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

            assert isinstance(p_func.circuit[0].op, sf.ops.Dgate)
            assert isinstance(p_func.circuit[1].op, sf.ops.Dgate)
            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)