pasqal-io / qadence-libs

A collection of libraries to enhance Qadence functionalities.
https://pasqal-io.github.io/qadence-libs/latest/
Apache License 2.0
6 stars 2 forks source link

[Fix] QNG optimizer not compatible with qadence training function #21

Open DanieleCucurachi opened 2 months ago

DanieleCucurachi commented 2 months ago

Description

QNG has been recently added to qinfo_tools. While it works smoothly with simple training loops, as shown here, it is not compatible with train(), function defined in qadence to automate the definition of the training process with gradient-based optimizers.

In particular, the error seems to be related to Python's pickle module having trouble pickling a local object:

Traceback (most recent call last):
  File ".../qadence/ml_tools/saveload.py", line 76, in write_checkpoint
    torch.save(
  File ".../torch/serialization.py", line 628, in save
    _save(obj, opened_zipfile, pickle_module, pickle_protocol, _disable_byteorder_record)
  File ".../torch/serialization.py", line 840, in _save
    pickler.dump(obj)
AttributeError: Can't pickle local object 'Parametric.__init__.<locals>.parse_values'
inafergra commented 2 months ago

Thanks for finding this @DanieleCucurachi. As discussed, I believe the issue is in the serialization of the optimizer's state_dict, as the QNG's state_dict holds a quantum circuit. We probably need to add some logic to correctly serialize it. I will take a look into it