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

♻️ Refactor setup.py for improved build process #435

Closed
wants to merge 3 commits into from

Conversation

munechika-koyo
Copy link
Contributor

  • replace os.path to pathlib.Path
  • formatted by ruff
  • add multiprocessing method "spawn" to intend windows build.

- replace `os.path` to `pathlib.Path`
- formatted by `ruff`
- add multiprocessing method `"spawn"` to intend windows build.
@munechika-koyo
Copy link
Contributor Author

seems like the Python 3.7 test became obsolete for the latest Ubuntu CI runner.

Copy link
Contributor

@jacklovell jacklovell left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. I'll let @CnlPepper give his say on this, but my general impression is that this produces a fair bit of code churn without significant practical benefits. Unless there is a genuine problem that needs to be solved with setup.py it's hard to see why it needs so many changes. But that may just be me.

Also, please don't use emojis in commit messages. They don't render properly in the git pager in most terminals. Keep to plain text.


multiprocessing.set_start_method('fork')

if os.name == "nt":
Copy link
Contributor

Choose a reason for hiding this comment

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

Raysect 0.8.x does not support Windows. The multiprocessing paradigm it uses relies on the Linux kernel's copy-on-write when forking processes, and this is not something Windows supports. The fix is to use a new parallel render engine which doesn't require fork's COW semantics, and this is not a small project. Adjusting setup.py to support building on Windows may give Windows users the false impression that they should expect Raysect to work well on this platform.

Copy link
Contributor Author

@munechika-koyo munechika-koyo Oct 16, 2024

Choose a reason for hiding this comment

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

Thank you for your review!
Is the incompatibility for Windows tied to all multiprocessing methods? If so, can I also fix this issue by modifying the workflow.py module?
(I guess things are not so simple...)

Copy link
Contributor

@vsnever vsnever Oct 17, 2024

Choose a reason for hiding this comment

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

Changing "fork" to "spawn" in MulticoreEngine will cause local copies of the entire scene graph, including all its data, to be created in child processes. Meshes used in Raysect/Cherab scenes can take up several gigabytes. With dozens of parallel processes, this can lead to out of memory problem, not to mention possible performance issues. The scene graph must be shared between all the processes instead of copying. This is currently achieved using the POSIX fork() Copy-on-Write semantics. I don't know of any other way to do this in pure Python. I think the best way to use Raysect on Windows is via WSL2.

Copy link
Contributor

@vsnever vsnever Oct 17, 2024

Choose a reason for hiding this comment

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

Python 3.13 added an experimental free-threading build. In the future, multithreading may replace multiprocessing in Raysect's MulticoreEngine.

Copy link
Member

Choose a reason for hiding this comment

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

If Matt and I ever get time to return to Raysect development (its not impossible, just impractical for now) I'll like to experiment with the new threading model.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vsnever, thank you for your comment! "fork" seems to use a shared memory scheme, doesn't it?
The GIL-free threading is very attractive and could be an option in the future.

@CnlPepper Thank you for commenting! I can't wait for you to come back as a developer😢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the "spawn" setting in the if case to raise OSError to throw an error if the OS is Windows.

setup.py Outdated
],
install_requires=['numpy', 'matplotlib'],
install_requires=["numpy", "matplotlib"],
Copy link
Contributor

Choose a reason for hiding this comment

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

In pyproject.toml we use oldest-supported-numpy. The project is thus built against numpy 1.x for all versions of Python where that is supported, and means in turn that numpy<2 is required at runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we should keep numpy<2.0 in runtime.
However, when I specify numpy > 2.0 in build time, raysect's unit tests seem to be succeeded according to the conda building process.
Needless to say, the unit test does not seem to cover all raysect's functionalities.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, some demo scripts were successfully executed even in numpy==2.1.2.

@munechika-koyo
Copy link
Contributor Author

munechika-koyo commented Oct 16, 2024

Sorry for the abuse of emojis in any commit.

As @jacklovell mentioned, this PR is not a mandatory change, but it will make codes readable by

  • using pathlib module to reduce for nested codes
  • using " not ' for strings

@CnlPepper
Copy link
Member

Thanks for the PR, however as Jack said I neither see the necessity nor do we support windows for reasons already identified.

@CnlPepper CnlPepper closed this Oct 17, 2024
@CnlPepper CnlPepper reopened this Oct 17, 2024
@CnlPepper
Copy link
Member

Sorry hit the wrong button.

@CnlPepper
Copy link
Member

What is the issue you are trying to solve?

@munechika-koyo
Copy link
Contributor Author

@CnlPepper I am trying to use pathlib module to specify the path to .pyx or .c files in order to intend to make codes modern and to remove specific path notation.

@CnlPepper
Copy link
Member

CnlPepper commented Oct 21, 2024

Why would you change known working code? The current pathing is not deprecated and it is already proven to function. Pythons packaging systems are fickle and difficult to debug across the range of tooling people use to install packages.

Wanting to "modernize* the code ia not a sufficient justification to change the code. i'm sorry, but I'm not merging this. All I'll be doing is creating a potential maintenace headache for myself.

@CnlPepper CnlPepper closed this Oct 21, 2024
@munechika-koyo
Copy link
Contributor Author

I agree that the Python packaging process is drastically changing, even though it was born decades ago.
Sorry for meddling too much. I will support your decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants