qubiter.Plotter module

class qubiter.Plotter.Plotter[source]

Bases: object

This class has no constructor. All its methods are static methods. It contains various utility methods for (1) creating pandas dataframes from state vectors and density matrices created by StateVec methods, and (2) plotting such dataframes. Dataframes with probability (resp., amplitude) entries are plotted as bar plots (resp., quiver plots). Casting things into dataframes is convenient because they are automatically displayed as html tables in jupyter notebooks.

static get_bit_probs_df(bit_probs)[source]

Admits as input a list bit_probs with num_bits items consisting of pairs of two floats. Returns a dataframe with two columns and num_bits rows. The rows are labelled by 0, 1, 2, …

Parameters:bit_probs (list[tuple(float, float)]) –
Returns:
Return type:pan.DataFrame
static get_den_mat_df(num_bits, den_mat, use_bin_labels=True)[source]

Admits as input a numpy array den_mat (a density matrix) of shape ( dim, dim), where dim= 2^num_bits and ZL convention is assumed. Returns square dataframe with entries of den_mat. The rows and columns are labelled by 0, 1, 2, … or their binary equivalents, depending on the bool value of use_bin_labels.

Parameters:
  • num_bits (int) –
  • den_mat (np.ndarray) –
  • use_bin_labels (bool) –
Returns:

Return type:

pan.DataFrame

static get_pd_df(num_bits, pd, use_bin_labels=True)[source]

Admits as input a 1-dim numpy array pd (probability distribution) with shape ( 2^num_bits, ) and ZL convention is assumed. Returns a dataframe with its entries. The rows are labelled by 0, 1, 2, … or their binary equivalents, depending on the bool value of use_bin_labels.

Parameters:
  • num_bits (int) –
  • pd (np.ndarray) –
  • use_bin_labels (bool) –
Returns:

Return type:

pan.DataFrame

static get_st_vec_df(trad_st_vec, use_bin_labels=True)[source]

Admits as input trad_st_vec which is a complex numpy array with shape (dim,) where dim= 2^num_bits and ZL convention is assumed. Returns a dataframe with a single column with 2^num_bit rows. The rows are labelled by 0, 1, 2, … or their binary equivalents, depending on the bool value of use_bin_labels.

Parameters:
  • trad_st_vec (np.ndarray) –
  • use_bin_labels (bool) –
Returns:

Return type:

pan.DataFrame

static get_states(num_bits, use_bin_labels=True, ZL=True)[source]

Returns list of strings [‘0’, ‘1’, ..] with 2^num_bits entries if use_bin_labels=False, or the binary string equivalents if use_bin_labels=True.

Parameters:
  • num_bits (int) –
  • use_bin_labels (bool) –
  • ZL (bool) – If True, appends “(ZL)” to state labels. Else appends “(ZF)”
Returns:

Return type:

list[str]

static plot_counts(state_name_to_counts)[source]

Plots an OrderedDict[str, int] called state_name_to_counts as a bar graph. Divides counts by their sum before plotting.

Parameters:state_name_to_counts (OrderedDict[str, int]) –
Returns:
Return type:None
static plot_phasors(titles, st_vec_df_list=None, den_mat_df_list=None)[source]

Admits as input a list of dataframes called ‘st_vec_df_list’ or one called ‘den_mat_df_list’ but not both. Exactly one of these lists must be None. The names of the dataframes are given by the list of strings ‘titles’. Let dim = 2^num_bits. The dataframes in st_vec_df_list have one column with dim rows, whereas those for den_mat_df_list are square with dim rows and columns. This function plots each dataframe in the list as a quiver plot (phasor->arrow) with dim rows and either one column or dim columns.

Parameters:
  • titles (list[str]) –
  • st_vec_df_list (list[pan.DataFrame]|None) –
  • den_mat_df_list (list[pan.DataFrame]|None) –
Returns:

Return type:

None

static plot_probs_col(titles, probs_col_df_list)[source]

Admits as input a list of dataframes called ‘probs_col_df_list’. The names of the dataframes are given by the list of strings ‘titles’. The dataframes all have a single column, and possibly different numbers of rows. All entries of all dataframes are floats between 0 and 1. This function plots each dataframe in the list as a barplot.

Parameters:
  • titles (list[str]) –
  • probs_col_df_list (list[pan.DataFrame]) –
Returns:

Return type:

None