src/proteingnn/model.py
def gnn_module(in_channels: int, hidden_channels: int, n_layers: int, leakyrelu_slope: float,
               dropout: float = 0., gnn_class: Any = 'GCNConv', gnorm_class: Any = None,
               gnn_args: str = 'x, edge_index -> x', **kwargs):
    """Stremalined GNN submodule.

    Does not support edge convolution.

    Args:
        in_channels: Input channel size.
        hidden_channels: Hidden channel size.
        n_layers: Number of layers.
        leakyrelu_slope: LeakyReLU slope.
        dropout: Dropout at the final layer.
        gnn_class: Conv name in string or class in pytorch_geometric.
        gnorm_class: Normalizaton name in string or class in pytorch_geometric.
        gnn_args: Argument input type for gnn_class in pytorch_geometric.nn.Sequential format.
        kwargs: kwargs for gnn_class.
    """
    assert n_layers >= 1

    if type(gnn_class) == str:
        gnn_class = getattr(gnn, gnn_class)
    elif gnorm_class is None:
        pass
    elif not issubclass(gnn_class, gnn.MessagePassing):
        raise TypeError(f'{gnn_class} is neither str nor MessagePassing subclass.')

    if type(gnorm_class) == str and gnorm_class:
        gnorm_class = getattr(gnn, gnorm_class)
    # elif gnorm_class is None:
    #     pass
    # elif not issubclass(gnorm_class, gnn.MessageNorm):  # BaseClass unavailable
    #     raise TypeError(f'{gnorm_class} is neither str nor MessageNorm subclass.')

    layers = [
        (gnn_class(in_channels, hidden_channels, **kwargs), gnn_args),
        nn.LeakyReLU(leakyrelu_slope)
    ]
    if gnorm_class:  # gnorm_class instantiation argument not supported
        layers.append(
            (gnorm_class(hidden_channels), 'x, batch -> x')
        )

    for _ in range(n_layers-1):
        layers.extend([
            (gnn_class(hidden_channels, hidden_channels, **kwargs), gnn_args),
            nn.LeakyReLU(leakyrelu_slope)
        ])
        if gnorm_class:
            layers.append(
                (gnorm_class(hidden_channels), 'x, batch -> x')
            )

    if dropout:
        layers.append(nn.Dropout(p=dropout))

    model = gnn.Sequential('x, edge_index, batch', layers)
    return model
Stremalined GNN submodule.

    Does not support edge convolution.

    Args:
        in_channels: Input channel size.
        hidden_channels: Hidden channel size.
        n_layers: Number of layers.
        leakyrelu_slope: LeakyReLU slope.
        dropout: Dropout at the final layer.
        gnn_class: Conv name in string or class in pytorch_geometric.
        gnorm_class: Normalizaton name in string or class in pytorch_geometric.
        gnn_args: Argument input type for gnn_class in pytorch_geometric.nn.Sequential format.
        kwargs: kwargs for gnn_class.
    
Stremalined GNN submodule.
Does not support edge convolution.
Stremalined GNN submodule . Does not support edge convolution .
def gnn_module(in_channels: int, hidden_channels: int, n_layers: int, leakyrelu_slope: float,
               dropout: float = 0., gnn_class: Any = 'GCNConv', gnorm_class: Any = None,
               gnn_args: str = 'x, edge_index -> x', **kwargs):
    assert n_layers >= 1
    if type(gnn_class) == str:
        gnn_class = getattr(gnn, gnn_class)
    elif gnorm_class is None:
        pass
    elif not issubclass(gnn_class, gnn.MessagePassing):
        raise TypeError(f'{gnn_class} is neither str nor MessagePassing subclass.')
    if type(gnorm_class) == str and gnorm_class:
        gnorm_class = getattr(gnn, gnorm_class)
    layers = [
        (gnn_class(in_channels, hidden_channels, **kwargs), gnn_args),
        nn.LeakyReLU(leakyrelu_slope)
    ]
    if gnorm_class:  
        layers.append(
            (gnorm_class(hidden_channels), 'x, batch -> x')
        )
    for _ in range(n_layers-1):
        layers.extend([
            (gnn_class(hidden_channels, hidden_channels, **kwargs), gnn_args),
            nn.LeakyReLU(leakyrelu_slope)
        ])
        if gnorm_class:
            layers.append(
                (gnorm_class(hidden_channels), 'x, batch -> x')
            )
    if dropout:
        layers.append(nn.Dropout(p=dropout))
    model = gnn.Sequential('x, edge_index, batch', layers)
    return model
def gnn_module ( in_channels : int , hidden_channels : int , n_layers : int , leakyrelu_slope : float , dropout : float = 0. , gnn_class : Any = 'GCNConv' , gnorm_class : Any = None , gnn_args : str = 'x, edge_index -> x' , ** kwargs ) : assert n_layers >= 1 if type ( gnn_class ) == str : gnn_class = getattr ( gnn , gnn_class ) elif gnorm_class is None : pass elif not issubclass ( gnn_class , gnn . MessagePassing ) : raise TypeError ( f'{gnn_class} is neither str nor MessagePassing subclass.' ) if type ( gnorm_class ) == str and gnorm_class : gnorm_class = getattr ( gnn , gnorm_class ) layers = [ ( gnn_class ( in_channels , hidden_channels , ** kwargs ) , gnn_args ) , nn . LeakyReLU ( leakyrelu_slope ) ] if gnorm_class : layers . append ( ( gnorm_class ( hidden_channels ) , 'x, batch -> x' ) ) for _ in range ( n_layers - 1 ) : layers . extend ( [ ( gnn_class ( hidden_channels , hidden_channels , ** kwargs ) , gnn_args ) , nn . LeakyReLU ( leakyrelu_slope ) ] ) if gnorm_class : layers . append ( ( gnorm_class ( hidden_channels ) , 'x, batch -> x' ) ) if dropout : layers . append ( nn . Dropout ( p = dropout ) ) model = gnn . Sequential ( 'x, edge_index, batch' , layers ) return model
Stremalined GNN submodule.
Stremalined GNN submodule .
"""Stremalined GNN submodule.

    Does not support edge convolution.

    Args:
        in_channels: Input channel size.
        hidden_channels: Hidden channel size.
        n_layers: Number of layers.
        leakyrelu_slope: LeakyReLU slope.
        dropout: Dropout at the final layer.
        gnn_class: Conv name in string or class in pytorch_geometric.
        gnorm_class: Normalizaton name in string or class in pytorch_geometric.
        gnn_args: Argument input type for gnn_class in pytorch_geometric.nn.Sequential format.
        kwargs: kwargs for gnn_class.
    """ # elif gnorm_class is None: #     pass # elif not issubclass(gnorm_class, gnn.MessageNorm):  # BaseClass unavailable #     raise TypeError(f'{gnorm_class} is neither str nor MessageNorm subclass.') # gnorm_class instantiation argument not supported
in_channels
int
Input channel size.
Input channel size .
hidden_channels
int
Hidden channel size.
Hidden channel size .
n_layers
int
Number of layers.
Number of layers .
leakyrelu_slope
float
None
dropout
float
Dropout at the final layer.
Dropout at the final layer .
gnn_class
Any
Conv name in string or class in pytorch_geometric.
Conv name in string or class in pytorch_geometric .
gnorm_class
Any
Normalizaton name in string or class in pytorch_geometric.
Normalizaton name in string or class in pytorch_geometric .
gnn_args
str
Argument input type for gnn_class in pytorch_geometric.nn.Sequential format.
Argument input type for gnn_class in pytorch_geometric . nn . Sequential format .
kwargs
kwargs for gnn_class.
kwargs for gnn_class .