Closed hykavitha closed 5 years ago
Qiskit Aqua version:
pip list | grep "qiskit"
qiskit 0.10.1
qiskit-aer 0.2.0
qiskit-aqua 0.5.0
qiskit-chemistry 0.5.0
qiskit-ibmq-provider 0.2.2
qiskit-ignis 0.1.1
qiskit-terra 0.8.0
Python version: 3.73
Operating system: OSX
What is the current behavior? I'm trying to run QSVM algorithm in IBMQ experience, want to run in one of those real quantum computers.
from qiskit import IBMQ IBMQ.load_accounts() print("Available backends:") IBMQ.backends()
[<IBMQSimulator('ibmq_qasm_simulator') from IBMQ(ibm-q, open, main)>, <IBMQBackend('ibmqx4') from IBMQ(ibm-q, open, main)>, <IBMQBackend('ibmqx2') from IBMQ(ibm-q, open, main)>, <IBMQBackend('ibmq_16_melbourne') from IBMQ(ibm-q, open, main)>, <IBMQSimulator('ibmq_qasm_simulator') from IBMQ()>]
backend = BasicAer.get_backend('ibmq_qasm_simulator') With the BasicAer I realize I'm using IBMQ's simulator and not the actual IBMQ device. if I chose 'ibmq_qasm_simulator', it works!!!
device = IBMQ.get_backend('ibmq_16_melbourne') # ibmx4
quantum_instance = QuantumInstance(device, shots=100, seed=seed, seed_transpiler=seed) result = qsvm.run(quantum_instance) The above code which is supposed to use real Quantum computer "ibmq_16_melbourne" throws me a
KeyError Traceback (most recent call last)
Just to add a little more information, the user stated that they were receiving this error when they were running this tutorial: https://github.com/Qiskit/qiskit-tutorials/tree/master/qiskit/artificial_intelligence, I am assuming qsvm_classification.ipynb
. (User stated this in the original stack exchange question https://quantumcomputing.stackexchange.com/questions/6295/how-to-run-quantum-svm-algorithm-from-qiskit-in-real-ibm-quantum-computer-using)
I tried running through this tutorial on ibmq_16_melbourne
, and received the same error. This is what the logger showed before throwing the error:
2019-06-04 11:51:16,594:qiskit.aqua.algorithms.many_sample.qsvm.qsvm:DEBUG: Building circuits:
|██████████████████████████████████████████████████| 780/780 [00:00:00:00]
2019-06-04 11:51:18,869:qiskit.aqua.utils.run_circuits:INFO: Circuit cache is empty, compiling from scratch.
Do you mind elaborating more details on the size of dataset or do you mind sharing the full scripts?
I just tried the notebook with ibmq_16_melbourne
backend, and it does not crash.
To test that, I reduce the size of the dataset to avoid submitting too many circuits. (4 training samples, 2 testing samples, and 2 unknown label samples)
Qiskit version:
qiskit 0.10.3
qiskit-aer 0.2.1
qiskit-aqua 0.5.1
qiskit-chemistry 0.5.0
qiskit-ibmq-provider 0.2.2
qiskit-ignis 0.1.1
qiskit-terra 0.8.1
Here is the log I had, it is still running but at least one of jobs is completed
019-06-04 13:30:01,138:qiskit.aqua.components.feature_maps.pauli_expansion:INFO: Pauli terms include: ['IZ', 'ZI', 'ZZ']
2019-06-04 13:30:01,142:qiskit.aqua.quantum_instance:INFO: backend_options can not used with the backends in IBMQ provider.
2019-06-04 13:30:01,143:qiskit.aqua.quantum_instance:INFO:
Qiskit Terra version: 0.8.1
Backend: 'ibmq_16_melbourne (<qiskit.providers.ibmq.ibmqprovider.IBMQProvider object at 0x127563400>)', with following setting:
{'basis_gates': ['u1', 'u2', 'u3', 'cx', 'id'], 'coupling_map': [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], [5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10], [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], [13, 12]]}
{'pass_manager': None, 'initial_layout': None, 'seed_transpiler': 10598}
RunConfig(max_credits=10, seed=10598, shots=1024)
{'timeout': None, 'wait': 5}
{}
{}
Measurement mitigation: None
2019-06-04 13:30:01,145:qiskit.aqua.algorithms.many_sample.qsvm.qsvm:DEBUG: Building circuits:
|██████████████████████████████████████████████████| 6/6 [00:00:00:00]
2019-06-04 13:30:01,289:qiskit.aqua.utils.run_circuits:INFO: Circuit cache is empty, compiling from scratch.
2019-06-04 13:30:09,195:qiskit.aqua.utils.run_circuits:INFO: Backend status: BackendStatus(backend_name='ibmq_16_melbourne', backend_version='1.0.0', operational=True, pending_jobs=119, status_msg='active')
2019-06-04 13:30:09,196:qiskit.aqua.utils.run_circuits:INFO: There are 1 jobs are submitted.
2019-06-04 13:30:09,196:qiskit.aqua.utils.run_circuits:INFO: All job ids:
['5cf6aa9d464bd40076d8f4e0']
2019-06-04 13:30:09,197:qiskit.aqua.utils.run_circuits:INFO: Running 0-th qobj, job id: 5cf6aa9d464bd40076d8f4e0
Got a 502 code response to /api/Jobs/5cf6aa9d464bd40076d8f4e0/status: 502 Bad Gateway: Registered endpoint failed to handle the request.
2019-06-04 16:53:44,053:qiskit.aqua.utils.run_circuits:INFO: COMPLETED the 0-th qobj, job id: 5cf6aa9d464bd40076d8f4e0
2019-06-04 16:53:44,067:qiskit.aqua.algorithms.many_sample.qsvm.qsvm:DEBUG: Calculating overlap:
|██████████████████████████████████████████████████| 6/6 [00:00:00:00]
2019-06-04 16:53:44,251:qiskit.aqua.utils.qp_solver:DEBUG: Solving QP problem is completed.
2019-06-04 16:53:44,252:qiskit.aqua.algorithms.many_sample.qsvm.qsvm:DEBUG: Building circuits:
|██████████████████████████████████████████████████| 8/8 [00:00:00:00]
2019-06-04 16:53:46,479:qiskit.aqua.utils.run_circuits:INFO: Circuit cache miss, recompiling. Cache miss reason: AquaError('Gate mismatch at gate 11 (u3, 3 params) of circuit against gate 11 (u2, 2 params) of cached qobj')
2019-06-04 16:53:52,610:qiskit.aqua.utils.run_circuits:INFO: Backend status: BackendStatus(backend_name='ibmq_16_melbourne', backend_version='1.0.0', operational=True, pending_jobs=80, status_msg='active')
2019-06-04 16:53:52,612:qiskit.aqua.utils.run_circuits:INFO: There are 1 jobs are submitted.
2019-06-04 16:53:52,613:qiskit.aqua.utils.run_circuits:INFO: All job ids:
['5cf6da5ea2f98a00755614a8']
I am unsure about the original user, however when I received the error I was using the defaults for everything. Whatever was already set in the notebook was what I was using.
However, when I made the changes you had made (changing the number of training samples and testing samples) the job was sent.
So it seems to work if run on a 20q machine. Fails on the 14 and 5 qubit devices. I had to dig into the internals to check, but it seems that the circuits use only two qubits, so it should work on all the devices. The fact that it gives an key error means that the chunks are likely not being computed correctly for the public devices. The public devices have different circuit limits than the larger devices, so perhaps that is not being taken into account correctly. So this is indeed a bug.
how do we fix this? And how do we know how many qubits are we using? Is this an error from our code or from qiskit (then this needsa bug filing)
It needs to be fixed in aqua. I dug into the internals to find the number of qubits. But the aqua developers can probably point out an easier way.
@nonhermitian and @hykavitha
Regarding the number of circuits in a job, Aqua is based on the backend property max_experiments
to split the number of circuits into jobs. E.g. if you submit 100 circuits, but the max_experiments
is 50, Aqua will automatically split the circuits into 2 jobs each with 50 circuits and then get back a single result for you.
Regarding the required number of qubits, you can check out the qiskit-tutorial to learn how the QSVM encodes the data into a quantum state. E.g., the default QSVM requires the same number of qubits to the dimension of data. The data we used in the example is two-dimension; thus we need two qubits. https://github.com/Qiskit/qiskit-tutorials/blob/master/qiskit/artificial_intelligence/qsvm_classification.ipynb
Furthermore, if you have a circuit whose qubits is larger than the targeted device, I believe that qiskit-terra will raise an error.
TranspilerError: 'Number of qubits greater than device.'
Regarding the key error for circuit caching in the first question, I can reproduce the error if I do not reduce the problem size. Will check that later in the stable branch. On the other hand, the error you encounter should already be fixed in the master branch.
In the meanwhile, you can disable the circuit cache and do qobj validation in the quantum instance to avoid the error, you should be able to run on the real device then.
quantum_instance = QuantumInstance(backend, shots=1024, seed=seed,
seed_transpiler=seed, circuit_caching=False, skip_qobj_validation=False)
I just ran the codes with the above modification (with the original amount of data) on ibmq_16_melbourne
. here is my log, It seems that there is some issues on the api to the backend. will update the post if I can successfully run on public devices. (I am able to run on the 20q device without an issue,)
updated: the jobs are completed on ibmq_16_melbourne
2019-06-11 01:53:18,973:qiskit.aqua.algorithms.many_sample.qsvm.qsvm:DEBUG: Building circuits:
|██████████████████████████████████████████████████| 780/780 [00:00:00:00]
Got a 400 code response to /api/Jobs: {"error":{"status":400,"message":"Generic error","code":"GENERIC_ERROR"}}
Got a 400 code response to /api/Jobs: {"error":{"status":400,"message":"Generic error","code":"GENERIC_ERROR"}}
Got a 400 code response to /api/Jobs: {"error":{"status":400,"message":"Generic error","code":"GENERIC_ERROR"}}
2019-06-11 04:49:35,089:qiskit.aqua.utils.run_circuits:INFO: Backend status: BackendStatus(backend_name='ibmq_16_melbourne', backend_version='1.0.0', operational=True, pending_jobs=21, status_msg='active')
2019-06-11 04:49:35,090:qiskit.aqua.utils.run_circuits:INFO: There are 11 jobs are submitted.
2019-06-11 04:49:35,091:qiskit.aqua.utils.run_circuits:INFO: All job ids:
['5cff424e43e51900734e221c', '5cff42b9711ca80077371510', '5cff43239bb71c007888317b', '5cff4391bd9211006b03f1e9', '5cff4394752445007027ceb9', '5cff43f75ee341007ad7aec4', '5cff43fe68bfba0075bad960', '5cff445b752445007027cebb', '5cff44be06c6bc0073aab339', '5cff4ddd68bfba0075bad974', '5cff6b1d42519f006f7a6f1d']
2019-06-11 04:49:35,092:qiskit.aqua.utils.run_circuits:INFO: Running 0-th qobj, job id: 5cff424e43e51900734e221c
2019-06-11 04:49:35,987:qiskit.aqua.utils.run_circuits:INFO: COMPLETED the 0-th qobj, job id: 5cff424e43e51900734e221c
2019-06-11 04:49:35,988:qiskit.aqua.utils.run_circuits:INFO: Running 1-th qobj, job id: 5cff42b9711ca80077371510
2019-06-11 05:10:22,821:qiskit.aqua.utils.run_circuits:INFO: COMPLETED the 1-th qobj, job id: 5cff42b9711ca80077371510
2019-06-11 05:10:22,822:qiskit.aqua.utils.run_circuits:INFO: Running 2-th qobj, job id: 5cff43239bb71c007888317b
2019-06-11 05:10:26,684:qiskit.aqua.utils.run_circuits:INFO: COMPLETED the 2-th qobj, job id: 5cff43239bb71c007888317b
2019-06-11 05:10:26,685:qiskit.aqua.utils.run_circuits:INFO: Running 3-th qobj, job id: 5cff4391bd9211006b03f1e9
2019-06-11 05:10:27,681:qiskit.aqua.utils.run_circuits:INFO: COMPLETED the 3-th qobj, job id: 5cff4391bd9211006b03f1e9
2019-06-11 05:10:27,681:qiskit.aqua.utils.run_circuits:INFO: Running 4-th qobj, job id: 5cff4394752445007027ceb9
2019-06-11 05:10:28,573:qiskit.aqua.utils.run_circuits:INFO: COMPLETED the 4-th qobj, job id: 5cff4394752445007027ceb9
2019-06-11 05:10:28,573:qiskit.aqua.utils.run_circuits:INFO: Running 5-th qobj, job id: 5cff43f75ee341007ad7aec4
2019-06-11 05:10:29,523:qiskit.aqua.utils.run_circuits:INFO: COMPLETED the 5-th qobj, job id: 5cff43f75ee341007ad7aec4
2019-06-11 05:10:29,523:qiskit.aqua.utils.run_circuits:INFO: Running 6-th qobj, job id: 5cff43fe68bfba0075bad960
2019-06-11 05:10:30,805:qiskit.aqua.utils.run_circuits:INFO: COMPLETED the 6-th qobj, job id: 5cff43fe68bfba0075bad960
2019-06-11 05:10:30,807:qiskit.aqua.utils.run_circuits:INFO: Running 7-th qobj, job id: 5cff445b752445007027cebb
2019-06-11 05:10:32,531:qiskit.aqua.utils.run_circuits:INFO: COMPLETED the 7-th qobj, job id: 5cff445b752445007027cebb
2019-06-11 05:10:32,535:qiskit.aqua.utils.run_circuits:INFO: Running 8-th qobj, job id: 5cff44be06c6bc0073aab339
2019-06-11 05:10:33,755:qiskit.aqua.utils.run_circuits:INFO: COMPLETED the 8-th qobj, job id: 5cff44be06c6bc0073aab339
2019-06-11 05:10:33,758:qiskit.aqua.utils.run_circuits:INFO: Running 9-th qobj, job id: 5cff4ddd68bfba0075bad974
2019-06-11 05:31:17,780:qiskit.aqua.utils.run_circuits:INFO: COMPLETED the 9-th qobj, job id: 5cff4ddd68bfba0075bad974
2019-06-11 05:31:17,781:qiskit.aqua.utils.run_circuits:INFO: Running 10-th qobj, job id: 5cff6b1d42519f006f7a6f1d
2019-06-11 05:31:20,498:qiskit.aqua.utils.run_circuits:INFO: COMPLETED the 10-th qobj, job id: 5cff6b1d42519f006f7a6f1d
Ok great. So it is fixed in master.
If I wanted to programmatically find out the number of qubits used, perhaps by accessing the underlying circuits or the like, how would I go about doing that?
Yes, for any algorithm and components, we usually have a construct_circuit
method e.g. in QSVM https://github.com/Qiskit/qiskit-aqua/blob/master/qiskit/aqua/algorithms/many_sample/qsvm/qsvm.py#L174
But each algorithm/component might need different parameters to get the circuits.
You can get the circuit easily after you construct the algorithm object.
E.g., QSVM uses the circuits to calculate the overlap between two data; thus, its construct_circuit
method requires two data and an optional flag to add the measurement gate or not.
like in the tutorials
feature_map = SecondOrderExpansion(feature_dimension=feature_dim, depth=2, entanglement='linear')
qsvm = QSVM(feature_map, training_input, test_input, datapoints[0])
qc = qsvm.construct_circuit(x1=datapoints[0][0], x2=datapoints[0][1]) # these are two data points.
qc.draw(output='latex')
and this is the circuit.
@chunfuchen : thats great to hear its fixed in the master branch. does it mean, this works at IBM-Q experience now? Also does we can access ibm-Q computer from a general public accessing public devices? Also, i have 2 questions,
wanted to know how are you printing while qsvm.run(quantum_instance) is running? I'm running the algorithm for training size 4 & test 2, its been 10 mins still that statement is executing with no sign of output. how did you get those informative print-outs while your qsvm.run() is happening?
in your circuit output, its using just 2 qubits q0, q1 & using U & C gates. When its using 2 qubits, shoudl it behave like a classical computer with two states (0 or 1) ?
@nonhermitian & @chunfuchen : I ran the test as per chunfuchen suggestion to get the qsvm work on tranining size 4 & testing size 2 I still couldnt use real Q. Here is the code & output -error
print("Available backends:") IBMQ.backends() Available backends: [<IBMQSimulator('ibmq_qasm_simulator') from IBMQ(ibm-q, open, main)>, <IBMQBackend('ibmqx4') from IBMQ(ibm-q, open, main)>, <IBMQBackend('ibmqx2') from IBMQ(ibm-q, open, main)>, <IBMQBackend('ibmq_16_melbourne') from IBMQ(ibm-q, open, main)>, <IBMQBackend('ibmqx4') from IBMQ()>, <IBMQBackend('ibmqx2') from IBMQ()>, <IBMQBackend('ibmq_16_melbourne') from IBMQ()>, <IBMQSimulator('ibmq_qasm_simulator') from IBMQ()>]
backend = IBMQ.get_backend('ibmq_16_melbourne', hub=None) print(backend)
backend = IBMQ.get_backend('ibmq_16_melbourne', hub=None) print(backend) ibmq_16_melbourne
quantum_instance = QuantumInstance(backend, shots=1024, seed=seed, seed_transpiler=seed) print(quantum_instance)
Qiskit Terra version: 0.8.1 Backend: 'ibmq_16_melbourne (<qiskit.providers.ibmq.ibmqprovider.IBMQProvider object at 0x7f400abfd3c8>)', with following setting: {'basis_gates': ['u1', 'u2', 'u3', 'cx', 'id'], 'coupling_map': [[1, 0], [1, 2], [2, 3], [4, 3], [4, 10], [5, 4], [5, 6], [5, 9], [6, 8], [7, 8], [9, 8], [9, 10], [11, 3], [11, 10], [11, 12], [12, 2], [13, 1], [13, 12]]} {'pass_manager': None, 'initial_layout': None, 'seed_transpiler': 10598} RunConfig(max_credits=10, seed=10598, shots=1024) {'timeout': None, 'wait': 5} {} {} Measurement mitigation: None
result = qsvm.run(quantum_instance)
KeyError Traceback (most recent call last)
@hykavitha, to see the log, you can turn Aqua log as we mentioned in the first cell of the notebook
# setup aqua logging
import logging
from qiskit.aqua import set_qiskit_aqua_logging
set_qiskit_aqua_logging(logging.DEBUG) # choose INFO, DEBUG to see the log
On the other hand, as I posted above, I am able to run the experiment with the original data size on the public device ibmq_16_melbourne
at the stable branch with the following modification:
quantum_instance = QuantumInstance(backend, shots=1024, seed=seed,
seed_transpiler=seed, circuit_caching=False, skip_qobj_validation=False)
@hykavitha do you still encounter any other issue? if no, I think we can close this issue.
@chunfuchen : I still face this issue. Once its fixed and confirmed after release is when you would close? or its fixed & tested at qiskit aqua developing stage?
@hykavitha what is the issue you encounter now? could changing setting of the quantum instance be a workaround?
I think this is fixed in the master branch. I can run the notebook as is if the master branch is used.
@chunfuchen : I still cant use the IBMQ device from my public account. Qiskit errors out with error key 1. When you say its fixed in the master branch. What does it mean for us having these versions of qiskit.
I have these versions: Qiskit Aqua version: pip list | grep "qiskit" qiskit 0.10.1 qiskit-aer 0.2.0 qiskit-aqua 0.5.0 qiskit-chemistry 0.5.0 qiskit-ibmq-provider 0.2.2 qiskit-ignis 0.1.1 qiskit-terra 0.8.0 Python version: 3.73 Operating system: OSX
I mean that you need to install everything from the source code, here is my qiskit version
qiskit-aer 0.3.0
qiskit-aqua 0.5.2
qiskit-chemistry 0.5.1
qiskit-ibmq-provider 0.2.3rc2
qiskit-ignis 0.2.0
qiskit-terra 0.9.0
however, do you mind posting the error log when you turn off the circuit cache? Thanks
This should no longer occur in Aqua 0.6. Closing, if the problem that you experienced still continues for you either reopen or raise a new issue.
Informations
What is the current behavior?
Steps to reproduce the problem
What is the expected behavior?
Suggested solutions