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

fixing error in the initialization of binary hamiltonians #351

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/tequila/grouping/binary_rep.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def init_from_qubit_hamiltonian(cls, hamiltonian: QubitHamiltonian, n_qubits=Non
del Hof.terms[()]
hamiltonian = QubitHamiltonian.from_openfermion(Hof)
if n_qubits is None:
n_qubits = hamiltonian.n_qubits
n_qubits = max(hamiltonian.qubits)+1
binary_terms = [
BinaryPauliString(
p.binary(n_qubits).binary,
Expand Down
12 changes: 9 additions & 3 deletions src/tequila/quantumchemistry/qc_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,8 @@ def make_uccsd_ansatz(self, trotter_steps: int = 1,
factor = 1.0 / trotter_steps
for step in range(trotter_steps):
for idx, angle in indices.items():
UCCSD += self.make_excitation_gate(indices=idx, angle=factor * angle)
converted = [(idx[2 * i], idx[2 * i + 1]) for i in range(len(idx) // 2)]
UCCSD += self.make_excitation_gate(indices=converted, angle=factor * angle)
if hasattr(initial_amplitudes,
"lower") and initial_amplitudes.lower() == "mp2" and parametrized and add_singles:
# mp2 has no singles, need to initialize them here (if not parametrized initializling as 0.0 makes no sense though)
Expand Down Expand Up @@ -1722,7 +1723,7 @@ def rdm2(self):

def compute_rdms(self, U: QCircuit = None, variables: Variables = None, spin_free: bool = True,
get_rdm1: bool = True, get_rdm2: bool = True, ordering="dirac", use_hcb: bool = False,
rdm_trafo: QubitHamiltonian = None):
rdm_trafo: QubitHamiltonian = None, decompose=None):
"""
Computes the one- and two-particle reduced density matrices (rdm1 and rdm2) given
a unitary U. This method uses the standard ordering in physics as denoted below.
Expand Down Expand Up @@ -2000,7 +2001,12 @@ def _build_2bdy_operators_hcb() -> list:

# Compute expected values
if rdm_trafo is None:
evals = simulate(ExpectationValue(H=qops, U=U, shape=[len(qops)]), variables=variables)
if decompose is not None:
print("MANIPULATED")
X = decompose(H=qops, U=U)
evals = simulate(X, variables=variables)
else:
evals = simulate(ExpectationValue(H=qops, U=U, shape=[len(qops)]), variables=variables)
else:
qops = [rdm_trafo.dagger()*qops[i]*rdm_trafo for i in range(len(qops))]
evals = simulate(ExpectationValue(H=qops, U=U, shape=[len(qops)]), variables=variables)
Expand Down
Loading