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

"math domain error" in mapping #111

Closed
1ucian0 opened this issue Oct 9, 2017 · 7 comments
Closed

"math domain error" in mapping #111

1ucian0 opened this issue Oct 9, 2017 · 7 comments
Assignees

Comments

@1ucian0
Copy link
Member

1ucian0 commented Oct 9, 2017

Current Behavior

The attached fuzz_reccztqq.txt triggers a ValueError: math domain error exception when executed with the mapping {0: [2], 1: [2], 2: [3], 3: []}:

from qiskit import QuantumProgram
qp = QuantumProgram()
qp.load_qasm_file("fuzz_reccztqq.txt", name='test')
qp.execute(["test"], backend="local_qasm_simulator", coupling_map={0: [2], 1: [2], 2: [3], 3: []})

Expected Behavior

It is my understanding that the program should execute just like as when there is no map restriction:

from qiskit import QuantumProgram
qp = QuantumProgram()
qp.load_qasm_file("fuzz_reccztqq.txt", name='test')
qp.execute(["test"], backend="local_qasm_simulator", coupling_map=None)

The attached example was generated by a fuzzer. It could be the current behavior is the expected. My apologies in that case...

@awcross1 awcross1 self-assigned this Oct 30, 2017
@awcross1
Copy link
Member

awcross1 commented Nov 1, 2017

This is due to numerical error in the argument of acos in yzy_to_zyz. For example, math.sin(math.pi/2) * math.cos(math.pi/4) / math.sin(math.pi/4) = 1.0000000000000002 > 1. One solution is to round the argument.

@1ucian0
Copy link
Member Author

1ucian0 commented Nov 1, 2017

One option is to round, but that might add errors after several computations. I suggest to move to symbolic computation instead of flouting point math to avoid this issue:

> import sympy
> sympy.sin(sympy.pi/2) * sympy.cos(sympy.pi/4) / sympy.sin(sympy.pi/4)
< 1

Comments?

@dcmckayibm
Copy link
Member

I think @awcross1 was giving an example where it fails, but it general the inputs are not symbolic they are floats.

@1ucian0
Copy link
Member Author

1ucian0 commented Nov 2, 2017

The particular case in yzy_to_zyz, can be solved symbolically. There are several other points in the mapper where math is used, that can be easily be replaced with sympy.

I'm not sure what you mean. In situations where user code has floats, that error is introduced by the user and we can represent exactly that error without adding more, using Decimal in the parser.

My point is, when possible, we should operate with symbols to avoid adding error.

@awcross1
Copy link
Member

awcross1 commented Nov 2, 2017

Thanks Luciano, I think it is worth investigating using symbols.

@awcross1
Copy link
Member

awcross1 commented Nov 4, 2017

Here is a self-contained test case from @dcmckayibm that triggers the error

from qiskit import QuantumProgram
import numpy as np

coupling_map_test = {0:[0]}
qp = QuantumProgram()
qr = qp.create_quantum_register('q', 1)
cr = qp.create_classical_register('c', 1)
qc = qp.create_circuit('qc1', qregisters=[qr], cregisters=[cr])
qc.u2(np.pi/2, 0, qr[0])
qc.u3(np.pi/2, np.pi/2, 0.0, qr[0])
qp.compile('qc1', coupling_map=coupling_map_test)

@1ucian0 1ucian0 mentioned this issue Nov 16, 2017
@diego-plan9
Copy link
Member

Closing the issue, as it was fixed by #151 - thanks Luciano!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants