Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B as alias is not parsed #56

Closed
quantumkoen opened this issue Jul 23, 2018 · 8 comments
Closed

B as alias is not parsed #56

quantumkoen opened this issue Jul 23, 2018 · 8 comments

Comments

@quantumkoen
Copy link
Contributor

This code from the qx simulator test suite is not parsed:

version 1.0 

# file   : full_adder.qc
# author : Nader Khammassi
# brief  : quantum full adder (carry-save addition)

# define 4 qubits
qubits 4

# rename qubits
map q[0],A 
map q[1],B
map q[2],C
map q[3],D


# init inputs to some values
.init
  x A 
  x C 

  display_binary  #  initial input value


# perform addition
.add

  toffoli B,C,D
  cnot    B,C 
  toffoli A,C,D
  cnot    A,C 

  display_binary #  result

.reverse_add

  cnot    A,C 
  toffoli A,C,D
  cnot    B,C 
  toffoli B,C,D

  display_binary #  result

# error_model depolarizing_channel, 0.1 

Reports:

[+] loading circuit from 'tests/circuits/full_adder.qc' ...
Error while parsing file tests/circuits/full_adder.qc: 
syntax error, unexpected BITHEAD, expecting NAME
@kel85uk
Copy link
Collaborator

kel85uk commented Jul 23, 2018

@quantumkoen And A, C without the B works? I think it's because of the precedence of b being parsed as a special token for bit identifiers.

@quantumkoen
Copy link
Contributor Author

@kel85uk hard to say what works exactly and what doesn't, as I'm not getting any line numbers with the syntax errors, but I suspect it's the B indeed because of the b[..] syntax.

@kel85uk
Copy link
Collaborator

kel85uk commented Jul 23, 2018

Yeap, tested using the new develop branch with the line reporting. It does say line 12, which is where b is located.

image

Consider the code:

version 1.0 

# file   : full_adder.qc
# author : Nader Khammassi
# brief  : quantum full adder (carry-save addition)

# define 4 qubits
qubits 4

# rename qubits
map q[0],A 
map q[1],B1
map q[2],C
map q[3],D


# init inputs to some values
.init
  x A 
  x C 

  display_binary  #  initial input value


# perform addition
.add

  toffoli B1,C,D
  cnot    B1,C 
  toffoli A,C,D
  cnot    A,C 

  display_binary #  result

.reverse_add

  cnot    A,C 
  toffoli A,C,D
  cnot    B1,C 
  toffoli B1,C,D

  display_binary #  result

# error_model depolarizing_channel, 0.1 

which results in:
image

@kel85uk
Copy link
Collaborator

kel85uk commented Jul 25, 2018

Question is, should b be supported as a string and not a special keyword, then if so, q would be open for such interpretation too. @quantumkoen @Nader-Khammassi @imranashraf @andreasppg

@kel85uk
Copy link
Collaborator

kel85uk commented Apr 8, 2019

Closing due to no response, and the way I interpret it is that b and q should be a special keyword for cQASM the same way as special registers (e.g. ax) are reserved for classical assembly.

@kel85uk kel85uk closed this as completed Apr 8, 2019
@quantumkoen
Copy link
Contributor Author

Given that it is trivial to distinguish between the use of b as a signifier for adressing bits vs using it as an alias, and given that the cqasm 1.0 syntax nowhere says b cannot be used as an alias, I think it should be supported by the parser.

@kel85uk
Copy link
Collaborator

kel85uk commented Apr 8, 2019

True, reopening this.

@jvanstraten
Copy link
Collaborator

This has been supported since #105, though due to a bug I stumbled on and fixed in #115 I think that particular mapping has only worked since then. Note that you wouldn't be able to refer to the measurement bits associated with the qubits once you redefine b though (unless you make another remap b first).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants