Code Documentation¶
- class src.markovanalyzer.polyspectra_calculator.System(transition_dict, measurement_op, gamma_ph=None, gamma_det=None)¶
Class that will represent the system of interest. It contains the parameters of the system and the methods for calculating and storing the polyspectra.
Parameters¶
Attributes¶
- freqdict
Stores the frequencies from the analytic spectra, order 2 to 4
- Sdict
Stores the analytic spectra, order 2 to 4
- numeric_f_datadict
Stores the frequencies from the numeric spectra, order 2 to 4
- numeric_spec_datadict
Stores the numeric spectra, order 2 to 4
- eigvalsarray
Stores eigenvalues of Liouvillian
- eigvecsarray
Stores eigenvectors of Liouvillian
- eigvecs_invarray
Stores the matrix inversion of the eigenvector matrix
- zero_indint
Contains the index of the steady state in the eigvalues
- A_primarray
Stores the measurement superoperator mathcal{A} as defined in 10.1103/PhysRevB.98.205143
- rho_steadyarray
Steady state of the Liouvillian
- s_karray
Stores small s (Eq. 7) from 10.1103/PhysRevB.102.119901
- Nint
Number of points in time series in window for the calculation of numerical spectra
- fsfloat
Sampling rate of the simulated signal for numerical spectra
- a_warray
Fourier coefficients of simulated signal for numerical spectra
- a_w_cutarray
Contains only the frequencies of interest from a_w (to speed up calculations)
- enable_gpubool
Set if GPU should be used for analytic spectra calculation
- gpu_0int
Stores pointer to zero an the GPU
- calc_a_w3(a_w)¶
Preparation of a_(w1+w2) for the calculation of the bispectrum
Parameters¶
- a_warray
Fourier coefficients of signal
Returns¶
- a_w3array
Matrix corresponding to a_(w1+w2)
- calculate_one_spectrum(f_data, order, bar=True, verbose=False, beta_offset=True, enable_gpu=False, cache_trispec=True)¶
Calculates analytic polyspectra (order 2 to 4) as described in 10.1103/PhysRevB.98.205143 and 10.1103/PhysRevB.102.119901
Parameters¶
- f_dataarray
Frequencies at which the spectra are calculated
- orderint {2,3,4}
Order of the polyspectra to be calculated
- g_primbool
Set if mathcal_a should be applied twice/squared (was of use when defining the current operator) But unnecessary for standard polyspectra
- barbool
Set if progress bars should be shown during calculation
- verbosebool
Set if more details about the current state of the calculation are needed
- correction_onlybool
Set if only the correction terms of the S4 from erratum 10.1103/PhysRevB.102.119901 should be calculated
- beta_offsetbool
Set if constant offset due to deetector noise should be added to the power spectrum
- enable_gpubool
Set if GPU should be used for calculation
- cache_trispecbool
Set if Matrix multiplication in the calculation of the trispectrum should be cached
Returns¶
- S[order]array
Returns spectral value at specified frequencies
- extension_for_single_photon(rates, m_op, gamma_ph, gamma_det)¶
Adds further connections to the rates dictionary based on the input array m_op and float gamma_det.
Parameters¶
- ratesdict
Existing rates dictionary where keys are in ‘from_state->to_state’ format and values are the rates.
- m_oplist
Array of rates used to connect the original levels with their corresponding replicated levels.
- gamma_detfloat
Rate used to connect each replicated level back to its original level.
Returns¶
- dict
Extended rates dictionary containing both the original, replicated, and new connection rates.
Example¶
>>> rates = {'0->1': 'gamma_in', '0->2': 'gamma_in', '1->0': 'gamma_A', '1->2': 'gamma_spin + gamma_R', '2->1': 'gamma_spin'} >>> m_op = ['m_op[0]', 'm_op[1]', 'm_op[2]'] >>> gamma_det = 'gamma_det' >>> extension_for_single_photon(rates, m_op, gamma_det) { '0->1': 'gamma_in', '0->2': 'gamma_in', '1->0': 'gamma_A', '1->2': 'gamma_spin + gamma_R', '2->1': 'gamma_spin', '3->4': 'gamma_in', '3->5': 'gamma_in', '4->3': 'gamma_A', '4->5': 'gamma_spin + gamma_R', '5->4': 'gamma_spin', '0->3': 'm_op[0]', '1->4': 'm_op[1]', '2->5': 'm_op[2]', '3->0': 'gamma_det', '4->1': 'gamma_det', '5->2': 'gamma_det' }
- first_matrix_step(rho, omega)¶
Helper method to move function out of the class. njit is not working within classes
- matrix_step(rho, omega)¶
Helper method to move function out of the class. njit is not working within classes
- plot_all(f_max=None)¶
Method for quick plotting of polyspectra
Parameters¶
- f_maxfloat
Maximum frequencies upto which the spectra should be plotted
Returns¶
Returns matplotlib figure
- replicate_and_extend_rates(rates)¶
Replicates the rates dictionary by adding the highest state number + 1 to all states. The replicated rates are then added to the original rates dictionary.
Parameters¶
- ratesdict
Original rates dictionary where keys are in ‘from_state->to_state’ format and values are the rates.
Returns¶
- dict
Extended rates dictionary containing both the original and replicated rates.
Example¶
>>> rates = {'0->1': 'gamma_in', '0->2': 'gamma_in', '1->0': 'gamma_A', '1->2': 'gamma_spin + gamma_R', '2->1': 'gamma_spin'} >>> replicate_and_extend_rates(rates) {'0->1': 'gamma_in', '0->2': 'gamma_in', '1->0': 'gamma_A', '1->2': 'gamma_spin + gamma_R', '2->1': 'gamma_spin', '3->4': 'gamma_in', '3->5': 'gamma_in', '4->3': 'gamma_A', '4->5': 'gamma_spin + gamma_R', '5->4': 'gamma_spin'}
- second_matrix_step(rho, omega, omega2)¶
Helper method to move function out of the class. njit is not working within classes
- transform_m_op(old_m_op)¶
Transforms the input array old_m_op to a new array new_m_op. The new array is twice as long, with the original entries set to 0, and the new entries set to 1.
Parameters¶
- old_m_opnumpy.ndarray
Original m_op array.
Returns¶
- new_m_opnumpy.ndarray
Transformed m_op array.
Example¶
>>> old_m_op = np.array([1, 0, 0]) >>> transform_m_op(old_m_op) array([0, 0, 0, 1, 1, 1])
- src.markovanalyzer.polyspectra_calculator.pickle_save(path, obj)¶
Helper function to pickle system objects
Parameters¶
- pathstr
Location of saved data
obj : System obj
- src.markovanalyzer.polyspectra_calculator.rates_to_matrix(rates)¶
Convert a dictionary of rates to a continuous-time Markov process transition rate matrix.
Parameters¶
- ratesdict
Dictionary containing the rates for each transition. Keys should be in the format ‘from_state->to_state’ and values should be non-negative floats representing the rates.
Returns¶
- np.ndarray
A NumPy array representing the transition rate matrix.
Raises¶
- ValueError
If the keys in the dictionary are not in the ‘from_state->to_state’ format or if rates are negative.
Example¶
>>> rates = {"1->2": 0.5, "2->1": 0.7, "2->3": 0.2} >>> rates_to_matrix(rates) array([[-0.5, 0.5, 0. ], [ 0.7, -0.9, 0.2], [ 0. , 0. , 0. ]])
- src.markovanalyzer.polyspectra_calculator.second_term(omega1, omega2, omega3, s_k, eigvals, enable_gpu)¶
For the calculation of the erratum correction terms of the S4. Calculates the second sum as defined in Eq. 109 in 10.1103/PhysRevB.102.119901.
Parameters¶
- enable_gpubool
Specify if GPU should be used
- omega1float
Frequency of interest
- omega2float
Frequency of interest
- omega3float
Frequency of interest
- s_karray
Array calculated with :func:small_s
- eigvalsarray
Eigenvalues of the Liouvillian
Returns¶
- out_sumarray
Second correction term as defined in Eq. 109 in 10.1103/PhysRevB.102.119901.
- src.markovanalyzer.polyspectra_calculator.small_s(rho_steady, a_prim, eigvecs, eigvec_inv, enable_gpu, zero_ind, gpu_zero_mat)¶
For the calculation of the erratum correction terms of the S4. Calculates the small s (Eq. 7) from 10.1103/PhysRevB.102.119901
Parameters¶
- zero_indint
Index of the steadystate eigenvector
- enable_gpubool
Specify if GPU should be used
- gpu_zero_mataf array
Zero array stored on the GPU
- rho_steadyarray
A @ Steadystate density matrix of the system
- a_primarray
Super operator A’ as defined in 10.1103/PhysRevB.98.205143
- eigvecsarray
Eigenvectors of the Liouvillian
- eigvec_invarray
The inverse eigenvectors of the Liouvillian
- reshape_indarray
Indices that give the trace of a flattened matrix.
Returns¶
- s_karray
Small s (Eq. 7) from 10.1103/PhysRevB.102.119901
- src.markovanalyzer.polyspectra_calculator.third_term(omega1, omega2, omega3, s_k, eigvals, enable_gpu)¶
For the calculation of the erratum correction terms of the S4. Calculates the third sum as defined in Eq. 109 in 10.1103/PhysRevB.102.119901.
Parameters¶
- enable_gpubool
Specify if GPU should be used
- omega1float
Frequency of interest
- omega2float
Frequency of interest
- omega3float
Frequency of interest
- s_karray
Array calculated with :func:small_s
- eigvalsarray
Eigenvalues of the Liouvillian
Returns¶
- out_sumarray
Third correction term as defined in Eq. 109 in 10.1103/PhysRevB.102.119901.
- src.markovanalyzer.fitting_tools.arcsinh_scaling(s_data, arcsinh_const, order, s_err=None, s_err_p=None, s_err_m=None)¶
Helper function to improve visibility in plotting (similar to a log scale but also works for negative values)
Parameters¶
- s_dataarray
spectral values of any order
- arcsinh_constfloat
these parameters sets the rescaling amount (the smaller, the stronger the rescaling)
- orderint
important since the error arrays are called differently in the second-order case
- s_errarray
spectral errors of order 3 or 4
- s_err_parray
spectral values + error of order 2
- s_err_marray
spectral values - error of order 2
Returns¶
- src.markovanalyzer.gpu_backend.second_term_gpu(omega1, omega2, omega3, s_k, eigvals)¶
For the calculation of the erratum correction terms of the S4. Calculates the second sum as defined in Eq. 109 in 10.1103/PhysRevB.102.119901.
Parameters¶
- omega1float
Frequency of interest
- omega2float
Frequency of interest
- omega3float
Frequency of interest
- s_karray
Array calculated with :func:small_s
- eigvalsarray
Eigenvalues of the Liouvillian
Returns¶
- out_sumarray
Second correction term as defined in Eq. 109 in 10.1103/PhysRevB.102.119901.
- src.markovanalyzer.gpu_backend.third_term_gpu(omega1, omega2, omega3, s_k, eigvals)¶
For the calculation of the erratum correction terms of the S4. Calculates the third sum as defined in Eq. 109 in 10.1103/PhysRevB.102.119901.
Parameters¶
- omega1float
Frequency of interest
- omega2float
Frequency of interest
- omega3float
Frequency of interest
- s_karray
Array calculated with :func:small_s
- eigvalsarray
Eigenvalues of the Liouvillian
Returns¶
- out_sumarray
Third correction term as defined in Eq. 109 in 10.1103/PhysRevB.102.119901.
- src.markovanalyzer.model_comparison_tools.compare_models(result1, result2)¶
Compare two lmfit.MinimizerResult objects.
Parameters: - result1: lmfit.MinimizerResult for the simpler model - result2: lmfit.MinimizerResult for the complex model
Returns: - A dictionary with AIC, BIC for each model and the p-value for the Likelihood Ratio Test
- src.markovanalyzer.njit_backend.second_term_njit(omega1, omega2, omega3, s_k, eigvals)¶
For the calculation of the erratum correction terms of the S4. Calculates the second sum as defined in Eq. 109 in 10.1103/PhysRevB.102.119901.
Parameters¶
- omega1float
Frequency of interest
- omega2float
Frequency of interest
- omega3float
Frequency of interest
- s_karray
Array calculated with :func:small_s
- eigvalsarray
Eigenvalues of the Liouvillian
Returns¶
- out_sumarray
Second correction term as defined in Eq. 109 in 10.1103/PhysRevB.102.119901.
- src.markovanalyzer.njit_backend.third_term_njit(omega1, omega2, omega3, s_k, eigvals)¶
For the calculation of the erratum correction terms of the S4. Calculates the third sum as defined in Eq. 109 in 10.1103/PhysRevB.102.119901.
Parameters¶
- omega1float
Frequency of interest
- omega2float
Frequency of interest
- omega3float
Frequency of interest
- s_karray
Array calculated with :func:small_s
- eigvalsarray
Eigenvalues of the Liouvillian
Returns¶
- out_sumarray
Third correction term as defined in Eq. 109 in 10.1103/PhysRevB.102.119901.