utils package¶
Submodules¶
utils.PerfectStateTransfer module¶
- isStrCospec(A, a, b)[source]¶
For a graph to have PST it needs to obey numerous rules and the first one is that the vertices with PST must be strongly cospectral. Two vertices a and b are strong cospectral if the characteristic polynomial of the matrix Ma, that has the colum and row a removed, is equal to the characteristic polynomial of the matrix Mb, that has the column and row b removed. This is easily checked using SymPy and it is what the function StrCospec does.
- Parameters:
A (_type_) – _description_
a (_type_) – _description_
b (_type_) – _description_
- Returns:
_description_
- Return type:
_type_
- isSimplePoles(phi, phiab)[source]¶
The second condition for strong cospectral is that the poles of phiab/phi must be simple. This is trickier to check and it starts by defning a polynomial g(x)=gcd(phi,phiab). Then, there will be no poles if f(x) = phi/g(x) is a polynomial without repeated roots. This occurs when gcd(f(x),f’(x)) is a constant, then we only need to check the coeeficients and see if all of them is zero except the last one. This is done by the function SimplePoles.
- Parameters:
phi (_type_) – _description_
phiab (_type_) – _description_
- Returns:
_description_
- Return type:
_type_
- sieveEratosthenes(n)[source]¶
One of the steps requires that we find square-free numbers, that is, numbers that have a prime decomposition with all primes being unique. Fist we use the Sieve of Eratosthenes, and the corresponding function, to find all primes from 1 to n. It works by choosing the first prime in the list, in this case 2, then squareing it and removing all its multiples from the list. The algorithm then choose the next prime and does the same procedure. At the end, we have a list with True at position i if i+1 is prime and False otherwise.
- Parameters:
n (_type_) – _description_
- Returns:
_description_
- Return type:
_type_
- getSquareFree(n)[source]¶
The function SquareFree gives a list of square-free number from 1 to n in a similar way that we found all primes. The algorithm get the list of primes from 1 to n, then it start a loop of integers from 2 to n, when i is prime the algorithm associates False to all multiples of i^2. It returns a list with True (False) in the entry i if i-1 is (not) square free.
- Parameters:
n (_type_) – _description_
- Returns:
_description_
- Return type:
_type_
- getEigenSupp(a, eigenvec, eigenval)[source]¶
Returns the eigenvalue support of the vertex a.
The eigenvalue support of the vertex a is the set of all eigenvalues such that the projection matrix of the eigenvalue r applied to the vector with 1 in the a-th entry and zero in all others is not zero.
- Parameters:
a (int) – The index of the vertex.
eigenvec (numpy.ndarray) – The eigenvectors of the graph.
eigenval (numpy.ndarray) – The eigenvalues of the graph.
- Returns:
The eigenvalues in the eigenvalue support of the vertex a.
- Return type:
list
- checkRoots(A, a, eigenvec, eigenval)[source]¶
CheckRoots is responsible for checking the second condition for PST which is that all eigenvalues is the eigenvalue support of a must be all integers or all quadratic integers with the format p+qr*Sqrt(delta)/2, with qr changing from eigenvalue to to eigenvalue. The frist step is to define h(x) = phi/gcd(phi,phia) that have all its roots in the eigenvalue support of a, then its degree k will be crucial. First, we check for integer roots in the interval [-n^4,n^4] that the eigenvalues should be. We check by putting the value in the loop, i, direct into h(i) and we see if it is equal to zero. If it is, then we check if i is in the eigenvalue support of a. With both conditions satisfied, it stores 1 to delta and sum one to intRoots. Then we check if all roots are quadratic integers p+qr*Sqrt(delta)/2. We know that p will be equal to the coefficient of the second bigest power of h(x). Then, all we need to do is loop through the values of delta in the list of square-free integers. Then, we loop qr until it is bigger than Sqrt(Tr(A²)) and check if is a root of h(x) and it is also in the eigenvalue support of a. In case it is true, we store the value of delta and sum one to quadRoots. Here we check if quadRoots or intRoots are bigger than k, which is the degree of our polynomial h(x). If none of them is then we know that PST is not possible and we return False. The time that PST occurs is just pi/g*Sqrt(delta) where g = gcd(theta0 - thetar), i.e. the gcd between all the differences of the eigenvalue theta0 (the biggest eigenvalue) and all others eigenvalues.
- Parameters:
A (_type_) – _description_
a (_type_) – _description_
eigenvec (_type_) – _description_
eigenval (_type_) – _description_
- Returns:
_description_
- Return type:
_type_
utils.jsonTools module¶
utils.plotTools module¶
- plot_qwak(x_value_matrix, y_value_matrix, x_label=None, y_label=None, plot_title=None, legend_labels=None, legend_title=None, legend_ncol=3, legend_loc='best', save_path=None, font_size=16, figsize=(12, 8), color_list=None, line_style_list=None, use_loglog=False, use_cbar=False, cbar_label=None, cbar_ticks_generator=None, cbar_num_ticks=3, cbar_tick_labels=['a', 'b', 'c'], x_num_ticks=None, y_num_ticks=None, x_round_val=3, y_round_val=3, v_line_values=None, v_line_style='--', v_line_list_index=None, v_line_colors=None, x_lim=None, use_grid=False, **kwargs)[source]¶
Plots data from a matrix of x values and a matrix of y values. Note that all parameters can be passed via a dictionary using the **kwargs syntax.
- Parameters:
x_value_matrix (array_like) – A matrix of x values. Each row is a set of x values for a single line.
y_value_matrix (array_like) – A matrix of y values. Each row is a set of y values for a single line.
x_label (str, optional) – The label for the x-axis. The default is None.
y_label (str, optional) – The label for the y-axis. The default is None.
plot_title (str, optional) – The title of the plot. The default is None.
legend_labels (list, optional) – A list of strings to be used as labels for the legend. The default is None.
legend_title (str, optional) – The title of the legend. The default is None.
legend_ncol (int, optional) – The number of columns in the legend. The default is 3.
legend_loc (str, optional) – The location of the legend. The default is ‘best’.
save_path (str, optional) – The path to save the plot to. The default is None.
font_size (int, optional) – The font size of the plot. The default is 12.
figsize (tuple, optional) – The size of the figure. The default is (10,6).
color_list (list, optional) – A list of colors to be used for the lines. The default is None.
line_style_list (list, optional) – A list of line styles to be used for the lines. The default is None.
use_loglog (bool, optional) – Whether to use a log-log plot. The default is False.
use_cbar (bool, optional) – Whether to use a colorbar. The default is False.
cbar_label (str, optional) – The label for the colorbar. The default is None.
cbar_ticks_generator (function, optional) – A function that generates the ticks for the colorbar. The default is None.
cbar_num_ticks (int, optional) – The number of ticks for the colorbar. The default is 3.
cbar_tick_labels (list, optional) – A list of strings to be used as labels for the colorbar ticks. The default is [‘a’,’b’,’c’].
x_num_ticks (int, optional) – The number of ticks for the x-axis. The default is None.
y_num_ticks (int, optional) – The number of ticks for the y-axis. The default is None.
x_round_val (int, optional) – The number of decimal places to round the x-axis ticks to. The default is 3.
y_round_val (int, optional) – The number of decimal places to round the y-axis ticks to. The default is 3.
v_line_values (list, optional) – A list of values to plot vertical lines at. The default is None.
v_line_style (str, optional) – The style of the vertical lines. The default is ‘–‘.
v_line_list_index (int, optional) – The index of the line to plot the vertical lines on. The default is None.
v_line_colors (list, optional) – A list of colors to be used for the vertical lines. The default is None.
x_lim (tuple, optional) – The limits of the x-axis. The default is None.
use_grid (bool, optional) – Whether to use a grid. The default is False.
marker_list (list, optional) – A list of markers to be used for the lines. The default is None.
marker_interval (int, optional) – Interval at which markers should be placed. The default is None.
- plot_qwak_heatmap(p_values, t_values, prob_values, x_num_ticks=5, y_num_ticks=5, x_round_val=3, y_round_val=3, filepath=None, N=None, xlabel=None, ylabel=None, cbar_label=None, font_size=12, figsize=(8, 6), cmap='coolwarm', x_vline_value=None, y_hline_value=None, title_font_size=16, xlabel_font_size=14, ylabel_font_size=14, tick_font_size=12, **kwargs)[source]¶
Plot a heatmap of the probability of a given p and t value.
- Parameters:
p_values (list of lists) – List of lists of p values.
t_values (list of lists) – List of lists of t values.
prob_values (list of lists) – List of lists of probability values.
x_num_ticks (int, optional) – Number of x-axis ticks. The default is 5.
y_num_ticks (int, optional) – Number of y-axis ticks. The default is 5.
x_round_val (int, optional) – Number of decimal places to round x-axis tick labels. The default is 3.
y_round_val (int, optional) – Number of decimal places to round y-axis tick labels. The default is 3.
filepath (str, optional) – Path to save the plot. The default is None.
N (int, optional) – Number of samples. The default is None.
xlabel (str, optional) – Label for the x-axis. The default is None.
ylabel (str, optional) – Label for the y-axis. The default is None.
cbar_label (str, optional) – Label for the colorbar. The default is None.
font_size (int, optional) – Font size for the plot. The default is 12.
figsize (tuple, optional) – Size of the plot. The default is (8, 6).
cmap (str, optional) – Colormap for the plot. The default is ‘coolwarm’.
x_vline_value (float, optional) – Value to draw a vertical line at. The default is None.
y_hline_value (float, optional) – Value to draw a horizontal line at. The default is None.
title_font_size (int, optional) – Font size for the title. The default is 16.
xlabel_font_size (int, optional) – Font size for the x-axis label. The default is 14.
ylabel_font_size (int, optional) – Font size for the y-axis label. The default is 14.
tick_font_size (int, optional) – Font size for the tick labels. The default is 12.