dacapo.compute_context
Submodules
Classes
Helper class that provides a standard way to create an ABC using |
|
The LocalTorch class is a subclass of the ComputeContext class. |
|
Helper class that provides a standard way to create an ABC using |
Functions
|
Create a compute context based on the global DaCapo options. |
Package Contents
- class dacapo.compute_context.ComputeContext
Helper class that provides a standard way to create an ABC using inheritance.
- distribute_workers: bool | None
The ComputeContext class is an abstract base class for defining the context in which computations are to be done. It is inherited from the built-in class ABC (Abstract Base Classes). Other classes can inherit this class to define their own specific variations of the context. It requires to implement several property methods, and also includes additional methods related to the context design.
- device
The device on which computations are to be done.
- _wrap_command(command)
Wraps a command in the context specific command.
- wrap_command(command)
Wraps a command in the context specific command and returns it.
- execute(command)
Runs a command in the context specific way.
Note
The class is abstract and requires to implement the abstract methods.
- abstract property device
Abstract property method to define the device on which computations are to be done.
A device can be a CPU, GPU, TPU, etc. It is used to specify the context in which computations are to be done.
- Returns:
The device on which computations are to be done.
- Return type:
str
- Raises:
NotImplementedError – If the method is not implemented in the derived class.
Examples
>>> context = ComputeContext() >>> device = context.device
Note
The method should be implemented in the derived class.
- wrap_command(command)
A method to wrap a command in the context specific command and return it.
- Parameters:
command (List[str]) – The command to be wrapped.
- Returns:
The wrapped command.
- Return type:
List[str]
- Raises:
NotImplementedError – If the method is not implemented in the derived class.
Examples
>>> context = ComputeContext() >>> command = ["python", "script.py"] >>> wrapped_command = context.wrap_command(command)
Note
The method should be implemented in the derived class.
- execute(command)
A method to run a command in the context specific way.
- Parameters:
command (List[str]) – The command to be executed.
- Raises:
NotImplementedError – If the method is not implemented in the derived class.
Examples
>>> context = ComputeContext() >>> command = ["python", "script.py"] >>> context.execute(command)
Note
The method should be implemented in the derived class.
- dacapo.compute_context.create_compute_context() ComputeContext
Create a compute context based on the global DaCapo options.
- Returns:
The compute context object.
- Return type:
- Raises:
ValueError – If the store type is unknown.
Examples
>>> context = create_compute_context()
Note
The method is implemented in the module.
- class dacapo.compute_context.LocalTorch
The LocalTorch class is a subclass of the ComputeContext class. It is used to specify the context in which computations are to be done. LocalTorch is used to specify that computations are to be done on the local machine using PyTorch.
- _device
This stores the type of device on which torch computations are to be done. It can
- Type:
Optional[str]
- take "cuda" for GPU or "cpu" for CPU. None value results in automatic detection of device type.
- oom_limit
The out of GPU memory to leave free in GB. If the free memory is below
- Type:
Optional[float | int]
- this limit, we will fall back on CPU.
- device()
Returns the torch device object.
Note
The class is a subclass of the ComputeContext class.
- distribute_workers: bool | None
The ComputeContext class is an abstract base class for defining the context in which computations are to be done. It is inherited from the built-in class ABC (Abstract Base Classes). Other classes can inherit this class to define their own specific variations of the context. It requires to implement several property methods, and also includes additional methods related to the context design.
- device
The device on which computations are to be done.
- _wrap_command(command)
Wraps a command in the context specific command.
- wrap_command(command)
Wraps a command in the context specific command and returns it.
- execute(command)
Runs a command in the context specific way.
Note
The class is abstract and requires to implement the abstract methods.
- property device
- 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".
- Returns:
The torch device object.
- Return type:
torch.device
- class dacapo.compute_context.Bsub
Helper class that provides a standard way to create an ABC using inheritance.
- distribute_workers: bool | None
The Bsub class is a subclass of the ComputeContext class. It is used to specify the context in which computations are to be done. Bsub is used to specify that computations are to be done on a cluster using LSF.
- queue
The queue to run on.
- Type:
str
- num_gpus
The number of gpus to train on. Currently only 1 gpu can be used.
- Type:
int
- num_cpus
The number of cpus to use to generate training data.
- Type:
int
- billing
Project name that will be paying for this Job.
- Type:
Optional[str]
- device()
Returns the device on which computations are to be done.
- _wrap_command(command)
Wraps a command in the context specific command.
Note
The class is a subclass of the ComputeContext class.
- queue: str
- num_gpus: int
- num_cpus: int
- property device
- A property method that returns the device on which computations are to be done.
A device can be a CPU, GPU, TPU, etc. It is used to specify the context in which computations are to be done.
- Returns:
The device on which computations are to be done.
- Return type:
str
Examples
>>> context = Bsub() >>> device = context.device