Skip to content

Commit

Permalink
Added examples to main() of SEO_reader and EchoingSEO_reader classes
Browse files Browse the repository at this point in the history
  • Loading branch information
rrtucci committed Aug 1, 2018
1 parent 4ad435d commit 0e5db32
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 16 deletions.
37 changes: 28 additions & 9 deletions EchoingSEO_reader.py
Expand Up @@ -5,19 +5,31 @@

class EchoingSEO_reader(SEO_reader):
"""
This class is a child of SEO_reader. The class reads any previously
created Qubiter English file and it writes new English & Picture files
wherein every line is echoed faithfully. The purpose of this class is to
act as a parent class to the Expander classes MultiplexorExpander and
DiagUnitaryExpander, both of which echo every line except those starting
with MP_Y and DIAG, respectively, and therefore need only override the
functions use_MP_Y() and use_DIAG, respectively, of this class.
This class is a child of SEO_reader. The class reads any previously
created Qubiter English file and it writes new English & Picture files
wherein every line is echoed faithfully, except maybe the qubits are
permuted.
The constructor of this class takes as input wr which should be a
SEO_writer or child thereof. If wr is a plain SEO_writer writing to a
file_prefix different to the file_prefix being read, this class will
generate a Picture File & English file starting from only an English
file. So it is an ASCII drawing class with an English file as input.
file.
This class has many uses. Here are some:
1. If given as input a pictureless English file, it can be used to draw
an ASCII picture of the input English file.
2. If wr permutes the qubits, it can be used to write new Picture File
& English files that have permuted qubits with respect to the input
English file.
3. It is the parent class to the Expander classes MultiplexorExpander
and DiagUnitaryExpander, both of which echo every line except those
starting with MP_Y and DIAG, respectively, and therefore need only
override the functions use_MP_Y() and use_DIAG, respectively, of this
class.
Attributes
----------
Expand Down Expand Up @@ -358,5 +370,12 @@ def do_log(self):

if __name__ == "__main__":
def main():
print(5)
file_prefix_in = 'io_folder/echo_test'
file_prefix_out = 'io_folder/echo_test_perm'
num_bits = 6
# permute qubits by advancing their positions by 1
bit_map = [1, 2, 3, 4, 5, 0]
emb = CktEmbedder(num_bits, num_bits, bit_map)
wr = SEO_writer(file_prefix_out, emb)
EchoingSEO_reader(file_prefix_in, num_bits, wr)
main()
19 changes: 12 additions & 7 deletions SEO_reader.py
Expand Up @@ -15,12 +15,15 @@ class because it has a bunch of use_ methods that must be overridden by
See the docstring for the class SEO_writer for more info about English
files.
This class is intended to be an intermediate class for use as a parent
class to a child class. However, one can create an object of it,
in which case it 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 SIGX (CNOT) operations, etc.
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.
Attributes
----------
Expand Down Expand Up @@ -769,5 +772,7 @@ def use_SWAP(self, bit1, bit2, controls):

if __name__ == "__main__":
def main():
print(5)
file_prefix = 'io_folder/expansions_examples_X1'
num_bits = 3
SEO_reader(file_prefix, num_bits, write_log=True)
main()
33 changes: 33 additions & 0 deletions io_folder/echo_test_6_eng.txt
@@ -0,0 +1,33 @@
SWAP 3 2
SWAP 3 1
SWAP 3 0
SWAP 2 1
SWAP 2 0
SWAP 1 0
HAD2 AT 0
P1PH 90.0 AT 1 IF 0T
P1PH 45.0 AT 2 IF 0T
P1PH 22.5 AT 3 IF 0T
HAD2 AT 1
P1PH 90.0 AT 2 IF 1T
P1PH 45.0 AT 3 IF 1T
HAD2 AT 2
P1PH 90.0 AT 3 IF 2T
HAD2 AT 3
NOTA do h.c. next
HAD2 AT 3
P1PH -90.0 AT 3 IF 2T
HAD2 AT 2
P1PH -45.0 AT 3 IF 1T
P1PH -90.0 AT 2 IF 1T
HAD2 AT 1
P1PH -22.5 AT 3 IF 0T
P1PH -45.0 AT 2 IF 0T
P1PH -90.0 AT 1 IF 0T
HAD2 AT 0
SWAP 1 0
SWAP 2 0
SWAP 2 1
SWAP 3 0
SWAP 3 1
SWAP 3 2
33 changes: 33 additions & 0 deletions io_folder/echo_test_perm_6_ZLpic.txt
@@ -0,0 +1,33 @@
| <---> | | |
| <---+---> | |
| <---+---+---> |
| | <---> | |
| | <---+---> |
| | | <---> |
| | | | H |
| | | @P--@ |
| | @P--+---@ |
| @P--+---+---@ |
| | | H | |
| | @P--@ | |
| @P--+---@ | |
| | H | | |
| @P--@ | | |
| H | | | |
NOTA do h.c. next
| H | | | |
| @P--@ | | |
| | H | | |
| @P--+---@ | |
| | @P--@ | |
| | | H | |
| @P--+---+---@ |
| | @P--+---@ |
| | | @P--@ |
| | | | H |
| | | <---> |
| | <---+---> |
| | <---> | |
| <---+---+---> |
| <---+---> | |
| <---> | | |
33 changes: 33 additions & 0 deletions io_folder/echo_test_perm_6_eng.txt
@@ -0,0 +1,33 @@
SWAP 4 3
SWAP 4 2
SWAP 4 1
SWAP 3 2
SWAP 3 1
SWAP 2 1
HAD2 AT 1
P1PH 90.0 AT 2 IF 1T
P1PH 45.0 AT 3 IF 1T
P1PH 22.5 AT 4 IF 1T
HAD2 AT 2
P1PH 90.0 AT 3 IF 2T
P1PH 45.0 AT 4 IF 2T
HAD2 AT 3
P1PH 90.0 AT 4 IF 3T
HAD2 AT 4
NOTA do h.c. next
HAD2 AT 4
P1PH -90.0 AT 4 IF 3T
HAD2 AT 3
P1PH -45.0 AT 4 IF 2T
P1PH -90.0 AT 3 IF 2T
HAD2 AT 2
P1PH -22.5 AT 4 IF 1T
P1PH -45.0 AT 3 IF 1T
P1PH -90.0 AT 2 IF 1T
HAD2 AT 1
SWAP 2 1
SWAP 3 1
SWAP 3 2
SWAP 4 1
SWAP 4 2
SWAP 4 3

0 comments on commit 0e5db32

Please sign in to comment.