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

Add algorithm for N-body simulation - retry #4298

Merged
merged 14 commits into from Apr 4, 2021

Conversation

@algobytewise
Copy link
Contributor

@algobytewise algobytewise commented Mar 28, 2021

Describe your change:

New pull request to replace #4245 since the old pull request ran into a branch conflict after updating. The changes to #4245 include better comments and more descriptive names.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

body.update_position(delta_time * self.time_factor)


def plot(

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Mar 28, 2021

As there is no test file in this pull request nor any test function or class in the file other/n_body_simulation.py, please provide doctest for the function plot

This comment has been minimized.

@algobytewise

algobytewise Mar 28, 2021
Author Contributor

No doctest provided since this function does not have a return value, it just plots the result of the algorithm.

)

# Function called once at the start of the animation
def init() -> list[patches.Circle]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Mar 28, 2021

As there is no test file in this pull request nor any test function or class in the file other/n_body_simulation.py, please provide doctest for the function init

This comment has been minimized.

@algobytewise

algobytewise Mar 28, 2021
Author Contributor

No doctest since this is an inner function.

This comment has been minimized.

@cclauss

cclauss Mar 28, 2021
Member

You mean that because it is an inner function it cannot contain bugs?

It needs tests.

This comment has been minimized.

@algobytewise

algobytewise Mar 28, 2021
Author Contributor

I'm not sure that it's possible to write a doctest for an inner function, for example, see https://stackoverflow.com/questions/2136910/can-i-unit-test-an-inner-function-in-python or https://bugs.python.org/issue1650090 . I could define the 2 functions outside the plot-function and add doctests. But that would be a little unintuitive, since they are just part of the plotting and not of the algorithm proper. But my experience with doctest is limited so I'm not sure what the best approach here is.

This comment has been minimized.

@cclauss

cclauss Mar 28, 2021
Member

I do not see the advantage of making this an inner function. Just make it a normal function with proper tests.

This comment has been minimized.

@algobytewise

algobytewise Mar 28, 2021
Author Contributor

I ran into some problems while trying to define init & update outside the scope of plot, since these functions make use of patches, which is defined inside plot. Something like this seems to be the normal procedure for using matplotlib animation, for example, see line in https://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/ .

I don't think that we can pass patches as an argument to these functions since animation.FuncAnimation uses them as callbacks. It might be possible to solve this problem through currying, but that would make it needlessly complicated and may defy the attempt to avoid using inner functions. But maybe there is an easier solution that I'm missing.

This comment has been minimized.

@algobytewise

algobytewise Mar 28, 2021
Author Contributor

Another approach would be to define patches (& possibly other local variables needed) globally and then import them into the functions using the global-keyword. It should work but it's not pretty.

This comment has been minimized.

@cclauss

cclauss Mar 28, 2021
Member

If you want to keep the inner functions then the outer function should be heavily tested. Let's put all calculation in a separate function from the plotting function.

Make the function that plots as small as possible... That is, make one well-tested function that calculates the results and another smaller, untested function that performs no calculations but merely plots the results.

This comment has been minimized.

@algobytewise

algobytewise Mar 29, 2021
Author Contributor

That sounds like a good solution.

return patches

# Function called at each step of the animation
def update(frame: int) -> list[patches.Circle]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Mar 28, 2021

As there is no test file in this pull request nor any test function or class in the file other/n_body_simulation.py, please provide doctest for the function update

This comment has been minimized.

@algobytewise

algobytewise Mar 28, 2021
Author Contributor

No doctest since this is an inner function.

This comment has been minimized.

@cclauss

cclauss Mar 28, 2021
Member

Same.

@@ -0,0 +1,262 @@
"""
In physics and astronomy, a gravitational N-body simulation is a simulation of a

This comment has been minimized.

@cclauss

cclauss Mar 28, 2021
Member

Should we have physics and/or (even better) astronomy directory so that we do not grow the other directory.

This comment has been minimized.

@algobytewise

algobytewise Mar 28, 2021
Author Contributor

If we make it physics, we could also include the files from electronics and remove one root-directory. But in any case, I think physics is the better choice since this is not specifically about celestial objects.

This comment has been minimized.

@cclauss

cclauss Mar 28, 2021
Member

Let's add physics with this algorithm but let's not migrate electronics into it.

plt.show()


if __name__ == "__main__":

This comment has been minimized.

@cclauss

cclauss Mar 28, 2021
Member

Please break this long collection of code into three separate functions.

Suggested change
if __name__ == "__main__":
if __name__ == "__main__":
example_1()
example_2()
example_3()
patches = []
for body in body_system.bodies:
patches.append(
plt.Circle((body.position_x, body.position_y), body.size, fc=body.color)
)
Comment on lines 157 to 161

This comment has been minimized.

@cclauss

cclauss Mar 28, 2021
Member

Let's do this as a list comprehension.

>>> body.velocity_x
1.0
Comment on lines 54 to 55

This comment has been minimized.

@cclauss

cclauss Mar 29, 2021
Member

Please also test body.velocity_y

>>> body = Body(0.,0.,1.,0.)
>>> body.update_position(1.)
>>> body.position_x
1.0

This comment has been minimized.

@cclauss

cclauss Mar 29, 2021
Member

Please also test body.position_y

>>> body_system = BodySystem([Body(0,0,0,0), Body(10,0,0,0)])
>>> body_system.update_system(1)
>>> body_system.bodies[0].position_x

This comment has been minimized.

@cclauss

cclauss Mar 29, 2021
Member

Please test other variables as well.

patches = []
for body in body_system.bodies:
patches.append(
plt.Circle((body.position_x, body.position_y), body.size, fc=body.color)
)
Comment on lines 157 to 161

This comment has been minimized.

@cclauss

cclauss Mar 29, 2021
Member

Suggested change
patches = []
for body in body_system.bodies:
patches.append(
plt.Circle((body.position_x, body.position_y), body.size, fc=body.color)
)
patches = [
plt.Circle((body.position_x, body.position_y), body.size, fc=body.color)
for body in body_system.bodies
]
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

body.update_position(delta_time * self.time_factor)


def plot(

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Mar 29, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function plot

)

# Function called once at the start of the animation
def init() -> list[patches.Circle]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Mar 29, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function init

return patches

# Function called at each step of the animation
def update(frame: int) -> list[patches.Circle]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Mar 29, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function update

Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

physics/n_body_simulation.py Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
@algobytewise algobytewise requested a review from dhruvmanila as a code owner Mar 29, 2021
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

physics/n_body_simulation.py Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

physics/n_body_simulation.py Show resolved Hide resolved
physics/n_body_simulation.py Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
@algobytewise
Copy link
Contributor Author

@algobytewise algobytewise commented Mar 29, 2021

Several additional doctests were added for the methods of Body & BodySystem. I managed to simplify the plot-function by getting rid of the init-function. The update-function now calls the function update_step, which has its own doctests. I also refactored the examples into separate functions.

Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

physics/n_body_simulation.py Show resolved Hide resolved
physics/n_body_simulation.py Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved

class Body:
def __init__(
self: Body,

This comment has been minimized.

@dhruvmanila

dhruvmanila Apr 4, 2021
Member

self should not be given a type hint. It is evaluated using dynamic dispatch during runtime. Please remove it from other places as well.

physics/n_body_simulation.py Outdated Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
physics/n_body_simulation.py Outdated Show resolved Hide resolved
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

self.color = color

@property
def position(self) tuple[float, float]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

An error occured while parsing the file: physics/n_body_simulation.py

Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.8/site-packages/libcst/_parser/base_parser.py", line 152, in _add_token
    plan = stack[-1].dfa.transitions[transition]
KeyError: TokenType(NAME)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/algorithms_keeper/parser/python_parser.py", line 145, in parse
    reports = lint_file(
libcst._exceptions.ParserSyntaxError: Syntax Error @ 47:24.
Incomplete input. Encountered 'tuple', but expected '->', or ':'.

    def position(self) tuple[float, float]:
                       ^
physics/n_body_simulation.py Outdated Show resolved Hide resolved
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

return self.position_x, self.position_y

@property
def velocity(self) tuple[float, float]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

An error occured while parsing the file: physics/n_body_simulation.py

Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.8/site-packages/libcst/_parser/base_parser.py", line 152, in _add_token
    plan = stack[-1].dfa.transitions[transition]
KeyError: TokenType(NAME)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/algorithms_keeper/parser/python_parser.py", line 145, in parse
    reports = lint_file(
libcst._exceptions.ParserSyntaxError: Syntax Error @ 51:24.
Incomplete input. Encountered 'tuple', but expected '->', or ':'.

    def velocity(self) tuple[float, float]:
                       ^
physics/n_body_simulation.py Outdated Show resolved Hide resolved
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

self.color = color

@property
def position(self) -> tuple[float, float]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function position

return self.position_x, self.position_y

@property
def velocity(self) -> tuple[float, float]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function velocity

self.time_factor = time_factor
self.softening_factor = softening_factor

def __len__() -> int:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function __len__

patch.center = (body.position_x, body.position_y)


def plot(

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function plot

ax.add_patch(patch)

# Function called at each step of the animation
def update(frame: int) -> list[plt.Circle]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function update

return BodySystem(bodies1, time_factor=3)


def example_2() -> BodySystem:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function example_2

return BodySystem([earth, moon], gravitation_constant, time_factor=1000000)


def example_3() -> BodySystem:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function example_3

physics/n_body_simulation.py Outdated Show resolved Hide resolved
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

self.color = color

@property
def position(self) -> tuple[float, float]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function position

return self.position_x, self.position_y

@property
def velocity(self) -> tuple[float, float]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function velocity

self.softening_factor = softening_factor

def __len__() -> int:
return len(self.bodies)

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function __len__



def plot(
title: str,

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function plot


# Function called at each step of the animation
def update(frame: int) -> list[plt.Circle]:
update_step(body_system, DELTA_TIME, patches)

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function update



def example_2() -> BodySystem:
"""

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function example_2



def example_3() -> BodySystem:
"""

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function example_3

Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

self.color = color

@property
def position(self) -> tuple[float, float]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function position

return self.position_x, self.position_y

@property
def velocity(self) -> tuple[float, float]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function velocity

self.time_factor = time_factor
self.softening_factor = softening_factor

def __len__(self) -> int:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function __len__

patch.center = (body.position_x, body.position_y)


def plot(

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function plot

ax.add_patch(patch)

# Function called at each step of the animation
def update(frame: int) -> list[plt.Circle]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function update

return BodySystem(bodies1, time_factor=3)


def example_2() -> BodySystem:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function example_2

return BodySystem([earth, moon], gravitation_constant, time_factor=1000000)


def example_3() -> BodySystem:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function example_3

Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

self.color = color

@property
def position(self) -> tuple[float, float]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function position

return self.position_x, self.position_y

@property
def velocity(self) -> tuple[float, float]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function velocity

self.time_factor = time_factor
self.softening_factor = softening_factor

def __len__(self) -> int:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function __len__

patch.center = (body.position_x, body.position_y)


def plot(

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function plot

ax.add_patch(patch)

# Function called at each step of the animation
def update(frame: int) -> list[plt.Circle]:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function update

return BodySystem(bodies1, time_factor=3)


def example_2() -> BodySystem:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function example_2

return BodySystem([earth, moon], gravitation_constant, time_factor=1000000)


def example_3() -> BodySystem:

This comment has been minimized.

@algorithms-keeper

algorithms-keeper bot Apr 4, 2021

As there is no test file in this pull request nor any test function or class in the file physics/n_body_simulation.py, please provide doctest for the function example_3

@cclauss
cclauss approved these changes Apr 4, 2021
Copy link
Member

@cclauss cclauss left a comment

I will create a follow up PR to add tests to examples.

@cclauss cclauss merged commit 536fb4b into TheAlgorithms:master Apr 4, 2021
2 checks passed
2 checks passed
@github-actions
build
Details
@github-actions
pre-commit
Details
@algobytewise
Copy link
Contributor Author

@algobytewise algobytewise commented Apr 4, 2021

Thanks for helping with all the changes. It's definitely more elegantly handled this way.

Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
* add n_body_simulation.py

* updating DIRECTORY.md

* Rename other/n_body_simulation.py to physics/n_body_simulation.py

* updating DIRECTORY.md

* Update build.yml

* refactor examples & add doctests

* removed type-hints from self-parameter

* Apply suggestions from code review

* Update physics/n_body_simulation.py

* Update physics/n_body_simulation.py

* Update physics/n_body_simulation.py

* Don't forget self

* Fix velocity

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants