-
Notifications
You must be signed in to change notification settings - Fork 7
Fix TQATrainer returning incorrect optimised QAOA angles #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix TQATrainer returning incorrect optimised QAOA angles #35
Conversation
…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.
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=...).
eggerdj
left a comment
There was a problem hiding this 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?
eggerdj
left a comment
There was a problem hiding this 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!
Summary
As per #30,
TQATrainerdoes not correctly populate theParamResult"optimized_qaoa_angles" list Instead, it's justdt, which should be "expanded" byTQATrainer.tqa_schedule. Furthermore, the"optimized_params"entry contained the true QAOA angles.Details and comments
TQATrainerhas a single parameterdtwhich controls the QAOA layer angles. These layer angles are generated byTQATrainer.tqa_scheduleand stored in aParamResultinstance, in the"optimized_qaoa_angles"entry. However, owing to a bug,tqa_schedulewas 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 theParamResultdictionary.This WIP PR adds failing tests for this bug. Fix to follow.This PR fixes
TQATrainerby introducing a custom function subclass forTQATrainer.qaoa_angles_function. However, becauseTQATrainer.tqa_schedulerequires the number of QAOA layers/reps, this solution does incur some technical debt. It works as follows:tqa_trainer.qaoa_angles_function(x)will return the correct QAOA angles ifTQATrainer.trainwas previously called. The number of repetitions will be the most recentrepsvalue passed totqa_trainer.train(). Iftrainwas not called, then an error is raised.tqa_trainer.qaoa_angles_function(x, reps=...)will always return a list of QAOA angles.tqa_trainer.qaoa_angles_functionis a wrapper aroundtqa_trainer.tqa_schedule(x, reps)with a default value forreps. The default value is updated at the beginning oftqa_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 theqaoa_training_pipeline_versionvalue 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_versionvariable and extend the main README.md.