コード例 #1
0
 def thermal_state(self):
     """Test the thermal state is correct."""
     self.logTestName()
     nbar = 0.5342
     means, cov = thermal_state(nbar, hbar=hbar)
     self.assertAllAlmostEqual(means, np.zeros([2]), delta=self.tol)
     self.assertTrue(np.all((cov.diag * 2 / hbar - 1) / 2 == nbar))
コード例 #2
0
    def test_apply_errors(self):
        """Test that apply fails for incorrect state preparation"""
        self.logTestName()

        with self.assertRaisesRegex(ValueError, 'incorrect size for the number of subsystems'):
            p = [thermal_state(0.5)]
            self.dev.apply('GaussianState', wires=[0], par=[p])
コード例 #3
0
    def test_apply_errors(self, gaussian_dev):
        """Test that apply fails for incorrect state preparation"""

        with pytest.raises(ValueError, match='incorrect size for the number of subsystems'):
            p = [thermal_state(0.5)]
            gaussian_dev.apply('GaussianState', wires=[0], par=[p])

        with pytest.raises(ValueError, match='Incorrect number of subsystems'):
            p = U
            gaussian_dev.apply('Interferometer', wires=[0], par=[p])

        with pytest.raises(ValueError, match="Invalid target subsystems provided in 'wires' argument"):
            p = U2
            #dev = DefaultGaussian(wires=4, shots=1000, hbar=hbar)
            gaussian_dev.apply('Interferometer', wires=[0, 1, 2], par=[p])
コード例 #4
0
    def test_apply_errors(self):
        """Test that apply fails for incorrect state preparation"""
        self.logTestName()

        with self.assertRaisesRegex(
                ValueError, 'incorrect size for the number of subsystems'):
            p = [thermal_state(0.5)]
            self.dev.apply('GaussianState', wires=[0], par=[p])

        with self.assertRaisesRegex(ValueError,
                                    'Incorrect number of subsystems'):
            p = U
            self.dev.apply('Interferometer', wires=[0], par=[p])

        with self.assertRaisesRegex(
                ValueError,
                "Invalid target subsystems provided in 'wires' argument"):
            p = U2
            dev = DefaultGaussian(wires=4, shots=0, hbar=hbar)
            self.dev.apply('Interferometer', wires=[0, 1, 2], par=[p])
コード例 #5
0
    def test_apply_errors(self):
        """Test that apply fails for incorrect state preparation"""
        self.logTestName()

        with self.assertRaisesRegex(
                ValueError, 'incorrect size for the number of subsystems'):
            p = [thermal_state(0.5)]
            self.dev.apply('GaussianState', wires=[0], par=[p])

        with self.assertRaisesRegex(ValueError,
                                    'incorrect number of subsystems'):
            p = U
            self.dev.apply('Interferometer', wires=[0], par=[p])

        with self.assertRaisesRegex(
                ValueError,
                'Only 2-mode interferometers are currently supported.'):
            p = U2
            dev = DefaultGaussian(wires=4, shots=0, hbar=hbar)
            self.dev.apply('Interferometer', wires=[0, 1, 2, 3], par=[p])
コード例 #6
0
 def thermal_state(self, tol):
     """Test the thermal state is correct."""
     nbar = 0.5342
     means, cov = thermal_state(nbar, hbar=hbar)
     assert means == pytest.approx(np.zeros([2]), abs=tol)
     assert np.all((cov.diag*2/hbar-1)/2 == nbar)