Coder Social home page Coder Social logo

qdata's People

Contributors

co9olguy avatar josh146 avatar mikeevmm avatar therooler avatar thisac avatar

Stargazers

 avatar

Watchers

 avatar  avatar

qdata's Issues

Add in example data

I have received example test data from a few collaborators. It would be good to include these in the current repository.

Once #3 and #4 are finished, we can convert these test datasets to the established circuit/operator data class and test whether the serialization and deserialization pipeline works for them

Serialization function

We will need a function which can take in the basic quantum circuit/operator data structure established in #3 and convert it to a valid string for our fork of qasm.

Eventually, this serialization function can be used to help people preparing new datasets to write their datasets to a text format.

Add tests

The beginnings of a test suite have been added in #8; the existing tests only test the ArithmeticOp class at the moment. However, we should extend this to include unit tests, plus integration tests that run on the example QASM scripts.

Avoid using `__repr__` for IR serialization implementation

Currently, the intermediate representation uses class composition; there is a container class QasmProgram that stores the parsed program; individual statements are then represented via a nested list of constituent classes (e.g., ArithmeticOperation, ClassicalRegister, Gate, etc.)

This is a nice approach; it preserves the tree-like structure of the program, and provides a convenient method of serialization; simply traverse the IR, and serialize each constituent class/node.

At the moment, each class in the IR computes its serialization via the __repr__ method:

class QuantumRegister(Declaration):
    def __init__(self, name, size):
        super().__init__(decl_type=Declarations.QREG, id_=name, size=size)

    def __repr__(self):
        return f"qreg {self.kwargs['id_']}[{self.kwargs['size']}];"

This was convenient when prototyping, as calling __repr__ is naturally recursive; any IR object appearing in the string returned by __repr__ will itself be serialized.

However, we should probably update this, as this is not ideal; just doing >>> qasm_program on an interactive prompt should not start the serialization process.

Instead, we should do the following:

  • Rename the __repr__ method in all IR class to either __str__ or serialize()

    • Renaming it to __str__ allows us to call str(qasm_program) to serialize the program, and avoids us needing to change the logic anywhere --- I'm not sure if this is a good thing or a bad thing.

      def __str__(self):
          return f"qreg {self.kwargs['id_']}[{self.kwargs['size']}];"
    • Renaming it to serialize() allows us to pass arguments later if needed. However, it will need us to update the logic; the returned string will need to manually call serialize on all child objects:

      def serialize(self, *args, **kwargs):
          return f"qreg {self.kwargs['id_'].serialize(*args, **kwargs)}[{self.kwargs['size']}];"

      (Note: the above example is pseudocode just for demonstration; quantum registers do not include nested IR objects).

  • Create new __repr__ methods, that return reasonable strings and does not do any recursive serialization:

    def __str__(self):
        return f"<QuantumRegister: name={self.id_}, size={self.size}>"

    That is, the returned string should only itself contain precomputed strings --- it should not result in any additional serialization occurring, either implicitly or explicitly.

Better parser validation

We should add proper validation and exception handling to the parser, to provide:

  • Context regarding any syntax/parsing issues
  • Additional information, such as the QASM line number/col number which is the root of the exception.

Lightweight data structure for representing circuits/operators

We need a simple framework-independent Python data structure for representing quantum circuits/operators that can be used as a parser output.

This data structure should be very lightweight (likely a class containing only simple attributes (lists, dicts, etc.). Eventually, this data structure will serve as the reference implementation, to confirm that a particular implementation is consistent with the spec.

Add functional end-to-end tests

As we refine the parser and package, it would be useful to have some functional end-to-end tests to ensure that changes/refactors do not affect the ability to serialize and deserialize the current QASM specification. These tests will likely make use of the qdata.load(s) and qdata.dump(s) functions, and compare their output vs. the expected output, for specific test data.

Note that this is separate to adding/extending the unit tests. While there should be a single PR adding functional end-to-end tests, unit tests should also be added in parallel as new features/code changes are implemented, to ensure that atomic units are functioning as expected.

Update parser to produce Python data structure

The first hacked-together version of the parser read in text files and parsed them. From the AST, it builds a string. The purpose of this was to verify that the parser was working as expected (it should be able to produce a string comparable to the input file).

As a next step, we'll need the parser to produce an intermediate python object representing the circuit/operators.

Use a more readable syntax for the tensor product

Currently, we use comma separated lists for the tensor product, which causes readability to suffer.

It was suggested in e5b8984#r42899786 to instead use @ to denote tensor products:

@josh146
I somewhat feel the same way; the comma-separated syntax feels 'fine', and gets the job done, but I keep wondering if there is something better/more elegant.

Perhaps even keeping the same layout (op wire, op wire), just changing the symbol?

operator zz a,b {
    z a @ z b;
}

Convert example data to internal representation and to qasm files

We have a few example datasets now added to the repo. However, they are in a variety of file formats (jupyter notebook, python files) and formats.

The next step for these data examples would be to convert them all to the same form (i.e., the lightweight format established in #3) and, once #4 is done, to qasm-type strings.

Problems with defining operators

I tried to write a parser that takes the QasmProgram output, grabs the operators defined in the tfi_chain.qasm and xxz_chain.qasmfile and then translates these to cirq.Paulisum objects.

It took me while to figure out a way to do this, but the following code does the job:

import qdata.parser as parser
import qdata.ir as ir
import cirq
import math

# Parse the Tree
fname = 'examples/example_data/tfi_chain.qasm'
with open(fname, 'r') as file:
    qasm_str = file.readlines()
tree = parser.qasm_parser.parse("".join(qasm_str))
tree = parser.QASMToIRTransformer().transform(tree)

# Define mappings for operators from a .qasm name to a cirq operator.
parsed_operators = {'x': lambda qubits: cirq.X(*qubits),
                    'y': lambda qubits: cirq.Y(*qubits),
                    'z': lambda qubits: cirq.Z(*qubits),
                    }


def operator_parser_paulisum(operator):
    """
    Return a function that implements the operator defined in the .qasm file.

    Args:
        operator:
            A ir.OperatorDeclaration object

    Returns:
        Tuple with name of the defined operator and a function that accepts the
        qubits on which to act
    """
    # get the name of the operator
    name = operator.kwargs['op'].name
    # parameter names in the .qasm
    lambda_wires = operator.kwargs['op'].wires

    def operator_fn(qubits):
        # first, we need to map the .qasm parameters to the qubits
        qubit_map = dict(zip(lambda_wires, qubits))
        # if we have a linear combination we need to sum the terms
        cirq_ops_sum = []
        for term in operator.goplist:
            # If the term is a TensorOp, we need to collect all the terms and
            # use math.prod to get the correct Paulisum tensor product
            if isinstance(term, ir.TensorOp):
                cirq_ops_tensor_product = []
                for op in term.ops:
                    cirq_ops_tensor_product.append(parsed_operators[op.name](
                        [qubit_map[q] for q in op.wires]))
                cirq_ops_sum.append(math.prod(
                    [op_i for op_i in cirq_ops_tensor_product]))
            # Otherwise, we assume it is a `Term` and add it to the linear comb
            else:
                cirq_ops_sum.append(parsed_operators[term.op.name](
                    [qubit_map[q] for q in term.op.wires]) * term.coeff)
        return sum(cirq_ops_sum)

    return name, operator_fn

# Define cirq qubits
qubits = cirq.GridQubit.rect(8, 1)

# go trough the statements and fine the operator definitions.
for statement in tree.statements:
    if isinstance(statement, ir.OperatorDeclaration):
        name, operator_function = operator_parser_paulisum(statement)
        # add the newly defined operators to the operator mapping
        if name not in parsed_operators.keys():
            parsed_operators[name] = operator_function

        else:
            raise KeyError(
                f'Operator {name} already defined in parsed_operators')
# Does it give the correct Pauli Strings? 
print(parsed_operators['zz']([qubits[i] for i in (0,1)]))
print(parsed_operators['tfi_energy_operator_open']([qubits[i] for i in list(range(8))]))

The things I struggled with were the differences between Terms, Gates, Ops and TensorOps objects.
For instance, this is a TensorOp:

operator energy a, b, c {
    zz a, b;
}

, which is fine. But this is a Term

operator energy a, b, c {
    1.0 zz a, b;
}

, even though it is not a linear combinations of terms. This is a 'Gate':

operator energy a {
    z a;
}

, but it should be an Op right?

In the next example, the first line is again a Gate, not a Term, even though the second line defines a Term.

operator energy a, b, c {
    zz a, b;
    -1.0 zz b, c;
}

Same here:

operator energy a, b, c {
    zz a, b;
    zz b, c;
}

, neither are Terms, but Gates instead.

All of this can make it confusing how to add things, because Terms have a coeff attribute, and Gates or Ops do not.
My suggestion is that if we have multiple lines in the operator definition, then each line is a Term so that it has a coeff attribute. Or you could always define operators as Terms, even if they contain a single operator definition. I hope this makes sense.

Tree recursion depth reached

Hi guys,

It's been a while, but I have finally gotten around to serializing all my data for the project into seperate .qasm files. I wrote a parser to reads these files and then construct cirq circuits from the qdata object to check that everything is correct.

Everything works fine, except for my 16 qubit circuit. I ran into the following issue (reproduced here without loading data):

import qdata.parser as parser
import qdata.ir as ir
qasm = """
gate xxz_circuit_closed a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p {
    x a;
    x b;
    x c;
    x d;
    x e;
    x f;
    x g;
    x h;
    x i;
    x j;
    x k;
    x l;
    x m;
    x n;
    x o;
    x p;
    h a;
    h c;
    h e;
    h g;
    h i;
    h k;
    h m;
    h o;
    cx a,b;
    cx c,d;
    cx e,f;
    cx g,h;
    cx i,j;
    cx k,l;
    cx m,n;
    cx o,p;
    zz(3.1963348388671875) b,c;
    yy(3.3196651935577393) b,c;
    xx(3.3196651935577393) b,c;
    zz(3.1963348388671875) d,e;
    yy(3.3196651935577393) d,e;
    xx(3.3196651935577393) d,e;
    zz(3.1963348388671875) f,g;
    yy(3.3196651935577393) f,g;
    xx(3.3196651935577393) f,g;
    zz(3.1963348388671875) h,i;
    yy(3.3196651935577393) h,i;
    xx(3.3196651935577393) h,i;
    zz(3.1963348388671875) j,k;
    yy(3.3196651935577393) j,k;
    xx(3.3196651935577393) j,k;
    zz(3.1963348388671875) l,m;
    yy(3.3196651935577393) l,m;
    xx(3.3196651935577393) l,m;
    zz(3.1963348388671875) n,o;
    yy(3.3196651935577393) n,o;
    xx(3.3196651935577393) n,o;
    zz(3.1963348388671875) p,a;
    yy(3.3196651935577393) p,a;
    xx(3.3196651935577393) p,a;
    zz(3.72210431098938) a,b;
    yy(3.717085838317871) a,b;
    xx(3.717085838317871) a,b;
    zz(3.72210431098938) c,d;
    yy(3.717085838317871) c,d;
    xx(3.717085838317871) c,d;
    zz(3.72210431098938) e,f;
    yy(3.717085838317871) e,f;
    xx(3.717085838317871) e,f;
    zz(3.72210431098938) g,h;
    yy(3.717085838317871) g,h;
    xx(3.717085838317871) g,h;
    zz(3.72210431098938) i,j;
    yy(3.717085838317871) i,j;
    xx(3.717085838317871) i,j;
    zz(3.72210431098938) k,l;
    yy(3.717085838317871) k,l;
    xx(3.717085838317871) k,l;
    zz(3.72210431098938) m,n;
    yy(3.717085838317871) m,n;
    xx(3.717085838317871) m,n;
    zz(3.72210431098938) o,p;
    yy(3.717085838317871) o,p;
    xx(3.717085838317871) o,p;
    zz(3.2088894844055176) b,c;
    yy(3.536816358566284) b,c;
    xx(3.536816358566284) b,c;
    zz(3.2088894844055176) d,e;
    yy(3.536816358566284) d,e;
    xx(3.536816358566284) d,e;
    zz(3.2088894844055176) f,g;
    yy(3.536816358566284) f,g;
    xx(3.536816358566284) f,g;
    zz(3.2088894844055176) h,i;
    yy(3.536816358566284) h,i;
    xx(3.536816358566284) h,i;
    zz(3.2088894844055176) j,k;
    yy(3.536816358566284) j,k;
    xx(3.536816358566284) j,k;
    zz(3.2088894844055176) l,m;
    yy(3.536816358566284) l,m;
    xx(3.536816358566284) l,m;
    zz(3.2088894844055176) n,o;
    yy(3.536816358566284) n,o;
    xx(3.536816358566284) n,o;
    zz(3.2088894844055176) p,a;
    yy(3.536816358566284) p,a;
    xx(3.536816358566284) p,a;
    zz(3.5637190341949463) a,b;
    yy(3.659609079360962) a,b;
    xx(3.659609079360962) a,b;
    zz(3.5637190341949463) c,d;
    yy(3.659609079360962) c,d;
    xx(3.659609079360962) c,d;
    zz(3.5637190341949463) e,f;
    yy(3.659609079360962) e,f;
    xx(3.659609079360962) e,f;
    zz(3.5637190341949463) g,h;
    yy(3.659609079360962) g,h;
    xx(3.659609079360962) g,h;
    zz(3.5637190341949463) i,j;
    yy(3.659609079360962) i,j;
    xx(3.659609079360962) i,j;
    zz(3.5637190341949463) k,l;
    yy(3.659609079360962) k,l;
    xx(3.659609079360962) k,l;
    zz(3.5637190341949463) m,n;
    yy(3.659609079360962) m,n;
    xx(3.659609079360962) m,n;
    zz(3.5637190341949463) o,p;
    yy(3.659609079360962) o,p;
    xx(3.659609079360962) o,p;
    zz(3.204713821411133) b,c;
    yy(3.6522107124328613) b,c;
    xx(3.6522107124328613) b,c;
    zz(3.204713821411133) d,e;
    yy(3.6522107124328613) d,e;
    xx(3.6522107124328613) d,e;
    zz(3.204713821411133) f,g;
    yy(3.6522107124328613) f,g;
    xx(3.6522107124328613) f,g;
    zz(3.204713821411133) h,i;
    yy(3.6522107124328613) h,i;
    xx(3.6522107124328613) h,i;
    zz(3.204713821411133) j,k;
    yy(3.6522107124328613) j,k;
    xx(3.6522107124328613) j,k;
    zz(3.204713821411133) l,m;
    yy(3.6522107124328613) l,m;
    xx(3.6522107124328613) l,m;
    zz(3.204713821411133) n,o;
    yy(3.6522107124328613) n,o;
    xx(3.6522107124328613) n,o;
    zz(3.204713821411133) p,a;
    yy(3.6522107124328613) p,a;
    xx(3.6522107124328613) p,a;
    zz(3.4316213130950928) a,b;
    yy(3.7154085636138916) a,b;
    xx(3.7154085636138916) a,b;
    zz(3.4316213130950928) c,d;
    yy(3.7154085636138916) c,d;
    xx(3.7154085636138916) c,d;
    zz(3.4316213130950928) e,f;
    yy(3.7154085636138916) e,f;
    xx(3.7154085636138916) e,f;
    zz(3.4316213130950928) g,h;
    yy(3.7154085636138916) g,h;
    xx(3.7154085636138916) g,h;
    zz(3.4316213130950928) i,j;
    yy(3.7154085636138916) i,j;
    xx(3.7154085636138916) i,j;
    zz(3.4316213130950928) k,l;
    yy(3.7154085636138916) k,l;
    xx(3.7154085636138916) k,l;
    zz(3.4316213130950928) m,n;
    yy(3.7154085636138916) m,n;
    xx(3.7154085636138916) m,n;
    zz(3.4316213130950928) o,p;
    yy(3.7154085636138916) o,p;
    xx(3.7154085636138916) o,p;
    zz(3.2198214530944824) b,c;
    yy(3.6855783462524414) b,c;
    xx(3.6855783462524414) b,c;
    zz(3.2198214530944824) d,e;
    yy(3.6855783462524414) d,e;
    xx(3.6855783462524414) d,e;
    zz(3.2198214530944824) f,g;
    yy(3.6855783462524414) f,g;
    xx(3.6855783462524414) f,g;
    zz(3.2198214530944824) h,i;
    yy(3.6855783462524414) h,i;
    xx(3.6855783462524414) h,i;
    zz(3.2198214530944824) j,k;
    yy(3.6855783462524414) j,k;
    xx(3.6855783462524414) j,k;
    zz(3.2198214530944824) l,m;
    yy(3.6855783462524414) l,m;
    xx(3.6855783462524414) l,m;
    zz(3.2198214530944824) n,o;
    yy(3.6855783462524414) n,o;
    xx(3.6855783462524414) n,o;
    zz(3.2198214530944824) p,a;
    yy(3.6855783462524414) p,a;
    xx(3.6855783462524414) p,a;
    zz(3.338473081588745) a,b;
    yy(3.7553672790527344) a,b;
    xx(3.7553672790527344) a,b;
    zz(3.338473081588745) c,d;
    yy(3.7553672790527344) c,d;
    xx(3.7553672790527344) c,d;
    zz(3.338473081588745) e,f;
    yy(3.7553672790527344) e,f;
    xx(3.7553672790527344) e,f;
    zz(3.338473081588745) g,h;
    yy(3.7553672790527344) g,h;
    xx(3.7553672790527344) g,h;
    zz(3.338473081588745) i,j;
    yy(3.7553672790527344) i,j;
    xx(3.7553672790527344) i,j;
    zz(3.338473081588745) k,l;
    yy(3.7553672790527344) k,l;
    xx(3.7553672790527344) k,l;
    zz(3.338473081588745) m,n;
    yy(3.7553672790527344) m,n;
    xx(3.7553672790527344) m,n;
    zz(3.338473081588745) o,p;
    yy(3.7553672790527344) o,p;
    xx(3.7553672790527344) o,p;
    zz(3.2734010219573975) b,c;
    yy(3.6916301250457764) b,c;
    xx(3.6916301250457764) b,c;
    zz(3.2734010219573975) d,e;
    yy(3.6916301250457764) d,e;
    xx(3.6916301250457764) d,e;
    zz(3.2734010219573975) f,g;
    yy(3.6916301250457764) f,g;
    xx(3.6916301250457764) f,g;
    zz(3.2734010219573975) h,i;
    yy(3.6916301250457764) h,i;
    xx(3.6916301250457764) h,i;
    zz(3.2734010219573975) j,k;
    yy(3.6916301250457764) j,k;
    xx(3.6916301250457764) j,k;
    zz(3.2734010219573975) l,m;
    yy(3.6916301250457764) l,m;
    xx(3.6916301250457764) l,m;
    zz(3.2734010219573975) n,o;
    yy(3.6916301250457764) n,o;
    xx(3.6916301250457764) n,o;
    zz(3.2734010219573975) p,a;
    yy(3.6916301250457764) p,a;
    xx(3.6916301250457764) p,a;
    zz(3.2772154808044434) a,b;
    yy(3.7851288318634033) a,b;
    xx(3.7851288318634033) a,b;
    zz(3.2772154808044434) c,d;
    yy(3.7851288318634033) c,d;
    xx(3.7851288318634033) c,d;
    zz(3.2772154808044434) e,f;
    yy(3.7851288318634033) e,f;
    xx(3.7851288318634033) e,f;
    zz(3.2772154808044434) g,h;
    yy(3.7851288318634033) g,h;
    xx(3.7851288318634033) g,h;
    zz(3.2772154808044434) i,j;
    yy(3.7851288318634033) i,j;
    xx(3.7851288318634033) i,j;
    zz(3.2772154808044434) k,l;
    yy(3.7851288318634033) k,l;
    xx(3.7851288318634033) k,l;
    zz(3.2772154808044434) m,n;
    yy(3.7851288318634033) m,n;
    xx(3.7851288318634033) m,n;
    zz(3.2772154808044434) o,p;
    yy(3.7851288318634033) o,p;
    xx(3.7851288318634033) o,p;
    zz(3.3246560096740723) b,c;
    yy(3.638864040374756) b,c;
    xx(3.638864040374756) b,c;
    zz(3.3246560096740723) d,e;
    yy(3.638864040374756) d,e;
    xx(3.638864040374756) d,e;
    zz(3.3246560096740723) f,g;
    yy(3.638864040374756) f,g;
    xx(3.638864040374756) f,g;
    zz(3.3246560096740723) h,i;
    yy(3.638864040374756) h,i;
    xx(3.638864040374756) h,i;
    zz(3.3246560096740723) j,k;
    yy(3.638864040374756) j,k;
    xx(3.638864040374756) j,k;
    zz(3.3246560096740723) l,m;
    yy(3.638864040374756) l,m;
    xx(3.638864040374756) l,m;
    zz(3.3246560096740723) n,o;
    yy(3.638864040374756) n,o;
    xx(3.638864040374756) n,o;
    zz(3.3246560096740723) p,a;
    yy(3.638864040374756) p,a;
    xx(3.638864040374756) p,a;
    zz(3.2508981227874756) a,b;
    yy(3.7592549324035645) a,b;
    xx(3.7592549324035645) a,b;
    zz(3.2508981227874756) c,d;
    yy(3.7592549324035645) c,d;
    xx(3.7592549324035645) c,d;
    zz(3.2508981227874756) e,f;
    yy(3.7592549324035645) e,f;
    xx(3.7592549324035645) e,f;
    zz(3.2508981227874756) g,h;
    yy(3.7592549324035645) g,h;
    xx(3.7592549324035645) g,h;
    zz(3.2508981227874756) i,j;
    yy(3.7592549324035645) i,j;
    xx(3.7592549324035645) i,j;
    zz(3.2508981227874756) k,l;
    yy(3.7592549324035645) k,l;
    xx(3.7592549324035645) k,l;
    zz(3.2508981227874756) m,n;
    yy(3.7592549324035645) m,n;
    xx(3.7592549324035645) m,n;
    zz(3.2508981227874756) o,p;
    yy(3.7592549324035645) o,p;
    xx(3.7592549324035645) o,p;
    zz(3.3544509410858154) b,c;
    yy(3.6125383377075195) b,c;
    xx(3.6125383377075195) b,c;
    zz(3.3544509410858154) d,e;
    yy(3.6125383377075195) d,e;
    xx(3.6125383377075195) d,e;
    zz(3.3544509410858154) f,g;
    yy(3.6125383377075195) f,g;
    xx(3.6125383377075195) f,g;
    zz(3.3544509410858154) h,i;
    yy(3.6125383377075195) h,i;
    xx(3.6125383377075195) h,i;
    zz(3.3544509410858154) j,k;
    yy(3.6125383377075195) j,k;
    xx(3.6125383377075195) j,k;
    zz(3.3544509410858154) l,m;
    yy(3.6125383377075195) l,m;
    xx(3.6125383377075195) l,m;
    zz(3.3544509410858154) n,o;
    yy(3.6125383377075195) n,o;
    xx(3.6125383377075195) n,o;
    zz(3.3544509410858154) p,a;
    yy(3.6125383377075195) p,a;
    xx(3.6125383377075195) p,a;
    zz(3.305846691131592) a,b;
    yy(3.718900203704834) a,b;
    xx(3.718900203704834) a,b;
    zz(3.305846691131592) c,d;
    yy(3.718900203704834) c,d;
    xx(3.718900203704834) c,d;
    zz(3.305846691131592) e,f;
    yy(3.718900203704834) e,f;
    xx(3.718900203704834) e,f;
    zz(3.305846691131592) g,h;
    yy(3.718900203704834) g,h;
    xx(3.718900203704834) g,h;
    zz(3.305846691131592) i,j;
    yy(3.718900203704834) i,j;
    xx(3.718900203704834) i,j;
    zz(3.305846691131592) k,l;
    yy(3.718900203704834) k,l;
    xx(3.718900203704834) k,l;
    zz(3.305846691131592) m,n;
    yy(3.718900203704834) m,n;
    xx(3.718900203704834) m,n;
    zz(3.305846691131592) o,p;
    yy(3.718900203704834) o,p;
    xx(3.718900203704834) o,p;
    zz(3.348297595977783) b,c;
    yy(3.5349605083465576) b,c;
    xx(3.5349605083465576) b,c;
    zz(3.348297595977783) d,e;
    yy(3.5349605083465576) d,e;
    xx(3.5349605083465576) d,e;
    zz(3.348297595977783) f,g;
    yy(3.5349605083465576) f,g;
    xx(3.5349605083465576) f,g;
    zz(3.348297595977783) h,i;
    yy(3.5349605083465576) h,i;
    xx(3.5349605083465576) h,i;
    zz(3.348297595977783) j,k;
    yy(3.5349605083465576) j,k;
    xx(3.5349605083465576) j,k;
    zz(3.348297595977783) l,m;
    yy(3.5349605083465576) l,m;
    xx(3.5349605083465576) l,m;
    zz(3.348297595977783) n,o;
    yy(3.5349605083465576) n,o;
    xx(3.5349605083465576) n,o;
    zz(3.348297595977783) p,a;
    yy(3.5349605083465576) p,a;
    xx(3.5349605083465576) p,a;
    zz(3.207159996032715) a,b;
    yy(3.3896963596343994) a,b;
    xx(3.3896963596343994) a,b;
    zz(3.207159996032715) c,d;
    yy(3.3896963596343994) c,d;
    xx(3.3896963596343994) c,d;
    zz(3.207159996032715) e,f;
    yy(3.3896963596343994) e,f;
    xx(3.3896963596343994) e,f;
    zz(3.207159996032715) g,h;
    yy(3.3896963596343994) g,h;
    xx(3.3896963596343994) g,h;
    zz(3.207159996032715) i,j;
    yy(3.3896963596343994) i,j;
    xx(3.3896963596343994) i,j;
    zz(3.207159996032715) k,l;
    yy(3.3896963596343994) k,l;
    xx(3.3896963596343994) k,l;
    zz(3.207159996032715) m,n;
    yy(3.3896963596343994) m,n;
    xx(3.3896963596343994) m,n;
    zz(3.207159996032715) o,p;
    yy(3.3896963596343994) o,p;
    xx(3.3896963596343994) o,p;
}
"""

tree = parser.qasm_parser.parse("".join(qasm))
tree = parser.QASMToIRTransformer().transform(tree)

outputs

...
  File "/home/rooler/anaconda3/envs/tfq/lib/python3.8/site-packages/lark_parser-0.10.1-py3.8.egg/lark/visitors.py", line 125, in _transform_tree
    children = list(self._transform_children(tree.children))
RecursionError: maximum recursion depth exceeded

adding

import sys
sys.setrecursionlimit(2000)

solves this, but this is probably not what we want.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.