def test_continuous_oscillation_optimal_control( continuous_oscillation_operator, density, coordinate_tensor, num_dims, periodic, control_weight): if not continuous_oscillation_operator.has_analytic_solution: pytest.skip() # Define the inputs t = np.sqrt(2) ic = md.evaluate_gaussian_kernel(coordinate_tensor, .25, 1, 0.05**2) ic = [ic, np.zeros_like(ic)] setpoint = md.evaluate_gaussian_kernel(coordinate_tensor, .75, 1, 0.05**2) setpoint = [setpoint, np.zeros_like(setpoint)] z_nc = continuous_oscillation_operator.integrate_analytic(ic, t) # Evaluate the control field control = continuous_oscillation_operator.evaluate_control( ic, setpoint, np.eye(2), control_weight * np.eye(2), t) z_wc = continuous_oscillation_operator.integrate_analytic(ic, t, control=control) # Check that the result with control is better than the one without corrcoef_nc = np.corrcoef(np.ravel(setpoint), z_nc.ravel())[0, 1] corrcoef_wc = np.corrcoef(np.ravel(setpoint), z_wc.ravel())[0, 1] assert corrcoef_wc > corrcoef_nc # Assert that we get the "right" result if the control weight is zero if control_weight == 0: md.assert_correlated(setpoint, z_wc)
def initial_conditions(coordinate_tensor, num_dims): center = np.random.uniform(0, 1, num_dims) ic = md.evaluate_gaussian_kernel(coordinate_tensor, center, 1, 0.5**2, domain=None) return ic[None] # Add the first dimension
def test_continous_oscillation_operator_with_control( continuous_oscillation_operator, density, coordinate_tensor, num_dims, periodic): center = np.random.uniform(0, 1, num_dims) ic = md.evaluate_gaussian_kernel(coordinate_tensor, center, 1, 0.05**2) ic = [ic, np.zeros_like(ic)] _test_integration(continuous_oscillation_operator, ic, control=np.ones_like(ic))
def test_continuous_oscillation_supramatrix(continuous_oscillation_operator, density, coordinate_tensor, num_dims, periodic): center = np.random.uniform(0, 1, num_dims) ic = md.evaluate_gaussian_kernel(coordinate_tensor, center, 1, 0.05 ** 2) ic = np.asarray([ic, np.zeros_like(ic)]) grad1 = continuous_oscillation_operator.evaluate_gradient(ic) grad2 = continuous_oscillation_operator.supramatrix.dot(ic.ravel()).reshape(ic.shape) corrcoef = np.corrcoef(grad1.ravel(), grad2.ravel()) assert corrcoef[0, 1] > 0.95