初始化#

在运行的最开始,需要进行初始化工作,其中包括依赖包的导入和参数的初始化。

模块导入#

首先需要进行所需要使用的模块与IFTS包的导入,这样可以在代码中成功调用这些模块内的函数来完成运行。

import torch
import numpy as np
import yaml
import IFTS
from sys import path
from IFTS.fiber_simulation.utils.show_progress import progress_info
from IFTS.simulation_main.modul_main import sig_main, tx_main, rx_main, channel_main
from IFTS.simulation_main.modul_para import simulation_para, signal_para, txsignal_para, channel_para, rxsignal_para, sigplot_para

参数初始化#

下一步需要进行参数的初始化,即从上一节完成的参数配置文件中读入仿真参数并初始化各模块。完成参数初始化过程后会提示初始化完成信息。

提醒

此处设置的路径config_path应修改为上一节用户构建完成的配置文件的路径。

seed = 20 # 随机数种子
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

if seed != -1:
    torch.manual_seed(seed)
config_path = '/home/usr/IFTS/simulation_main/config/paras.yml'
with open(config_path) as f:
    configs = yaml.safe_load(f.read())

## 选用 NN 信道时,需进行NN信道配置参数读入
if configs['Ch_Para']['fiber_config']['mode'] =='NN' and configs['Simu_Para']['channel_type'] == 1:
    nn_config_path='/home/usr/IFTS/simulation_main/config/' + 'paras_'+configs['Ch_Para']['fiber_config']['nn_model']+'.yml'
    with open(nn_config_path) as f2:
        nn_configs = yaml.safe_load(f2.read())
    for key in nn_configs.keys():
        configs[key].update(nn_configs[key])

print('---------------- Parameters initializing... ----------------')
simu_para = simulation_para.Simu_Para(seed, configs)
print(' sig_para initializing...')
sig_para = signal_para.Sig_Para(seed, configs)
print(' tx_para initializing...')
tx_para = txsignal_para.Tx_Para(seed, configs)
print(' rx_para initializing...')
rx_para = rxsignal_para.Rx_para(seed, configs)
print(' ch_para initializing...')
ch_para = channel_para.Ch_Para(seed, configs)
print(' plot_para initializing...')
plot_para = sigplot_para.Plot_Para(seed, configs)
print('---------------- Parameters initialized! -------------------')

---------------- Parameters initializing... ----------------
sig_para initializing...
tx_para initializing...
rx_para initializing...
    rx_para LPF: brickwall filter and bandwidth 28.00 GHz
ch_para initializing...
    channel_para: you are using a simulation fiber channel
    ch_para: SSFM is used
plot_para initializing...
---------------- Parameters initialized! -------------------