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=Wires([0]), par=[p]) with pytest.raises(ValueError, match='Incorrect number of subsystems'): p = U gaussian_dev.apply('Interferometer', wires=Wires([0]), par=[p]) with pytest.raises(qml.wires.WireError, match="Did not find some of the wires"): p = U2 #dev = DefaultGaussian(wires=4, shots=1000, hbar=hbar) gaussian_dev.apply('Interferometer', wires=Wires([0, 1, 2]), par=[p])
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)