Найти в Дзене
Борис Державец

Multi-threaded Python (3.14.3t) calculation based on principle of argument (theory of functions of a complex variable)

Утилита командной строки "aqtinstall" позволяет строить графики в Python 3.14.3t, автоматизируя установку бинарных файлов Qt (например, PyQt6), необходимых для таких библиотек, как Matplotlib, для отображения интерактивных графиков. Она служит альтернативой официальному установщику Qt, упрощая настройку необходимых графических фреймворков, часто в средах CI или для определенных версий Python. Управление зависимостями: она разрешает и устанавливает необходимые компоненты Qt, позволяя pip install matplotlib корректно работать для создания интерактивных графиков. Совместимость версий: она может устанавливать определенные предварительно собранные бинарные файлы Qt, совместимые с последними версиями Python, такими как 3.14, ориентируясь на необходимую ОС и компилятор. Интеграция: установленные библиотеки Qt позволяют встраивать графики Matplotlib непосредственно в графические приложения, предоставляя интерактивные, масштабируемые и перемещаемые графики. Both samples of code below were verif
Runtime of both modules snapshot
Runtime of both modules snapshot

Утилита командной строки "aqtinstall" позволяет строить графики в Python 3.14.3t, автоматизируя установку бинарных файлов Qt (например, PyQt6), необходимых для таких библиотек, как Matplotlib, для отображения интерактивных графиков. Она служит альтернативой официальному установщику Qt, упрощая настройку необходимых графических фреймворков, часто в средах CI или для определенных версий Python. Управление зависимостями: она разрешает и устанавливает необходимые компоненты Qt, позволяя pip install matplotlib корректно работать для создания интерактивных графиков. Совместимость версий: она может устанавливать определенные предварительно собранные бинарные файлы Qt, совместимые с последними версиями Python, такими как 3.14, ориентируясь на необходимую ОС и компилятор. Интеграция: установленные библиотеки Qt позволяют встраивать графики Matplotlib непосредственно в графические приложения, предоставляя интерактивные, масштабируемые и перемещаемые графики.

Both samples of code below were verified on both Debian Stable/Testing

For python3.14.3t instead of PyQt6 install
$ pip install aqtinstall
in virtual environment of python3.14.3t

$ mkdir MULTITHREAD
$ cd MULTITHREAD
$ python3.14t -m venv .env
$ source .env/bin/activate
$ pip install aqtinstall
$ pip install --upgrade pip
$ pip install numpy matplotlib cxroots

(.env) boris@Debian13TRIXIE:~/MULTITHREAD$ cat complexThreaded10.py

import os

import numpy as np

import matplotlib.pyplot as plt

from cxroots import Circle

from concurrent.futures import ThreadPoolExecutor

# Silence Qt warnings

os.environ["QT_LOGGING_RULES"] = "*.debug=false;qt.qpa.fonts.warning=false"

def count_zeros_task(f, df, contour_points):

>> """Calculates zeros via the Argument Principle."""

>> fz, dfz = f(contour_points), df(contour_points)

>> integrand = dfz / fz

>> dz = np.diff(contour_points, append=contour_points[0])

>> integral = np.sum(integrand * dz)

>> return int(np.round((integral / (2j * np.pi)).real))

def find_roots_task(contour, f, df):

>> """Calculates specific root locations using cxroots."""

>> return contour.roots(f, df)

# 1. Setup Data

f = lambda z: z**13 + 5*z + 2

df = lambda z: 13*z**12 + 5

t = np.linspace(0, 2 * np.pi, 1000)

circle_pts = 4 * np.exp(1j * t)

C = Circle(0, 4)

print("Starting concurrent calculations...")

# 2. Parallel Execution

with ThreadPoolExecutor() as executor:

>> # Submit both tasks to run simultaneously

>> future_count = executor.submit(count_zeros_task, f, df, circle_pts)

>> future_roots = executor.submit(find_roots_task, C, f, df)

>> # Retrieve results (this waits for each to finish)

>> zero_count = future_count.result()

>> roots_result = future_roots.result()

# 3. Output and Visualization

print(f"\nVerification (Argument Principle): {zero_count} zeros found.")

print(f"Detailed Root Analysis:\n{roots_result}")

# Plotting must happen on the main thread

roots_result.show()

plt.show()

================================================================

(.env) boris@Debian13TRIXIE:~/MULTITHREAD$ cat complexThreaded08.py

import os

import numpy as np

import matplotlib.pyplot as plt

from cxroots import Circle

from concurrent.futures import ThreadPoolExecutor

# Silence Qt warnings

os.environ["QT_LOGGING_RULES"] = "*.debug=false;qt.qpa.fonts.warning=false"

def count_zeros_task(f, df, contour_points):

>> """Calculates zeros via the Argument Principle."""

>> fz, dfz = f(contour_points), df(contour_points)

>> integrand = dfz / fz

>> dz = np.diff(contour_points, append=contour_points[0])

>> integral = np.sum(integrand * dz)

>> return int(np.round((integral / (2j * np.pi)).real))

def find_roots_task(contour, f, df):

>> """Calculates specific root locations using cxroots."""

>> return contour.roots(f, df)

# 1. Setup Data

f = lambda z: 4*z**5 + 4*z**3 - 4*z + 9

df = lambda z: 20*z**4 + 12*z**2 - 4

t = np.linspace(0, 2 * np.pi, 1000)

circle_pts = 4 * np.exp(1j * t)

C = Circle(0, 4)

print("Starting concurrent calculations...")

# 2. Parallel Execution

with ThreadPoolExecutor() as executor:

>> # Submit both tasks to run simultaneously

>> future_count = executor.submit(count_zeros_task, f, df, circle_pts)

>> future_roots = executor.submit(find_roots_task, C, f, df)

>> # Retrieve results (this waits for each to finish)

>> zero_count = future_count.result()

>> roots_result = future_roots.result()

# 3. Output and Visualization

print(f"\nVerification (Argument Principle): {zero_count} zeros found.")

print(f"Detailed Root Analysis:\n{roots_result}")

# Plotting must happen on the main thread

roots_result.show()

plt.show()