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

Incorrect QASM conversion of SetBits operation #1491

Closed
cqc-alec opened this issue Jul 10, 2024 · 2 comments · Fixed by #1510
Closed

Incorrect QASM conversion of SetBits operation #1491

cqc-alec opened this issue Jul 10, 2024 · 2 comments · Fixed by #1510
Assignees
Labels
bug Something isn't working

Comments

@cqc-alec
Copy link
Collaborator

from pytket.circuit import Bit, Circuit
from pytket.qasm import circuit_to_qasm_str


c = Circuit(0, 3)
c.add_c_setbits(values=[True, True], args=[Bit(1), Bit(2)], condition=Bit(0))

print(c.get_commands())
print("======")
print(circuit_to_qasm_str(c, header="hqslib1"))

Output:

[IF ([c[0]] == 1) THEN SetBits(11) c[1], c[2];]
======
OPENQASM 2.0;
include "hqslib1.inc";

creg c[3];
if(c[0]==1) c[1] = 1;
c[2] = 1;
@cqc-alec cqc-alec added the bug Something isn't working label Jul 10, 2024
@yao-cqc yao-cqc self-assigned this Jul 17, 2024
@yao-cqc
Copy link
Contributor

yao-cqc commented Jul 30, 2024

This issue seems to be affecting other classical gates, for example

c = Circuit(0, 5)
c.add_c_copybits(args_in=[Bit(1), Bit(2)], args_out=[Bit(3), Bit(4)], condition=Bit(0))
qasm = circuit_to_qasm_str(c, header="hqslib1")

and a different error I get from

set_bits = SetBitsOp([True, True, False])
multi_bit = MultiBitOp(set_bits, 2)
c = Circuit(0, 7)
c.add_gate(multi_bit, [0, 1, 2, 3, 4, 5], condition=Bit(6))
qasm = circuit_to_qasm_str(c, header="hqslib1") 

@yao-cqc
Copy link
Contributor

yao-cqc commented Jul 31, 2024

A more concerning example

range_predicate = RangePredicateOp(6, 27, 27)
c = Circuit(0, 8)
c.add_gate(range_predicate, [0, 1, 2, 3, 4, 5, 6], condition=Bit(7))
qasm = circuit_to_qasm_str(c, header="hqslib1")
OPENQASM 2.0;
include "hqslib1.inc";

creg c[8];
if(c[7]==1) if(c==27) c[6] = 1;
if(c!=27) c[6] = 0;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants