Ejemplo n.º 1
0
 def test_interferometer_uniform_dimensions(self, n_subsystems):
     """Confirm that pennylane.init.interferometer_uniform()
      returns an array with the right dimensions."""
     a = (n_subsystems, )
     b = (n_subsystems * (n_subsystems - 1) // 2, )
     p = interferometer_uniform(n_wires=n_subsystems, seed=0)
     dims = [p_.shape for p_ in p]
     assert dims == [b, b, a]
Ejemplo n.º 2
0
 def test_interferometer_uniform_seed(self, seed, tol):
     """Confirm that pennylane.init.interferometer_uniform() invokes the correct np.random sampling function
     for a given seed."""
     low = -2
     high = 1
     n_wires = 3
     n_if = n_wires * (n_wires - 1) // 2
     p = interferometer_uniform(n_wires=n_wires,
                                low=low,
                                high=high,
                                seed=seed)
     np.random.seed(seed)
     theta = np.random.uniform(low=low, high=high, size=(n_if, ))
     phi = np.random.uniform(low=low, high=high, size=(n_if, ))
     varphi = np.random.uniform(low=low, high=high, size=(n_wires, ))
     p_target = [theta, phi, varphi]
     assert np.allclose(p, p_target, atol=tol, rtol=0.)
Ejemplo n.º 3
0
 def test_interferometer_uniform_edgecase(self, seed, tol):
     """Test sampling edge case of pennylane.init.interferometer_uniform()."""
     p = interferometer_uniform(n_wires=10, low=1, high=1, seed=seed)
     p_mean = np.mean(np.array([np.mean(pp) for p_ in p for pp in p_]))
     assert np.allclose(p_mean, 1, atol=tol, rtol=0.)
Ejemplo n.º 4
0
 def test_interferometer_uniform_interval(self, seed):
     """Confirm that no uniform sample in pennylane.init.interferometer_uniform() lies outside of interval."""
     low = -2
     high = 1
     p = interferometer_uniform(n_wires=10, low=low, high=high, seed=seed)
     assert all([(p_ <= high).all() and (p_ >= low).all() for p_ in p])