qubiter.SEO_Lista module

class qubiter.SEO_Lista.SEO_Lista(num_bits, line_list=None)[source]

Bases: object

Whereas with Qubiter, the main way of storing circuits is in files, with programs like PyQuil (by Rigetti) and Cirq (by Google), circuits ( aka programs) are stored entirely in memory, essentially as Python lists of gates. Lists of this type can be sliced, combined, etc. When using such lists, it is easy to randomly access any gate of the circuit at will. This is convenient, for instance, when doing circuit optimizations (i.e., replacing the circuit by an equivalent but hopefully shorter one, what IBM qiskit calls “transpiling”).

In this class, we support Qubiter’s version of PyQuil’s and Cirq’s gate lists. In Qubiter, we use simply a Python list of the lines, stored as strings, with the ending n removed, of the circuit’s English file.

Variables:
  • line_list (list[str]) –
  • num_bits (int) –
__add__(other)[source]

define + of two SEO_Lista objects

Parameters:other (SEO_Lista) –
Returns:
Return type:SEO_Lista
__getitem__(item)[source]

define self[item]

Parameters:item (slice) –
Returns:
Return type:SEO_Lista
__iadd__(other)[source]

define += for inplace addition of an SEO_Lista object to self

Parameters:other (SEO_Lista) –
Returns:
Return type:SEO_Lista
__init__(num_bits, line_list=None)[source]

Constructor

add_xy_meas_coda(bit_pos_to_xy_str)[source]

This method adds a “coda” (tail ending) to self using data in bit_pos_to_xy_str to determine what coda will be.

Parameters:bit_pos_to_xy_str (dict[int, str]) –
Returns:
Return type:None
append(fun_name, param_list, emb=None)[source]

This method adds at the end of self a new single line for a single gate. fun_name is the name of any function in SEO_writer whose name starts with the string ‘write_’ and param_list is a list containing values for the arguments of fun_name. This method creates an object of SEO_writer called wr and calls

eval(‘wr.’ + fun_name + ‘(*param_list)’).

Instead of creating temporary English and Picture files as was done in a previous version of this function, wr now writes into in-streams which are StringIO that live purely in memory. This is much more efficient because it involves no files at any time.

Parameters:
  • fun_name (str) –
  • param_list (list) –
  • emb (CktEmbedder) –
static eng_file_to_line_list(file_prefix, num_bits)[source]

This static method reads an English file with file prefix file_prefix and it returns a list of its line strings. Note that the ‘n’ at the end of each line in the English file is removed before adding it to the line list.

Parameters:
  • file_prefix (str) –
  • num_bits (int) –
Returns:

Return type:

list[str]

get_var_nums_and_fun_names()[source]

This method returns 2 lists: * a list of all the distinct variable numbers * a list of all the distinct function names encountered in the circuit.

Returns:
Return type:list[int], list[str]
herm()[source]

This method returns an EngLineList which is the Hermitian conjugate of self.

Returns:
Return type:SEO_Lista
static line_list_to_eng_and_pic_files(line_list, file_prefix, num_bits)[source]

This method does the reverse of eng_file_to_line_list(). It writes both an English file and a Picture file with file prefix=file_prefix. Note that an ‘n’ is added at the end of each line in the line list before writing the line to the English file.

Parameters:
  • line_list (list[str]) –
  • file_prefix (str) –
  • num_bits (int) –
Returns:

Return type:

None

print()[source]

prints self.line_list, one item per line

Returns:
Return type:None
simulate(**kwargs1)[source]

This method creates a temporary English file from self, and uses that to create an object of SEO_simulator called sim. This has the effect of evolving the state vector to its final state. The method ends by deleting the temporary English file, and returning sim. The output sim can be used to access the final state vector, etc.

Parameters:kwargs1 (list) – key-word arguments of SEO_simulator
Returns:
Return type:SEO_simulator
write_eng_and_pic_files(file_prefix)[source]

This method does the same as line_list_to_eng_and_pic_files(), except it is called by an object of this class instead of being a static method.

Parameters:file_prefix (str) –
Returns:
Return type:None