Code Documentation

class src.quantumcatch.simulation.System(h, psi_0, c_ops, sc_ops, e_ops, c_measure_strength, sc_measure_strength)

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

hQobj

Hamiltonian of the system.

psi_0Qobj

Initial state of the system for the integration of the SME.

c_opsdict

Dictionary containing the collaps operators (as Qobj) with arbitrary str as keys.

sc_opsdict

Dictionary containing the stochastic collaps operators (as Qobj) with arbitrary str as keys.

e_opsdict

Dictionary containing the operators (as Qobj) used for the calculation of the expectation values with arbitrary str as keys.

c_measure_strengthdict

Dictionary containing the prefactor (float) of the collaps operators. Should have the same keys as the corresponding collaps operators in c_ops.

sc_measure_strengthdict

Dictionary containing the prefactor (float) of the stochastic collaps operators. Should have the same keys as the corresponding collaps operators in sc_ops.

Attributes

Harray

Hamiltonian of the system

Larray

Liouvillian of the system

psi_0: array

Start state for the integration of the stochastic master equation

c_opsdict

Dictionary containing the collaps operators (as Qobj) with arbitrary str as keys.

sc_opsdict

Dictionary containing the stochastic collaps operators (as Qobj) with arbitrary str as keys.

e_opsdict

Dictionary containing the operators (as Qobj) used for the calculation of the expectation values with arbitrary str as keys.

c_measure_strengthdict

Dictionary containing the prefactor (float) of the collaps operators. Should have the same keys as the corresponding collaps operators in c_ops.

sc_measure_strengthdict

Dictionary containing the prefactor (float) of the stochastic collaps operators. Should have the same keys as the corresponding collaps operators in sc_ops.

time_series_data_emptydataframe

Empty version of the simulation results dataframe to reset any results.

time_series_datadataframe

Stores expectation values after the integration of the SME

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

expect_datadict

Stores expectation values calculated during the integration of the SME (daemon view), keys as in e_ops

expect_with_noisedict

Stores expectation + detector noise values calculated during the integration of the SME, keys as in e_ops

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

reshape_ind: array

Extracts the trace from a flatted matrix (to avoid reshaping)

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)

calc_transient(t, seed=None, _solver=None, progress_bar=None, _nsubsteps=1, _normalize=None, options=None, return_result=False)

This function integrates the Stochastic Master Equation (SME) for the system defined by mathcal{L} and the initial state rho_0. The results, including the daemon view and measurement with detector noise, are saved in a dataframe.

Parameters

tarray

The time points at which the SME is integrated.

seedint, optional

The seed for the random number generator used in the generation of the Wiener Process.

_solverstr, optional

The name of the solver used for the integration of the SME. Refer to the qutip documentation for more information on available solvers.

_nsubstepsint, optional

The number of substeps to be taken between two points in t. This can help reduce numerical errors.

_normalizebool, optional

If set to True, the density matrix will be normalized after each integration step.

progress_barbool, optional

If set to True, a progress bar will be displayed during the integration process.

optionsdict, optional

A dictionary of solver options. Refer to the qutip documentation for more information on available options.

return_resultbool, optional

If set to True, the solver result will be returned in addition to the dataframe.

Returns

dataframe

A dataframe containing the daemon view and measurement with detector noise. If return_result is set to True, the solver result will also be returned.

calculate_one_spectrum(f_data, order, measure_op=None, mathcal_a=None, g_prim=False, bar=True, verbose=False, beta=None, correction_only=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

measure_opstr

Key of the operator in sc_ops to be used as measurement operator

mathcal_aarray

Stores the measurement superoperator mathcal{A} as defined in 10.1103/PhysRevB.98.205143

g_primbool

!Depreciated! 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

betafloat

Measurement strength used for the calculation. If not set beta is the prefactor in sc_measure_strength[measure_op]

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

first_matrix_step(rho, omega)

Helper method to move function out of the class. njit is not working within classes

g_prim(t)

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

numeric_spec(t_window_in, measure_op, f_max, power, order, max_samples, m=5, _solver='milstein', plot_after=12, title_in=None, with_noise=False, _normalize=None, roll=False, plot_simulation=False, backend='opencl')

Old method! Not functioning! Method for the automated calculation of the polyspectra from the numerical integration of the SME. Can be used as an alternative to the analytic quantum polyspectra or to estimated measurement time and noise levels of the spectra.

Parameters

t_window_inarray

Times at with the SME will be integrated

measure_opstr

Key of the operator in sc_ops that should be used as measurement operator

f_maxfloat

Maximum frequency of interest to speed up calculation of polyspectra

powerfloat

Power to which the detector output should be raised before the calculation of the spectra (Was useful during the experimentation with the current operator.)

orderint {2,3,4}

Order of the polyspectra to be calculated

max_samplesint

Number of spectra with m windows to be calculated. The final result will be an average over all these spectra

mint

number of frames used from the calculation of one spectrum

_solverstr

Name of the solver used for the intergration of the SME (see the qutip docs for more information)

plot_afterint

Each number of spectra after with the current average spectrum should be displayed

title_instr

Add a str to customize title

with_noisebool

Set if detector output with noise should be used for the calculation of the spectra instead of the daemon view

_normalizebool

Set if density matrix should be normalized during integration of the SME

rollbool

Set if trace should be shifted against itself during squaring

plot_simulationbool

Set if simulation result / trace should be plot. Useful to check for numerical errors during integration

backendstr {cpu, opencl, cuda}

Backend to be used by arrayfire

Returns

Return frequencies and the spectral values as arrays

parallel_tranisent(seed, measure_op, t=None, _solver=None, with_noise=False, _nsubsteps=1, _normalize=None)

Method for the quick integration of the SME (avoids saving the results into dataframes). Is used for parallelization of the integration.

Parameters

seedint

Seed for the generation of random numbers for the Wiener process

measure_opstr

Key of the measurement operator in sc_ops

tarray

Times at which the integration takes place

_solverstr

Name of the solver used for the intergration of the SME (see the qutip docs for more information)

with_noisebool

Set if detector noise should be added to the trace

_nsubstepsint

Number of substeps between to point in t. Reduces numerical errors.

_normalizebool

Set if density matrix should be normalized after each integration step

Returns

outarray

Simulated detector output

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

plot_spectrum(order, title=None, log=False, x_range=False, imag_plot=False)

Method for the visualization of single spectra with an interactive plot

Parameters

orderint {2,3,4}

Order of polyspectrum to be plotted

titlestr

Title of the plot

logbool

Set if log scales should be used

x_rangearray

Sets limits of x axis

imag_plotbool

Set if imaginary of the spectrum should be shown

Returns

Returns plotly figure

plot_transient(ops_with_power, title=None, shift=False)

Interactive plot of the integration results.

Parameters

ops_with_powerdict

Key of the operators in e_ops as key with integer labels corresponding the exponent to with the corresponding trace should be raised to. (Was useful during the experimentation with the current operator.)

titlestr

Title of plot

shiftbool

Set if traces should be shifted up to avoid overlapping of multiple traces

Returns

Plotly figure

save_spec(path)

Save System class with spectral data

Parameters

pathstr

Location of file

second_matrix_step(rho, omega, omega2)

Helper method to move function out of the class. njit is not working within classes

single_plot(order, f_max, f_min=0, arcsinh_plot=False, arcsinh_const=0.02, contours=False, s3_filter=0, s4_filter=0, s2_data=None, s3_data=None, s4_data=None, s2_f=None, s3_f=None, s4_f=None, imag_plot=False, title=None)

Generates plot of the polyspectum of order “order”

Parameters

orderint {2,3,4}

Order of polyspectrum to be plotted

f_maxfloat

Maximum value of frequency axis

f_minfloat

Minimum value of frequency axis

arcsinh_plotbool

Set if spectral values should be scaled by an arcsinh function (improves visability of small features)

arcsinh_constfloat

Constant to customize the effenct of the scaling

contoursbool

Set if contours should be shown in the 2D plots

s3_filterint

Width of the Gaussian filter applied to the S3

s4_filterint

Width of the Gaussian filter applied to the S4

s2_dataarray

Spectral data for the S2

s3_dataarray

Spectral data for the S3

s4_dataarray

Spectral data for the S4

s2_farray

Frequencies corresponding to the spectral data of the S2

s3_farray

Frequencies corresponding to the spectral data of the S3

s4_farray

Frequencies corresponding to the spectral data of the S4

imag_plotbool

Set if imaginary part of the spectrum should be plotted

titleset

Title of the plot

Returns

Matplotlib figure

src.quantumcatch.simulation.calc_liou(rho_, h, c_ops_)

This function calculates the outcome of applying the Liouvillian to the density matrix. It is used to calculate the superoperator form of the Liouvillian.

Parameters

rho_array

The input test states, typically represented as a list of zeros and ones (e.g., [1,0,0,…]).

harray

The Hamiltonian operator, represented as an array.

c_ops_array

The collapse operators for the Lindblad dampers, represented as an array.

Returns

liouarray

The result of applying the Liouvillian to rho_, represented as an array. Mathematically, this is equivalent to mathcal{L} @ rho_.

src.quantumcatch.simulation.calc_super_A(op)

Calculates the super operator of A as defined in 10.1103/PhysRevB.98.205143

Parameters

oparray

Operator a for the calculation of A[a]

Returns

op_superarray

Superoperator A

src.quantumcatch.simulation.calc_super_liou(h_, c_ops)

Calculates the superoperator form of the Liouvillian by checking one basis state of the density matrix after the other: [1,0,0…], [0,1,0,0,…], etc.

Parameters

h_array

The Hamiltonian operator.

c_opsarray

The collapse operators for the Lindblad dampers.

Returns

op_superarray

The superoperator form of the Liouvillian.

src.quantumcatch.simulation.cgw(len_y)

Creates an array corresponding to the approx. confined gaussian window function

Parameters

len_yint

Length of the window

Returns

window : array

src.quantumcatch.simulation.pickle_save(path, obj)

This function pickles and saves system objects to a specified location. Pickling is the process of converting a Python object into a byte stream, and it’s useful for saving and loading complex objects.

Parameters

pathstr

The path where the pickled object will be saved. This should include the full directory path as well as the filename and .pickle extension.

objSystem obj

The system object to be pickled and saved. This can be any Python object.

src.quantumcatch.simulation.plotly(x, y, title, domain, order=None, y_label=None, x_label=None, legend=None, filter_window=None)

This function provides an easy interface for creating plots with Plotly. It allows for customization of various aspects of the plot, including the title, axis labels, and legend.

Parameters

xarray

The x-coordinates for the points in the plot.

yarray

The y-coordinates for the points in the plot.

titlestr

The title of the plot.

domainstr (‘freq’, ‘time’)

Specifies the domain of the data. This changes the plot style depending on whether the input is in the frequency or time domain.

orderint (2, 3, 4), optional

The order of the spectrum to be shown. This can be 2, 3, or 4.

y_labelstr, optional

The label for the y-axis.

x_labelstr, optional

The label for the x-axis.

legendlist, optional

A list of trace names for the legend.

filter_windowint, optional

For noisy data, the spectra can be convoluted with a Gaussian of length filter_window. This can help smooth out the noise and make the underlying signal more apparent.

Returns

figure

The resulting Plotly figure. This can be displayed or saved using Plotly’s built-in functions.

src.quantumcatch.simulation.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.quantumcatch.simulation.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.quantumcatch.simulation.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.quantumcatch.simulation.small_s(rho_steady, a_prim, eigvecs, eigvec_inv, reshape_ind, 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.quantumcatch.simulation.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.quantumcatch.simulation.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.quantumcatch.simulation.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.

src.quantumcatch.simulation.time_series_setup(sc_ops, e_ops)

Creates a dataframe for storing the simulation results.

Parameters

sc_opsdict

Dictionary with all stochastic collapse operators with corresponding names as keys.

e_opsdict

Dictionary with all operators for the calculation of the expectation values with corresponding names as keys.

Returns

Returns a dataframe with columns names like the keys.

src.quantumcatch.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