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

Qasms with composite gates don't load #1566

Closed
dcmckayibm opened this issue Dec 19, 2018 · 11 comments · Fixed by #3393
Closed

Qasms with composite gates don't load #1566

dcmckayibm opened this issue Dec 19, 2018 · 11 comments · Fixed by #3393
Labels
bug Something isn't working priority: high

Comments

@dcmckayibm
Copy link
Member

Here is the qasm string

'OPENQASM 2.0;\ninclude "qelib1.inc";\ngate r q { h q; s q; h q; s q; }\ngate rinv q {sdg q; h q; sdg q; h q; }\ngate sinv q {s q; z q;}\nqreg q[3];\ncreg c[3];\nrinv q[0];\ncx q[1], q[2];\nr q[1];\nrinv q[2];\ncx q[0], q[2];\nrinv q[0];\nr q[2];\ncx q[0], q[1];\nrinv q[1];\ny q[0];\nbarrier q[0], q[1], q[2];\nr q[1];\ncx q[0], q[1];\nrinv q[2];\nr q[0];\ncx q[0], q[2];\nr q[2];\nrinv q[1];\ncx q[1], q[2];\nr q[0];\nx q[0];\nz q[1];\nmeasure q[0] -> c[0];\nmeasure q[1] -> c[1];\nmeasure q[2] -> c[2];'

If I run from_qasm_str

I get

QiskitError: 'unknown operation for ast node name rinv'

Informations

  • Qiskit Terra version:
  • Python version:
  • Operating system:

What is the current behavior?

Steps to reproduce the problem

What is the expected behavior?

Suggested solutions

@jaygambetta
Copy link
Member

yeah, this will not work. We give you an alternative way to do it soon.

@1ucian0 1ucian0 added this to To do in Transpiler via automation Dec 19, 2018
@1ucian0 1ucian0 added this to To do in Circuits via automation Dec 19, 2018
@jaygambetta
Copy link
Member

oops im sorry. This needs to be fixed. @1ucian0 can you look at this.

@1ucian0 1ucian0 self-assigned this Jan 1, 2019
@1ucian0 1ucian0 added the bug Something isn't working label Feb 8, 2019
@1ucian0
Copy link
Member

1ucian0 commented Feb 8, 2019

This is part of a bigger problem that we have with composite gates, I think.

@ardeleanasm
Copy link

Is there an alternative way to do it?

@1ucian0
Copy link
Member

1ucian0 commented Mar 25, 2019

Smaller program to reproduce the problem:

QuantumCircuit.from_qasm_str('OPENQASM 2.0;\ninclude "qelib1.inc";\ngate rinv q {sdg q; h q; sdg q; h q; }\nqreg q[3];\nrinv q[2];')

@ajavadia , is there any alternative way?

@1ucian0
Copy link
Member

1ucian0 commented May 6, 2019

Now that composite gates are fixed... I will try to attack this issue... which me luck 🤞

@itoko
Copy link
Contributor

itoko commented Jun 27, 2019

@1ucian0 Thank you for tackling this issue. Any progress for non-opaque gates? I've encountered the following error when loading qasm file with custom gates and found this issue.

qiskit.exceptions.QiskitError: 'Custom non-opaque gates are not supported by as_to_dag module'

@1ucian0
Copy link
Member

1ucian0 commented Jun 27, 2019

The problem is that we dont have an easy way to bind variables at DAG level. We are planing to refactoring the DAG, so I'm not fully sure if its worthy. What do you think @kdk ?

@1ucian0 1ucian0 removed their assignment Oct 23, 2019
@msegado
Copy link

msegado commented Nov 2, 2019

What's the current timeline to add this functionality back in? I just upgraded some production code from Qiskit 0.6.x (ancient, I know) and am trying to determine whether I'll need to create a workaround or whether I should just wait for a fix to land. Thanks!

Re. implementation: wouldn't it make more sense to just do AST -> circuit directly rather than AST -> DAG -> circuit? The only place ast_to_dag is used in Qiskit is in conjunction with dag_to_circuit to create a circuit from QASM, and going to a circuit directly would allow you to leverage their existing machinery for custom instructions, variable binding, etc. Maintaining backwards compatibility would also be easy (at least for users not importing AstInterpreter directly):

def ast_to_dag(ast):
    return circuit_to_dag(ast_to_circuit(ast))

@francabrera
Copy link
Member

this issue is also affecting the IBM Quantum Experience composer users (some have complained on the Slack channel) since the transpiling process using Qiskit fails when running a OpenQASM with "subroutines" (custom gates) in any of the cloud backends.

@jwoehr
Copy link
Contributor

jwoehr commented Feb 15, 2020

My nuqasm2 compiles any subroutine to circuit by simply unrolling it on the spot as it attempts to make a circuit. They could toss that in the backend, even if the team doesn't want to use it in mainline Qiskit.

@mergify mergify bot closed this as completed in #3393 Mar 9, 2020
Transpiler automation moved this from To do to done Mar 9, 2020
Circuits automation moved this from To do to Done Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: high
Projects
Circuits
  
Done
Transpiler
  
done
Development

Successfully merging a pull request may close this issue.

8 participants