Exemplo n.º 1
0
def show(*args, **kwargs):
    """Auto-detect and forward to the ``show_*`` optimal for the specified
    arguments.

    For description of accepted arguments, see of :func:`.show_qmi`,
    :func:`.show_bqm_response`, or :func:`.show_bqm_sampleset`.

    Note:
        Low-level data capture is enabled on `dwave.inspector` import. Data
        captured includes the full quantum machine instruction (QMI), QPU
        response, embedding context, warnings, and sampling parameters.

        If data capture is enabled prior to embedding/sampling, you need
        provide to :func:`~dwave.inspector.show` only a response or problem ID
        for QMI inspection or a :class:`~dimod.SampleSet` for logical problem
        and QMI inspection.

        If data capture is not enabled prior to embedding/sampling, provide
        all relevant data explicitly to :func:`~dwave.inspector.show`.

    Examples:

        This example shows ways to visualize just a QMI (not a logical problem)::

            show(response)
            show((h, J), response)
            show(Q, response)
            show('69ace80c-d3b1-448a-a028-b51b94f4a49d')

        This example visualizes a QMI and explicit embedding::

            show((h, J), response, dict(embedding=embedding, chain_strength=5))

        This example shows embedding and warnings read from the sampleset::

            show(bqm, sampleset)

        This example shows embedding and warnings read from a :class:`~dimod.SampleSet`,
        from which the logical problem is reconstructed::

            show(sampleset)

    """
    block = kwargs.pop('block', Block.ONCE)
    timeout = kwargs.pop('timeout', None)
    data = from_objects(*args, **kwargs)
    id_ = push_inspector_data(data)
    return open_problem(id_, block=block, timeout=timeout)
Exemplo n.º 2
0
    def test_from_objects(self, m1, m2, m3):
        # qmi
        self.assertEqual(from_objects(self.problem, self.response),
                         'qmi_response')
        self.assertEqual(from_objects(self.response, self.problem),
                         'qmi_response')
        self.assertEqual(
            from_objects(response=self.response, problem=self.problem),
            'qmi_response')
        self.assertEqual(
            from_objects(self.embedding_context,
                         response=self.response,
                         problem=self.problem), 'qmi_response')
        self.assertEqual(
            from_objects(self.bqm,
                         response=self.response,
                         problem=self.problem), 'qmi_response')
        self.assertEqual(from_objects({
            (0, 0): 1,
            (0, 1): 0
        }, self.response), 'qmi_response')

        # reconstruction directly from problem_id
        self.assertEqual(from_objects(self.response.id), 'qmi_response')

        # qmi takes precedence
        self.assertEqual(
            from_objects(self.bqm,
                         self.embedding_context,
                         response=self.response,
                         problem=self.problem), 'qmi_response')

        # bqm/response -> with problem_id in response ==> qmi takes precedence
        self.assertEqual(
            from_objects(self.response, self.bqm, self.embedding_context),
            'qmi_response')
        self.assertEqual(
            from_objects(self.embedding_context,
                         response=self.response,
                         bqm=self.bqm), 'qmi_response')
        self.assertEqual(
            from_objects(response=self.response,
                         bqm=self.bqm,
                         embedding_context=self.embedding_context),
            'qmi_response')

        # bqm/response -> without problem_id in response
        self.response.id = None
        self.assertEqual(
            from_objects(self.response, self.bqm, self.embedding_context),
            'bqm_response')
        self.assertEqual(
            from_objects(self.embedding_context,
                         response=self.response,
                         bqm=self.bqm), 'bqm_response')
        self.assertEqual(
            from_objects(response=self.response,
                         bqm=self.bqm,
                         embedding_context=self.embedding_context),
            'bqm_response')

        # bqm/sampleset
        sampler = MockDWaveSampler()
        sampleset = self.response.sampleset
        warnings = [{'message': 'test'}]
        self.assertEqual(from_objects(self.bqm, sampleset, sampler),
                         'bqm_sampleset')
        self.assertEqual(from_objects(self.bqm, sampleset, sampler, warnings),
                         'bqm_sampleset')
        self.assertEqual(
            from_objects(sampler, warnings, sampleset=sampleset, bqm=self.bqm),
            'bqm_sampleset')