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

added a quick_simulate function #4780

Closed
wants to merge 2 commits into from
Closed

Conversation

edwinagnew
Copy link

Summary

A function which can quickly simulate a QuantumCircuit. It can also take an input string to modify the input. For example to test a 1-bit adder:

`from qiskit import QuantumCircuit, quick_simulate
#make adder
qc = QuantumCircuit(4,2)
qc.cx(0,2)
qc.cx(1,2)
qc.ccx(0,1,3)
qc.barrier()
qc.measure(2,0)
qc.measure(3,1)

#get results
quick_simulate(qc) #returns {'00':1024}
quick_simulate(qc, x="10") # returns {'01': 1024}
etc.`

Details and comments

I wasn't exactly sure where to place the import statement. At the moment it can be imported as 'from qiskit import simulate' but if it would be better placed in the providers directory then line 82 in qiskit/init.py can be moved to qiskit/providers/init.py
I also just copied and pasted the license agreement without signing anything anywhere, it that OK?

@edwinagnew edwinagnew requested review from jyu00 and a team as code owners July 22, 2020 17:44
@CLAassistant
Copy link

CLAassistant commented Jul 22, 2020

CLA assistant check
All committers have signed the CLA.

@1ucian0
Copy link
Member

1ucian0 commented Sep 5, 2020

Hi @edwinagnew,
This sort of extension on the high level interface is usually discussed in a discussion issue first to check for consensus. I would recommend you to submit one of those (no need to close the PR, but setting on hold until consensus is reached) and, based on that, decide the direction for this PR.

@1ucian0 1ucian0 added the on hold Can not fix yet label Sep 5, 2020
@ajavadia
Copy link
Member

ajavadia commented Sep 8, 2020

Hi, thanks for your contribution. However for this kind of thing you can use the built-in quantum_info module which is designed as a native way of extracting quantum information from a circuit (statevector, expectation value, equivalent unitary, counts). So here's how you can do it in a one liner, I don't think we need to create yet another function for this.

from qiskit.quantum_info import *
Statevector.from_instruction(qc).sample_counts(1000)

@ajavadia ajavadia closed this Sep 8, 2020
@edwinagnew
Copy link
Author

edwinagnew commented Sep 9, 2020

@ajavadia Hi, thanks for pointing that out, I wasn't aware and I agree this would be redundant.
I still believe the functionality of being able to prepare a circuit on a given classical input is useful as I find myself needing that a lot, so could I add that to the sample_counts method?

@1ucian0
Copy link
Member

1ucian0 commented Sep 19, 2020

I did not try it, but the functionally you are searching for seems very similar to what https://pypi.org/project/kaleidoscope/ (from @nonhermitian ) offers. Check the example here: https://twitter.com/nonhermitian/status/1306548622012620801

@nonhermitian
Copy link
Contributor

Yes it works similar with respect to getting a statevector, unitary, or counts directly from a circuit object. I found this to be extremely handy to have.

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

Successfully merging this pull request may close these issues.

None yet

5 participants