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 6, 2024
2 parents 1e536bf + 4c7fecd commit 62d4d29
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions pyqrack/qrack_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
try:
from qiskit.circuit.quantumcircuit import QuantumCircuit
from qiskit.compiler.transpiler import transpile
from qiskit.circuit.library import UnitaryGate
from qiskit.circuit.library import UCGate
import numpy as np
import cmath
import math
import sys
except ImportError:
Expand Down Expand Up @@ -362,29 +361,22 @@ def string_to_qiskit_circuit(circ_string):
mtrx.append(float(amp[0]) + float(amp[1])*1j)
i += 1

payloads[key] = mtrx
op = np.eye(2, dtype=complex)
op[0][0] = mtrx[0]
op[0][1] = mtrx[1]
op[1][0] = mtrx[2]
op[1][1] = mtrx[3]

payloads[key] = op

gate_list=[]
control_pow = 1 << control_count
for c, p in payloads.items():
if control_count > 0:
op = np.eye(1 << (control_count + 1), dtype=complex)
q = c << 1
op[q][q] = p[0]
op[q][q + 1] = p[1]
op[q + 1][q] = p[2]
op[q + 1][q + 1] = p[3]
circ.append(
UnitaryGate(op, check_input=False),
[target] + controls
)
for j in range(control_pow):
if j in payloads:
gate_list.append(payloads[j])
else:
op = np.zeros((2,2), dtype=complex)
op[0][0] = p[0]
op[0][1] = p[1]
op[1][0] = p[2]
op[1][1] = p[3]

circ.append(UnitaryGate(op, check_input=False), [target])
gate_list.append(np.array([[1, 0],[0, 1]]))
circ.append(UCGate(gate_list), controls + [target])

return circ

Expand Down

0 comments on commit 62d4d29

Please sign in to comment.