{"id":25188997,"url":"https://github.com/yuricst/parivp","last_synced_at":"2025-05-07T16:50:59.553Z","repository":{"id":47267921,"uuid":"401567585","full_name":"Yuricst/parivp","owner":"Yuricst","description":"Parallel IVP in Python","archived":false,"fork":false,"pushed_at":"2024-08-09T03:36:20.000Z","size":6157,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-09T04:39:59.867Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Yuricst.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-31T04:03:10.000Z","updated_at":"2024-08-09T03:36:24.000Z","dependencies_parsed_at":"2022-09-13T14:02:03.102Z","dependency_job_id":"779c5472-f93c-4513-b233-62a220bf3c75","html_url":"https://github.com/Yuricst/parivp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yuricst%2Fparivp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yuricst%2Fparivp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yuricst%2Fparivp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yuricst%2Fparivp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yuricst","download_url":"https://codeload.github.com/Yuricst/parivp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238017346,"owners_count":19402730,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-09T20:34:50.386Z","updated_at":"2025-02-09T20:34:50.998Z","avatar_url":"https://github.com/Yuricst.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# parivp: Parallel IVP in Python using multiprocessing\n\nThis module allows for parallel integration of initial value problems (IVP) using Python's multiprocessing features. Syntax follows those of `scipy.integrate.solve_ivp()`, hence enabling parallelization with minimal changes. \n\nSee [here](https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.solve_ivp.html) for scipy's documentation on `solve_ivp()`.\n\n\n### Dependencies\n\n- `multiprocessing`, `numpy`, `scipy`\n\n\n### Basic usage\n\nWhen solving a single IVP, `solve_ivp()` takes in as basic arguments the ODE function, the time-span, the initial condition, and optionally additional arguments passed to the ODE function. \n\nThe parallelized version of this function, `parivp.parsolve_ivp()`, takes in as arguments *lists* of these basic arguments. \n\n\n#### Example\n\nWe start by importing relevant modules (`matplotlib` is for plotting the results later), and defining the ODE; here, we are using the restricyed twobody problem: \n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt  # optional, for plotting results later\nfrom parivp import parsolve_ivp\n\ndef twobody(t,state,mu):\n    \"\"\"Two-body equation of motion\"\"\"\n    dstate = np.zeros(6,)\n    dstate[0:3] = state[3:6]\n    dstate[3:6] = -mu/np.linalg.norm(state[0:3])**3 * state[0:3]\n    return dstate\n```\n\nWe now prepare lists of the time-span, initial conditions, and additional arguments; in this case, we are only varying the initial conditition, and we keep the time-spans and arguments the same. \n\n```python\n# number of integrations to perform\nn = 50\n\n# create list of final times\nt0 = 0.0\ntf = 10.0\nt_spans = [(t0,tf) for el in range(n)]\n\n# create list of initial conditions\nics = []\nstate0 = np.array([1.0, 0.0, 0.2, 0.0, 1.0, -0.02])\nsigR, sigV = 0.02, 0.01\nfor idx in range(n):\n    ics.append(state0 + np.concatenate((sigR*np.random.rand(3),sigV*np.random.rand(3))))\n\n# create list of argument to EOM\nps = [(1.0,) for el in range(n)]\n```\n\nWe can now call the parallel integrator function\n\n```python\n# integrate in parallel\nn_cpu = 4\nt_eval = np.linspace(t0,tf,1000)\nrespar = parsolve_ivp(fun=twobody, t_spans=t_spans, ics=ics, ps=ps, n_cpu=n_cpu, t_eval=t_eval)\n```\n\nWe can visualize the results \n\n```python\n# plot result\nfig = plt.figure(figsize=(6,6))\nax = fig.add_subplot()\nfor sol in respar:\n    ax.plot(sol.y[0,:], sol.y[1,:], linewidth=0.5)\nax.axis('equal')\nax.set(xlabel=\"x\", ylabel=\"y\")\nplt.show()\n\n```\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./tests/parallel_twobody.png\" width=\"550\" title=\"Two-body example\"\u003e\n\u003c/p\u003e\n\n\n### More Examples\n\nFor examples, see scripts in `./tests`. \n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuricst%2Fparivp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuricst%2Fparivp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuricst%2Fparivp/lists"}