qiskit-aqt-provider icon indicating copy to clipboard operation
qiskit-aqt-provider copied to clipboard

Batching Circuits

Open DanyaLearning opened this issue 5 months ago • 8 comments

Informations

  • Qiskit AQT Provider version: qiskit-aqt-provider==1.1.0
  • Python version: 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
  • Operating system: Windows 10

What is the current behavior?

I wanted to try out sending circuit batches as described in the User Guide

from numpy import pi
from qiskit import QuantumCircuit, transpile, execute

from qiskit_aqt_provider import AQTProvider
from qiskit_aqt_provider.primitives import AQTSampler

circuit = QuantumCircuit(2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure_all()

provider = AQTProvider("ACCESS_TOKEN")
backend = provider.get_backend("offline_simulator_no_noise")

job = execute(circuit, backend)
result = job.result()

if result.success:
    counts = result.get_counts()
    print(counts)

else:
    raise RuntimeError

circuit2 = QuantumCircuit(3)
circuit2.h(0)
circuit2.cx(0,1)
circuit2.cx(1,2)
circuit2.measure_all()

batch = [circuit, circuit2]

job2 = execute(batch, backend)
print(job2.progress())
result2 = job2.result()
print(result2.get_counts())

Then I get the error:

‘TypeError: cannot pickle 'dict_keys' object’

Steps to reproduce the problem

Running the script.

What is the expected behavior?

Expected output is two dictionaries with a quasi-probability distribution, for example: [{3: 0.57, 0: 0.43}, {'111': 516, '000': 508}]

Suggested solutions

I have no idea where this comes from. Using the aer-simulator instead works perfectly fine.

DanyaLearning avatar Jan 24 '24 10:01 DanyaLearning

Similar to issue #121 this is a problem specific to Windows. We are investigating the source of the problem and try to come up with a solution.

fg-aqt avatar Jan 24 '24 15:01 fg-aqt

I can confirm, working on Linux everything is fine.

DanyaLearning avatar Jan 24 '24 15:01 DanyaLearning

Was your error message ‘TypeError: cannot pickle 'dict_keys' object’ related to another issue or did it also appear here?

chma100 avatar Jan 24 '24 16:01 chma100

Upsi, it is here where I get the TypeError and #121 Where I have the 'ValueError: Operation ‘cx’ not in the basis gate set: {rz, r, rxx}' I am sorry for mixing up!

Edit: I updated the issue.

DanyaLearning avatar Jan 24 '24 16:01 DanyaLearning

Thanks for the bug report.

We unfortunately cannot reproduce the issue with the script you provided. See for example this CI job (the "Run examples (windows)" step runs the reproduction script on Windows 2022 server with Python 3.9).

Does the issue persist if you re-create the relevant Python environment from scratch?

If so, could you please post the full exception traceback? It should point to the calling site of the code raising the exception.

airwoodix avatar Jan 25 '24 10:01 airwoodix

This is the full exception traceback:

File "C:\Users\pranjic\Documents\Python Scripts\Access AQT\access_aqt_offline_simulator.py", line 53, in <module>
    job2 = execute(batch, backend)

  File "C:\Users\pranjic\Anaconda3\lib\site-packages\qiskit\execute_function.py", line 286, in execute
    experiments = transpile(

  File "C:\Users\pranjic\Anaconda3\lib\site-packages\qiskit\compiler\transpiler.py", line 428, in transpile
    out_circuits = pm.run(circuits, callback=callback)

  File "C:\Users\pranjic\Anaconda3\lib\site-packages\qiskit\transpiler\passmanager.py", line 534, in run
    return super().run(circuits, output_name, callback)

  File "C:\Users\pranjic\Anaconda3\lib\site-packages\qiskit\transpiler\passmanager.py", line 553, in wrapper
    return meth(*meth_args, **meth_kwargs)

  File "C:\Users\pranjic\Anaconda3\lib\site-packages\qiskit\transpiler\passmanager.py", line 291, in run
    return super().run(

  File "C:\Users\pranjic\Anaconda3\lib\site-packages\qiskit\passmanager\passmanager.py", line 242, in run
    task_kwargs={"pass_manager_bin": dill.dumps(self)},

  File "C:\Users\pranjic\Anaconda3\lib\site-packages\dill\_dill.py", line 304, in dumps
    dump(obj, file, protocol, byref, fmode, recurse, **kwds)#, strictio)

  File "C:\Users\pranjic\Anaconda3\lib\site-packages\dill\_dill.py", line 276, in dump
    Pickler(file, protocol, **_kwds).dump(obj)

  File "C:\Users\pranjic\Anaconda3\lib\site-packages\dill\_dill.py", line 498, in dump
    StockPickler.dump(self, obj)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 487, in dump
    self.save(obj)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 603, in save
    self.save_reduce(obj=obj, *rv)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 717, in save_reduce
    save(state)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 560, in save
    f(self, obj)  # Call unbound method with explicit self

  File "C:\Users\pranjic\Anaconda3\lib\site-packages\dill\_dill.py", line 990, in save_module_dict
    StockPickler.save_dict(pickler, obj)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 971, in save_dict
    self._batch_setitems(obj.items())

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 997, in _batch_setitems
    save(v)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 560, in save
    f(self, obj)  # Call unbound method with explicit self

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 931, in save_list
    self._batch_appends(obj)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 955, in _batch_appends
    save(x)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 560, in save
    f(self, obj)  # Call unbound method with explicit self

  File "C:\Users\pranjic\Anaconda3\lib\site-packages\dill\_dill.py", line 990, in save_module_dict
    StockPickler.save_dict(pickler, obj)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 971, in save_dict
    self._batch_setitems(obj.items())

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 997, in _batch_setitems
    save(v)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 560, in save
    f(self, obj)  # Call unbound method with explicit self

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 931, in save_list
    self._batch_appends(obj)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 955, in _batch_appends
    save(x)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 603, in save
    self.save_reduce(obj=obj, *rv)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 717, in save_reduce
    save(state)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 560, in save
    f(self, obj)  # Call unbound method with explicit self

  File "C:\Users\pranjic\Anaconda3\lib\site-packages\dill\_dill.py", line 990, in save_module_dict
    StockPickler.save_dict(pickler, obj)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 971, in save_dict
    self._batch_setitems(obj.items())

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 997, in _batch_setitems
    save(v)

  File "C:\Users\pranjic\Anaconda3\lib\pickle.py", line 578, in save
    rv = reduce(self.proto)

TypeError: cannot pickle 'dict_keys' object

DanyaLearning avatar Jan 25 '24 16:01 DanyaLearning

Thanks for the extra piece of information. Unfortunately, we're still unable to reproduce the error, which makes debugging very difficult.

Which exact version of the qiskit (or qiskit-terra) packages do you use? (e.g. through python -c "import qiskit; print(qiskit.version.get_version_info())")

Does the problem persist in a brand new environment where the only package is qiskit-aqt-provider (i.e. with qiskit installed as transitive dependency)?

Debugging background so far: The error occurs when qiskit attempts to pickle the PassManager to be able to parallelize the circuit transpilation. Since the qiskit-aqt-provider registers transpilation plugins, the PassManager is influenced by the use of the the AQT provider. However, there's no intentional behavior change between platforms in the AQT provider code and the ability to pickle should be platform-independent.

airwoodix avatar Jan 29 '24 16:01 airwoodix

Other qiskit libraries that I have installed are:

qiskit==0.45.2 qiskit-aer==0.12.2 qiskit-aqt-provider==1.1.0 qiskit-ibm-provider==0.7.1 qiskit-ibm-runtime==0.13.0 qiskit-ibmq-provider==0.20.0 qiskit-ignis==0.7.0 qiskit-machine-learning==0.6.1 qiskit-qryd-provider==0.2.8 qiskit-terra==0.45.2

DanyaLearning avatar Jan 29 '24 16:01 DanyaLearning