MHGphormer: Metapath-based Heterogeneous Graph-Transformer Network
June 8, 2026 ยท View on GitHub
This is the official PyTorch implementation of the Metapath-based Heterogeneous Graph-Transformer Network (MHGphormer). The architecture and its application are proposed in our paper:
"Joint Spectrum, Precoding, and Phase Shifts Design for RIS-Aided Multiuser MIMO THz Systems"
Accepted for publication in IEEE Transactions on Communications, 2024.
MHGphormer leverages advanced heterogeneous graph transformer architectures to optimize joint spectrum, precoding, and phase shifts for Reconfigurable Intelligent Surface (RIS)-aided multiuser MIMO systems in the Terahertz (THz) band.
๐ Table of Contents
- Architecture Overview
- Repository Structure
- Requirements & Installation
- Usage
- Configuration
- Citation
- Contact
๐ง Architecture Overview
The system models the complex interactions between Users, the Base Station (BS), and the RIS as a heterogeneous graph. MHGphormer captures these interactions through multiple carefully designed metapaths and aggregates them via a novel Transformer-based attention mechanism.
Key components optimized by the network:
- Precoding Matrix (Beamforming): Formulated at the BS to maximize signal power directed toward users while minimizing inter-user interference.
- RIS Phase Shifts: Optimized via complex-valued layers to properly reflect and align incoming THz signals.
- Sub-band Allocation: Predicts optimal bandwidth allocations for different users using custom constrained multi-layer perceptrons.
๐ Repository Structure
The codebase has been refactored for modularity, readability, and scalability.
MHGphormer/
โ
โโโ src/
โ โโโ __init__.py
โ โโโ config.py # Global hyperparameters, system setup & bounds
โ โโโ dataset.py # Data generation and Dataloader utilities
โ โโโ trainer.py # Model training, validation loop, and custom loss formulation
โ โโโ models/ # Neural network definitions
โ โโโ __init__.py
โ โโโ layers.py # Custom MLPs, Complex MLPs, and Transformer building blocks
โ โโโ mhgphormer.py # Main SeHGNN architecture
โ
โโโ main.py # Execution entry point
โโโ requirements.txt # Python dependencies
โโโ README.md # Project documentation
๐ Requirements & Installation
Prerequisites
Ensure you have Python 3.8+ and a CUDA-capable GPU. The implementation heavily relies on PyTorch's CUDA backend for accelerated tensor computations.
Installation
-
Clone the repository:
git clone https://github.com/Ali-Meh619/MHGphormer.git cd MHGphormer -
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows, use: venv\Scripts\activate -
Install dependencies:
pip install -r requirements.txt
๐ Usage
You can train and evaluate the model using the provided main.py entry point. It automatically orchestrates dataset generation, model initialization, training loop, and final evaluation.
python main.py
What happens during execution?
- Dataset Generation (
src/dataset.py): Randomizes user locations and calculates corresponding THz channel gains, delays, and path losses. Converts system graphs into heterogeneous meta-paths. - Model Initialization (
src/models/mhgphormer.py): Instantiates the MHGphormer network. - Training (
src/trainer.py): Starts the epoch loop. During each iteration, the model outputs beamforming vectors, phase shifts, and bandwidth allocation. The physical layer optimization problem is directly embedded into the loss function. - Evaluation: Outputs the final achievable sum-rate over the test dataset and saves the optimized model checkpoint in the
RIS-MIMO-THzdirectory.
โ ๏ธ Memory Note: The original default parameters (
batch=250,int_samp=100000) require upwards of 80GB of GPU VRAM due to the massive continuous tensor allocations for channel integration. If you encounterCUDA Out of Memoryerrors, please lowerint_samp(e.g.,10000) or reduce thebatchsize insrc/config.py.
โ๏ธ Configuration
Hyperparameters, network dimensions, and system assumptions (like transmission power, noise density, frequencies, etc.) are centralized in src/config.py.
To experiment with different RIS sizes, BS antennas, or learning rates, simply modify the ARGS dictionary inside src/config.py:
ARGS = {
"IRS_elements": 64, # Number of reflecting elements on the RIS
"BS_antenna": 32, # Number of Base Station antennas
"num_users": 6, # Number of simultaneous users
"epochs": 250, # Training iterations
"lr_init": 0.0005, # Initial learning rate
...
}
๐ Citation
If you find our paper or this codebase useful in your research, please kindly cite our paper:
@article{b16,
title={Joint spectrum, precoding, and phase shifts design for {RIS}-aided multiuser {MIMO} {TH}z systems},
author={Mehrabian, Ali and Wong, Vincent W. S.},
journal={IEEE Trans. Commun.},
volume={72},
number={8},
pages={5087-5101},
month={Aug.},
year={2024}
}
๐ฌ Contact
For any questions, discussions, or bug reports, please feel free to reach out:
- Ali Mehrabian: alimehrabian619@ece.ubc.ca | alimehrabian619@yahoo.com