Skip to content

optimise writes a .lif that the parser will not read back #1

Description

@cleitonaugusto

The two halves of the pipeline do not compose. Writing the optimised IR to a
file and reading it back fails.

lift-cli optimise examples/quantum_bell.lif --output out.lif
lift-cli export out.lif --backend qasm

Error: Parse errors: [UnexpectedToken { found: "^bb0", expected: "statement",
line: 3, col: 9 }, UnexpectedToken { found: ":", expected: "=", line: 3,
col: 17 }, ...]

The printer emits a block label. out.lif starts like this:

module @bell_state {
    func @bell(%v0: qubit, %v1: qubit) -> (qubit, qubit) {
        ^bb0(%v2: qubit, %v3: qubit):
            %v4 = "quantum.h"(%v2) : (qubit) -> qubit
            %v5, %v6 = "quantum.cx"(%v4, %v3) : (qubit, qubit) -> (qubit, qubit)
            "core.return"(%v5, %v6) : (qubit, qubit) -> ()

There are two separate problems in there. I checked them one at a time.

The lexer does tokenize ^bb0, it produces CaretIdent at lexer.rs:229. The parser
has no rule that accepts it as a statement.

If I delete the ^bb0 line by hand, the parse gets past that point and then fails
with "Undefined value: %v2". The block arguments declared on the ^bb0 line are
what the body refers to, while the function signature above declares %v0 and %v1,
so removing the line leaves the body pointing at names that no longer exist.

The printer also drops the "#dialect quantum" header that the input had. Adding
that back on its own does not help. I tried it, ^bb0 is what blocks the parse.

So round tripping through a file does not work at the moment for any input, as
far as I can tell. Everything I found about the optimisation passes had to be
done through the library instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions