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

Draw circuits with midcircuit-measurement and conditional gates #50

Open
royess opened this issue Jul 19, 2022 · 6 comments
Open

Draw circuits with midcircuit-measurement and conditional gates #50

royess opened this issue Jul 19, 2022 · 6 comments
Labels
bug Something isn't working enhancement New feature or request feedback welcome We'd like to listen to the feedback from everyone

Comments

@royess
Copy link
Contributor

royess commented Jul 19, 2022

Issue Description

Draw circuits with conditional gates. Currently, such attempt will raise a qiskit.extensions.exceptions.ExtensionError: 'Input matrix is not unitary.'

Proposed Solution

I am not very sure whether it is easy to implement by still using the drawing utilities of qiskit. So I do not have very good solution proposed.

Additional References

In qiskit, it is done by introducing classical registers, e.g. https://quantum-computing.ibm.com/lab/docs/iql/manage/systems/midcircuit-measurement/.

@refraction-ray
Copy link
Member

This is indeed a known issue, since we have no classical register concepts (which I think is a too heavy abstraction) in tensorcircuit, it is indeed hard to visualize this, especially when integrated with qiskit.

Currently, one workaround to avoid the error is by adding several lines in the codebase: just ignore nonunitary gate when do the qiskit trasformation (I'll fix like this soon). Still, the obtained circuit.draw() will contain no ingredient of cond_gates, though no error raised.

@refraction-ray refraction-ray added bug Something isn't working feedback welcome We'd like to listen to the feedback from everyone labels Jul 20, 2022
@refraction-ray refraction-ray self-assigned this Jul 20, 2022
@refraction-ray
Copy link
Member

Screen Shot 2022-07-20 at 12 52 48 PM

results from current solution, any suggestions or ideas?

@royess
Copy link
Contributor Author

royess commented Jul 20, 2022

Screen Shot 2022-07-20 at 12 52 48 PM

results from current solution, any suggestions or ideas?

I think this is a good solution at the moment. But just I want to make sure conditional gates (conditional_gate) or other
utilities involving Qiskit's classical bits can also work in the same way.

This is indeed a known issue, since we have no classical register concepts (which I think is a too heavy abstraction) in tensorcircuit, it is indeed hard to visualize this, especially when integrated with qiskit.

I agree that classical registers are not necessary and seem like over-abstraction for tensorcircuit. But I think to guarantee tensorcircuit circuit objects can always be run or simulated on practical quantum computers by using Qiskit is also an important feature for some users.

And I am thinking perhaps we can introduce classical registers when translating tensorcircuit to Qiskit by calling to_qir. In this way, tensorcircuit itself remains clean. And I suppose we can also support translating Qiskit object with classical registers to tensorcircuit in a similar manner if it is not supported yet.

@refraction-ray refraction-ray added the enhancement New feature or request label Jul 21, 2022
@refraction-ray refraction-ray removed their assignment Jul 21, 2022
@refraction-ray
Copy link
Member

Thanks for sharing your thoughts. For now, the translation from cond_measure (which is just a non-unitary gate for any tensorcircuit circuit instance) is translated as an identity gate in qiskit (just with the name measure), therefore, only the visualization is not broken and the measure information is intrinsically lost when translating from tc to qiskit.

As you described, support mid circuit measurement translation between tc and qiskit is very important for users who would like to try some hardware experiments. The difficult part is that, the measurement results is just a int Tensor, and when does this Tensor is utilized in python is hard to track in circuit intermediate representation level. Though this may be solved with some more deep thoughts and refactoring. In a word, the enhancement you suggested is worth a try and indeed helpful but the implementation is not that easy to me for now. Let's keep this issue open and see whether we can have better inputs or ideas from other developers and users

@EmilianoG-byte
Copy link
Contributor

Hi! Is there any update regarding the mid circuit measurements? My use case would be to convert a qiskit circuit to TensorCircuit, where the former contains mid circuit measurements (no classical conditional gates)

@refraction-ray
Copy link
Member

Hi! Is there any update regarding the mid circuit measurements? My use case would be to convert a qiskit circuit to TensorCircuit, where the former contains mid circuit measurements (no classical conditional gates)

Could you provide a minimal python demo on the qiskit circuit, i.e. which circuit object exactly you want to feed into tc.Circuit.from_qiskit()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request feedback welcome We'd like to listen to the feedback from everyone
Projects
Status: No status
Development

No branches or pull requests

3 participants