Skip to content

Commit

Permalink
Add the shallow copy method in the base class StreamObject
Browse files Browse the repository at this point in the history
Remove copy statements in mcscf modules
  • Loading branch information
sunqm committed Sep 10, 2023
1 parent ed48497 commit deae6e0
Show file tree
Hide file tree
Showing 83 changed files with 145 additions and 227 deletions.
3 changes: 1 addition & 2 deletions pyscf/agf2/ragf2.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,7 @@ def density_fit(self, auxbasis=None, with_df=None):
myagf2.with_df = with_df

if auxbasis is not None and myagf2.with_df.auxbasis != auxbasis:
import copy
myagf2.with_df = copy.copy(myagf2.with_df)
myagf2.with_df = myagf2.with_df.copy()
myagf2.with_df.auxbasis = auxbasis

return myagf2
Expand Down
3 changes: 1 addition & 2 deletions pyscf/agf2/uagf2.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,7 @@ def density_fit(self, auxbasis=None, with_df=None):
myagf2.with_df = with_df

if auxbasis is not None and myagf2.with_df.auxbasis != auxbasis:
import copy
myagf2.with_df = copy.copy(myagf2.with_df)
myagf2.with_df = myagf2.with_df.copy()
myagf2.with_df.auxbasis = auxbasis

return myagf2
Expand Down
3 changes: 1 addition & 2 deletions pyscf/cc/ccsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1355,8 +1355,7 @@ def density_fit(self, auxbasis=None, with_df=None):
if with_df is not None:
mycc.with_df = with_df
if mycc.with_df.auxbasis != auxbasis:
import copy
mycc.with_df = copy.copy(mycc.with_df)
mycc.with_df = mycc.with_df.copy()
mycc.with_df.auxbasis = auxbasis
return mycc

Expand Down
3 changes: 1 addition & 2 deletions pyscf/cc/test/test_ccsd_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import copy
import tempfile
import unittest
import numpy
Expand Down Expand Up @@ -114,7 +113,7 @@ def test_ccsd(self):

def test_restart(self):
ftmp = tempfile.NamedTemporaryFile()
cc1 = copy.copy(mycc)
cc1 = mycc.copy()
cc1.max_cycle = 5
cc1.solve_lambda()
l1ref = cc1.l1
Expand Down
3 changes: 1 addition & 2 deletions pyscf/cc/test/test_dfccsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.

import unittest
import copy
import numpy
from functools import reduce

Expand All @@ -24,7 +23,7 @@
from pyscf.cc import dfccsd, eom_rccsd

def make_mycc1():
mf1 = copy.copy(mf)
mf1 = mf.copy()
no = mol.nelectron // 2
n = mol.nao_nr()
nv = n - no
Expand Down
1 change: 0 additions & 1 deletion pyscf/cc/test/test_eom_gccsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.

import unittest
import copy
import numpy
from functools import reduce

Expand Down
4 changes: 2 additions & 2 deletions pyscf/cc/test/test_eom_rccsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pyscf.cc import ccsd, rccsd, eom_rccsd, rintermediates, gintermediates

def make_mycc1():
mf1 = copy.copy(mf)
mf1 = mf.copy()
no = mol.nelectron // 2
n = mol.nao_nr()
nv = n - no
Expand Down Expand Up @@ -67,7 +67,7 @@ def setUpModule():
mf1, mycc1, eris1 = make_mycc1()
no, nv = mycc1.t1.shape

mycci = copy.copy(mycc1)
mycci = mycc1.copy()
erisi = copy.copy(eris1)
erisi.oooo = eris1.oooo + numpy.sin(eris1.oooo)*1j
erisi.oooo = erisi.oooo + erisi.oooo.conj().transpose(1,0,3,2)
Expand Down
11 changes: 5 additions & 6 deletions pyscf/cc/test/test_eom_uccsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import copy
import unittest
import numpy
import numpy as np
Expand Down Expand Up @@ -47,7 +46,7 @@ def setUpModule():
mol1.spin = 2
mol1.build()
mf0 = scf.UHF(mol1).run(conv_tol=1e-12)
mf1 = copy.copy(mf0)
mf1 = mf0.copy()

nocca, noccb = mol1.nelec
nmo = mol1.nao_nr()
Expand Down Expand Up @@ -218,7 +217,7 @@ def test_ucc_eomee_ccsd_matvec(self):
self.assertAlmostEqual(float(abs(gr2-uee1.spatial2spin(r2, orbspin)).max()), 0, 9)
self.assertAlmostEqual(lib.fp(vec1), 49.499911123484523, 9)

ucc2 = copy.copy(ucc1)
ucc2 = ucc1.copy()
ucc2.direct = True
uee1 = eom_uccsd.EOMEESpinKeep(ucc2)
vec1 = uee1.matvec(vec)
Expand Down Expand Up @@ -293,7 +292,7 @@ def test_ucc_eomsf_ccsd_matvec(self):
self.assertAlmostEqual(float(abs(gr1-myeom.spatial2spin(v1, orbspin)).max()), 0, 9)
self.assertAlmostEqual(float(abs(gr2-myeom.spatial2spin(v2, orbspin)).max()), 0, 9)

ucc2 = copy.copy(ucc1)
ucc2 = ucc1.copy()
ucc2.direct = True
myeom = eom_uccsd.EOMEESpinFlip(ucc2)
vec1 = myeom.matvec(vec)
Expand Down Expand Up @@ -322,7 +321,7 @@ def test_ucc_eomip_matvec(self):
self.assertAlmostEqual(float(abs(gr1-myeom.spatial2spin(v1, orbspin)).max()), 0, 9)
self.assertAlmostEqual(float(abs(gr2-myeom.spatial2spin(v2, orbspin)).max()), 0, 9)

ucc2 = copy.copy(ucc1)
ucc2 = ucc1.copy()
ucc2.direct = True
myeom = eom_uccsd.EOMIP(ucc2)
vec1 = myeom.matvec(vec)
Expand Down Expand Up @@ -351,7 +350,7 @@ def test_ucc_eomea_matvec(self):
self.assertAlmostEqual(float(abs(gr1-myeom.spatial2spin(v1, orbspin)).max()), 0, 9)
self.assertAlmostEqual(float(abs(gr2-myeom.spatial2spin(v2, orbspin)).max()), 0, 9)

ucc2 = copy.copy(ucc1)
ucc2 = ucc1.copy()
ucc2.direct = True
myeom = eom_uccsd.EOMEA(ucc2)
vec1 = myeom.matvec(vec)
Expand Down
5 changes: 2 additions & 3 deletions pyscf/cc/test/test_gccsd_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import unittest
import numpy
import copy
from functools import reduce

from pyscf import gto, scf, lib, symm
Expand All @@ -36,7 +35,7 @@ def setUpModule():
mol.basis = '3-21g'
mol.symmetry = 'C2v'
mol.build()
mol1 = copy.copy(mol)
mol1 = mol.copy()
mol1.symmetry = False

mf = scf.UHF(mol1).run(conv_tol=1e-14)
Expand All @@ -53,7 +52,7 @@ def test_gccsd_t_compare_uccsd_t(self):
self.assertAlmostEqual(myucc.ccsd_t(), mygcc.ccsd_t(t1=None), 7)

def test_gccsd_t(self):
mf1 = copy.copy(mf)
mf1 = mf.copy()
nao, nmo = mf.mo_coeff[0].shape
numpy.random.seed(10)
mf1.mo_coeff = numpy.random.random((2,nao,nmo))
Expand Down
6 changes: 3 additions & 3 deletions pyscf/cc/test/test_rccsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def ao2mofn(mos):
self.assertAlmostEqual(abs(eris1.vvvv.imag-eris.vvvv).max(), 0, 11)

def test_dump_chk(self):
cc1 = copy.copy(mycc)
cc1 = mycc.copy()
cc1.nmo = mf.mo_energy.size
cc1.nocc = mol.nelectron // 2
cc1.dump_chk()
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_vector_size(self):
self.assertEqual(mycc.vector_size(), 860)

def test_rccsd_frozen(self):
cc1 = copy.copy(mycc)
cc1 = mycc.copy()
cc1.frozen = 1
self.assertEqual(cc1.nmo, 12)
self.assertEqual(cc1.nocc, 4)
Expand Down Expand Up @@ -383,7 +383,7 @@ def test_add_vvvv(self):
nocc, nvir = t1.shape
tau = t2 + numpy.einsum('ia,jb->ijab', t1, t1)
eris1 = copy.copy(eris)
mycc1 = copy.copy(mycc)
mycc1 = mycc.copy()
ovvv = eris1.get_ovvv()
tmp = -numpy.einsum('ijcd,ka,kdcb->ijba', tau, t1, ovvv)
t2a = tmp + tmp.transpose(1,0,3,2)
Expand Down
3 changes: 1 addition & 2 deletions pyscf/cc/test/test_rccsd_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import copy
import unittest
import numpy
import numpy as np
Expand Down Expand Up @@ -170,7 +169,7 @@ def test_rdm(self):
self.assertAlmostEqual(e1, mycc.e_tot, 6)

d1 = ccsd_rdm._gamma1_intermediates(mycc, mycc.t1, mycc.t2, mycc.l1, mycc.l2)
mycc1 = copy.copy(mycc)
mycc1 = mycc.copy()
mycc1.max_memory = 0
d2 = ccsd_rdm._gamma2_intermediates(mycc1, mycc.t1, mycc.t2, mycc.l1, mycc.l2, True)
dm2 = ccsd_rdm._make_rdm2(mycc, d1, d2, with_dm1=True, with_frozen=True)
Expand Down
2 changes: 1 addition & 1 deletion pyscf/cc/test/test_uccsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def test_amplitudes_from_rccsd(self):
self.assertAlmostEqual(abs(t2[2]-myucc.t2[2]).max(), 0, 5)

def test_uccsd_frozen(self):
ucc1 = copy.copy(myucc)
ucc1 = myucc.copy()
ucc1.frozen = 1
self.assertEqual(ucc1.nmo, (12,12))
self.assertEqual(ucc1.nocc, (4,4))
Expand Down
5 changes: 2 additions & 3 deletions pyscf/cc/test/test_uccsd_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import unittest
import numpy
import copy
from functools import reduce

from pyscf import gto, scf, lib, symm
Expand Down Expand Up @@ -43,7 +42,7 @@ def setUpModule():
mol.basis = '3-21g'
mol.symmetry = 'C2v'
mol.build()
mol1 = copy.copy(mol)
mol1 = mol.copy()
mol1.symmetry = False

mf = scf.UHF(mol1).run(conv_tol=1e-14)
Expand All @@ -58,7 +57,7 @@ def tearDownModule():

class KnownValues(unittest.TestCase):
def test_uccsd_t(self):
mf1 = copy.copy(mf)
mf1 = mf.copy()
nao, nmo = mf.mo_coeff[0].shape
numpy.random.seed(10)
mf1.mo_coeff = numpy.random.random((2,nao,nmo)) - .5
Expand Down
3 changes: 1 addition & 2 deletions pyscf/df/addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#

import sys
import copy
import numpy
from pyscf.lib import logger
from pyscf import gto
Expand Down Expand Up @@ -204,7 +203,7 @@ def make_auxmol(mol, auxbasis=None):
See also the paper JCTC, 13, 554 about generating auxiliary fitting basis.
'''
pmol = copy.copy(mol) # just need shallow copy
pmol = mol.copy(deep=False)

if auxbasis is None:
auxbasis = make_auxbasis(mol)
Expand Down
3 changes: 1 addition & 2 deletions pyscf/df/df.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
'''


import copy
import tempfile
import contextlib
import numpy
Expand Down Expand Up @@ -277,7 +276,7 @@ def range_coulomb(self, omega):
if key in self._rsh_df:
rsh_df = self._rsh_df[key]
else:
rsh_df = self._rsh_df[key] = copy.copy(self).reset()
rsh_df = self._rsh_df[key] = self.copy().reset()
if hasattr(self, '_dataname'):
rsh_df._dataname = f'{self._dataname}/lr/{key}'
logger.info(self, 'Create RSH-DF object %s for omega=%s', rsh_df, omega)
Expand Down
4 changes: 1 addition & 3 deletions pyscf/df/df_jk.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# Author: Qiming Sun <[email protected]>
#

import copy

import ctypes
import numpy
import scipy.linalg
Expand Down Expand Up @@ -83,7 +81,7 @@ def density_fit(mf, auxbasis=None, with_df=None, only_dfj=False):
mf.with_df = with_df
elif getattr(mf.with_df, 'auxbasis', None) != auxbasis:
#logger.warn(mf, 'DF might have been initialized twice.')
mf = copy.copy(mf)
mf = mf.copy()
mf.with_df = with_df
mf.only_dfj = only_dfj
return mf
Expand Down
1 change: 0 additions & 1 deletion pyscf/df/grad/sacasscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#

import numpy as np
import copy
import time
import gc
from functools import reduce
Expand Down
3 changes: 1 addition & 2 deletions pyscf/dft/dks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
'''


import copy
import numpy
from pyscf import lib
from pyscf.lib import logger
Expand Down Expand Up @@ -118,7 +117,7 @@ def to_dhf(self):

def to_dks(self, xc=None):
if xc is not None and xc != self.xc:
mf = copy.copy(self)
mf = self.copy()
mf.xc = xc
mf.converged = False
return self
Expand Down
3 changes: 1 addition & 2 deletions pyscf/dft/libxc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import sys
import warnings
import copy
import ctypes
import math
import numpy
Expand Down Expand Up @@ -1661,5 +1660,5 @@ def define_xc_(ni, description, xctype='LDA', hyb=0, rsh=(0,0,0)):
return ni

def define_xc(ni, description, xctype='LDA', hyb=0, rsh=(0,0,0)):
return define_xc_(copy.copy(ni), description, xctype, hyb, rsh)
return define_xc_(ni.copy(), description, xctype, hyb, rsh)
define_xc.__doc__ = define_xc_.__doc__
3 changes: 1 addition & 2 deletions pyscf/dft/xcfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
U. Ekstrom et al, J. Chem. Theory Comput., 6, 1971
'''

import copy
import ctypes
from functools import lru_cache
import math
Expand Down Expand Up @@ -1080,5 +1079,5 @@ def define_xc_(ni, description, xctype='LDA', hyb=0, rsh=(0,0,0)):
return ni

def define_xc(ni, description, xctype='LDA', hyb=0, rsh=(0,0,0)):
return define_xc_(copy.copy(ni), description, xctype, hyb, rsh)
return define_xc_(ni.copy(), description, xctype, hyb, rsh)
define_xc.__doc__ = define_xc_.__doc__
5 changes: 2 additions & 3 deletions pyscf/eph/eph_fd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
electron-phonon matrix from finite difference
'''

import copy
import numpy as np
from pyscf import scf, dft, gto, hessian
from pyscf.eph import rhf as rhf_eph
Expand All @@ -35,9 +34,9 @@ def run_mfs(mf, mols_a, mols_b):
dm0 = mf.make_rdm1()
mflist = []
for i in range(nconfigs):
mf1 = copy.copy(mf)
mf1 = mf.copy()
mf1.reset(mols_a[i])
mf2 = copy.copy(mf)
mf2 = mf.copy()
mf2.reset(mols_b[i])
mf1.kernel(dm0=dm0)
mf2.kernel(dm0=dm0)
Expand Down
Loading

0 comments on commit deae6e0

Please sign in to comment.