qubiter.LoopFileGenerator module

class qubiter.LoopFileGenerator.LoopFileGenerator(file_prefix, num_qbits, **kwargs)[source]

Bases: qubiter.SEO_reader.SEO_reader

This class is important to you only if you are interested in using loops in the English file.

This class reads an English file (a .txt text file) with nested loops in it and it writes a Loop File (a .py python script). Like all SEO_reader’s, this class has a PlaceholderManager call vars_manager ( variables manager), but for this class, the vars_manager is of the special type LoopyPlaceholderManager.

Variables:
  • indentation_li (list[int]) – one item list containing an int that stores the current number of indentation spaces in the Loop File being written
  • loop_out (_io.TextIOWrapper) – out stream to Loop File being generated.
__init__(file_prefix, num_qbits, **kwargs)[source]

Constructor

Parameters:
  • file_prefix (str) –
  • num_qbits (int) –
  • kwargs (dict) –
do_log()[source]

We override this to prevent writing of log, because when we do, we get a wrong count for the number of elem ops, because this SEO_reader is performing a flat reading of the English file (i.e., not jumping back at NEXTs)

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

This method overrides method of same name in parent class SEO_reader.

Its purpose is to write a “for” line in the Loop File. It also increases the indentation in the Loop File by 4 spaces. This gives Python style indentation for for-loops in Loop File.

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

Return type:

None

use_NEXT(loop_num)[source]

This method overrides method of same name in parent class SEO_reader. It reduces the indentation in the Loop File by 4 spaces. This gives Python style indentation for for-loops in Loop File.

The use_NEXT in the parent class is responsible for jumping back from NEXT line to LOOP line if the total number of reps (nreps) hasn’t been completed. This override doesn’t do that jump. This gives a flat reading of the English file, without jumping back at NEXTs.

Parameters:loop_num (int) –
Returns:
Return type:None