3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

量子コンピュータAdvent Calendar 2018

Day 12

D-Waveクライアントライブラリのログを出力する

Last updated at Posted at 2019-01-01

たぶん公式ドキュメントにも載ってないと思うのでメモ。
環境変数 DWAVE_LOG_LEVELDEBUG もしくは TRACE を設定しておくと、 D-Wave のクライアントライブラリ dwave-cloud-client が D-Wave の REST API との通信ログ出力してくれて便利です。

実行例

環境変数設定して、

import os
os.environ["DWAVE_LOG_LEVEL"] = "TRACE"

EmbeddingComposite — dwave-system latest documentation
のサンプルコードを実行してみると、

from dwave.system.samplers import DWaveSampler
from dwave.system.composites import EmbeddingComposite
sampler = EmbeddingComposite(DWaveSampler())
h = {'a': -1., 'b': 2}
J = {('a', 'b'): 1.5}
response = sampler.sample_ising(h, J)

こんな感じのログが吐かれます。

2018-12-31 23:32:40,492 dwave.cloud.client DEBUG Config loaded: {'token': ...
2018-12-31 23:32:40,494 dwave.cloud.client DEBUG Final config used for qpu.Client(): {'token': ...
2018-12-31 23:32:40,494 dwave.cloud.client DEBUG Creating a client for endpoint: 'https://cloud.dwavesys.com/sapi'
2018-12-31 23:32:40,497 dwave.cloud.client DEBUG Looking for solver with name=None or features=None
2018-12-31 23:24:13,312 dwave.cloud.solver TRACE Encoded sample request: {"solver": "DW_2000Q_2_1", "data": {"format": "qp", "lin": ...
2018-12-31 23:24:13,314 dwave.cloud.solver DEBUG Submitting new problem to: DW_2000Q_2_1
2018-12-31 23:24:13,315 dwave.cloud.client DEBUG Submitting 1 problems
2018-12-31 23:24:13,739 dwave.cloud.client DEBUG Finished submitting 1 problems
2018-12-31 23:24:13,740 dwave.cloud.client TRACE Handling response: {'status': 'PENDING', 'earliest_estimated_completion': '2018-12-31T14:24:13.681834Z', 'solver': 'DW_2000Q_2_1', 'submitted_on': '2018-12-31T14:24:13.674010Z', 'latest_estimated_completion': '2018-12-31T14:24:13.786675Z', 'type': 'qubo', 'id': ...
...
2018-12-31 23:24:14,056 dwave.cloud.client TRACE Handling response: {'status': 'COMPLETED', 'earliest_estimated_completion': '2018-12-31T14:24:13.681834Z', 'solved_on': '2018-12-31T14:24:13.845923Z', 'solver': 'DW_2000Q_2_1', 'submitted_on': '2018-12-31T14:24:13.674010Z', 'answer': {'num_variables': 2048, 'format': ...
...

ライブラリの該当箇所

dwave-cloud-client/dwave/cloud/__init__.py で環境変数読んでいて、

def _apply_loglevel_from_env(logger):
    name = os.getenv('DWAVE_LOG_LEVEL') or ''
    if not name:
        return
    levels = {'debug': logging.DEBUG, 'trace': logging.TRACE}
    requested_level = levels.get(name.lower())
    if requested_level:
        logger.setLevel(requested_level)

dwave-cloud-client/dwave/cloud/solver.py などでロギングしています。

        _LOGGER.trace("Encoded sample request: %s", body)

実行環境

$ python --version
Python 3.6.6

$ pip list | grep -e dwave-cloud-client -e dwave-system
dwave-cloud-client  0.4.16    
dwave-system        0.5.4     
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?