Skip to content
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

钙钛矿太阳能电池人工神经网络ppsci实现 #1055

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

ZhangPassion
Copy link

@ZhangPassion ZhangPassion commented Dec 30, 2024

PR types

New features

PR changes

  1. Add perovskite solar cells neural network model (psc_nn.py)
  2. Add configuration file for the model (psc_nn.yaml)
  3. Implement hyperparameter optimization using Optuna
  4. Add evaluation and visualization functionality

Describe

This PR implements a neural network model for predicting the short-circuit current density (Jsc) of perovskite solar cells. Key features include:

  1. Model Architecture:

    • Multi-layer perceptron (MLP) with configurable layers and units
    • Hyperparameter optimization using Optuna
    • Support for multiple optimizers (Adam, RMSProp, SGD)
  2. Training Features:

    • Weighted MSE loss function
    • Learning rate scheduling with warmup
    • Evaluation during training
    • Model checkpointing
  3. Evaluation:

    • Multiple metrics (RMSE, R2, MAPE)
    • Results visualization
    • Model validation
  4. Configuration:

    • YAML-based configuration
    • Flexible hyperparameter settings
    • Separate train/eval modes

@CLAassistant
Copy link

CLAassistant commented Dec 30, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@HydrogenSulfate HydrogenSulfate left a comment

Choose a reason for hiding this comment

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

感谢提交PR,有几点PR相关的问题:

  1. 请使用pre-commit对代码进行格式化
    image
  2. 除了mkdocs之外,请同步更新README.md和index.md内的案例列表

Copy link
Collaborator

@HydrogenSulfate HydrogenSulfate left a comment

Choose a reason for hiding this comment

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

ML_Pipeline文件夹名字建议改一下,如perovskite_solar_cells

Copy link
Collaborator

Choose a reason for hiding this comment

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

该文件已经上传,请将所有相关的路径替换为以下url:
https://paddle-org.bj.bcebos.com/paddlescience/models/PerovskiteSolarCells/solar_cell_pretrained.pdparams

Copy link
Collaborator

Choose a reason for hiding this comment

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

文件名建议改为相关明确的,nn_optuna_ppsci看不出来是什么案例的配置文件

)

def create_validator(input_dict, batch_size, name="validator"):
"""创建评估器"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

注释建议改为英文

Copy link
Collaborator

Choose a reason for hiding this comment

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

文件名建议改为案例相关的名字,比如perovskite_solar_cells之类的

Copy link
Collaborator

Choose a reason for hiding this comment

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

文件名使用小写,并且改成有意义的名字,如overview、pipeline

Copy link
Collaborator

Choose a reason for hiding this comment

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

同样的文件名问题

Comment on lines 69 to 73
"sampler": {
"name": "BatchSampler",
"drop_last": False,
"shuffle": False,
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

69-73这个sampler字段在drop_last和shuffle都是false情况下,可以删掉

Comment on lines 1 to 4
mode: "train"
seed: 42
output_dir: "./output"

Copy link
Collaborator

Choose a reason for hiding this comment

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

文件开头建议加上如下的配置:

defaults:
- ppsci_default
- TRAIN: train_default
- TRAIN/ema: ema_default
- TRAIN/swa: swa_default
- EVAL: eval_default
- INFER: infer_default
- hydra/job/config/override_dirname/exclude_keys: exclude_keys_default
- _self_
hydra:
run:
# dynamic output directory according to running time and override name
dir: outputs_allen_cahn_piratenet/${now:%Y-%m-%d}/${now:%H-%M-%S}/${hydra.job.override_dirname}
job:
name: ${mode} # name of logfile
chdir: false # keep current working directory unchanged
callbacks:
init_callback:
_target_: ppsci.utils.callbacks.InitCallback
sweep:
# output directory for multirun
dir: ${hydra.run.dir}
subdir: ./

eval:
batch_size: 64
eval_with_no_grad: true
pretrained_model_path: null # 预训练模型路径,可以是本地路径或URL
Copy link
Collaborator

Choose a reason for hiding this comment

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

注释建议改为英文

Comment on lines 122 to 128
print("Starting training...")
ppsci.utils.misc.set_random_seed(cfg.seed)
logger.init_logger("ppsci", osp.join(cfg.output_dir, f"{cfg.mode}.log"), "info")

if not os.path.exists(cfg.output_dir):
os.makedirs(cfg.output_dir)

Copy link
Collaborator

Choose a reason for hiding this comment

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

这里可以删除,配置文件中添加了callback字段后,会自动创建output_dir

Comment on lines 170 to 174
eval_during_train=True,
eval_freq=5,
save_freq=10,
eval_with_no_grad=True,
log_freq=50,
Copy link
Collaborator

Choose a reason for hiding this comment

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

这些字段建议移动到yaml中,由yaml控制

Comment on lines 218 to 221
eval_freq=5,
save_freq=10,
eval_with_no_grad=cfg.eval.eval_with_no_grad,
log_freq=50,
Copy link
Collaborator

Choose a reason for hiding this comment

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

同上

Comment on lines 243 to 246
print("Starting evaluation...")
ppsci.utils.misc.set_random_seed(cfg.seed)
logger.init_logger("ppsci", osp.join(cfg.output_dir, f"{cfg.mode}.log"), "info")

Copy link
Collaborator

Choose a reason for hiding this comment

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

同上,可删除

@HydrogenSulfate
Copy link
Collaborator

HydrogenSulfate commented Jan 2, 2025

@ZhangPassion pre-commit运行时需要指定--files为你的修改文件examples/perovskite_solar_cells,否则jointContribution文件夹下也会受到影响,可以通过git checkout develop jointContribution还原这个文件夹的改动。

image

@HydrogenSulfate
Copy link
Collaborator

@ZhangPassion 完善一下PR描述,
image


mode: "train"
seed: 42
output_dir: "./output"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
output_dir: "./output"
output_dir: ${hydra:run.dir}

Comment on lines +52 to +53
warmup_epoch: 2
warmup_start_lr: 1.0e-6
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
warmup_epoch: 2
warmup_start_lr: 1.0e-6
warmup_epoch: 2
warmup_start_lr: 1.0e-6

Comment on lines 90 to 93
gamma=0.95,
decay_steps=5,
warmup_epoch=2,
warmup_start_lr=1.0e-6,
Copy link
Collaborator

Choose a reason for hiding this comment

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

这里请使用cfg的配置

Copy link

paddle-bot bot commented Jan 6, 2025

Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants