This is the offical repository of the paper "Meta-Learning for Quantum Optimization via Quantum Sequence Model"
The Quantum Approximate Optimization Algorithm (QAOA) is a leading approach for solving combinatorial optimization problems on near-term quantum processors. However, finding good variational parameters remains a significant challenge due to the non-convex energy landscape, often resulting in slow convergence and poor solution quality. In this work, we propose a quantum meta-learning framework that trains advanced quantum sequence models to generate effective parameter initialization policies. We investigate four classical or quantum sequence models, including the Quantum Kernel-based Long Short-Term Memory (QK-LSTM), as learned optimizers in a "learning to learn" paradigm. Our numerical experiments on the Max-Cut problem demonstrate that the QK-LSTM optimizer achieves superior performance, obtaining the highest approximation ratios and exhibiting the fastest convergence rate across all tested problem sizes (
In this project, we address a major challenge in running variational quantum algorithma (VQA) like QAOA: finding the good starting point. The cost landscape for these algorithms is often like a rocky, unpredictable terrain, making the traditional search for the best "angles" (parameters) slow and inconsistent. Our appoach is inspired by the meta-learning framework developed by Verdon et al., which focuses on learning to learn optimization strategies. We extend this paradigm by training an intelligent sequence model—like a skilled quantum coach—to guide the optimization process. This coach is trained on many different random graph instances from the Max-Cut problem. Its job is to observe the current problem structure and quickly predict a highly effective initial parameter set.
Our optimization follows a two-phase strategy:
- Phase I (Sequence Model Guidance): The trained sequence model is used as a fast, black-box controller to optimize the QAOA parameters for a few initial steps.
- Phase II (Refinement): Once the sequence model has landed the parameters in a good region of the landscape, we switch to a common, robust optimizer (like ADAM) for fine-tuning and reaching the final minimum.
By employing both classical and quantum sequence models (including our novel QK-LSTM), we aim to find a universally good starting point that dramatically accelerates convergence across many different problem sizes.
We recommend setting up a dedicated Conda environment to manage dependencies:
- Create a new Conda environment with Python 3.10:
conda create --name [your_env_name] python=3.10
- Activate the newly created environment:
conda create [your_env_name]
- Install the required package using pip:
pip install -r requirements.txt
--Train_and_Test: Default isTrue. Set toTrueto run both training and testing phases sequentially.--Only_train: Default isFalse. Set toTrueto perform training only (will save model checkpoint).--Only_test: Default isFalse. Set toTrueto perform training only (will save model checkpoint).
--device: Default iscpu. Use--deviceto set the device to use for PyTorch computation (cpuorcuda:0).--backend_sequence: Default islightning.qubit. Use--backend_sequenceto set the pennylane backend for the quantum sequence moodel.--backend_QAOA: Default isdefault.qubit. Use--backend_QAOAto set the pennylane backend for the QAOA.
--dataset_save_path: Default isdatasets.pkl. Use--dataset_save_pathto load your dataset file.--model_save_path: Default ismodels_default. Use--model_save_pathto set the file name to save model parameters.--Results_save_path: Default isresults_default. Use--Results_save_pathto set the file name to save test result (CSV, NPZ, SVG).--load_path: Default isNone. Use--load_pathto load the pre-trained model parameters (.pthfile) if you need.
--model_type: Use--model_typeto set the type of sequence model, e.g.LSTM,QK,QLSTM,QFWP.--mapping_type: Default isID. Use--mapping_typeto set the type of mapping model if you need (e.g.,LinearorIDfor identity).--layers: Default is1. Use--layersto set the number of layers for the sequence model.--input_feature_dim: Default is2. Use--input_feature_dimto set the number of parameters input to the sequence model (doesn't inclue one parameter for cost).--max_total_params: Default is2. Use--max_total_paramsto set the number of parameter for the QAOA ansatz.--qubits: Default is4. Use--qubitsto set the number of qubits for the QK-LSTM and QLSTM model.--loss_function_type: Default isweighted. Use--loss_function_typeto set the type of meta-loss function, (e.g.,weightedorobserved improvement).--lr_sequence: Default is6e-6. Use--lr_sequenceto set the learning rate for the sequence model.--lr_mapping: Default is1e-4. Use--lr_mappingto set the learning rate for the mapping model.--epochs: Default is50. Use--epochsto set the number of training epochs.--steps_recurrent_loop_train: Default is10. Use--steps_recurrent_loop_trainto set the number of recurrent steps during training.--conv_tol_sequence: Default is1e-5. Use--conv_tol_sequenceto set the convergence tolerance for training.--time_out: Default is7200. Use--time_outto set the timeout in seconds for training.--continue_train: Default isFalse. Use--continue_trainif yoy already have the model parameters file and you plan to continue tain.--steps_recurrent_loop_test: Default is10. Use--steps_recurrent_loop_testto set the number of recurrent steps during testing (Phase I).
--qaoa_layers: Default is1. Use--qaoa_layersto set the number of layers in QAOA MaxCut.--qaoa_optimizer: Default isSGD. Use--qaoa_optimizerto set the optimizer for the QAOA optimization, e.g.SGDandADAM.--lr_qaoa: Default is1e-3. Use--lr_qaoato set the learning rate for the QAOA optimization.--max_iter_qaoa: Default is300. Use--max_iter_qaoato set the max iterations for QAOA optimization.--conv_tol_qaoa: Default is1e-6. Use--conv_tol_qaoato set the convergence tolerance for QAOA optimization.
The dataset file (.pkl format) must contain the train_data, val_data, and test_data sets. Each graph generated by the networkx package. You can also generate graph by yourself but the graph must possess the necessary attributes: .nodes, .edges, and .edges.data("weight").
This is the standard workflow. The best model parameters found during training will be automatically loaded for the testing phase.
python main.py -- Train_and_Test True --dataset_save_path [dataset_path.pkl] --model_type QK --mapping_type Linear Use this if you want to train and save the model, and test it later.
python main.py -- Train_and_Test False --Only_train True --dataset_save_path [dataset_path.pkl] --model_type QK --mapping_type LinearUse this when you have an existing .pth file and want to evaluate its performance on the test set.
python main.py -- Train_and_Test False --Only_test True --dataset_save_path [dataset_path.pkl] --load_path [your_model_params._path.pth] --model_type QK --mapping_type LinearThe model generates three main result file:
the file include NumPy array of sequence model output and QAOA parameter history during test
QAOA_Random_node_[nodes_of_the_graph]_edge_[edges_of_the_graph]_[i].npz
the file saves cost history in DataFrame format
[args.Results_save_path]_node_[nodes_of_the_graph]_edge_[edges_of_the_graph]_[i].csv
the file saves the convergence plot image
Result_[args.Results_save_path]_node_[nodes_of_the_graph]_edges_[edges_of_the_graph]_[i].svg
When saving model checkpoints, the folder follows this format:
the model with the best validation performance
best_[args.model_type]_model_[args.model_save_path].pth
the model at the end of the last training epoch
[Model_save_path]_[model_type]_[lr_sequence]_[lr_mapping].pth
- 2025.02.06 – 🎉 Our paper has been accepted by the International Conference on Quantum Communications, Networking, and Computing (QCNC 2026).
📚 If you find our work or this code useful in your research, please consider citing our paper:
@article{lin2025meta,
title = {Meta-Learning for Quantum Optimization via Quantum Sequence Model},
author = {Lin, Yu-Cheng and Hsu, Yu-Chao and Chen, Samuel Yen-Chi},
journal = {arXiv preprint arXiv:2512.05058},
year = {2025}
}
