Skip to content

Commit

Permalink
Merge pull request #569 from SRI-International/compiler-opt-changes-TL
Browse files Browse the repository at this point in the history
First cut at printing inverse circuit in method 3
  • Loading branch information
rtvuser1 authored Jul 10, 2024
2 parents 9f41ddf + bbd5235 commit 022808c
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions hamlib/qiskit/hamlib_simulation_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,17 @@

verbose = False

global_U = None
global_enc = None
global_ratio = None
global_rinst = None
global_h = 0.1
global_pbc_val = "pbc"

# Saved circuits and subcircuits for display
QC_ = None
QCI_ = None
QCD_ = None
HAM_ = None
EVO_ = None

Expand Down Expand Up @@ -175,7 +183,7 @@ def create_circuit(n_spins: int, time: float = 1, num_trotter_steps: int = 5, me
global global_h, global_pbc_val
global global_U, global_enc
global global_ratio, global_rinst
global QCI_
global QCI_, QCD_

# Replace placeholders with actual n_qubits value: n_spins
dataset_name_template = dataset_name_template.replace("{ratio}", str(global_ratio)).replace("{rinst}", str(global_rinst))
Expand All @@ -201,7 +209,7 @@ def create_circuit(n_spins: int, time: float = 1, num_trotter_steps: int = 5, me

# Build the evolution gate
# label = "e\u2071\u1D34\u1D57" # superscripted, but doesn't look good
evo_label = "e^iHt"
evo_label = "e^-iHt"
evo = PauliEvolutionGate(operator, time=time/num_trotter_steps, label=evo_label)

# Plug it into a circuit
Expand All @@ -223,7 +231,7 @@ def create_circuit(n_spins: int, time: float = 1, num_trotter_steps: int = 5, me

if method == 3:
# if you want to retun a circuit combined with the inverse
circuit_inverse = circuit_without_initial_state.inverse()
QCD_ = circuit_inverse = circuit_without_initial_state.inverse()
circuit.append(circuit_inverse,range(operator.num_qubits))

# if you only want to return the inverse circuit
Expand Down Expand Up @@ -326,14 +334,24 @@ def kernel_draw(hamiltonian: str = "hamlib", use_XX_YY_ZZ_gates: bool = False, m
print(QC_)

# create a small circuit, just to display this evolution subciruit structure
print(" Evolution Operator (e^iHt) =")
print(" Evolution Operator (e^-iHt) =")
qctt = QuantumCircuit(QC_.num_qubits)
qctt.append(EVO_, range(QC_.num_qubits))
print(transpile(qctt, optimization_level=3))

if QCI_ is not None:
print(f" Initial State {QCI_.name}:")
print(QCI_)

if QCD_ is not None:
print(f" Inverse State {QCD_.name}:")
print(QCD_)

# create a small circuit, just to display this inverse evolution subcircuit structure
print(" Inverse Evolution Operator (e^iHt) =")
qctt = QuantumCircuit(QC_.num_qubits)
qctt.append(EVO_.inverse(), range(QC_.num_qubits))
print(transpile(qctt, optimization_level=3))

else:
print(" ... circuit too large!")
Expand Down

0 comments on commit 022808c

Please sign in to comment.