我是 dask 的新手,我发现拥有一个可以轻松实现并行化的模块真是太好了。我正在做一个项目,我可以在一台机器上并行化一个循环,正如你在这里看到的。但是,我想转移到dask.distributed
. 我对上面的类应用了以下更改:
diff --git a/mlchem/fingerprints/gaussian.py b/mlchem/fingerprints/gaussian.py
index ce6a72b..89f8638 100644
--- a/mlchem/fingerprints/gaussian.py
+++ b/mlchem/fingerprints/gaussian.py
@@ -6,7 +6,7 @@ from sklearn.externals import joblib
from .cutoff import Cosine
from collections import OrderedDict
import dask
-import dask.multiprocessing
+from dask.distributed import Client
import time
@@ -141,13 +141,14 @@ class Gaussian(object):
for image in images.items():
computations.append(self.fingerprints_per_image(image))
+ client = Client()
if self.scaler is None:
- feature_space = dask.compute(*computations, scheduler='processes',
+ feature_space = dask.compute(*computations, scheduler='distributed',
num_workers=self.cores)
feature_space = OrderedDict(feature_space)
else:
stacked_features …
Run Code Online (Sandbox Code Playgroud) 我是Python的新手.我知道这已经被问到了,我道歉,但这种新情况的不同之处在于字符串之间的空格不相等.我有一个名为coord的文件,它包含以下空格分隔的字符串:
1 C 6.00 0.000000000 1.342650315 0.000000000
2 C 6.00 0.000000000 -1.342650315 0.000000000
3 C 6.00 2.325538562 2.685300630 0.000000000
4 C 6.00 2.325538562 -2.685300630 0.000000000
5 C 6.00 4.651077125 1.342650315 0.000000000
6 C 6.00 4.651077125 -1.342650315 0.000000000
7 C 6.00 -2.325538562 2.685300630 0.000000000
8 C 6.00 -2.325538562 -2.685300630 0.000000000
9 C 6.00 -4.651077125 1.342650315 0.000000000
10 C 6.00 -4.651077125 -1.342650315 0.000000000
11 H 1.00 2.325538562 4.733763602 0.000000000
12 H 1.00 2.325538562 -4.733763602 0.000000000
13 H 1.00 -2.325538562 4.733763602 …
Run Code Online (Sandbox Code Playgroud) 当执行“大量”任务时,我收到此错误:
考虑使用 client.scatter 提前分散大型对象,以减轻调度程序负担并保留工作人员的数据
我还收到了一堆这样的消息:
tornado.application - ERROR - Exception in callback <bound method BokehTornado._keep_alive of <bokeh.server.tornado.BokehTornado object at 0x7f20d25e10b8>>
Traceback (most recent call last):
File "/home/muammar/.local/lib/python3.7/site-packages/tornado/ioloop.py", line 907, in _run
return self.callback()
File "/home/muammar/.local/lib/python3.7/site-packages/bokeh/server/tornado.py", line 542, in _keep_alive
c.send_ping()
File "/home/muammar/.local/lib/python3.7/site-packages/bokeh/server/connection.py", line 80, in send_ping
self._socket.ping(codecs.encode(str(self._ping_count), "utf-8"))
File "/home/muammar/.local/lib/python3.7/site-packages/tornado/websocket.py", line 447, in ping
raise WebSocketClosedError()
tornado.websocket.WebSocketClosedError
tornado.application - ERROR - Exception in callback <bound method BokehTornado._keep_alive of <bokeh.server.tornado.BokehTornado object at 0x7f20d25e10b8>>
Traceback (most recent call last):
File "/home/muammar/.local/lib/python3.7/site-packages/tornado/ioloop.py", line …
Run Code Online (Sandbox Code Playgroud) 我正在使用 PyQt5 在菜单系统托盘中工作。我对 PyQt5 很陌生,我想做的是触发一个动作而不会阻止菜单(多线程)。在阅读了很多地方之后,我得出的结论是 usingQthread
应该是要走的路(但如果我能理解该类的工作原理......)。但是,threading
考虑到我的应用程序非常简单,使用也不会那么糟糕。因此,我尝试使用以下代码import threading
:
from PyQt5 import QtCore, QtGui, QtWidgets
import threading
class menubar(object):
def __init__(self):
signal.signal(signal.SIGINT, signal.SIG_DFL)
self.systray = True
self.stopped = False
def search_menu(self):
self.SearchAction = menu.addAction("Search")
self.SearchAction.triggered.connect(self.search_cast)
def _search_cast_(self):
args.select_cc = True
self.cc.initialize_cast()
self.cast_list()
def search_cast(self):
threading.Thread(target=self._search_cast_).start()
#some more methods here...
def main():
menubar()
app = QtWidgets.QApplication(sys.argv)
tray = QtWidgets.QSystemTrayIcon(icon)
menu = QtWidgets.QMenu()
start = menubar()
start.search_menu()
start.separator_menu()
start.populating_menu()
start.separator_menu()
start.stop_menu()
start.resetaudio_menu()
start.about_menu()
start.exit_menu()
tray.setContextMenu(menu)
tray.show()
app.exec_()
if …
Run Code Online (Sandbox Code Playgroud) 我有一个字符串列表如下:
a = ['aaa-t1', 'aaa-t2', 'aab-t1', 'aab-t2', 'aab-t3', 'abc-t2']
Run Code Online (Sandbox Code Playgroud)
我想通过相似性来聚类这些字符串.您可能会注意到,a[0]
并a[1]
共享相同的根:aaa
.我想生成一个新的列表列表,如下所示:
b = [['aaa-t1', 'aaa-t2'], ['aab-t1', 'aab-t2', 'aab-t3'], ['abc-t2']]
Run Code Online (Sandbox Code Playgroud)
怎么办呢?到目前为止,我没有成功,我没有任何体面的代码可以显示.我正在尝试比较字符串,fuzzywuzzy
但这样做需要创建可能的字符串组合,并且与列表的长度严重缩放.