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

Revert "Docstrings" #137

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ To run tests with coverage locally:
`pytest tests --color=yes --cov --cov-report=term-missing`
This will also be run automatically when a PR is made to master and a codecov report will be generated telling you if your PR increased or decreased coverage.

## Doc Generation
Docstrings are generated using github action. but you can generate them using
`sphinx-build -M html docs/source/ docs/Cbuild/`

## Branching and PRs
- Users that have been added to the CellMap organization and the DaCapo project should be able to develop directly into the CellMap fork of DaCapo. Other users will need to create a fork.
Expand Down
18 changes: 0 additions & 18 deletions dacapo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
"""
dacapo module
==============

This module contains several useful methods for performing common tasks in dacapo library.

Modules:
-----------
Options - Deals with configuring aspects of the program's operations.
experiments - This module is responsible for conducting experiments.
apply - Applies the results of the training process to the given dataset.
train - Trains the model using given data set.
validate - This module is for validating the model.
predict - This module is used to generate predictions based on the model.

"""

from .options import Options # noqa
from . import experiments # noqa
from .apply import apply # noqa
from .train import train # noqa
from .validate import validate # noqa
from .predict import predict # noqa

22 changes: 2 additions & 20 deletions dacapo/compute_context/local_torch.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
"""
This module provides the LocalTorch class which is used to determine and set the local torch device (CPU or GPU) for
computation. This information can be particularly useful for deep learning computations where use of GPU can
significantly speed up computations.

"""
from .compute_context import ComputeContext

import torch
import attr

from typing import Optional


@attr.s
class LocalTorch(ComputeContext):
"""
The LocalTorch class is a subclass of the ComputeContext class. It is decorated with the attrs library, which
provides a convenient way of structuring data. It focuses on determining the type of device on which torch
computations will be done. It defaults to GPU (if available) over CPU.

Attributes:
_device (Optional[str]): This stores the type of device on which torch computations are to be done. It can
take "cuda" for GPU or "cpu" for CPU. None value results in automatic detection of device type.
"""

_device: Optional[str] = attr.ib(
default=None,
metadata={
Expand All @@ -32,10 +18,6 @@ class LocalTorch(ComputeContext):

@property
def device(self):
"""
A property method that returns the torch device object. It automatically detects and uses "cuda" (GPU) if
available, else it falls back on using "cpu".
"""
if self._device is None:
if torch.cuda.is_available():
return torch.device("cuda")
Expand Down
43 changes: 0 additions & 43 deletions dacapo/experiments/__init__.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,7 @@
"""
This module imports the components of the funkelab dacapo python library which are required
to build models and run configurations. It also includes functionalities to perform training,
validation and retrieving statistics or scores from these processes.

This includes:

- Definition and structure of the Model.
- Configuration and execution of a Run.
- Settings and preferences for a Run through RunConfig.
- Extraction of statistics from each iteration in a training through TrainingIterationStats.
- Overall statistics from a full training session through TrainingStats.
- Scores from each iteration in validation through ValidationIterationScores.
- Overall scores from a full validation session through ValidationScores.
"""

from .model import Model # noqa
"""
Defining the structure and methods for Model in the library
"""

from .run import Run # noqa
"""
Defining the structure and methods for Run in the library. This includes setting up a run, execution and returning results.
"""

from .run_config import RunConfig # noqa
"""
Defining the settings and configurations available for use during a run.
"""

from .training_iteration_stats import TrainingIterationStats # noqa
"""
Provides functionalities to extract and present statistics from each training iteration during a run.
"""

from .training_stats import TrainingStats # noqa
"""
Provides functionalities to extract and present overall training statistics from a complete run.
"""

from .validation_iteration_scores import ValidationIterationScores # noqa
"""
Provides functionalities to extract and present scores from each validation iteration during a run.
"""

from .validation_scores import ValidationScores # noqa
"""
Provides functionalities to extract and present overall validation scores from a complete run.
"""
51 changes: 6 additions & 45 deletions dacapo/experiments/architectures/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,35 @@


class Architecture(torch.nn.Module, ABC):
"""
An abstract base class for defining the architecture of a neural network model.
It is inherited from PyTorch's Module and built-in class `ABC` (Abstract Base Classes).
Other classes can inherit this class to define their own specific variations of architecture.
It requires to implement several property methods, and also includes additional methods related to the architecture design.
"""
@property
@abstractmethod
def input_shape(self) -> Coordinate:
"""
Abstract method to define the spatial input shape for the neural network architecture.
The shape should not account for the channels and batch dimensions.

Returns:
Coordinate: The spatial input shape.
"""
"""The spatial input shape (i.e., not accounting for channels and batch
dimensions) of this architecture."""
pass

@property
def eval_shape_increase(self) -> Coordinate:
"""
Provides information about how much to increase the input shape during prediction.

Returns:
Coordinate: An instance representing the amount to increase in each dimension of the input shape.
How much to increase the input shape during prediction.
"""
return Coordinate((0,) * self.input_shape.dims)

@property
@abstractmethod
def num_in_channels(self) -> int:
"""
Abstract method to return number of input channels required by the architecture.

Returns:
int: Required number of input channels.
"""
"""Return the number of input channels this architecture expects."""
pass

@property
@abstractmethod
def num_out_channels(self) -> int:
"""
Abstract method to return the number of output channels provided by the architecture.

Returns:
int: Number of output channels.
"""
"""Return the number of output channels of this architecture."""
pass

@property
def dims(self) -> int:
"""
Returns the number of dimensions of the input shape.

Returns:
int: The number of dimensions.
"""
return self.input_shape.dims

def scale(self, input_voxel_size: Coordinate) -> Coordinate:
"""
Method to scale the input voxel size as required by the architecture.

Args:
input_voxel_size (Coordinate): The original size of the input voxel.

Returns:
Coordinate: The scaled voxel size.
"""
return input_voxel_size
return input_voxel_size
27 changes: 6 additions & 21 deletions dacapo/experiments/architectures/architecture_config.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import attr

from typing import Tuple


@attr.s
class ArchitectureConfig:
"""Base class for architecture configurations. Each subclass of an
`Architecture` should have a corresponding config class derived from
`ArchitectureConfig`.
"""
A class to represent the base configurations of any architecture.

Attributes
----------
name : str
a unique name for the architecture.

Methods
-------
verify()
validates the given architecture.

"""
name: str = attr.ib(
metadata={
"help_text": "A unique name for this architecture. This will be saved so "
Expand All @@ -28,13 +20,6 @@ class ArchitectureConfig:

def verify(self) -> Tuple[bool, str]:
"""
A method to validate an architecture configuration.

Returns
-------
bool
A flag indicating whether the config is valid or not.
str
A description of the architecture.
Check whether this is a valid architecture
"""
return True, "No validation for this Architecture"
return True, "No validation for this Architecture"
55 changes: 3 additions & 52 deletions dacapo/experiments/architectures/dummy_architecture.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
"""
This module implements dummy architecture layer for a 3D convolutional neural network.

Classes:
DummyArchitecture(Architecture)
"""

from .architecture import Architecture

from funlib.geometry import Coordinate

import torch


class DummyArchitecture(Architecture):
"""
A class used to represent a dummy architecture layer for a 3D CNN.

Attributes:
channels_in: An integer representing the number of input channels.
channels_out: An integer representing the number of output channels.
conv: A 3D convolution object.
input_shape: A coordinate object representing the shape of the input.

Methods:
forward(x): Performs the forward pass of the network.
"""

def __init__(self, architecture_config):
"""
Args:
architecture_config: An object containing the configuration settings for the architecture.
"""
super().__init__()

self.channels_in = architecture_config.num_in_channels
Expand All @@ -38,42 +16,15 @@ def __init__(self, architecture_config):

@property
def input_shape(self):
"""
Returns the input shape for this architecture.

Returns:
Coordinate: Input shape of the architecture.
"""
return Coordinate(40, 20, 20)

@property
def num_in_channels(self):
"""
Returns the number of input channels for this architecture.

Returns:
int: Number of input channels.
"""
return self.channels_in

@property
def num_out_channels(self):
"""
Returns the number of output channels for this architecture.

Returns:
int: Number of output channels.
"""
return self.channels_out

def forward(self, x):
"""
Perform the forward pass of the network.

Args:
x: Input tensor.

Returns:
Tensor: Output tensor after the forward pass.
"""
return self.conv(x)
return self.conv(x)
26 changes: 3 additions & 23 deletions dacapo/experiments/architectures/dummy_architecture_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,8 @@

@attr.s
class DummyArchitectureConfig(ArchitectureConfig):
"""A dummy architecture configuration class used for testing purposes.

It extends the base class "ArchitectureConfig". This class contains dummy attributes and always
returns that the configuration is invalid when verified.

Attributes:
architecture_type (:obj:`DummyArchitecture`): A class attribute assigning
the DummyArchitecture class to this configuration.
num_in_channels (int): The number of input channels. This is a dummy attribute and has no real
functionality or meaning.
num_out_channels (int): The number of output channels. This is also a dummy attribute and
has no real functionality or meaning.
"""
"""This is just a dummy architecture config used for testing. None of the
attributes have any particular meaning."""

architecture_type = DummyArchitecture

Expand All @@ -29,13 +18,4 @@ class DummyArchitectureConfig(ArchitectureConfig):
num_out_channels: int = attr.ib(metadata={"help_text": "Dummy attribute."})

def verify(self) -> Tuple[bool, str]:
"""Verifies the configuration validity.

Since this is a dummy configuration for testing purposes, this method always returns False
indicating that the configuration is invalid.

Returns:
tuple: A tuple containing a boolean validity flag and a reason message string.
"""

return False, "This is a DummyArchitectureConfig and is never valid"
return False, "This is a DummyArchitectureConfig and is never valid"
9 changes: 1 addition & 8 deletions dacapo/experiments/arraytypes/arraytype.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,4 @@ class ArrayType(ABC):
@property
@abstractmethod
def interpolatable(self) -> bool:
"""
This is an abstract method which should be overridden in each of the subclasses
to determine if an array is interpolatable or not.

Returns:
bool: True if the array is interpolatable, False otherwise.
"""
pass
pass
Loading
Loading