qubiter.SEO_reader module

class qubiter.SEO_reader.SEO_reader(file_prefix, num_qbits, vars_manager=None, verbose=False, write_log=False, xfile_num=-1)[source]

Bases: qubiter.SEO_pre_reader.SEO_pre_reader

This class inherits from the class SEO_pre_reader. It’s an abstract class because it has a bunch of use_ methods that must be overridden by a child class. This class reads each line of an English file, parses it, and sends the info obtained to a use_ method for further processing. One very important child of this class is SEO_simulator which uses each line of the English file to evolve by one further step a quantum state vector.

See the docstring for the class SEO_writer for more info about English files.

The main use of this “abstract” class is as an intermediate class that is a parent class to a child class. However, this class is not 100% abstract. An object of it can be created without getting an error message iff the write_log input parameter, which is False by default, is set to True instead. In that case, creating an object of the class will produce a log file about the English file that it reads. That log file will contain useful information about the English file, like its number of lines, its number of elementary ops, its number of CNOT operations (SIGX with one control), etc.

Variables:
  • english_in (_io.TextIOWrapper) – file object for input text file that stores English description of circuit
  • line_count (int) –
  • loop_to_cur_rep (dict[int, int]) – a dictionary mapping loop number TO current repetition
  • if outside if_m block, else a control specifying the current (mcase_trols) – if_m case
  • measured_bits (list(int)) – list of bits that have been measured with type 2 measurement and haven’t been reset to |0> or |1>
  • num_cnots (int) –
  • num_ops (int) –
  • split_line (list[str]) –
  • vars_manager (PlaceholderManager) – handles variables indicated by #int in the English file being read
  • verbose (bool) –
  • write_log (bool) –
  • xfile_num (int) – You can ignore this if the English file has no loops. This number is -1 by default. If you change it to something non-negative, the class looks in the io_folder for a “Loop xfile” with a very specific name that mentions the xfile_num: file_prefix + ‘_’ + str( num_qbits) + ‘_loop’ + str(xfile_num) + “.py”. If the class can’t find that xfile , it will abort. Otherwise, it tries to exec() that xfile. A Loop xfile is a file that you write yourself from a template file called “Loop File” that is generated by the classes LoopFileGenerator and LoopyPlaceholder. The Loop File has the same name as the Loop xfile, except that the Loop xfile has that additional xfile_num before the “.py”. Read docstrings and main() of classes LoopFileGenerator and LoopyPlaceholder for more info and examples illustrating how to use Loop Files and Loop xfiles.
__init__(file_prefix, num_qbits, vars_manager=None, verbose=False, write_log=False, xfile_num=-1)[source]

Constructor

Parameters:
  • file_prefix (str) –
  • num_qbits (int) –
  • vars_manager (PlaceholderManager) –
  • verbose (bool) –
  • write_log (bool) –
  • xfile_num (int) –
degs_str_to_rads(degs_str)[source]

Wrapper for function of same name in PlaceholderManager.

Parameters:degs_str (str) –
Returns:
Return type:float | str
do_log()[source]

Write a log file and print info on console too.

Returns:
Return type:None
fill_history_lists_by_executing_loop_xfile()[source]

This method is called by the constructor of this class, iff the user enters a valid (non-negative) xfile number. Before using this method, user is expected to have generated a Loop File from an English file via classes LoopFileGenerator and LoopyPlaceholderManager, and created a Loop xfile by editing that Loop File. This class executes the Loop xfile to fill its history dictionaries (the ones that end in _hist).

Returns:
Return type:None
finalize_next_line()[source]

Useful for intercepting the end of each call to next_line().

get_log_file_path(rel=False)[source]

Returns path (relative if rel is True, absolute if rel is False) of log file.

Parameters:rel (bool) –
Returns:
Return type:str
next_line()[source]

Analyze the inputted line. Send info to use_ methods labelled by first four letters of line) for further use.

Returns:
Return type:None
print_log_file()[source]

Prints log file.

Returns:
Return type:None
read_P_phase_factor(projection_bit)[source]

Collect useful info from P0PH or P1PH split_line and forward it to use_ method.

Parameters:projection_bit (int) –
Returns:
Return type:None
read_ROT(axis)[source]

Collect useful info from ROTX, ROTY, or ROTZ split_line and forward it to use_ method.

Parameters:axis (int) –
Returns:
Return type:None
read_SIG(axis)[source]

Collect useful info from SIGX, SIGY, or SIGZ split_line and forward it to use_ method.

Parameters:axis (int) –
Returns:
Return type:None
read_TF_controls(tokens)[source]

Same as read_multi_controls() but only allows T/F kind controls.

Parameters:tokens (list[str]) –
Returns:
Return type:Controls
read_multi_controls(tokens, allow_only_TF=False)[source]

Given a list of tokens of the form: * an int followed by either T or F, * int, colon, int,

construct a control out of it.

Parameters:
  • tokens (list[str]) –
  • allow_only_TF (bool) –
Returns:

Return type:

Controls

use_DIAG(trols, rad_angles)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • trols (Controls) –
  • rad_angles (list[float]) –
Returns:

Return type:

None

use_HAD2(tar_bit_pos, controls)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_IF_M_beg(controls)[source]

Abstract use_ method that must be overridden by child class.

Parameters:controls (Controls) –
Returns:
Return type:None
use_IF_M_end()[source]

Abstract use_ method that must be overridden by child class.

Returns:
Return type:None
use_LOOP(loop_num, nreps)[source]

Don’t override this unless you know what you are doing and have very good reasons. It has been carefully set up to deal properly with embedded loops.

Parameters:
  • loop_num (int) –
  • nreps (int) –
Returns:

Return type:

None

use_MEAS(tar_bit_pos, kind)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • kind (int) –
  • tar_bit_pos (int) –
Returns:

Return type:

None

use_MP_Y(tar_bit_pos, trols, rad_angles)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • tar_bit_pos (int) –
  • trols (Controls) –
  • rad_angles (list[float]) –
Returns:

Return type:

None

use_NEXT(loop_num)[source]

Don’t override this unless you know what you are doing and have very good reasons. It has been carefully set up to deal properly with embedded loops.

Parameters:loop_num (int) –
Returns:
Return type:None
use_NOTA(bla_str)[source]

Abstract use_ method that must be overridden by child class.

Parameters:bla_str (str) –
Returns:
Return type:None
use_PHAS(angle_rads, tar_bit_pos, controls)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • angle_rads (float) –
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_PRINT(style, line_num)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • style (str) –
  • line_num (int) –
Returns:

Return type:

None

use_P_PH(projection_bit, angle_rads, tar_bit_pos, controls)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • projection_bit (int) –
  • angle_rads (float) –
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_ROTA(axis, angle_rads, tar_bit_pos, controls)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • axis (int) –
  • angle_rads (float) –
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_ROTN(angle_x_rads, angle_y_rads, angle_z_rads, tar_bit_pos, controls)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • angle_x_rads (float) –
  • angle_y_rads (float) –
  • angle_z_rads (float) –
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_SIG(axis, tar_bit_pos, controls)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • axis (int) –
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_SWAP(bit1, bit2, controls)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • bit1 (int) –
  • bit2 (int) –
  • controls (Controls) –
Returns:

Return type:

None

use_SWAY(bit1, bit2, controls, rads_list)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • bit1 (int) –
  • bit2 (int) –
  • controls (Controls) –
  • rads_list (list[float | str]) –
Returns:

Return type:

None

use_U_2_(rads0, rads1, rads2, rads3, tar_bit_pos, controls)[source]

Abstract use_ method that must be overridden by child class.

Parameters:
  • rads0 (float) –
  • rads1 (float) –
  • rads2 (float) –
  • rads3 (float) –
  • tar_bit_pos (int) –
  • controls (Controls) –
Returns:

Return type:

None

static xed_file_prefix(file_prefix)[source]

Xed file_prefix. Returns file_prefix + ‘_X1’, assuming that ‘_X’ + str(k) for some integer k is not already the ending of file_prefix. If it is, then the ending is changed to ‘_X’ + str( k+1). Classes that use this are called “expanders” throughout Qubiter. The X stands for expanded.

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