Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial_state parameter yields an error #79

Closed
mdecandia opened this issue Mar 4, 2020 · 2 comments
Closed

initial_state parameter yields an error #79

mdecandia opened this issue Mar 4, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@mdecandia
Copy link
Member

mdecandia commented Mar 4, 2020

When submitting a problem that specifies an initial_state, the inspector fails to start up as the below error is thrown:

ERROR    dwave.inspector.server:app.py:1891 Exception on /api/problems/d6684f12-cc17-4ba3-a4bf-74c3e2dc31db [GET]
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    return self.finalize_request(rv)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 1967, in finalize_request
    response = self.make_response(rv)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/app.py", line 2111, in make_response
    rv = jsonify(rv)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/json/__init__.py", line 370, in jsonify
    dumps(data, indent=indent, separators=separators) + "\n",
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/json/__init__.py", line 211, in dumps
    rv = _json.dumps(obj, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/flask/json/__init__.py", line 100, in default
    return _json.JSONEncoder.default(self, o)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type int8 is not JSON serializable

The browser window shows a blue screen with Error: Unexpected token < in JSON at position 0
Example problem:

        h = {}
        J = {(0, 4): 1}

        # get solver properties
        anneal_offset_ranges = solver.properties['anneal_offset_ranges']
        num_qubits = solver.properties['num_qubits']
        anneal_offset = [0] * num_qubits

        for i in solver.nodes:
            anneal_offset[i] = anneal_offset_ranges[i][0]

        forward_answer = solver.sample_ising(h, J, annealing_time=25)
        i5 = int(5.0 / 95 * len(forward_answer.samples))
        initial = dict(zip(forward_answer.variables, forward_answer.sampleset._record[i5].sample))

        params = {
            "anneal_offsets": anneal_offset,
            "anneal_schedule": [[0.0, 1.0], [10.0, 1.0]],
            "h_gain_schedule": [[0.0, 1.0], [10.0, 1.0]],
            "initial_state": initial,
            "reinitialize_state": True
        }

        # sample
        response = solver.sample_ising(h, J, **params)

        # inspect
        dwave.inspector.show((h, J), response)
@fionahanington fionahanington added the bug Something isn't working label Mar 9, 2020
@randomir
Copy link
Member

The problem here is not with the initial_state per se, it's that numpy.ndarray is not JSON serializable by default -- and you're using it for (some) params.

A general fix will be with #81.

@randomir
Copy link
Member

randomir commented Jan 26, 2023

Fixed with #135.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants