Giter Club home page Giter Club logo

nuqasm2's People

Contributors

jwoehr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nuqasm2's Issues

Multi-character register names not parsed correctly

Hi, firstly, thanks for the package! It has been a huge help to me.

I have found that when the names of qregs or cregs are multiple characters, only the last character of the name appears in the 'qreg_name' entry of elements in 'c_sect' with 'type' ASTType.QREG or ASTType.CREG. For example, a register called 'reg' would give return the value 'g' for the 'qreg_name' key.

This behaviour seems to stem from the line 233 to 235 of nuqasm2/qasmast.py (accessed 19/10/2023. The relevant lines are:

x = QTRegEx.REG_DECL.match(self.source)
self.qreg_name = x.group(1)
self.qreg_num = x.group(2)

One can replicate the issue without needing to run a specific file by modifying the above lines to read:

from nuqasm2.qasmast import QTRegEx

a_string = 'qreg reg[5]'
x = QTRegEx.REG_DECL.match(a_string)
print(x.group()) #gives 'qreg reg[5]'. This demonstrates that the matching is working as expected
qreg_name = x.group(1)
print(qreg_name) #gives 'g', rather than 'reg'

As I am new to regex, I personally fixed this using the 3rd-party pyparsing package by implementing the class:

import pyparsing as pp

class QasmParsingElement():
    l_sqr_brace = pp.Literal('[').suppress()
    r_sqr_brace = pp.Literal(']').suppress()
    idQasm = pp.Regex(r'[a-z][A-Za-z0-9]*') 
    nninteger = pp.Regex(r'[1-9]+[0-9]*|0')
    reg_index_slice = l_sqr_brace + nninteger + r_sqr_brace
    decl =  (pp.Keyword('qreg') + idQasm + reg_index_slice |
                 pp.Keyword('creg') + idQasm + reg_index_slice ) 

and then changing 233 to 235 of nuqasm2/qasmast.py to

parsed_line = QasmParsingElement.decl.parse_string(self.source)
self.qreg_name = parsed_line[1]
self.qreg_num = parsed_line[2]

However, obviously this does have the drawback of adding another dependency to the nuqasm2 package.

NOTE: The issue with cregs is identical.

Parameters of custom gates not recognized

I created a custom gate cu1mol(theta) a, b in a file containing definitions of quantum gates.
`
OPENQASM 2.0;

include "qelib1.inc";
gate cxmol a, b {
h b;
cz a, b;
h b;
}

gate cu1mol(theta) a, b {
u1(theta/2) a;
cxmol a, b;
u1(-theta/2) b;
cxmol a, b;
u1(theta/2) b;
}
If I try to define in a qasm file a gate likecu1mol(pi/2) q[1], q[0];nuqasm2 does not recognizepi/2, thus having on the output file u1(theta/2) q[1];instead ofu1(pi/2) q[1];`

Ops which cannot be unrolled are silently ignored.

Unrolling does not test for failure nor throw an exception when an op from the AST is in proper form but yet cannot be unrolled into a circuit.

E.g.,

// Here's an unknown op 'u(a,b,c)'
u(pi/2,pi/4,pi/15) q[0] ;

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.