diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ec175b40..cb31c169d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,8 @@ -# This file is autogenerated by maturin v1.7.4 +# This file is autogenerated by maturin v1.7.8 # To update, run # # maturin generate-ci github # - name: CI on: @@ -25,17 +24,17 @@ jobs: strategy: matrix: platform: - - runner: ubuntu-latest + - runner: ubuntu-22.04 target: x86_64 - - runner: ubuntu-latest + - runner: ubuntu-22.04 target: x86 - - runner: ubuntu-latest + - runner: ubuntu-22.04 target: aarch64 - - runner: ubuntu-latest + - runner: ubuntu-22.04 target: armv7 - - runner: ubuntu-latest + - runner: ubuntu-22.04 target: s390x - - runner: ubuntu-latest + - runner: ubuntu-22.04 target: ppc64le steps: - uses: actions/checkout@v4 @@ -45,7 +44,6 @@ jobs: - name: Build wheels uses: PyO3/maturin-action@v1 with: - maturin-version: "1.7.4" target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter sccache: 'true' @@ -61,13 +59,13 @@ jobs: strategy: matrix: platform: - - runner: ubuntu-latest + - runner: ubuntu-22.04 target: x86_64 - - runner: ubuntu-latest + - runner: ubuntu-22.04 target: x86 - - runner: ubuntu-latest + - runner: ubuntu-22.04 target: aarch64 - - runner: ubuntu-latest + - runner: ubuntu-22.04 target: armv7 steps: - uses: actions/checkout@v4 @@ -77,7 +75,6 @@ jobs: - name: Build wheels uses: PyO3/maturin-action@v1 with: - maturin-version: "1.7.4" target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter sccache: 'true' @@ -106,7 +103,6 @@ jobs: - name: Build wheels uses: PyO3/maturin-action@v1 with: - maturin-version: "1.7.4" target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter sccache: 'true' @@ -121,7 +117,7 @@ jobs: strategy: matrix: platform: - - runner: macos-12 + - runner: macos-13 target: x86_64 - runner: macos-14 target: aarch64 @@ -133,7 +129,6 @@ jobs: - name: Build wheels uses: PyO3/maturin-action@v1 with: - maturin-version: "1.7.4" target: ${{ matrix.platform.target }} args: --release --out dist --find-interpreter sccache: 'true' @@ -150,7 +145,6 @@ jobs: - name: Build sdist uses: PyO3/maturin-action@v1 with: - maturin-version: "1.7.4" command: sdist args: --out dist - name: Upload sdist @@ -178,11 +172,10 @@ jobs: with: subject-path: 'wheels-*/*' - name: Publish to PyPI - if: "startsWith(github.ref, 'refs/tags/')" + if: ${{ startsWith(github.ref, 'refs/tags/') }} uses: PyO3/maturin-action@v1 env: MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} with: - maturin-version: "1.7.4" command: upload args: --non-interactive --skip-existing wheels-*/* \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index db1887429..c3a8da34d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,12 +8,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" -[[package]] -name = "bitflags" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" - [[package]] name = "cfg-if" version = "1.0.0" @@ -22,9 +16,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "indoc" @@ -38,16 +32,6 @@ version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" -[[package]] -name = "lock_api" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "matrixmultiply" version = "0.3.9" @@ -109,9 +93,9 @@ dependencies = [ [[package]] name = "numpy" -version = "0.21.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec170733ca37175f5d75a5bea5911d6ff45d2cd52849ce98b685394e4f2f37f4" +checksum = "b94caae805f998a07d33af06e6a3891e38556051b8045c615470a71590e13e78" dependencies = [ "libc", "ndarray", @@ -128,29 +112,6 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" -[[package]] -name = "parking_lot" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - [[package]] name = "portable-atomic" version = "1.9.0" @@ -168,15 +129,15 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e00b96a521718e08e03b1a622f01c8a8deb50719335de3f60b3b3950f069d8" +checksum = "e484fd2c8b4cb67ab05a318f1fd6fa8f199fcc30819f08f07d200809dba26c15" dependencies = [ "cfg-if", "indoc", "libc", "memoffset", - "parking_lot", + "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", @@ -186,9 +147,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7883df5835fafdad87c0d888b266c8ec0f4c9ca48a5bed6bbb592e8dedee1b50" +checksum = "dc0e0469a84f208e20044b98965e1561028180219e35352a2afaf2b942beff3b" dependencies = [ "once_cell", "target-lexicon", @@ -196,9 +157,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01be5843dc60b916ab4dad1dca6d20b9b4e6ddc8e15f50c47fe6d85f1fb97403" +checksum = "eb1547a7f9966f6f1a0f0227564a9945fe36b90da5a93b3933fc3dc03fae372d" dependencies = [ "libc", "pyo3-build-config", @@ -206,9 +167,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77b34069fc0682e11b31dbd10321cbf94808394c56fd996796ce45217dfac53c" +checksum = "fdb6da8ec6fa5cedd1626c886fc8749bdcbb09424a86461eb8cdf096b7c33257" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -218,9 +179,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.21.2" +version = "0.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08260721f32db5e1a5beae69a55553f56b99bd0e1c3e6e0a5e8851a9d0f5a85c" +checksum = "38a385202ff5a92791168b1136afae5059d3ac118457bb7bc304c197c2d33e7d" dependencies = [ "heck", "proc-macro2", @@ -244,15 +205,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" -[[package]] -name = "redox_syscall" -version = "0.5.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" -dependencies = [ - "bitflags", -] - [[package]] name = "rshgf" version = "0.1.0" @@ -263,21 +215,9 @@ dependencies = [ [[package]] name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "smallvec" -version = "1.13.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" [[package]] name = "syn" @@ -307,67 +247,3 @@ name = "unindent" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7de7d73e1754487cb58364ee906a499937a0dfabd86bcb980fa99ec8c8fa2ce" - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml index 2f5937bac..9a4a51e9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,5 +10,5 @@ crate-type = ["cdylib", "rlib"] path = "src/lib.rs" # The source file of the target. [dependencies] -pyo3 = { version = "0.21.2", features = ["extension-module"] } -numpy = "0.21" \ No newline at end of file +pyo3 = { version = "0.23.3", features = ["extension-module"] } +numpy = "0.23" \ No newline at end of file diff --git a/src/model.rs b/src/model.rs index 9d4d0860c..15e9fee99 100644 --- a/src/model.rs +++ b/src/model.rs @@ -194,7 +194,7 @@ impl Network { } #[getter] - pub fn get_node_trajectories<'py>(&self, py: Python<'py>) -> PyResult<&'py PyList> { + pub fn get_node_trajectories<'py>(&self, py: Python<'py>) -> PyResult> { let py_list = PyList::empty(py); @@ -210,27 +210,27 @@ impl Network { if let Some(vector_node) = self.node_trajectories.vectors.get(node_idx) { for (vector_key, vector_value) in vector_node { // Create a new Python dictionary - py_dict.set_item(vector_key, PyArray::from_vec2_bound(py, &vector_value).unwrap()).expect("Failed to set item in PyDict"); + py_dict.set_item(vector_key, PyArray::from_vec2(py, &vector_value).unwrap()).expect("Failed to set item in PyDict"); } } py_list.append(py_dict)?; } // Create a PyList from Vec - Ok(py_list) + Ok(py_list.into()) } #[getter] - pub fn get_inputs<'py>(&self, py: Python<'py>) -> PyResult<&'py PyList> { - let py_list = PyList::new(py, &self.inputs); // Create a PyList from Vec - Ok(py_list) + pub fn get_inputs<'py>(&self, py: Python<'py>) -> PyResult> { + let py_list = PyList::new(py, &self.inputs)?; // Create a PyList from Vec + Ok(py_list.into()) } #[getter] - pub fn get_edges<'py>(&self, py: Python<'py>) -> PyResult<&'py PyList> { + pub fn get_edges<'py>(&self, py: Python<'py>) -> PyResult> { // Create a new Python list let py_list = PyList::empty(py); - + // Convert each struct in the Vec to a Python object and add to PyList for i in 0..self.edges.len() { // Create a new Python dictionary for each MyStruct @@ -239,40 +239,48 @@ impl Network { py_dict.set_item("value_children", &self.edges[&i].value_children)?; py_dict.set_item("volatility_parents", &self.edges[&i].volatility_parents)?; py_dict.set_item("volatility_children", &self.edges[&i].volatility_children)?; - + // Add the dictionary to the list py_list.append(py_dict)?; } - Ok(py_list) + + // Return the PyList object directly + Ok(py_list.into()) } + #[getter] - pub fn get_update_sequence<'py>(&self, py: Python<'py>) -> PyResult<&'py PyList> { + pub fn get_update_sequence<'py>(&self, py: Python<'py>) -> PyResult> { - let func_map = get_func_map(); - let py_list = PyList::empty(py); - // Iterate over the Rust vector and convert each tuple - for &(num, func) in self.update_sequence.predictions.iter() { - // Retrieve the function name from the map - let func_name = func_map.get(&func).unwrap_or(&"unknown"); - - // Convert the Rust tuple to a Python tuple with the function name as a string - let py_tuple = PyTuple::new(py, &[num.into_py(py), (*func_name).into_py(py)]); - - // Append the Python tuple to the Python list - py_list.append(py_tuple)?; - } - for &(num, func) in self.update_sequence.updates.iter() { - // Retrieve the function name from the map - let func_name = func_map.get(&func).unwrap_or(&"unknown"); - - // Convert the Rust tuple to a Python tuple with the function name as a string - let py_tuple = PyTuple::new(py, &[num.into_py(py), (*func_name).into_py(py)]); - - // Append the Python tuple to the Python list - py_list.append(py_tuple)?; - } - Ok(py_list) + let func_map = get_func_map(); + let py_list = PyList::empty(py); + + // Iterate over the Rust vector and convert each tuple + for &(num, func) in self.update_sequence.predictions.iter() { + + // Resolve the Python objects from the Rust values + let py_func_name = func_map.get(&func).unwrap_or(&"unknown").into_pyobject(py)?.into_any().unbind(); + let py_num = num.into_pyobject(py)?.into_any().unbind(); // Converts num to PyObject + + // Create a Python tuple + let py_tuple = PyTuple::new(py, &[py_num, py_func_name])?; + + // Append the Python tuple to the Python list + py_list.append(py_tuple)?; + } + for &(num, func) in self.update_sequence.updates.iter() { + + // Resolve the Python objects from the Rust values + let py_func_name = func_map.get(&func).unwrap_or(&"unknown").into_pyobject(py)?.into_any().unbind(); + let py_num = num.into_pyobject(py)?.into_any().unbind(); // Converts num to PyObject + + // Create a Python tuple + let py_tuple = PyTuple::new(py, &[py_num, py_func_name])?; + + // Append the Python tuple to the Python list + py_list.append(py_tuple)?; + } + Ok(py_list.into()) } }