def test_phase_factor_coefficients(): """This test will generate the phase factor coefficients (see Eqns. 5.7 5.12 in Kittara's thesis) once using the calculate_phase_factor_coeff() function from the qmix.qtcurrent module, and once using the _calculate_phase_factor_coeff() function found at the bottom of this file. The code found in the _calculate_phase_factor_coeff() function was taken from an old version of the QMix code. It is much simpler than the current version because it hasn't been optimized. It is relatively easy to ensure that this code is correct. In this way, we can use it to validate the optimized code.""" # Generate dummy input values num_f = 4 # Number of tones num_p = 2 # Number of harmonics num_b = 15 # Number of Bessel functions cct = EmbeddingCircuit(num_f, num_p) cct.freq[1] = 0.30 # LO cct.freq[2] = 0.33 # USB cct.freq[3] = 0.27 # LSB cct.freq[4] = 0.03 # IF vj = cct.initialize_vj() vj[1, 1, :] = 0.30 * np.exp(1j * 2.0) vj[2, 1, :] = 0.10 * np.exp(1j * 1.5) vj[3, 1, :] = 0.10 * np.exp(1j * -0.3) vj[4, 1, :] = 0.00 * np.exp(1j * 1.0) vj[1, 2, :] = 0.03 * np.exp(1j * 0.2) vj[2, 2, :] = 0.01 * np.exp(1j * -1.7) vj[3, 2, :] = 0.01 * np.exp(1j * -0.2) vj[4, 2, :] = 0.00 * np.exp(1j * -1.5) ckh_known = _calculate_phase_factor_coeff(vj, cct.freq, num_f, num_p, num_b) ckh_qmix = calculate_phase_factor_coeff(vj, cct.freq, num_f, num_p, num_b) np.testing.assert_almost_equal(ckh_qmix, ckh_known, decimal=12)
def two_tone(): calculate_phase_factor_coeff(vj, cct.freq, 2, 2, num_b)
def one_tone(): calculate_phase_factor_coeff(vj, cct.freq, 1, 2, num_b)
def four_tone(): calculate_phase_factor_coeff(vj, cct.freq, 4, 2, num_b)
def three_tone(): calculate_phase_factor_coeff(vj, cct.freq, 3, 2, num_b)
cct = qmix.circuit.EmbeddingCircuit(1, 2) cct.freq[1] = 0.3 vj = cct.initialize_vj() vj[1, 1, :] = 0.3 vj[1, 2, :] = 0.03 def one_tone(): calculate_phase_factor_coeff(vj, cct.freq, 1, 2, num_b) t_1tone = min(timeit.Timer(one_tone).repeat(1000, 1)) print("1 tone:\t\t{:.2f} ms".format(t_1tone * 1000)) ccc1 = calculate_phase_factor_coeff(vj, cct.freq, 1, 2, num_b) if args.overwrite: print(" -> Save ccc1") with open('data/coeff1.data', 'wb') as f: pickle.dump(ccc1, f) else: print(" -> Load ccc1") with open('data/coeff1.data', 'rb') as f: ccc1_test = pickle.load(f) np.testing.assert_allclose(ccc1, ccc1_test, atol=1e-7) # plt.plot(ccc1) # plt.plot(ccc1_test) # plt.show() # 2 tone ---------------------------------------------------------------------