# Path: libcirc/compile/compilecirc.py
# def standardGate(line, listMode=False, lineMode=False):
#     if line == "main":
#         if listMode or lineMode:
#             raise ValueError("Can't bring 'main' into list form.")
#         return "main"
# 
#     if not lineMode:
#         toRemove = ["_", "M"]
#         for r in toRemove:
#             line = line.replace(r, "")
# 
#     elems = []
#     for letter in line:
#         if not letter.islower(): elems.append(letter)
#         else: elems = elems[:-1] + [elems[-1] + letter]
# 
#     if lineMode: return elems
#     if listMode: return sorted(elems)
#     return "".join(sorted(elems))


from libcirc.compile.compilecirc import standardGate
import numpy as np
#
# file: gadgetize.py
# input a file with a compiled circuit (h,s,CNOT,t) only
# output stabilizer projectors g(x,y) and h(x)
#



# count the number of random bits to generate
# this is the number of Ts plus measured ancillas
# assumes circuit consists only of gates in the gate set, i.e. is compiled
def countY(circuit):
    Ts = 0
    Tcache = []  # recent T gates to check for any consecutive Ts
    Ms = []

    MTs = []
    # measurements depending on which a T is performed
    # depending on postselection we might not need those T
    # these are not counted in Ts variable

    lineNr = 0
    for line in circuit.splitlines():
        lineNr += 1

# Path: libcirc/compile/compilecirc.py
# def standardGate(line, listMode=False, lineMode=False):
#     if line == "main":
#         if listMode or lineMode:
#             raise ValueError("Can't bring 'main' into list form.")
#         return "main"
# 
#     if not lineMode:
#         toRemove = ["_", "M"]
#         for r in toRemove:
#             line = line.replace(r, "")
# 
#     elems = []
#     for letter in line:
#         if not letter.islower(): elems.append(letter)
#         else: elems = elems[:-1] + [elems[-1] + letter]
# 
#     if lineMode: return elems
#     if listMode: return sorted(elems)
#     return "".join(sorted(elems))


# Path: libcirc/compile/gadgetize.py
from libcirc.compile.compilecirc import standardGate
import numpy as np

#
# file: gadgetize.py
# input a file with a compiled circuit (h,s,CNOT,t) only
# output stabilizer projectors g(x,y) and h(x)
#



# count the number of random bits to generate
# this is the number of Ts plus measured ancillas
# assumes circuit consists only of gates in the gate set, i.e. is compiled
def countY(circuit):
    Ts = 0
    Tcache = []  # recent T gates to check for any consecutive Ts
    Ms = []

    MTs = []
    # measurements depending on which a T is performed
    # depending on postselection we might not need those T
    # these are not counted in Ts variable

    lineNr = 0
    for line in circuit.splitlines():
        lineNr += 1

        gate = standardGate(line, lineMode=True)