Skip to content

Commit

Permalink
add spin to adapt_ansatz arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesB-1qbit committed Nov 1, 2022
1 parent dc0e95e commit 0aea371
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tangelo/algorithms/variational/adapt_vqe_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def build(self):
# Build / set ansatz circuit.
ansatz_options = {"mapping": self.qubit_mapping, "up_then_down": self.up_then_down,
"reference_state": "HF" if self.ref_state is None else "zero"}
self.ansatz = ADAPTAnsatz(self.n_spinorbitals, self.n_electrons, ansatz_options)
self.ansatz = ADAPTAnsatz(self.n_spinorbitals, self.n_electrons, self.spin, ansatz_options)

# Build underlying VQE solver. Options remain consistent throughout the ADAPT cycles.
self.vqe_options = {"qubit_hamiltonian": self.qubit_hamiltonian,
Expand Down
6 changes: 4 additions & 2 deletions tangelo/toolboxes/ansatz_generator/adapt_ansatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ADAPTAnsatz(Ansatz):
Attributes:
n_spinorbitals (int): Number of spin orbitals in a given basis.
n_electrons (int): Number of electrons.
spin (int): Spin of system.
operators (list of QubitOperator): List of operators to consider at the
construction step. Can be useful for restarting computation.
ferm_operators (list of FermionOperator): Same as operators, but in
Expand All @@ -43,7 +44,7 @@ class ADAPTAnsatz(Ansatz):
circuit (Circuit): Quantum circuit defined by a list of Gates.
"""

def __init__(self, n_spinorbitals, n_electrons, ansatz_options=None):
def __init__(self, n_spinorbitals, n_electrons, spin, ansatz_options=None):
default_options = {"operators": list(), "ferm_operators": list(),
"mapping": "jw", "up_then_down": False,
"reference_state": "HF"}
Expand All @@ -60,6 +61,7 @@ def __init__(self, n_spinorbitals, n_electrons, ansatz_options=None):

self.n_spinorbitals = n_spinorbitals
self.n_electrons = n_electrons
self.spin = spin

self.var_params = None
self.circuit = None
Expand Down Expand Up @@ -105,7 +107,7 @@ def update_var_params(self, var_params):
def prepare_reference_state(self):
"""Prepare a circuit generating the HF reference state."""
if self.reference_state.upper() == "HF":
return get_reference_circuit(n_spinorbitals=self.n_spinorbitals, n_electrons=self.n_electrons, mapping=self.mapping, up_then_down=self.up_then_down)
return get_reference_circuit(n_spinorbitals=self.n_spinorbitals, n_electrons=self.n_electrons, mapping=self.mapping, up_then_down=self.up_then_down, spin=self.spin)
else:
return Circuit(n_qubits=get_qubit_number(self.mapping, self.n_spinorbitals))

Expand Down

0 comments on commit 0aea371

Please sign in to comment.