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

Setting noise for local qasm simulator (c++) #537

Closed
chunfuchen opened this issue Jun 6, 2018 · 4 comments
Closed

Setting noise for local qasm simulator (c++) #537

chunfuchen opened this issue Jun 6, 2018 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@chunfuchen
Copy link
Contributor

Informations
local_qasm_simulator_cpp fails when setting particular noise params (the one copied from simulator readme.)
https://github.com/QISKit/qiskit-core/tree/master/src/qasm-simulator-cpp#example

  • QISKit (Python SDK) version: 0.5.3 and build from the master branch
  • Operating system: mac OS 10.13.3
  • Python version: 3.6.3

What is the current behavior?
c++ simulator fails with particular noise params setting. (Note that python simulator works well, and if I deleted U_error field, it works well, too.)

case 1 (installed from pip), trackback

Traceback (most recent call last):
  File "/Users/rchen/.pythonVirtualEnv/quantum/lib/python3.6/site-packages/qiskit/backends/local/localjob.py", line 66, in result
    return self._future.result(timeout=timeout)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/concurrent/futures/_base.py", line 432, in result
    return self.__get_result()
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/rchen/.pythonVirtualEnv/quantum/lib/python3.6/site-packages/qiskit/backends/local/qasm_simulator_cpp.py", line 90, in _run_job
    result = run(qobj, self._configuration['exe'])
  File "/Users/rchen/.pythonVirtualEnv/quantum/lib/python3.6/site-packages/qiskit/backends/local/qasm_simulator_cpp.py", line 235, in run
    return json.loads(sim_output, cls=QASMSimulatorDecoder)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py", line 367, in loads
    return cls(**kw).decode(s)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

case 2 (installed qiskit from the master branch)

Traceback (most recent call last):
  File "/Users/rchen/Developer/Quantum/qiskit-sdk-py/qiskit/_result.py", line 259, in get_counts
    return self.get_data(circuit_name)['counts']
  File "/Users/rchen/Developer/Quantum/qiskit-sdk-py/qiskit/_result.py", line 239, in get_data
    raise QISKitError('No data for circuit "{0}"'.format(circuit_name))
qiskit._qiskiterror.QISKitError: 'No data for circuit "circuit1"'

Steps to reproduce the problem

Here is the codes:

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.wrapper import available_backends, get_backend
from qiskit.wrapper import execute as q_execute

q = QuantumRegister(2, name='q')
c = ClassicalRegister(2, name='c')
qc = QuantumCircuit(q,c)

qc.h(q[0])
qc.h(q[1])
qc.cx(q[0], q[1])
qc.measure(q, c)
noise_params = {'U':
                        {'gate_time': 1,
                        'p_depol': 0.001,
                        'p_pauli': [0, 0, 0.01],
                        'U_error': [
                                [[1, 0], [0, 0]],
                                [[0, 0], [0.995004165, 0.099833417]]
                                ]
                        }
                    }
config = {"noise_params": noise_params}
ret = q_execute(qc, 'local_qasm_simulator_cpp', shots=1024, config=config)
ret = ret.result()
print(ret.get_counts())

What is the expected behavior?

Run without error.

Suggested solutions

No idea.

@chriseclectic
Copy link
Member

chriseclectic commented Jun 7, 2018

This is because the simulator checks if the U_error matrix is unitary and (should) raise an error if it isn't. In your example z = 0.995004165 + 1j * 0.099833417, and abs(z) = 0.99999999975862153, not 1.

If I change the noise params in your code to the following it runs:

z = 0.995004165 + 1j * 0.099833417
z = z / abs(z)
u_error = np.array([[1, 0], [0, z]])
noise_params = {'U':
                        {'gate_time': 1,
                        'p_depol': 0.001,
                        'p_pauli': [0, 0, 0.01],
                        'U_error': u_error
                        }
                    }

However there still seems to be a bug that the error that should be raised by the simulator isn't being caught and passed through to the results: If I run the compiled qojb directly from the command line it just appears to abort.

@diego-plan9 diego-plan9 added the bug Something isn't working label Jun 8, 2018
@chunfuchen
Copy link
Contributor Author

okay, I do not double check whether or not the U_error is a unitary matrix, I just copy and paste the example in the README.

Thanks.

@ajavadia
Copy link
Member

ajavadia commented Jun 17, 2018

So it seems like to close this issue, the following should be done:
a) the README should be updated to include the normalization.
b) the error raised by the simulator should be passed through to the result and available to the user.

@jaygambetta
Copy link
Member

closing as this is not part of terra anymore and will be documented in aer.

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

6 participants