Skip to content

Commit

Permalink
Merge branch 'main' into cpu-only
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Dec 7, 2024
2 parents 980d7e0 + a96ad11 commit 26bca88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions pyqrack/qrack_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 26bca88

Please sign in to comment.