При экспорте файла SVG невозможно получить доступ к серверу Orca - PullRequest
0 голосов
/ 31 октября 2018

Я пытаюсь экспортировать гистограмму на графике в файл SVG. Это работает хорошо, пока я не попытаюсь обработать большое количество точек данных. Приведенный ниже код работает для 1000000 моделируемых точек данных, но разбивается на 10000000 точек.

import plotly.graph_objs as go
import plotly.io as pio

import numpy as np

# simulate small input data: this works
# data_1 = list(np.random.randint(0, 2**63, 1_000_000))
# data_2 = list(np.random.randint(0, 2**63, 1_000_000))

# simulate larger input data: this works
data_1 = list(np.random.randint(0, 2**63, 10_000_000))
data_2 = list(np.random.randint(0, 2**63, 10_000_000))

# assemble two histograms and plot them into one figure
g1 = go.Histogram(x=data_1, opacity=0.75)
g2 = go.Histogram(x=data_2, opacity=0.75)
data = [g1, g2]
figure = go.Figure(data=data)

# write the plot as html, this works
plotly.offline.plot(figure, auto_open=True, filename="/tmp/foo.html")

# writing the plot as svg (or png) file doesn't work
pio.write_image(figure, "/tmp/foo.svg")

При запуске с 10000000 смоделированных точек данных я получаю следующее сообщение об ошибке (полная трассировка стека ниже):

ValueError: 
For some reason plotly.py was unable to communicate with the
local orca server process, even though the server process seems to be running.

Проблема в том, что с моим настоящим набором данных я не могу просто уменьшить количество точек. Кто-нибудь знает, что здесь происходит и как это исправить?

Это немного похоже на тайм-аут сервера orca, потому что вычисление занимает слишком много времени, но длительность тайм-аута для сервера (по умолчанию) установлена ​​на None, т.е. нет тайм-аута. Я также пытался изменить порт сервера (как предложено здесь ), но это не помогло.


Дополнительная информация

Я использую график 3.3.0 и orca 1.1.1. Моя конфигурация orca (print(pio.orca.config)) выглядит так:

orca configuration
------------------
    executable: orca
    port: None
    timeout: None
    default_width: None
    default_height: None
    default_scale: 1
    default_format: png
    mathjax: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js
    topojson: None
    mapbox_access_token: None

constants
---------
    plotlyjs: /home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/plotly/package_data/plotly.min.js 
    config_file: /home/m00am/.plotly/.orca

Полная трассировка стека

Traceback (most recent call last):
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 356, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/http/client.py", line 1065, in _send_output
    self.send(chunk)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/http/client.py", line 986, in send
    self.sock.sendall(data)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 649, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/packages/urllib3/util/retry.py", line 347, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/packages/urllib3/packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 356, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/http/client.py", line 1065, in _send_output
    self.send(chunk)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/http/client.py", line 986, in send
    self.sock.sendall(data)
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/plotly/io/_orca.py", line 1305, in to_image
    height=height)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/retrying.py", line 49, in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/retrying.py", line 212, in call
    raise attempt.get()
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/retrying.py", line 247, in get
    six.reraise(self.value[0], self.value[1], self.value[2])
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/six.py", line 693, in reraise
    raise value
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/retrying.py", line 200, in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/plotly/io/_orca.py", line 1201, in request_image_with_retrying
    response = requests.post(server_url + '/', data=json_str)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/api.py", line 110, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/api.py", line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/requests/adapters.py", line 473, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "bar.py", line 107, in <module>
    distribution_comparison()
  File "bar.py", line 97, in distribution_comparison
    pio.write_image(figure, "/tmp/foo.png")
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/plotly/io/_orca.py", line 1492, in write_image
    validate=validate)
  File "/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/plotly/io/_orca.py", line 1322, in to_image
    """.format(info=status_str))
ValueError: 
For some reason plotly.py was unable to communicate with the
local orca server process, even though the server process seems to be running.

Please review the process and connection information below:

orca status
-----------
    state: running
    executable: /home/m00am/miniconda3/envs/my_conda_env/bin/orca
    version: 1.1.1
    port: 40887
    pid: 3277
    command: ['/home/m00am/miniconda3/envs/my_conda_env/bin/orca', 'serve', '-p', '40887', '--plotly', '/home/m00am/miniconda3/envs/my_conda_env/lib/python3.6/site-packages/plotly/package_data/plotly.min.js', '--graph-only', '--mathjax', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js']

1 Ответ

0 голосов
/ 31 октября 2018

Это похоже на проблему тайм-аута, к сожалению, параметр timeout в конфигурации orca не имеет ничего общего с тайм-аутом запроса, который, по-видимому, жестко задан в источниках сервера *1003*. Вы можете попробовать построить orca с большим requestTimeout или отправить вопрос в репо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...