question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't parse quil code with a call to a DEFCIRCUIT with no arguments

See original GitHub issue

This does not parse:

DEFCIRCUIT FOO:
    NOP
FOO

But this is OK:

DEFCIRCUIT FOO a:
    NOP
FOO 1

python -c 'from pyquil._parser.PyQuilListener import run_parser; run_parser("DEFCIRCUIT FOO:\n NOP\nFOO")'

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ecpetersoncommented, Feb 6, 2019

I’d like to add my opinion that I don’t like that the body of a DEFCIRCUIT can reference static qubit literals at all. I’d strongly prefer FOO 1 to account for all of the qubits touched by FOO: the qubit 1, and only qubit 1.

0reactions
braised-babbagecommented, Sep 16, 2019

A basic issue is that pyquil has no distinction between gate applications and circuit applications (everything gets parsed into Gate objects), and resolution is done by name via global lookup tables like QUANTUM_GATES.

For example, one easy way to allow for nullary circuit applications in the parser is to change

gate                : modifier* name ( LPAREN param ( COMMA param )* RPAREN )? qubit? ;

to

gate                : modifier* name ( LPAREN param ( COMMA param )* RPAREN )? qubit* ;

in Quil.g4, and correspondingly remove

        if not isinstance(qubits, list) or not qubits:
            raise TypeError("Gate arguments must be a non-empty list")

from Gate.__init__.

But this is a bad idea, because we should be enforcing the non-nullary condition for gate applications.

The way that the quilc parser addresses this is to actually do two passes. The initial parsing produces an “unresolved application” object. A second pass resolves applications to gate applications or circuit applications, depending on the presence of suitable DEFCIRCUIT etc. The resolved objects are tagged with some important information: a pointer to their corresponding gate or circuit definitions. This is an additional level of detail that pyquil does not maintain (in pyquil, a Gate instruction has only a name, with no explicit reference to its corresponding definition).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Editor error thrown: Quill is not defined · Issue #518 - GitHub
An error is thrown when opening the Rich Text Editor for the first time or if reloading the page using Empty Cache and...
Read more >
Javascript JSON.parse() error while trying to parse stringified ...
2 Answers 2 · Still cannot parse the following string resulted from changing data.toString() to JSON. · That's not valid JSON. Put it...
Read more >
API - Quill Rich Text Editor
Quill is a free, open source WYSIWYG editor built for the modern web. Completely customize it for any need with its modular architecture...
Read more >
ED311449.pdf - ERIC - Department of Education
This book contains 25 essays about English words, and how they are defined, valued, and discussed. The book is divided into four sections....
Read more >
The Death Penalty in 2021: Year End Report
Once again, only defendants of color were executed for cross-racial murders and no white defendant was sentenced to death in a trial that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found