OperationalError: Error connecting to Elasticsearch: elasticsearch-dbapi - elasticsearch

I am trying to connect to Elasticsearch using the elasticsearch-dbapi library. I want to be able to execute SQL queries on my Elasticsearch cluster.
However, I keep getting this error when I attempt to run a query,
---------------------------------------------------------------------------
gaierror Traceback (most recent call last)
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\urllib3\connection.py:174, in HTTPConnection._new_conn(self)
173 try:
--> 174 conn = connection.create_connection(
175 (self._dns_host, self.port), self.timeout, **extra_kw
176 )
178 except SocketTimeout:
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\urllib3\util\connection.py:72, in create_connection(address, timeout, source_address, socket_options)
68 return six.raise_from(
69 LocationParseError(u"'%s', label empty or too long" % host), None
70 )
---> 72 for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
73 af, socktype, proto, canonname, sa = res
File ~\Anaconda3\envs\elasticsearch\lib\socket.py:955, in getaddrinfo(host, port, family, type, proto, flags)
954 addrlist = []
--> 955 for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
956 af, socktype, proto, canonname, sa = res
gaierror: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
NewConnectionError Traceback (most recent call last)
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\elasticsearch\connection\http_urllib3.py:251, in Urllib3HttpConnection.perform_request(self, method, url, params, body, timeout, ignore, headers)
249 request_headers["content-encoding"] = "gzip"
--> 251 response = self.pool.urlopen(
252 method, url, body, retries=Retry(False), headers=request_headers, **kw
253 )
254 duration = time.time() - start
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\urllib3\connectionpool.py:787, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
785 e = ProtocolError("Connection aborted.", e)
--> 787 retries = retries.increment(
788 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
789 )
790 retries.sleep()
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\urllib3\util\retry.py:525, in Retry.increment(self, method, url, response, error, _pool, _stacktrace)
523 if self.total is False and error:
524 # Disabled, indicate to re-raise the error.
--> 525 raise six.reraise(type(error), error, _stacktrace)
527 total = self.total
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\urllib3\packages\six.py:770, in reraise(tp, value, tb)
769 raise value.with_traceback(tb)
--> 770 raise value
771 finally:
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\urllib3\connectionpool.py:703, in HTTPConnectionPool.urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
702 # Make the request on the httplib connection object.
--> 703 httplib_response = self._make_request(
704 conn,
705 method,
706 url,
707 timeout=timeout_obj,
708 body=body,
709 headers=headers,
710 chunked=chunked,
711 )
713 # If we're going to release the connection in ``finally:``, then
714 # the response doesn't need to know about the connection. Otherwise
715 # it will also try to release it and we'll have a double-release
716 # mess.
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\urllib3\connectionpool.py:386, in HTTPConnectionPool._make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
385 try:
--> 386 self._validate_conn(conn)
387 except (SocketTimeout, BaseSSLError) as e:
388 # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\urllib3\connectionpool.py:1042, in HTTPSConnectionPool._validate_conn(self, conn)
1041 if not getattr(conn, "sock", None): # AppEngine might not have `.sock`
-> 1042 conn.connect()
1044 if not conn.is_verified:
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\urllib3\connection.py:358, in HTTPSConnection.connect(self)
356 def connect(self):
357 # Add certificate verification
--> 358 self.sock = conn = self._new_conn()
359 hostname = self.host
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\urllib3\connection.py:186, in HTTPConnection._new_conn(self)
185 except SocketError as e:
--> 186 raise NewConnectionError(
187 self, "Failed to establish a new connection: %s" % e
188 )
190 return conn
NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x00000236CF7A3D60>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed
During handling of the above exception, another exception occurred:
ConnectionError Traceback (most recent call last)
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\es\baseapi.py:318, in BaseCursor.elastic_query(self, query)
317 try:
--> 318 response = self.es.transport.perform_request("POST", path, body=payload)
319 except es_exceptions.ConnectionError:
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\elasticsearch\transport.py:413, in Transport.perform_request(self, method, url, headers, params, body)
412 if attempt == self.max_retries:
--> 413 raise e
414 else:
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\elasticsearch\transport.py:381, in Transport.perform_request(self, method, url, headers, params, body)
380 try:
--> 381 status, headers_response, data = connection.perform_request(
382 method,
383 url,
384 params,
385 body,
386 headers=headers,
387 ignore=ignore,
388 timeout=timeout,
389 )
391 except TransportError as e:
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\elasticsearch\connection\http_urllib3.py:266, in Urllib3HttpConnection.perform_request(self, method, url, params, body, timeout, ignore, headers)
265 raise ConnectionTimeout("TIMEOUT", str(e), e)
--> 266 raise ConnectionError("N/A", str(e), e)
268 # raise warnings if any from the 'Warnings' header.
ConnectionError: ConnectionError(<urllib3.connection.HTTPSConnection object at 0x00000236CF7A3D60>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed) caused by: NewConnectionError(<urllib3.connection.HTTPSConnection object at 0x00000236CF7A3D60>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed)
During handling of the above exception, another exception occurred:
OperationalError Traceback (most recent call last)
Input In [16], in <cell line: 2>()
1 curs = conn.cursor()
----> 2 curs.execute(
3 "select * from kibana_sample_data_ecommerce LIMIT 10"
4 )
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\es\baseapi.py:36, in check_closed.<locals>.wrap(self, *args, **kwargs)
32 if self.closed:
33 raise exceptions.Error(
34 "{klass} already closed".format(klass=self.__class__.__name__)
35 )
---> 36 return f(self, *args, **kwargs)
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\es\elastic\api.py:158, in Cursor.execute(self, operation, parameters)
155 return self.get_array_type_columns(re_table_name[1])
157 query = apply_parameters(operation, parameters)
--> 158 results = self.elastic_query(query)
159 # We need a list of tuples
160 rows = [tuple(row) for row in results.get("rows", [])]
File ~\Anaconda3\envs\elasticsearch\lib\site-packages\es\baseapi.py:320, in BaseCursor.elastic_query(self, query)
318 response = self.es.transport.perform_request("POST", path, body=payload)
319 except es_exceptions.ConnectionError:
--> 320 raise exceptions.OperationalError("Error connecting to Elasticsearch")
321 except es_exceptions.RequestError as ex:
322 raise exceptions.ProgrammingError(f"Error ({ex.error}): {ex.info}")
OperationalError: Error connecting to Elasticsearch
This is what my code looks like,
from es.elastic.api import connect
conn = connect(
host='https://<endpoint-alias>.es.eastus2.azure.elastic-cloud.com',
port=9200,
scheme="https",
user='elastic',
password='<password>'
)
curs = conn.cursor()
curs.execute(
"select * from kibana_sample_data_ecommerce LIMIT 10"
)
What exactly is the problem here?
Note: I am using the elasticsearch-dbapi package because although it is possible to execute SQL queries using elasticsearch, there does not seem to be an option to scan through all of the results. I want to access all the hits that are returned by a query.
However, when I tried connecting using elasticsearch, it worked without any problem. But, I used the Cloud ID to establish the connection. Is there some issue with the host that I have used?

Related

Getting HTTPError: HTTP Error 404: Not Found error when loaded a dataset using seaborn

I have a dataset with name "haberman.csv" in my current directory and upon trying to load the dataset with below load_dataset function then it throws an error saying HTTPError: HTTP Error 404: Not Found.
But when loaded a different dataset with name "tips.csv" in the same directory it works well.
What is the reason behind this error that one dataset when loaded works and another doesn't.
import seaborn as sns
sns.set()
haberman_plot = sns.load_dataset("haberman")
Error:
<ipython-input-58-fb9fa2439b0a> in <module>()
4
5 sns.set()
----> 6 haberman_plot = sns.load_dataset("haberman")
~/.local/lib/python3.6/site-packages/seaborn/utils.py in load_dataset(name, cache, data_home, **kws)
426 os.path.basename(full_path))
427 if not os.path.exists(cache_path):
--> 428 urlretrieve(full_path, cache_path)
429 full_path = cache_path
430
~/anaconda3/lib/python3.6/urllib/request.py in urlretrieve(url, filename, reporthook, data)
246 url_type, path = splittype(url)
247
--> 248 with contextlib.closing(urlopen(url, data)) as fp:
249 headers = fp.info()
250
~/anaconda3/lib/python3.6/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
221 else:
222 opener = _opener
--> 223 return opener.open(url, data, timeout)
224
225 def install_opener(opener):
~/anaconda3/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout)
530 for processor in self.process_response.get(protocol, []):
531 meth = getattr(processor, meth_name)
--> 532 response = meth(req, response)
533
534 return response
~/anaconda3/lib/python3.6/urllib/request.py in http_response(self, request, response)
640 if not (200 <= code < 300):
641 response = self.parent.error(
--> 642 'http', request, response, code, msg, hdrs)
643
644 return response
~/anaconda3/lib/python3.6/urllib/request.py in error(self, proto, *args)
568 if http_err:
569 args = (dict, 'default', 'http_error_default') + orig_args
--> 570 return self._call_chain(*args)
571
572 # XXX probably also want an abstract factory that knows when it makes
~/anaconda3/lib/python3.6/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
502 for handler in handlers:
503 func = getattr(handler, meth_name)
--> 504 result = func(*args)
505 if result is not None:
506 return result
~/anaconda3/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
648 class HTTPDefaultErrorHandler(BaseHandler):
649 def http_error_default(self, req, fp, code, msg, hdrs):
--> 650 raise HTTPError(req.full_url, code, msg, hdrs, fp)
651
652 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 404: Not Found```

Graphviz reports not finding executables although they are in my system's Path

I have downloaded the graphviz files and put them in the directory C:\graphviz of my PC (I am running Windows 10).
Then I added the address of the executables to the System's PATH :
Still when I run the diagnostic code:
from graphviz import Digraph
dot = Digraph(comment='The Round Table')
dot #doctest: +ELLIPSIS
dot.node('A', 'King Arthur')
dot.node('B', 'Sir Bedevere the Wise')
dot.node('L', 'Sir Lancelot the Brave')
dot.edges(['AB', 'AL'])
dot.edge('B', 'L', constraint='false')
print(dot.source) # doctest: +NORMALIZE_WHITESPACE
dot.render('test-output/round-table.gv', view=True) # doctest: +SKIP
I get an exception:
// The Round Table
digraph {
A [label="King Arthur"]
B [label="Sir Bedevere the Wise"]
L [label="Sir Lancelot the Brave"]
A -> B
A -> L
B -> L [constraint=false]
}
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\graphviz\backend.py in render(engine, format, filepath, quiet)
128 try:
--> 129 subprocess.check_call(args, stderr=stderr, **POPEN_KWARGS)
130 except OSError as e:
C:\ProgramData\Anaconda3\lib\subprocess.py in check_call(*popenargs, **kwargs)
285 """
--> 286 retcode = call(*popenargs, **kwargs)
287 if retcode:
C:\ProgramData\Anaconda3\lib\subprocess.py in call(timeout, *popenargs, **kwargs)
266 """
--> 267 with Popen(*popenargs, **kwargs) as p:
268 try:
C:\ProgramData\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
706 errread, errwrite,
--> 707 restore_signals, start_new_session)
708 except:
C:\ProgramData\Anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
991 os.fspath(cwd) if cwd is not None else None,
--> 992 startupinfo)
993 finally:
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
ExecutableNotFound Traceback (most recent call last)
<ipython-input-1-1b23fb1e1f3e> in <module>()
14 print(dot.source) # doctest: +NORMALIZE_WHITESPACE
15
---> 16 dot.render('test-output/round-table.gv', view=True) # doctest: +SKIP
C:\ProgramData\Anaconda3\lib\site-packages\graphviz\files.py in render(self, filename, directory, view, cleanup)
174 filepath = self.save(filename, directory)
175
--> 176 rendered = backend.render(self._engine, self._format, filepath)
177
178 if cleanup:
C:\ProgramData\Anaconda3\lib\site-packages\graphviz\backend.py in render(engine, format, filepath, quiet)
130 except OSError as e:
131 if e.errno == errno.ENOENT:
--> 132 raise ExecutableNotFound(args)
133 else: # pragma: no cover
134 raise
ExecutableNotFound: failed to execute ['dot', '-Tpdf', '-O', 'test-output/round-table.gv'], make sure the Graphviz executables are on your systems' PATH
The following might also help in the diagnosis:
C:\graphviz\bin should be appended to system variable path.
https://stackoverflow.com/a/49699078/8037585

Localhost UDP client not receiving packets from UDP proxy [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I have a proxy that acts between a Minecraft (Windows 10 Edition) client and a server, the protocol is UDP. The client broadcasts an unconnected ping, then server replies with an unconnected pong, everything with that is okay. The thing is when the server sends the packet to my proxy, my proxy sends it to client but for some reason something happens during that part; either my proxy is not sending the packet or the client is not receiving the packet, but most likely it's the second option.
Edit: I got the unconnected pings and pongs working, now the server shows online on the server list, now the problem is mainly the open connection requests/replies. How I got the the pings and pongs working was I re-encoded the buffers and send them instead of sending them raw.
Here you can see from wireshark, the minecraft client sends an unconnected ping the proxy:
NO. Time. Source. Dest. Proto. Len. Packet
417 10.452413 10.0.0.248 10.0.0.255 RakNet 75 Unconnected Ping (client -> proxy)
430 10.457000 10.0.0.248 x.x.x.x RakNet 610 Unconnected Ping (proxy -> server)
431 10.587214 x.x.x.x 10.0.0.248 RakNet 212 Unconnected Pong (server -> proxy -> client)
Now the proxy receive the unconnected pong, send it to the client, and the client doesn't receive it, I can confirm this because on the game the server shows offline and doesn't show any data:
Localhost Server Screenshot
In my code, I first bind the proxy on port 19132 and set the server address I want to communicate with:
var config = NewConfig()
var proxy = Proxy{}
var err error
proxy.UDPConn, err = net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP(config.BindAddr), Port: config.BindPort})
if err != nil {
Panic(err.Error())
os.Exit(1)
}
Info("Starting proxy on " + config.BindAddr + ":" + strconv.Itoa(config.BindPort))
addrs, err := net.LookupHost(config.ServerAddr)
if err != nil {
Panic(err.Error())
os.Exit(1)
}
conn := NewConnection(&proxy)
conn.server.SetAddress(net.UDPAddr{IP: net.ParseIP(addrs[0]), Port: config.ServerPort})
conn.HandleIncomingPackets()
Now my proxy starts receiving and sending packets automatically.
for true {
buffer := make([]byte, 2048)
_, addr, err := conn.proxy.UDPConn.ReadFromUDP(buffer)
if err != nil {
Alert(err.Error())
continue
}
MessageId := buffer[0]
Debug("Message Id : " + strconv.Itoa(int(MessageId))) // this is the packet id
if conn.client.IsConnected() { // client is connected
if conn.IsServer(*addr) {
conn.pkHandler.HandleIncomingPacket(buffer, conn.client) // if server send to client
}else{
conn.pkHandler.HandleIncomingPacket(buffer, conn.server) // if client send to server
}
} else {
switch MessageId {
case byte(IdUnconnectedPingOpenConnection):
conn.handleUnconnectedPing(*addr, buffer) // send this server
break
case byte(IdUnconnectedPongOpenConnection):
conn.handleUnconnectedPong(*addr, buffer) // parse server data and send to client
break
case byte(IdOpenConnectionRequest1):
conn.handleConnectionRequest1(*addr, buffer) // connect client and send to server
break
//case byte(IdOpenConnectionReply1):
// conn.handleConnectionReply1(*addr, buffer)
// break
}
}
}
This is the message id log:
[2018-06-10 13:52:12][Log/DEBUG]: Message Id : 1
[2018-06-10 13:52:12][Log/INFO]: Received unconnected ping from client address: 10.0.0.248
[2018-06-10 13:52:12][Log/DEBUG]: Message Id : 28
[2018-06-10 13:52:12][Log/INFO]: Received unconnected pong from server address: x.x.x.x
[2018-06-10 13:52:13][Log/DEBUG]: Message Id : 1
[2018-06-10 13:52:13][Log/INFO]: Received unconnected ping from client address: 10.0.0.248
[2018-06-10 13:52:13][Log/DEBUG]: Message Id : 28
[2018-06-10 13:52:13][Log/INFO]: Received unconnected pong from server address: x.x.x.x
Another way I confirmed the client is not receiving packets is that when in the game I click the server in the server list, the client sends an open connection request 1 (5) and the server replies with open connection reply 1 (6), the client is supposed to receive this and continue with an open connection request 2 (7) then finally the server replies with open connection reply 2 (8), but the client never sends open connection request 2 (7), because it never got the open connection reply 1 (6) from the proxy and hence times out and disconnects, here is a log showing this:
[2018-06-10 11:07:46][Log/DEBUG]: Message Id : 5
[5 0 255 255 0 254 254 254 254 253 253 253 253 18 52 86 120 8]
[2018-06-10 11:07:47][Log/DEBUG]: Message Id : 6
[6 0 255 255 0 254 254 254 254 253 253 253 253 18 52 86 120 36 149 162 237 197 55 226 161 0 8 28]
[2018-06-10 11:07:47][Log/DEBUG]: Message Id : 5
[5 0 255 255 0 254 254 254 254 253 253 253 253 18 52 86 120 8]
[2018-06-10 11:07:47][Log/DEBUG]: Message Id : 6
[6 0 255 255 0 254 254 254 254 253 253 253 253 18 52 86 120 36 149 162 237 197 55 226 161 0 8 28]
[2018-06-10 11:07:47][Log/DEBUG]: Message Id : 1
[1 0 0 0 0 3 3 91 191 0 255 255 0 254 254 254 254 253 253 253 253 18 52 86 120 191 216 14 215 31 123 8 249]
After so much debugging and testing, I figured I just needed to continue sending the datagram buffers, if it came from the server send it to client and vice-versa. If I cancelled the packet from sending I needed to send an ACK. It was all that simple.

XGboost keeps failing in Latest H2O stable release

I downloaded the latest release of H2O (3.18.0.1) and XGboost keeps failing. I am not sure whether to post to the JIRA issues or here.
h2o.init()
from h2o.estimators import H2OXGBoostEstimator
is_xgboost_available = H2OXGBoostEstimator.available()
train_path = 'https://s3.amazonaws.com/h2o-public-test-data/bigdata/laptop/higgs_train_imbalance_100k.csv'
test_path = 'https://s3.amazonaws.com/h2o-public-test-data/bigdata/laptop/higgs_test_imbalance_100k.csv'
df_train = h2o.import_file(train_path)
df_test = h2o.import_file(test_path)
# Transform first feature into categorical feature
df_train[0] = df_train[0].asfactor()
df_test[0] = df_test[0].asfactor()
param = {
"ntrees" : 500
}
model = H2OXGBoostEstimator(**param)
model.train(x = list(range(1, df_train.shape[1])), y = 0, training_frame = df_train)
I can run random forest, GBM without an issue but xgboost keeps failing.
I am running on Ubuntu 16.04. Java Version: java version "1.8.0_161"; Java(TM) SE Runtime Environment (build 1.8.0_161-b12); Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode). Anaconda Python 3.6
I reinstalled Anaconda and reinstalled JRE, but am still having the same issue.
It keeps giving me the following error:
xgboost Model Build progress: |████████████████████████████████████████
---------------------------------------------------------------------------
ConnectionResetError Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
600 body=body, headers=headers,
--> 601 chunked=chunked)
602
~/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
386 # otherwise it looks like a programming error was the cause.
--> 387 six.raise_from(e, None)
388 except (SocketTimeout, BaseSSLError, SocketError) as e:
~/anaconda3/lib/python3.6/site-packages/urllib3/packages/six.py in raise_from(value, from_value)
~/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
382 try:
--> 383 httplib_response = conn.getresponse()
384 except Exception as e:
~/anaconda3/lib/python3.6/http/client.py in getresponse(self)
1330 try:
-> 1331 response.begin()
1332 except ConnectionError:
~/anaconda3/lib/python3.6/http/client.py in begin(self)
296 while True:
--> 297 version, status, reason = self._read_status()
298 if status != CONTINUE:
~/anaconda3/lib/python3.6/http/client.py in _read_status(self)
257 def _read_status(self):
--> 258 line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
259 if len(line) > _MAXLINE:
~/anaconda3/lib/python3.6/socket.py in readinto(self, b)
585 try:
--> 586 return self._sock.recv_into(b)
587 except timeout:
ConnectionResetError: [Errno 104] Connection reset by peer
During handling of the above exception, another exception occurred:
ProtocolError Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
439 retries=self.max_retries,
--> 440 timeout=timeout
441 )
~/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
638 retries = retries.increment(method, url, error=e, _pool=self,
--> 639 _stacktrace=sys.exc_info()[2])
640 retries.sleep()
~/anaconda3/lib/python3.6/site-packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
356 if read is False or not self._is_method_retryable(method):
--> 357 raise six.reraise(type(error), error, _stacktrace)
358 elif read is not None:
~/anaconda3/lib/python3.6/site-packages/urllib3/packages/six.py in reraise(tp, value, tb)
684 if value.__traceback__ is not tb:
--> 685 raise value.with_traceback(tb)
686 raise value
~/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
600 body=body, headers=headers,
--> 601 chunked=chunked)
602
~/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
386 # otherwise it looks like a programming error was the cause.
--> 387 six.raise_from(e, None)
388 except (SocketTimeout, BaseSSLError, SocketError) as e:
~/anaconda3/lib/python3.6/site-packages/urllib3/packages/six.py in raise_from(value, from_value)
~/anaconda3/lib/python3.6/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
382 try:
--> 383 httplib_response = conn.getresponse()
384 except Exception as e:
~/anaconda3/lib/python3.6/http/client.py in getresponse(self)
1330 try:
-> 1331 response.begin()
1332 except ConnectionError:
~/anaconda3/lib/python3.6/http/client.py in begin(self)
296 while True:
--> 297 version, status, reason = self._read_status()
298 if status != CONTINUE:
~/anaconda3/lib/python3.6/http/client.py in _read_status(self)
257 def _read_status(self):
--> 258 line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
259 if len(line) > _MAXLINE:
~/anaconda3/lib/python3.6/socket.py in readinto(self, b)
585 try:
--> 586 return self._sock.recv_into(b)
587 except timeout:
ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
ConnectionError Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/h2o/backend/connection.py in request(self, endpoint, data, json, filename, save_to)
399 headers=headers, timeout=self._timeout, stream=stream,
--> 400 auth=self._auth, verify=self._verify_ssl_cert, proxies=self._proxies)
401 self._log_end_transaction(start_time, resp)
~/anaconda3/lib/python3.6/site-packages/requests/api.py in request(method, url, **kwargs)
57 with sessions.Session() as session:
---> 58 return session.request(method=method, url=url, **kwargs)
59
~/anaconda3/lib/python3.6/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
507 send_kwargs.update(settings)
--> 508 resp = self.send(prep, **send_kwargs)
509
~/anaconda3/lib/python3.6/site-packages/requests/sessions.py in send(self, request, **kwargs)
617 # Send the request
--> 618 r = adapter.send(request, **kwargs)
619
~/anaconda3/lib/python3.6/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
489 except (ProtocolError, socket.error) as err:
--> 490 raise ConnectionError(err, request=request)
491
ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
During handling of the above exception, another exception occurred:
H2OConnectionError Traceback (most recent call last)
<ipython-input-22-37b26d4dfbfd> in <module>()
1 start = time.time()
----> 2 model.train(x = list(range(1, df_train.shape[1])), y = 0, training_frame = df_train)
3 end = time.time()
4 print(end - start)
~/anaconda3/lib/python3.6/site-packages/h2o/estimators/estimator_base.py in train(self, x, y, training_frame, offset_column, fold_column, weights_column, validation_frame, max_runtime_secs, ignored_columns, model_id, verbose)
229 return
230
--> 231 model.poll(verbose_model_scoring_history=verbose)
232 model_json = h2o.api("GET /%d/Models/%s" % (rest_ver, model.dest_key))["models"][0]
233 self._resolve_model(model.dest_key, model_json)
~/anaconda3/lib/python3.6/site-packages/h2o/job.py in poll(self, verbose_model_scoring_history)
56 pb.execute(self._refresh_job_status, print_verbose_info=lambda x: self._print_verbose_info() if int(x * 10) % 5 == 0 else " ")
57 else:
---> 58 pb.execute(self._refresh_job_status)
59 except StopIteration as e:
60 if str(e) == "cancelled":
~/anaconda3/lib/python3.6/site-packages/h2o/utils/progressbar.py in execute(self, progress_fn, print_verbose_info)
167 # Query the progress level, but only if it's time already
168 if self._next_poll_time <= now:
--> 169 res = progress_fn() # may raise StopIteration
170 assert_is_type(res, (numeric, numeric), numeric)
171 if not isinstance(res, tuple):
~/anaconda3/lib/python3.6/site-packages/h2o/job.py in _refresh_job_status(self)
91 def _refresh_job_status(self):
92 if self._poll_count <= 0: raise StopIteration("")
---> 93 jobs = h2o.api("GET /3/Jobs/%s" % self.job_key)
94 self.job = jobs["jobs"][0] if "jobs" in jobs else jobs["job"][0]
95 self.status = self.job["status"]
~/anaconda3/lib/python3.6/site-packages/h2o/h2o.py in api(endpoint, data, json, filename, save_to)
101 # type checks are performed in H2OConnection class
102 _check_connection()
--> 103 return h2oconn.request(endpoint, data=data, json=json, filename=filename, save_to=save_to)
104
105
~/anaconda3/lib/python3.6/site-packages/h2o/backend/connection.py in request(self, endpoint, data, json, filename, save_to)
408 else:
409 self._log_end_exception(e)
--> 410 raise H2OConnectionError("Unexpected HTTP error: %s" % e)
411 except requests.exceptions.Timeout as e:
412 self._log_end_exception(e)
H2OConnectionError: Unexpected HTTP error: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

Monte Carlo solver in parallel with QuTiP

I'm trying to run some code in QuTiP, but when I run a function in parallel with parfor I am getting an error.
results= parfor(func2, range(len(delta)))
Error:
AssertionError
Traceback (most recent call last)
<ipython-input-206-6c2ffcb32b4f> in <module>()
----> 1 results= parfor(func2, range(len(delta)))
/usr/lib/python2.7/dist-packages/qutip/parallel.pyc in parfor(func, *args, **kwargs)
119 try:
120 map_args = ((func, v, os.getpid()) for v in var)
--> 121 par_return = list(pool.map(task_func, map_args))
122
123 pool.terminate()
/usr/lib/python2.7/multiprocessing/pool.py in map(self, func, iterable, chunksize)
249 '''
250 assert self._state == RUN
--> 251 return self.map_async(func, iterable, chunksize).get()
252
253 def imap(self, func, iterable, chunksize=1):
/usr/lib/python2.7/multiprocessing/pool.py in get(self, timeout)
556 return self._value
557 else:
--> 558 raise self._value
559
560 def _set(self, i, obj):
AssertionError: daemonic processes are not allowed to have children
Here is my code:
def func2(x):
def H1_coeff(t,args):
return exp(-((t-4)/2.0) ** 2)
H0 = np.pi*w * a.dag() *a
Hi= delta[x]*(a.dag())
H = [H0, [Hi,H1_coeff]]
result = mesolve(H, psi0, tlist, c_ops, [])
numer=expect(n,result.states)
print delta[x], "done"
return numer
Does anybody know what's wrong here?
I think you need to move the definition of H1_coeff outside of func2.

Resources