Skip to content

Bring python binding back to work #16

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

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0d8cb2c
update polyfem
Huangzizhou Jun 30, 2024
fe02e7e
fix set_log_level
Huangzizhou Jun 30, 2024
96420e6
separate classes into separate folders
Huangzizhou Jun 30, 2024
5d713ba
polyfem_command
Huangzizhou Jul 1, 2024
a5de325
command line tool
Huangzizhou Jul 1, 2024
d317a58
shape derivative python interface
Huangzizhou Jul 2, 2024
94b57c5
fix memory issue, support multiple states
Huangzizhou Jul 2, 2024
6433fec
python binding for adjoint form
Huangzizhou Jul 26, 2024
1c0de74
Update README.md
Huangzizhou Jul 26, 2024
6bb996e
Update README.md
Huangzizhou Jul 26, 2024
51f0e8d
initial condition opt
Huangzizhou Jul 27, 2024
946d4bf
Merge branch 'main' of https://github.com/Huangzizhou/polyfem-python
Huangzizhou Jul 27, 2024
84e5221
python binding material opt
Huangzizhou Jul 27, 2024
40e9b2d
python binding for friction coeff
Huangzizhou Jul 27, 2024
670378e
more util functions
Huangzizhou Jul 27, 2024
37cdee6
update polyfem
Huangzizhou Aug 22, 2024
ced1fdd
fix bug in test
Huangzizhou Aug 22, 2024
2fc4990
fix missing option
Huangzizhou Aug 22, 2024
4ec050b
fix import error
Huangzizhou Aug 22, 2024
41179a1
Update README.md
Huangzizhou Aug 22, 2024
9c90b3a
fix double free
Huangzizhou Aug 22, 2024
53e4959
Merge branch 'main' of github.com:Huangzizhou/polyfem-python
Huangzizhou Aug 22, 2024
b0b5490
Update README.md
Huangzizhou Aug 22, 2024
a40b7f3
fix test
Huangzizhou Aug 22, 2024
d205e08
update polyfem
Huangzizhou Sep 15, 2024
fc87731
Merge branch 'main' of https://github.com/Huangzizhou/polyfem-python
Huangzizhou Sep 15, 2024
323b256
fix tests
Huangzizhou Sep 25, 2024
efb6bfa
comment missing files
Huangzizhou Oct 10, 2024
68cb9a7
Update Pybind
Huangzizhou Oct 16, 2024
aa0c9df
python binding fixes
arvigj Dec 7, 2024
e63f747
Merge pull request #2 from arvigj/main
Huangzizhou Apr 1, 2025
efc994f
Update setup.py
arvigj May 10, 2025
c5c25f9
Update setup.py
arvigj May 10, 2025
566f0d2
Merge pull request #3 from arvigj/main
Huangzizhou May 10, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/continuous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ jobs:
- name: Tests
if: matrix.name == 'Linux' || matrix.name == 'MacOS' || (matrix.config == 'Debug' && runner.os == 'Windows')
run: |
python test/test_bending.py
python test/test_basic.py
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################
# Check required CMake version
set(REQUIRED_CMAKE_VERSION "3.14.0")
set(REQUIRED_CMAKE_VERSION "3.25.0")
cmake_minimum_required(VERSION ${REQUIRED_CMAKE_VERSION})

if(INPUT_POLYFEMPY_DATA_ROOT)
Expand All @@ -13,11 +13,18 @@ if(NOT EXISTS ${POLYFEMPY_DATA_ROOT})
endif()

project(polyfempy)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

################################################################################

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/recipes/")

include(polyfem_cpm_cache)

# Color output
include(UseColors)

Expand Down Expand Up @@ -51,11 +58,9 @@ include(polyfem_data)
################################################################################
# Subdirectories
################################################################################
add_library(polyfempy MODULE src/binding.cpp src/raster.cpp)
pybind11_add_module(polyfempy)
add_subdirectory(src)
target_include_directories(polyfempy PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries(polyfempy PRIVATE polyfem::polyfem pybind11::module pybind11::json)

set_target_properties(polyfempy PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" SUFFIX "${PYTHON_MODULE_EXTENSION}")




29 changes: 10 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,21 @@
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/polyfempy/badges/platforms.svg)](https://anaconda.org/conda-forge/polyfempy)
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/polyfempy/badges/installer/conda.svg)](https://conda.anaconda.org/conda-forge)




The python bindings are in alpha. Expect a lot of API changes and possible bugs. Use at your own peril!
The Python bindings are in alpha. Expect a lot of API changes and possible bugs. Use at your own peril!

<br/>
I am making efforts to provide a simple python interface to Polyfem.

For doing so I am maintaining a *conda* package which can be easily installed [https://anaconda.org/conda-forge/polyfempy](https://anaconda.org/conda-forge/polyfempy).

Note that the conda deployment is slow and this tutorial will follow the deployment version.
To use the Python bindings, clone the current repository and use anaconda to install:

If you hare in a hurry for the juicy latest feature you can clone the repository [Polyfem-python](https://github.com/polyfem/polyfem-python) and use `pip` to install:
```
python setup.py install
```
and
```
python setup.py test
```
for testing.
conda create -n diffipc python=3.9
conda activate diffipc
conda install numpy scipy conda-forge::cython pytorch::pytorch

For python documentation [https://polyfem.github.io/python/](https://polyfem.github.io/python/).
# optional
export N_THREADS=16

For python jupyter notebook [https://polyfem.github.io/python_examples/](https://polyfem.github.io/python_examples/).
cd polyfem-python/
pip install . -v
```

For full documentation see [https://polyfem.github.io/](https://polyfem.github.io/).
33 changes: 33 additions & 0 deletions cmake/recipes/CPM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set(CPM_DOWNLOAD_VERSION 0.39.0)

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

function(download_cpm)
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endfunction()

if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
download_cpm()
else()
# resume download if it previously failed
file(READ ${CPM_DOWNLOAD_LOCATION} check)
if("${check}" STREQUAL "")
download_cpm()
endif()
unset(check)
endif()

include(${CPM_DOWNLOAD_LOCATION})
19 changes: 10 additions & 9 deletions cmake/recipes/polyfem.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ endif()

message(STATUS "Third-party: creating target 'polyfem::polyfem'")

include(FetchContent)
FetchContent_Declare(
polyfem
GIT_REPOSITORY https://github.com/polyfem/polyfem.git
GIT_TAG 12ac634833f91a3946cff26db01972fdb2ec3214
GIT_SHALLOW FALSE
)
FetchContent_MakeAvailable(polyfem)

# include(FetchContent)
# FetchContent_Declare(
# polyfem
# GIT_REPOSITORY https://github.com/polyfem/polyfem.git
# GIT_TAG 07ee824f836c445699bbc47ee6f19afbfe39bad4
# GIT_SHALLOW FALSE
# )
# FetchContent_MakeAvailable(polyfem)

include(CPM)
CPMAddPackage("gh:polyfem/polyfem#e8bd3d3")
24 changes: 24 additions & 0 deletions cmake/recipes/polyfem_cpm_cache.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Copyright 2021 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#

if(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_SOURCE_CACHE_DEFAULT $ENV{CPM_SOURCE_CACHE})
else()
# Set CPM cache folder if unset
file(REAL_PATH "~/.cache/CPM" CPM_SOURCE_CACHE_DEFAULT EXPAND_TILDE)
endif()

set(CPM_SOURCE_CACHE
${CPM_SOURCE_CACHE_DEFAULT}
CACHE PATH "Directory to download CPM dependencies"
)
message(STATUS "Using CPM cache folder: ${CPM_SOURCE_CACHE}")
2 changes: 1 addition & 1 deletion cmake/recipes/polyfem_data.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include(FetchContent)
FetchContent_Declare(
polyfem_data
GIT_REPOSITORY https://github.com/polyfem/polyfem-data
GIT_TAG 29a46df1fd90c237a82c219f346a956e72bd17d3
GIT_TAG f2089eb6eaa22071f7490e0f144e10afe85d4eba
GIT_SHALLOW FALSE
SOURCE_DIR ${POLYFEMPY_DATA_ROOT}
)
Expand Down
26 changes: 5 additions & 21 deletions cmake/recipes/pybind11.cmake
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
#
# Copyright 2020 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.
#
# pybind11 (https://github.com/pybind/pybind11)
# License: BSD-style
if(TARGET pybind11::pybind11)
return()
endif()

message(STATUS "Third-party: creating target 'pybind11::pybind11'")

include(FetchContent)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.9.2
GIT_SHALLOW FALSE
)

if (POLICY CMP0094) # https://cmake.org/cmake/help/latest/policy/CMP0094.html
cmake_policy(SET CMP0094 NEW) # FindPython should return the first matching Python
endif ()
Expand All @@ -39,7 +22,8 @@ endif ()
# Pybind11 still uses the deprecated FindPythonInterp. So let's call CMake's
# new FindPython module and set PYTHON_EXECUTABLE for Pybind11 to pick up.
# This works well with conda environments.
find_package(Python REQUIRED COMPONENTS Interpreter Development)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE})

FetchContent_MakeAvailable(pybind11)
include(CPM)
CPMAddPackage("gh:pybind/pybind11@2.13.6")
156 changes: 0 additions & 156 deletions polyfempy/Settings.py

This file was deleted.

Loading
Loading