qiboteam / boostvqe

Using DBI to boost VQE optimization
4 stars 1 forks source link

Clean up #55

Closed andrea-pasquale closed 4 months ago

andrea-pasquale commented 4 months ago

As I was reviewing the code I decided to remove some parts that are currently not used (or so I believe). The script is working also on this branch. @marekgluza I noticed that when I try to run things using the first order group commutator the code is crashing with the following error:

Traceback (most recent call last):
  File "/home/andreapasquale/boostvqe/compiling.py", line 228, in <module>
    main(args)
  File "/home/andreapasquale/boostvqe/compiling.py", line 97, in main
    _, best_s, _, eo_d = select_recursion_step_gd_circuit(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andreapasquale/boostvqe/src/boostvqe/utils.py", line 320, in select_recursion_step_gd_circuit
    eo_d, s, l, eval_dict, params, best_lr = choose_gd_params(
                                             ^^^^^^^^^^^^^^^^^
  File "/home/andreapasquale/boostvqe/src/boostvqe/models/dbi/utils_gci_optimization.py", line 305, in choose_gd_params
    best_lr, best_loss, _, exit_criterion = adaptive_binary_search(
                                            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andreapasquale/boostvqe/src/boostvqe/models/dbi/utils_scheduling.py", line 231, in adaptive_binary_search
    eval_func_at_points(eval_points)
  File "/home/andreapasquale/boostvqe/src/boostvqe/models/dbi/utils_scheduling.py", line 225, in eval_func_at_points
    val = loss_func(point)
          ^^^^^^^^^^^^^^^^
  File "/home/andreapasquale/boostvqe/src/boostvqe/models/dbi/utils_gci_optimization.py", line 284, in loss_func_lr
    ) = adaptive_binary_search(
        ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andreapasquale/boostvqe/src/boostvqe/models/dbi/utils_scheduling.py", line 231, in adaptive_binary_search
    eval_func_at_points(eval_points)
  File "/home/andreapasquale/boostvqe/src/boostvqe/models/dbi/utils_scheduling.py", line 225, in eval_func_at_points
    val = loss_func(point)
          ^^^^^^^^^^^^^^^^
  File "/home/andreapasquale/boostvqe/src/boostvqe/models/dbi/utils_gci_optimization.py", line 285, in <lambda>
    lambda s: gci.loss(s, eo_d) if s > 0 else float("inf"),
              ^^^^^^^^^^^^^^^^^
  File "/home/andreapasquale/boostvqe/src/boostvqe/models/dbi/group_commutator_iteration_transpiler.py", line 241, in loss
    circ = self.recursion_step_circuit(step_duration, eo_d, mode_dbr) + circ
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andreapasquale/boostvqe/src/boostvqe/models/dbi/group_commutator_iteration_transpiler.py", line 279, in recursion_step_circuit
    return self.group_commutator(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andreapasquale/boostvqe/src/boostvqe/models/dbi/group_commutator_iteration_transpiler.py", line 218, in group_commutator
    "forwards": reduce(Circuit.__add__, query_list_forward[::-1]),
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/andreapasquale/qibo/src/qibo/models/circuit.py", line 264, in __add__
    raise_error(
  File "/home/andreapasquale/qibo/src/qibo/config.py", line 46, in raise_error
    raise exception(message)
ValueError: Cannot add circuits with different kwargs. nqubits is 9 for first circuit and 10 for the second.

Instead when I run with the third order commutator everything seems fine.

marekgluza commented 4 months ago

https://github.com/qiboteam/boostvqe/blob/38fbbe6ad51a1fbac3cdcb4e641cea2ff783af51/compiling.py#L135

f"boosting_data_{nqubits}q_{nlayers}l_{seed}s_{epoch}e.json