Skip to content

Conversation

@conradhaupt
Copy link
Contributor

@conradhaupt conradhaupt commented Oct 30, 2025

Summary

As per #30, TQATrainer does not correctly populate the ParamResult "optimized_qaoa_angles" list Instead, it's just dt, which should be "expanded" by TQATrainer.tqa_schedule. Furthermore, the "optimized_params" entry contained the true QAOA angles.

Details and comments

TQATrainer has a single parameter dt which controls the QAOA layer angles. These layer angles are generated by TQATrainer.tqa_schedule and stored in a ParamResult instance, in the "optimized_qaoa_angles" entry. However, owing to a bug, tqa_schedule was never called and thus all returned "optimized_qaoa_angles" values were just the lists [dt]. Furthermore, "optimized_params" was populated by the QAOA angles instead of the trainer parameters, i.e., [dt], effectively swapping their values in the ParamResult dictionary.

This WIP PR adds failing tests for this bug. Fix to follow.

This PR fixes TQATrainer by introducing a custom function subclass for TQATrainer.qaoa_angles_function. However, because TQATrainer.tqa_schedule requires the number of QAOA layers/reps, this solution does incur some technical debt. It works as follows:

  1. tqa_trainer.qaoa_angles_function(x) will return the correct QAOA angles if TQATrainer.train was previously called. The number of repetitions will be the most recent reps value passed to tqa_trainer.train(). If train was not called, then an error is raised.
  2. tqa_trainer.qaoa_angles_function(x, reps=...) will always return a list of QAOA angles.
  3. The tqa_trainer.qaoa_angles_function is a wrapper around tqa_trainer.tqa_schedule(x, reps) with a default value for reps. The default value is updated at the beginning of tqa_trainer.train().

Furthermore, the results dictionary has been fixed so that "optimized_params" is the list [dt], i.e., the Trotterized Quantum Annealer time step, and "optimized_qaoa_angles" is the list of QAOA angles. Before this PR, these were swapped. Because of this change, I have incremented the qaoa_training_pipeline_version value to 16. There are also tests to validate "optimized_params" and "optimized_qaoa_angles" in the results dictionary.

Version updated

Please increment the qaoa_training_pipeline_version variable and extend the main README.md.

  • [x]

…Trainer

It turns out that TQATrainer does not populate the ParamResult
"optimized_qaoa_angles" list with the correct number of values. Instead
it's just `dt`, which should be "expanded" by `TQATrainer.tqa_schedule`.
This commit adds failing tests for this check. Fix to follow.
@conradhaupt conradhaupt marked this pull request as draft October 30, 2025 14:26
TQATrainer didn't set qaoa_angles_function, which meant that
"optimized_qaoa_angles" was never set correctly. Furthermore,
"optimized_params" and "optimized_qaoa_angles" were swapped in the
result dictionary. This commit fixes that by implementing a
TQATrainerFunction that takes the tqa_schedule method from TQATrainer
and uses it to compute the qaoa angles.

This requires having trained once or passing reps to
tqa_trainer.qaoa_angles_function(..., reps=...).
@conradhaupt conradhaupt changed the title [WIP] Fix TQATrainer returning incorrect optimised QAOA angles Fix TQATrainer returning incorrect optimised QAOA angles Nov 5, 2025
@conradhaupt conradhaupt marked this pull request as ready for review November 5, 2025 15:47
Copy link
Collaborator

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. One extra change to make: in the top-level README.md we have a table with one-liners relating the version of the code defined in param_result.py to a short description of the changes. Can you add a one-liner here?

@conradhaupt
Copy link
Contributor Author

I've added a description of the increase in qaoa_training_pipeline to version 16 (fa0c641) and fixed the incorrect error message when reps is not known by TQATrainerFunction (70cb81d).

@conradhaupt conradhaupt requested a review from eggerdj November 6, 2025 08:33
Copy link
Collaborator

@eggerdj eggerdj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks a lot!

@eggerdj eggerdj merged commit bc03508 into qiskit-community:main Nov 6, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants