diff --git a/mindscience/models/__init__.py b/mindscience/models/__init__.py index 2cc514aa99bf2e676f033151dff32fb1a9228b98..880307d2dbcf753171c712202e15bdbb3e5759d9 100644 --- a/mindscience/models/__init__.py +++ b/mindscience/models/__init__.py @@ -19,13 +19,13 @@ This package contains various neural network models and related components. It includes implementations of popular architectures such as Vision Transformer, Graph Neural Networks, and other domain-specific models. """ -from .GraphCast import * +from .graphcast import * from .layers import * from .neural_operator import * from .transformer import * __all__ = [] -__all__.extend(GraphCast.__all__) +__all__.extend(graphcast.__all__) __all__.extend(layers.__all__) __all__.extend(neural_operator.__all__) __all__.extend(transformer.__all__) diff --git a/mindscience/models/GraphCast/__init__.py b/mindscience/models/graphcast/__init__.py similarity index 100% rename from mindscience/models/GraphCast/__init__.py rename to mindscience/models/graphcast/__init__.py diff --git a/mindscience/models/GraphCast/graphcast.py b/mindscience/models/graphcast/graphcast.py similarity index 96% rename from mindscience/models/GraphCast/graphcast.py rename to mindscience/models/graphcast/graphcast.py index 56acace187627d9db3f5edeaedddbd9e8aac11ae..a4eb9113b4979df17f8350aac05946a21bd31fb2 100644 --- a/mindscience/models/GraphCast/graphcast.py +++ b/mindscience/models/graphcast/graphcast.py @@ -17,9 +17,7 @@ from __future__ import absolute_import import numpy as np -import mindspore as ms -import mindspore.nn as nn -from mindspore import ops, set_seed, Tensor +from mindspore import nn, ops, set_seed, Tensor set_seed(0) np.random.seed(0) @@ -61,7 +59,7 @@ class MLPNet(nn.Cell): out_channels, latent_dims, has_layernorm=True): - super(MLPNet, self).__init__() + super().__init__() cell_list = [nn.Dense(in_channels, latent_dims, has_bias=False, @@ -96,7 +94,7 @@ class Embedder(nn.Cell): eg2m_in_channels, em2g_in_channels, latent_dims): - super(Embedder, self).__init__() + super().__init__() self.v_g_embedder = MLPNet(in_channels=vg_in_channels, out_channels=latent_dims, latent_dims=latent_dims) self.v_m_embedder = MLPNet(in_channels=vm_in_channels, out_channels=latent_dims, latent_dims=latent_dims) self.e_m_embedder = MLPNet(in_channels=em_in_channels, out_channels=latent_dims, latent_dims=latent_dims) @@ -132,7 +130,7 @@ class G2MGnn(nn.Cell): latent_dims, src_idx, dst_idx): - super(G2MGnn, self).__init__() + super().__init__() self.interaction = InteractionLayer(node_in_channels, node_out_channels, edge_in_channels, @@ -165,7 +163,7 @@ class Encoder(nn.Cell): latent_dims, src_idx, dst_idx): - super(Encoder, self).__init__() + super().__init__() self.feature_embedder = Embedder(vg_in_channels, vm_in_channels, em_in_channels, @@ -209,7 +207,7 @@ class InteractionLayer(nn.Cell): src_idx, dst_idx, is_homo): - super(InteractionLayer, self).__init__() + super().__init__() # process node self.node_fn = MLPNet(in_channels=node_in_channels + edge_out_channels, @@ -235,7 +233,7 @@ class InteractionLayer(nn.Cell): dst_feats = ops.gather(dst_node_feats, self.dst_idx, axis=0) updated_edge_feats = self.edge_fn( ops.Concat(-1)((src_feats, dst_feats, edge_feats))) - temp_node = ms.ops.Zeros()((dst_node_feats.shape[0], edge_feats.shape[-1]), updated_edge_feats.dtype) + temp_node = ops.Zeros()((dst_node_feats.shape[0], edge_feats.shape[-1]), updated_edge_feats.dtype) scattered_edge_feats = ops.TensorScatterAdd()( temp_node, self.dst_idx.reshape(-1, 1), updated_edge_feats) updated_dst_feats = self.node_fn( @@ -256,7 +254,7 @@ class Processor(nn.Cell): latent_dims, src_idx, dst_idx): - super(Processor, self).__init__() + super().__init__() self.processing_steps = processing_steps self.cell_list = nn.SequentialCell() for _ in range(self.processing_steps): @@ -287,7 +285,7 @@ class M2GGnn(nn.Cell): latent_dims, src_idx, dst_idx): - super(M2GGnn, self).__init__() + super().__init__() self.interaction = InteractionLayer(node_in_channels, node_out_channels, edge_in_channels, @@ -320,7 +318,7 @@ class Decoder(nn.Cell): latent_dims, src_idx, dst_idx): - super(Decoder, self).__init__() + super().__init__() self.m2g_gnn = M2GGnn(node_in_channels, node_out_channels, diff --git a/mindscience/models/GraphCast/graphcastnet.py b/mindscience/models/graphcast/graphcastnet.py similarity index 98% rename from mindscience/models/GraphCast/graphcastnet.py rename to mindscience/models/graphcast/graphcastnet.py index cc820a43b3df1fbcead0736bf890e1b6d632536f..49328faac70b65ffd75d097ec0bb0ef1d292209e 100644 --- a/mindscience/models/GraphCast/graphcastnet.py +++ b/mindscience/models/graphcast/graphcastnet.py @@ -14,7 +14,9 @@ # ============================================================================ """GraphCastNet base class""" -from mindspore import nn, ops, Tensor +from mindspore import nn +from mindspore import ops +from mindspore import Tensor from .graphcast import Encoder, Processor, Decoder @@ -135,7 +137,7 @@ class GraphCastNet(nn.Cell): per_variable_level_mean, per_variable_level_std, recompute=False): - super(GraphCastNet, self).__init__() + super().__init__() self.vg_out_channels = vg_out_channels self.mesh_node_feats = mesh_node_feats self.mesh_edge_feats = mesh_edge_feats