qubiter.adv_applications.StairsDerivThrCkt_writer module

class qubiter.adv_applications.StairsDerivThrCkt_writer.StairsDerivThrCkt_writer(deriv_direc, dpart_name, gate_str_to_rads_list, file_prefix, emb, **kwargs)[source]

Bases: qubiter.SEO_writer.SEO_writer

(Stairs Derivative Threaded Circuit) This class is a subclass of SEO_writer. It writes English and Picture files for several derivative circuits used for calculating the gradients of a quantum cost function ( mean hamiltonian).

This class calls class StairsDerivCkt_writer many times. Each time, a new sub-circuit is built that acts on fresh set of qubits not used before. So this class builds many threads, i.e., independent sub-circuits which can be evolved in parallel.

If you compare the constructor of this “threaded” writer class with that of the “non-threaded” writer class StairsDerivCkt_writer, you will see that the constructor of this class has two fewer arguments, namely deriv_gate_str, has_neg_polarity. All other arguments are the same for both classes. The reason for this is that all the possibilities for those two arguments are included as (parallel, independent) subcircuits of the giant quantum circuit created by this class.

Most attributes of this class are the same as those for StairsDerivCkt_writer. One new attribute is subckt_to_large_small_bit_pair.

subckts are labeled by a pair: (deriv_gate_str, has_neg_polarity).

subckt_to_large_small_bit_pair maps each subckt to its edge qubits.

Variables:
  • deriv_direc (int) –
  • dpart_name (str) –
  • gate_str_to_rads_list (dict[int, list[float]]) –
  • parent_num_bits (int) –
  • subckt_to_large_small_bit_pair (dict[(str, bool), tuple[int]]) –
__init__(deriv_direc, dpart_name, gate_str_to_rads_list, file_prefix, emb, **kwargs)[source]

Constructor

This constructor writes English and Picture files but it doesn’t close those files after writing them. You must do that yourself using close_files().

Parameters:
  • deriv_direc (int) –
  • dpart_name (str) –
  • gate_str_to_rads_list (dict[int, list[float]]) –
  • file_prefix (str) –
  • emb (CktEmbedder) –
  • kwargs (dict) – key-word arguments of SEO_writer
get_coef_of_dpart(subckt, deriv_direc, dpart_name, var_num_to_rads=None)[source]

This method returns a dict mapping each subckt (labeled by a pair: ( deriv_gate_str, has_neg_polarity)) to its coefficient of dpart (either p1, ps or -p1*ps).

var_num_to_rads is used if self wrote the English file with #int string symbols for placeholder variables. var_num_to_rads is used to float those strings. This is necessary before analytical calculation of the output of this method can proceed.

Parameters:
  • subckt ((str, bool)) –
  • deriv_direc (int) –
  • dpart_name (str) –
  • var_num_to_rads (dict[int, float]) –
Returns:

Return type:

dict[(str, bool), float]

get_fun_name_to_fun(deriv_direc, dpart_name)[source]

This method returns a dictionary fun_name_to_fun mapping the function name to function, for all functions defined by this class. It combines the fun_name_to_fun of all the subckts.

Parameters:
  • deriv_direc (int) –
  • dpart_name (str) –
Returns:

Return type:

dict[str, function]

get_tot_num_bits()[source]

This is the self version of sta_get_tot_num_bits()

Returns:
Return type:int
static sta_get_tot_num_bits(parent_num_bits, gate_str_to_rads_list)[source]

This static (sta) method returns the total number of qbits for the quantum circuit generated by this class, i.e., it returns the sum of the qbits used by each subcircuit.

Parameters:
  • parent_num_bits (int) –
  • gate_str_to_rads_list (dict[str, list[float]]) –
Returns:

Return type:

int

write()[source]

This method writes English and Picture files for a giant quantum circuit which consists of many parallel, independent subcircuits, each subcircuit acting on a distinct set of qbits. The subcircuits are generated by calling StairsDerivCkt_writer for all the possibilities of deriv_gate_str and has_neg_polarity