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

Improved documentation layout for algorithm class #1809

Merged
merged 10 commits into from
Aug 23, 2024

Conversation

MargaretDuff
Copy link
Member

@MargaretDuff MargaretDuff commented May 16, 2024

Description

Closes #1793

Looks better

Help on class Algorithm in module cil.optimisation.algorithms.Algorithm:

class Algorithm(builtins.object)
 |  Algorithm(update_objective_interval=1, max_iteration=None, log_file=None)
 |  
 |  Base class for iterative algorithms that provides the minimal infrastructure.
 |  
 |  Algorithms are iterables so can be easily run in a for loop. They will stop as soon as the stop criterion is met.
 |  The user is required to implement the :code:`set_up`, :code:`__init__`, :code:`update` and :code:`update_objective` methods.
 |  
 |  The method :code:`run` is available to run :code:`n` iterations. The method accepts a :code:`callbacks` list of callables, each of which receive the current Algorithm object (
which in turn contains the iteration number and the actual objective value) and can be used to trigger print to screens and other user interactions. The :code:`run` method will st
op when the stopping criterion is met or `StopIteration` is raised.
 |  
 |  Parameters
 |  ----------
 |  update_objective_interval: int, optional, default 1
 |      the interval every which we would save the current objective. 1 means every iteration, 2 every 2 iteration and so forth. This is by default 1 and should be increased when 
evaluating the objective is computationally expensive.
 |  
 |  Methods defined here:
 |  
 |  __init__(self, update_objective_interval=1, max_iteration=None, log_file=None)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  
 |  __iter__(self)
 |      Algorithm is an iterable
 |  
 |  __next__(self)
 |      Algorithm is an iterable
 |      
 |      This method triggers :code:`update()` and :code:`update_objective()`
 |  
 |  get_last_loss(self, return_all=False)
 |      Returns the last stored value of the loss function. If `update_objective_interval` is 1 it is the value of the objective at the current iteration. If update_objective_inte
rval > 1 it is the last stored value.
 |      Returns
 |      -------
 |      Float
 |          Last stored value of the loss function
 |  
 |  get_last_objective = get_last_loss(self, return_all=False)
 |  
 |  get_output(self)
 |      Returns the current solution.
 |  
 |  is_provably_convergent(self)
 |      Check if the algorithm is convergent based on the provable convergence criterion.
 |      
 |      Returns
 |      -------
 |      Boolean
 |          Outcome of the convergence check
|  
 |  max_iteration_stop_criterion(self)
 |      Do not use: this is being deprecated
 |  
 |  objective_to_dict(self, verbose=False)
 |      Internal function to save and print objective functions
 |  
 |  objective_to_string(self, verbose=False)
 |      Do not use: this is being deprecated
 |  
 |  run(self, iterations=None, callbacks: Optional[List[cil.optimisation.utilities.callbacks.Callback]] = None, verbose=1, **kwargs)
 |      run upto :code:`iterations` with callbacks/logging.
 |      
 |      For a demonstration of callbacks see https://github.com/TomographicImaging/CIL-Demos/blob/main/misc/callback_demonstration.ipynb
 |      
 |      Parameters
 |      -----------
 |      iterations: int, default is None
 |          Number of iterations to run. If not set the algorithm will run until :code:`should_stop()` is reached
 |      callbacks: list of callables, default is Defaults to :code:`[ProgressCallback(verbose)]`
 |          List of callables which are passed the current Algorithm object each iteration. Defaults to :code:`[ProgressCallback(verbose)]`.
 |      verbose: 0=quiet, 1=info, 2=debug
 |          Passed to the default callback to determine the verbosity of the printed output.
 |  
 |  set_up(self, *args, **kwargs)
 |      Set up the algorithm
 |  
 |  should_stop(self)
 |      default stopping criterion: number of iterations
 |      
 |      The user can change this in concrete implementation of iterative algorithms.
 |  
 |  update(self)
 |      A single iteration of the algorithm
 |  
 |  update_objective(self)
 |      calculates the objective with the current solution
 |  
 |  verbose_header(self, *_, **__)
 |      Do not use: this is being deprecated
 |  
 |  verbose_output(self, *_, **__)
 |      Do not use: this is being deprecated
 |  
 |  ----------------------------------------------------------------------
 |  Readonly properties defined here:
 |  
 |  iterations
 |      returns the iterations at which the objective has been evaluated
 |  
 |  loss
 |      returns the list of the values of the objective during the iteration
     
 |      The length of this list may be shorter than the number of iterations run when the update_objective_interval > 1
 |  
 |  objective
 |      returns the list of the values of the objective during the iteration
 |      
 |      The length of this list may be shorter than the number of iterations run when the update_objective_interval > 1
 |  
 |  solution
 |      Returns the current solution.
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)
 |  
 |  max_iteration
 |      gets the maximum number of iterations
 |  
 |  update_objective_interval
 |      gets the update_objective_interval

Checklist

  • I have performed a self-review of my code
  • I have added docstrings in line with the guidance in the developer guide
  • I have updated the relevant documentation
    - [ ] I have implemented unit tests that cover any new or modified functionality
  • CHANGELOG.md has been updated with any functionality change
  • Request review from all relevant developers
  • Change pull request label to 'Waiting for review'

Contribution Notes

Please read and adhere to the developer guide and local patterns and conventions.

  • The content of this Pull Request (the Contribution) is intentionally submitted for inclusion in CIL (the Work) under the terms and conditions of the Apache-2.0 License
  • I confirm that the contribution does not violate any intellectual property rights of third parties

@MargaretDuff
Copy link
Member Author

image
image
image
image
image

Copy link
Contributor

@jakobsj jakobsj left a comment

Choose a reason for hiding this comment

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

Very nice improvements to layout and contents of algorithm documentation. I added a few further suggestions.

Wrappers/Python/cil/optimisation/algorithms/Algorithm.py Outdated Show resolved Hide resolved
Wrappers/Python/cil/optimisation/algorithms/Algorithm.py Outdated Show resolved Hide resolved
Wrappers/Python/cil/optimisation/algorithms/Algorithm.py Outdated Show resolved Hide resolved
Wrappers/Python/cil/optimisation/algorithms/Algorithm.py Outdated Show resolved Hide resolved
Wrappers/Python/cil/optimisation/algorithms/Algorithm.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jakobsj jakobsj left a comment

Choose a reason for hiding this comment

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

Thank you, the description reads well!

Copy link
Member

@lauramurgatroyd lauramurgatroyd left a comment

Choose a reason for hiding this comment

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

Looks great, just added some minor comments

Wrappers/Python/cil/optimisation/algorithms/Algorithm.py Outdated Show resolved Hide resolved
Wrappers/Python/cil/optimisation/algorithms/Algorithm.py Outdated Show resolved Hide resolved
Wrappers/Python/cil/optimisation/algorithms/Algorithm.py Outdated Show resolved Hide resolved
Wrappers/Python/cil/optimisation/algorithms/Algorithm.py Outdated Show resolved Hide resolved
@lauramurgatroyd
Copy link
Member

Looks great, thanks!

Signed-off-by: Margaret Duff <43645617+MargaretDuff@users.noreply.github.com>
Signed-off-by: Margaret Duff <43645617+MargaretDuff@users.noreply.github.com>
@MargaretDuff
Copy link
Member Author

Jenkins is happy
image

@MargaretDuff MargaretDuff enabled auto-merge (squash) August 23, 2024 07:58
@MargaretDuff MargaretDuff merged commit 75f439c into TomographicImaging:master Aug 23, 2024
7 checks passed
@MargaretDuff MargaretDuff deleted the algorithm_docs branch August 23, 2024 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: PRs to review
Development

Successfully merging this pull request may close these issues.

docstring ugly formatting for Algorithm
3 participants