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

First cut at printing inverse circuit in method 3 #569

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading