diff --git a/pyqrack/qrack_circuit.py b/pyqrack/qrack_circuit.py index 0acdef2..539fe58 100644 --- a/pyqrack/qrack_circuit.py +++ b/pyqrack/qrack_circuit.py @@ -74,12 +74,12 @@ def _mtrx_to_u4(m): nrm = abs(m[0]) if (nrm * nrm) < sys.float_info.epsilon: phase = 1.0 + 0.0j - th = math.pi / 2; + th = math.pi; else: phase = m[0] / nrm if nrm > 1.0: nrm = 1.0 - th = math.acos(nrm) + th = 2 * math.acos(nrm) nrm1 = abs(m[1]) nrm2 = abs(m[2]) @@ -107,13 +107,16 @@ def _u3_to_mtrx(params): return [c + 0j, -el * s, ep * s, ep * el * c] def _u4_to_mtrx(params): - m = _u3_to_mtrx(params) + m = QrackCircuit._u3_to_mtrx(params) g = np.exp(1j * float(params[3])) for i in range(4): m[i] *= g return m + def _make_mtrx_unitary(m): + return QrackCircuit._u4_to_mtrx(QrackCircuit._mtrx_to_u4(m)) + def clone(self): """Make a new circuit that is an exact clone of this circuit @@ -337,6 +340,7 @@ def string_to_qiskit_circuit(circ_string): num_gates = int(tokens[i]) i += 1 + identity = np.eye(2, dtype=complex) for g in range(num_gates): target = int(tokens[i]) i += 1 @@ -361,6 +365,8 @@ def string_to_qiskit_circuit(circ_string): mtrx.append(float(amp[0]) + float(amp[1])*1j) i += 1 + mtrx = QrackCircuit._make_mtrx_unitary(mtrx) + op = np.eye(2, dtype=complex) op[0][0] = mtrx[0] op[0][1] = mtrx[1] @@ -369,14 +375,13 @@ def string_to_qiskit_circuit(circ_string): payloads[key] = op - identity = np.eye(2, dtype=complex) gate_list=[] for j in range(1 << control_count): if j in payloads: gate_list.append(payloads[j]) else: gate_list.append(identity) - circ.append(UCGate(gate_list), controls + [target]) + circ.append(UCGate(gate_list), [target] + controls) return circ diff --git a/setup.py b/setup.py index f1baa07..5583780 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup -VERSION = "1.34.5" +VERSION = "1.34.6" # Read long description from README. README_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'README.md')