Beispiel #1
0
 def test_cvqnnlayers_normal_dimensions(self, n_subsystems, n_layers):
     """Confirm that pennylane.init.cvqnn_layers_normal()
      returns an array with the right dimensions."""
     a = (n_layers, n_subsystems)
     b = (n_layers, n_subsystems * (n_subsystems - 1) // 2)
     p = cvqnn_layers_normal(n_wires=n_subsystems,
                             n_layers=n_layers,
                             seed=0)
     dims = [p_.shape for p_ in p]
     assert dims == [b, b, a, a, a, b, b, a, a, a, a]
Beispiel #2
0
 def test_cvqnnlayers_normal_edgecase(self, seed, tol):
     """Test sampling edge case of pennylane.init.cvqnn_layers_normal()."""
     n_layers = 3
     p = cvqnn_layers_normal(n_layers=n_layers,
                             n_wires=10,
                             mean=1,
                             std=0,
                             mean_active=1,
                             std_active=0,
                             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.)
Beispiel #3
0
 def test_cvqnnlayers_normal_range(self, seed, tol):
     """Confirm that pennylane.init.cvqnn_layers_normal() invokes the correct np.random sampling function."""
     mean = -0.5
     std = 1
     mean_a = 0.5
     std_a = 2
     n_wires = 3
     n_layers = 3
     n_if = n_wires * (n_wires - 1) // 2
     p = cvqnn_layers_normal(n_layers=n_layers,
                             n_wires=n_wires,
                             mean=mean,
                             std=std,
                             mean_active=mean_a,
                             std_active=std_a,
                             seed=seed)
     np.random.seed(seed)
     theta_1 = np.random.normal(loc=mean, scale=std, size=(n_layers, n_if))
     phi_1 = np.random.normal(loc=mean, scale=std, size=(n_layers, n_if))
     varphi_1 = np.random.normal(loc=mean,
                                 scale=std,
                                 size=(n_layers, n_wires))
     r = np.random.normal(loc=mean_a, scale=std_a, size=(n_layers, n_wires))
     phi_r = np.random.normal(loc=mean, scale=std, size=(n_layers, n_wires))
     theta_2 = np.random.normal(loc=mean, scale=std, size=(n_layers, n_if))
     phi_2 = np.random.normal(loc=mean, scale=std, size=(n_layers, n_if))
     varphi_2 = np.random.normal(loc=mean,
                                 scale=std,
                                 size=(n_layers, n_wires))
     a = np.random.normal(loc=mean_a, scale=std_a, size=(n_layers, n_wires))
     phi_a = np.random.normal(loc=mean, scale=std, size=(n_layers, n_wires))
     k = np.random.normal(loc=mean_a, scale=std_a, size=(n_layers, n_wires))
     p_target = [
         theta_1, phi_1, varphi_1, r, phi_r, theta_2, phi_2, varphi_2, a,
         phi_a, k
     ]
     assert np.allclose(p, p_target, atol=tol, rtol=0.)