You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feature Request: Deepcopy of SecondQuantizedMolecule
At this time, the SecondQuantizedMolecule can't be deepcopied:
fromcopyimportdeepcopyfromtangeloimportSecondQuantizedMoleculexyz_H2=""" H 0. 0. 0.00 H 0. 0. 0.75"""mol=SecondQuantizedMolecule(xyz_H2)
deepcopy(mol)
outputs
Traceback (most recent call last):
File "/home/alex/Scratch/mo_coeff_bug.py", line 14, in<module>
deepcopy(mol)
File "/home/alex/.pyenv/versions/3.10.13/lib/python3.10/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/home/alex/.pyenv/versions/3.10.13/lib/python3.10/copy.py", line 271, in _reconstruct
state = deepcopy(state, memo)
File "/home/alex/.pyenv/versions/3.10.13/lib/python3.10/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/home/alex/.pyenv/versions/3.10.13/lib/python3.10/copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/alex/.pyenv/versions/3.10.13/lib/python3.10/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/home/alex/.pyenv/versions/3.10.13/lib/python3.10/copy.py", line 271, in _reconstruct
state = deepcopy(state, memo)
File "/home/alex/.pyenv/versions/3.10.13/lib/python3.10/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/home/alex/.pyenv/versions/3.10.13/lib/python3.10/copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/alex/.pyenv/versions/3.10.13/lib/python3.10/copy.py", line 161, in deepcopy
rv = reductor(4)
TypeError: cannot pickle 'module' object
This is not a critical bug at this moment, but it would be useful to be able to create a copy and update its attributes. For e.g.,
fromcopyimportcopyfromopenfermion.linalgimporteigenspectrumdefdoing_something_with_molecule(sqmol):
sqmol_copy=copy(sqmol)
# Doing awesome stuff with mo_coeff and creating new_mo_coeff.sqmol_copy.mo_coeff=new_coeffreturnsqmol_copyeigenvalues_original=eigenspectrum(mol.fermionic_hamiltonian)
updated_mol=doing_something_with_molecule(mol)
eigenvalues_verif=eigenspectrum(mol.fermionic_hamiltonian) # Should be the same as eigenvalues_original, but it is not.# Doing other stuff with updated_mol...
The function doing_something_with_molecule is changing the MO coefficients of the sqmol_copy, but as the copy is shallow, it is also changing the MO coefficients of the mol object. This can introduce unexpected behaviour, as I experienced when working with FNO -> the MO coefficients were bound to the active space selection, so the fermionic Hamiltonian computed after the doing_something_with_molecule call wasn't trowing an error, but was physically wrong.
The text was updated successfully, but these errors were encountered:
Feature Request: Deepcopy of SecondQuantizedMolecule
At this time, the
SecondQuantizedMolecule
can't be deepcopied:outputs
This is not a critical bug at this moment, but it would be useful to be able to create a copy and update its attributes. For e.g.,
The function
doing_something_with_molecule
is changing the MO coefficients of thesqmol_copy
, but as the copy is shallow, it is also changing the MO coefficients of themol
object. This can introduce unexpected behaviour, as I experienced when working with FNO -> the MO coefficients were bound to the active space selection, so the fermionic Hamiltonian computed after thedoing_something_with_molecule
call wasn't trowing an error, but was physically wrong.The text was updated successfully, but these errors were encountered: