Skip to content

Commit

Permalink
Add option to fix value associated with the HF bitstring
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb-johnson committed Dec 6, 2022
1 parent 5b0b10a commit 2802bb6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ class EntanglementForgingAnsatz:
used for the second subsystem in the Schmidt decomposition. Must be the
same shape as bitstrings_u. If not provided, then bitstrings_u is used
for both subsystems.
- fix_first_bitstring (bool): Fix Hartree-Fock value for corresponding
bitstring circuit
"""

def __init__(
self,
circuit_u: QuantumCircuit,
bitstrings_u: List[Bitstring],
bitstrings_v: Optional[List[Bitstring]] = None,
fix_first_bitstring: bool = False,
):
"""
Assign the necessary member variables and check for shaping errors.
Expand All @@ -71,6 +74,8 @@ def __init__(
used for the second subsystem in the Schmidt decomposition. Must be the
same shape as bitstrings_u. If not provided, then bitstrings_u is used
for both subsystems.
- fix_first_bitstring (bool): Fix Hartree-Fock value for corresponding
bitstring circuit
Returns:
- None
Expand Down Expand Up @@ -99,6 +104,7 @@ def __init__(
self._circuit_u: QuantumCircuit = circuit_u
self._bitstrings_u: List[Bitstring] = bitstrings_u
self._bitstrings_v: List[Bitstring] = bitstrings_v or bitstrings_u
self._fix_first_bitstring: bool = fix_first_bitstring

@property
def circuit_u(self) -> QuantumCircuit:
Expand Down Expand Up @@ -130,6 +136,16 @@ def bitstrings_v(self) -> List[Bitstring]:
"""
return self._bitstrings_v

@property
def fix_first_bitstring(self) -> bool:
"""
Property function for the fix_first_bitstring field.
Returns:
- (bool): fix the Hartree-Fock bitstring values
"""
return self._fix_first_bitstring

@property
def bitstrings_are_symmetric(self) -> bool:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,6 @@ class EntanglementForgingKnitter:
ansatz parameters and Schmidt coefficients.
"""

# Attributes:
# - _ansatz (EntanglementForgingAnsatz): the ansatz containing the
# information for the circuit structure and bitstrings to be used
# - _backend_names (List[str]): the names of the backends to use
# - _service (QiskitRuntimeService): the service used to access backends
# - _tensor_circuits_u (List[QuantumCircuit]): the set of circuits used for the first
# operator that have the same Schmidt values
# - _superposition_circuits_u (List[QuantumCircuit]): the set of circuits used for
# the first operator that have different Schmidt values
# - _tensor_circuits_v (List[QuantumCircuit]): the set of circuits used for the second
# operator that have the same Schmidt values
# - _superposition_circuits_v (List[QuantumCircuit]): the set of circuits used for
# the second operator that have different Schmidt values

def __init__(
self,
ansatz: EntanglementForgingAnsatz,
Expand Down Expand Up @@ -100,7 +86,9 @@ def __init__(
(
self._tensor_circuits_u,
self._superposition_circuits_u,
) = _construct_stateprep_circuits(self._ansatz.bitstrings_u)
) = _construct_stateprep_circuits(
self._ansatz.bitstrings_u, fix_first_bitstring=self._ansatz.fix_first_bitstring
)
if self._ansatz.bitstrings_are_symmetric:
self._tensor_circuits_v, self._superposition_circuits_v = (
self._tensor_circuits_u,
Expand All @@ -111,7 +99,8 @@ def __init__(
self._tensor_circuits_v,
self._superposition_circuits_v,
) = _construct_stateprep_circuits(
self._ansatz.bitstrings_v # type: ignore
self._ansatz.bitstrings_v, # type: ignore
fix_first_bitstring=self._ansatz.fix_first_bitstring,
)

@property
Expand Down Expand Up @@ -469,6 +458,7 @@ def close_sessions(self) -> None:
def _construct_stateprep_circuits(
bitstrings: List[Bitstring],
subsystem_id: Optional[str] = None,
fix_first_bitstring: bool = False,
) -> Tuple[List[QuantumCircuit], List[QuantumCircuit]]: # noqa: D301
r"""Prepare all circuits.
Expand Down Expand Up @@ -537,6 +527,7 @@ def _construct_stateprep_circuits(

if subsystem_id is None:
subsystem_id = "u"

# If the spin-up and spin-down spin orbitals are together a 2*N qubit system,
# the bitstring should be N bits long.
bitstring_array = np.asarray(bitstrings)
Expand All @@ -545,6 +536,11 @@ def _construct_stateprep_circuits(
for bs_idx, bs in enumerate(bitstring_array)
]

if fix_first_bitstring:
# Drops the HF bitstring, which is assumed to be first,
# Generally, the ansatze should be designed to leave it unchanged
tensor_prep_circuits = tensor_prep_circuits[1:]

superpos_prep_circuits = []
# Create superposition circuits for each bitstring pair
for bs1_idx, bs1 in enumerate(bitstring_array):
Expand Down

0 comments on commit 2802bb6

Please sign in to comment.