I have a code that I ran on a quantum simulator and it executed perfectly fine. I want to run it on one of IBM's actual quantum computers, I am using ibm_kyoto. To switch from a simulator to a QPU, I think the only modifications I need to do to are in the measurement function. I am having issues with my measurement function, I keep getting the error 'PrimitiveResult' object has no attribute 'get_counts', although when I ran the code on the simulator and used the 'get_counts' method, it didn't cause any issue. I was once able to extract my result (I expect my result to be a binary number), and the result was incorrect (due to noise?). This is my first time running a code on an actual QPU, and I honestly don't understand how it works and why I am facing these issues. I tried looking up Qiskit's documentation to try to understand, but it didn't help me.
$\begingroup$
$\endgroup$
7
-
$\begingroup$ It would be helpful, if you could share a code snippet and an error prompt. Otherwise I can recommend just following a qiskit tutorial like this one can help understanding the usage. You can skip Step 1, which is just implementing the Grover algorithm. $\endgroup$– Refik MansurogluCommented Jul 8 at 11:41
-
1$\begingroup$ Here's a series of videos on precisely this subject. Parts 6 and 7 are probably what you are looking for: youtube.com/… $\endgroup$– diemilioCommented Jul 8 at 13:14
-
$\begingroup$ @RefikMansuroglu thank you for replying. I followed the qiskit tutorial you gave me, and for now the code executed and I was able to retrieve the counts. Although it was the same thing I was doing before, I don't know why now it works. I retrieved my results and they were not accurate (the binary number that I am looking for is not being measured the most frequently), so now my next step is to use error mitigation techniques to improve the accuracy of my results. If you have any tips on that, I would be thankful! $\endgroup$– karenCommented Jul 8 at 13:51
-
$\begingroup$ Happy to hear that! I'm afraid, I have no universal advice for debugging/error mitigation. You can checkout the qiskit documentary, they have some built-in routines, but also this extensive review. If you have a specific question, feel free to ask, preferably with a bit of code and where the expected outcome fails to show. $\endgroup$– Refik MansurogluCommented Jul 8 at 14:52
-
$\begingroup$ @RefikMansuroglu I applied Qiskit's built-in error mitigation, and I was waiting to see if I encounter a problem, but my code ran successfully! My code is an attempt at proving Collatz conjecture for certain numbers (calculating 3x+ if odd and x/2 if even until reaching 1), but the code is extremely slow (3s for every number). I doubt that it can be as fast as if it were done classically, but I'm hoping to speed up the execution of my code. I'm wondering if you would have any reccomendations for that, or if it's even feasible. If you would like a code snippet for reference please let me know! $\endgroup$– karenCommented Jul 18 at 9:57
|
Show 2 more comments
1 Answer
$\begingroup$
$\endgroup$
You can run from Classiq on IBM hardwares easily and it takes care of the execution process for you.
from classiq import *
# Design your quantum model
@QFunc
def main(res: Output[QArray[QBit]]) -> None:
allocate(2, res)
CX(res[0], res[1])
ibm_provider = IBMBackendProvider(
hub="Hub name", group="Group name", Project="Project name"
)
ibm_preferences = IBMBackendPreferences(
backend_name="Name of requsted quantum hardware",
access_token="A Valid API access token to IBM Quantum",
provider=ibm_provider,
)
execution_preferences = ExecutionPreferences(
backend_preferences=ibm_preferences
)
# Set the preferences
model = set_execution_preferences(model, execution_preferences)
# Create the model
model = create_model(main)
# Synthesize a quantum program from the quantum model
quantum_program = synthesize(model)
# Execute the quantum program and access the result
job = execute(quantum_program)
results = job.result()
For examples on how to use the Classiq platform in general, I suggest looking into the Classiq library. https://github.com/Classiq/classiq-library
Disclaimer - I am a Classiq employee