本文整理汇总了Python中numpy.complex128方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.complex128方法的具体用法?Python numpy.complex128怎么用?Python numpy.complex128使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.complex128方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _eigen_components
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def _eigen_components(self):
components = [(0, np.diag([1, 1, 1, 0, 1, 0, 0, 1]))]
nontrivial_part = np.zeros((3, 3), dtype=np.complex128)
for ij, w in zip([(1, 2), (0, 2), (0, 1)], self.weights):
nontrivial_part[ij] = w
nontrivial_part[ij[::-1]] = w.conjugate()
assert np.allclose(nontrivial_part, nontrivial_part.conj().T)
eig_vals, eig_vecs = np.linalg.eigh(nontrivial_part)
for eig_val, eig_vec in zip(eig_vals, eig_vecs.T):
exp_factor = -eig_val / np.pi
proj = np.zeros((8, 8), dtype=np.complex128)
nontrivial_indices = np.array([3, 5, 6], dtype=np.intp)
proj[nontrivial_indices[:, np.newaxis], nontrivial_indices] = (
np.outer(eig_vec.conjugate(), eig_vec))
components.append((exp_factor, proj))
return components
示例2: qubit_generator_matrix
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def qubit_generator_matrix(self):
"""The (Hermitian) matrix G such that the gate's unitary is
exp(-i * G).
"""
generator = np.zeros((1 << 4,) * 2, dtype=np.complex128)
# w0 |1001><0110| + h.c.
generator[9, 6] = self.weights[0]
generator[6, 9] = self.weights[0].conjugate()
# w1 |1010><0101| + h.c.
generator[10, 5] = self.weights[1]
generator[5, 10] = self.weights[1].conjugate()
# w2 |1100><0011| + h.c.
generator[12, 3] = self.weights[2]
generator[3, 12] = self.weights[2].conjugate()
return generator
示例3: test_cubic_fermionic_simulation_gate_consistency_docstring
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def test_cubic_fermionic_simulation_gate_consistency_docstring(
weights, exponent):
generator = np.zeros((8, 8), dtype=np.complex128)
# w0 |110><101| + h.c.
generator[6, 5] = weights[0]
generator[5, 6] = weights[0].conjugate()
# w1 |110><011| + h.c.
generator[6, 3] = weights[1]
generator[3, 6] = weights[1].conjugate()
# w2 |101><011| + h.c.
generator[5, 3] = weights[2]
generator[3, 5] = weights[2].conjugate()
expected_unitary = la.expm(-1j * exponent * generator)
gate = ofc.CubicFermionicSimulationGate(weights, exponent=exponent)
actual_unitary = cirq.unitary(gate)
assert np.allclose(expected_unitary, actual_unitary)
示例4: test_quartic_fermionic_simulation_unitary
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def test_quartic_fermionic_simulation_unitary(weights, exponent):
generator = np.zeros((1 << 4,) * 2, dtype=np.complex128)
# w0 |1001><0110| + h.c.
generator[9, 6] = weights[0]
generator[6, 9] = weights[0].conjugate()
# w1 |1010><0101| + h.c.
generator[10, 5] = weights[1]
generator[5, 10] = weights[1].conjugate()
# w2 |1100><0011| + h.c.
generator[12, 3] = weights[2]
generator[3, 12] = weights[2].conjugate()
expected_unitary = la.expm(-1j * exponent * generator)
gate = ofc.QuarticFermionicSimulationGate(weights, exponent=exponent)
actual_unitary = cirq.unitary(gate)
assert np.allclose(expected_unitary, actual_unitary)
示例5: test_get_matrix_of_eigs
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def test_get_matrix_of_eigs():
"""
Generate the matrix of [exp(i (li - lj)) - 1] / (i(li - lj)
:return:
"""
lam_vals = np.random.randn(4) + 1j * np.random.randn(4)
mat_eigs = np.zeros((lam_vals.shape[0],
lam_vals.shape[0]),
dtype=np.complex128)
for i, j in product(range(lam_vals.shape[0]), repeat=2):
if np.isclose(abs(lam_vals[i] - lam_vals[j]), 0):
mat_eigs[i, j] = 1
else:
mat_eigs[i, j] = (np.exp(1j * (lam_vals[i] - lam_vals[j])) - 1) / (
1j * (lam_vals[i] - lam_vals[j]))
test_mat_eigs = get_matrix_of_eigs(lam_vals)
assert np.allclose(test_mat_eigs, mat_eigs)
示例6: test_rhf_vcut_sph
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def test_rhf_vcut_sph(self):
mf = pbchf.RHF(cell, exxdiv='vcut_sph')
e1 = mf.kernel()
self.assertAlmostEqual(e1, -4.29190260870812, 8)
self.assertTrue(mf.mo_coeff.dtype == numpy.double)
mf = pscf.KRHF(cell, [[0,0,0]], exxdiv='vcut_sph')
e0 = mf.kernel()
self.assertTrue(numpy.allclose(e0,e1))
numpy.random.seed(1)
k = numpy.random.random(3)
mf = pbchf.RHF(cell, k, exxdiv='vcut_sph')
e1 = mf.kernel()
self.assertAlmostEqual(e1, -4.1379172088570595, 8)
self.assertTrue(mf.mo_coeff.dtype == numpy.complex128)
mf = pscf.KRHF(cell, k, exxdiv='vcut_sph')
e0 = mf.kernel()
self.assertTrue(numpy.allclose(e0,e1))
示例7: test_rhf_exx_ewald_with_kpt
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def test_rhf_exx_ewald_with_kpt(self):
numpy.random.seed(1)
k = numpy.random.random(3)
mf = pbchf.RHF(cell, k, exxdiv='ewald')
e1 = mf.kernel()
self.assertAlmostEqual(e1, -4.2048655827967139, 8)
self.assertTrue(mf.mo_coeff.dtype == numpy.complex128)
kmf = pscf.KRHF(cell, k, exxdiv='ewald')
e0 = kmf.kernel()
self.assertTrue(numpy.allclose(e0,e1))
# test bands
numpy.random.seed(1)
kpt_band = numpy.random.random(3)
e1, c1 = mf.get_bands(kpt_band)
e0, c0 = kmf.get_bands(kpt_band)
self.assertAlmostEqual(abs(e0-e1).max(), 0, 7)
self.assertAlmostEqual(lib.finger(e1), -6.8312867098806249, 7)
示例8: cc_Fov
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def cc_Fov(cc, t1, t2, eris):
t1a, t1b = t1
t2aa, t2ab, t2bb = t2
nkpts, nocc_a, nvir_a = t1a.shape
nocc_b, nvir_b = t1b.shape[1:]
fov = eris.fock[0][:,:nocc_a,nocc_a:]
fOV = eris.fock[1][:,:nocc_b,nocc_b:]
fa = np.zeros((nkpts,nocc_a,nvir_a), dtype=np.complex128)
fb = np.zeros((nkpts,nocc_b,nvir_b), dtype=np.complex128)
for km in range(nkpts):
fa[km]+=fov[km]
fb[km]+=fOV[km]
for kn in range(nkpts):
fa[km]+=einsum('nf,menf->me',t1a[kn],eris.ovov[km,km,kn])
fa[km]+=einsum('nf,menf->me',t1b[kn],eris.ovOV[km,km,kn])
fa[km]-=einsum('nf,mfne->me',t1a[kn],eris.ovov[km,kn,kn])
fb[km]+=einsum('nf,menf->me',t1b[kn],eris.OVOV[km,km,kn])
fb[km]+=einsum('nf,nfme->me',t1a[kn],eris.ovOV[kn,kn,km])
fb[km]-=einsum('nf,mfne->me',t1b[kn],eris.OVOV[km,kn,kn])
return fa,fb
示例9: get_M_mat
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def get_M_mat(self):
'''
Construct the ovelap matrix: M_{m,n}^{(\mathbf{k,b})}
Equation (25) in MV, Phys. Rev. B 56, 12847
'''
M_matrix_loc = np.empty([self.num_kpts_loc, self.nntot_loc, self.num_bands_loc, self.num_bands_loc], dtype = np.complex128)
for k_id in range(self.num_kpts_loc):
for nn in range(self.nntot_loc):
k1 = self.cell.get_abs_kpts(self.kpt_latt_loc[k_id])
k_id2 = self.nn_list[nn, k_id, 0] - 1
k2_ = self.kpt_latt_loc[k_id2]
k2_scaled = k2_ + self.nn_list[nn, k_id, 1:4]
k2 = self.cell.get_abs_kpts(k2_scaled)
s_AO = df.ft_ao.ft_aopair(self.cell, -k2+k1, kpti_kptj=[k2,k1], q = np.zeros(3))[0]
Cm = self.mo_coeff_kpts[k_id][:,self.band_included_list]
Cn = self.mo_coeff_kpts[k_id2][:,self.band_included_list]
M_matrix_loc[k_id, nn,:,:] = np.einsum('nu,vm,uv->nm', Cn.T.conj(), Cm, s_AO, optimize = True).conj()
return M_matrix_loc
示例10: export_unk
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def export_unk(self, grid = [50,50,50]):
'''
Export the periodic part of BF in a real space grid for plotting with wannier90
'''
from scipy.io import FortranFile
grids_coor, weights = periodic_grid(self.cell, grid, order = 'F')
for k_id in range(self.num_kpts_loc):
spin = '.1'
if self.spin_up != None and self.spin_up == False : spin = '.2'
kpt = self.cell.get_abs_kpts(self.kpt_latt_loc[k_id])
ao = numint.eval_ao(self.cell, grids_coor, kpt = kpt)
u_ao = np.einsum('x,xi->xi', np.exp(-1j*np.dot(grids_coor, kpt)), ao, optimize = True)
unk_file = FortranFile('UNK' + "%05d" % (k_id + 1) + spin, 'w')
unk_file.write_record(np.asarray([grid[0], grid[1], grid[2], k_id + 1, self.num_bands_loc], dtype = np.int32))
mo_included = self.mo_coeff_kpts[k_id][:,self.band_included_list]
u_mo = np.einsum('xi,in->xn', u_ao, mo_included, optimize = True)
for band in range(len(self.band_included_list)):
unk_file.write_record(np.asarray(u_mo[:,band], dtype = np.complex128))
unk_file.close()
示例11: test_get_eri_gamma
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def test_get_eri_gamma(self):
odf = df.DF(cell)
odf.linear_dep_threshold = 1e-7
odf.auxbasis = 'weigend'
odf.mesh = (6,)*3
eri0000 = odf.get_eri()
self.assertTrue(eri0000.dtype == numpy.double)
self.assertAlmostEqual(eri0000.real.sum(), 41.61280626625331, 9)
self.assertAlmostEqual(finger(eri0000), 1.9981472468639465, 9)
eri1111 = kmdf.get_eri((kpts[0],kpts[0],kpts[0],kpts[0]))
self.assertTrue(eri1111.dtype == numpy.double)
self.assertAlmostEqual(eri1111.real.sum(), 41.61280626625331, 9)
self.assertAlmostEqual(eri1111.imag.sum(), 0, 9)
self.assertAlmostEqual(finger(eri1111), 1.9981472468639465, 9)
self.assertAlmostEqual(abs(eri1111-eri0000).max(), 0, 9)
eri4444 = kmdf.get_eri((kpts[4],kpts[4],kpts[4],kpts[4]))
self.assertTrue(eri4444.dtype == numpy.complex128)
self.assertAlmostEqual(eri4444.real.sum(), 62.55120674032798, 9)
self.assertAlmostEqual(abs(eri4444.imag).sum(), 0.0016507912195378644, 7)
self.assertAlmostEqual(finger(eri4444), 0.6206014899350296-7.413680313987067e-05j, 8)
eri0000 = ao2mo.restore(1, eri0000, cell.nao_nr()).reshape(eri4444.shape)
self.assertAlmostEqual(abs(eri0000-eri4444).max(), 0, 4)
示例12: _contract_rho
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def _contract_rho(bra, ket):
#:rho = numpy.einsum('pi,pi->p', bra.real, ket.real)
#:rho += numpy.einsum('pi,pi->p', bra.imag, ket.imag)
bra = bra.T
ket = ket.T
nao, ngrids = bra.shape
rho = numpy.empty(ngrids)
if not (bra.flags.c_contiguous and ket.flags.c_contiguous):
rho = numpy.einsum('ip,ip->p', bra.real, ket.real)
rho += numpy.einsum('ip,ip->p', bra.imag, ket.imag)
elif bra.dtype == numpy.double and ket.dtype == numpy.double:
libdft.VXC_dcontract_rho(rho.ctypes.data_as(ctypes.c_void_p),
bra.ctypes.data_as(ctypes.c_void_p),
ket.ctypes.data_as(ctypes.c_void_p),
ctypes.c_int(nao), ctypes.c_int(ngrids))
elif bra.dtype == numpy.complex128 and ket.dtype == numpy.complex128:
libdft.VXC_zcontract_rho(rho.ctypes.data_as(ctypes.c_void_p),
bra.ctypes.data_as(ctypes.c_void_p),
ket.ctypes.data_as(ctypes.c_void_p),
ctypes.c_int(nao), ctypes.c_int(ngrids))
else:
rho = numpy.einsum('ip,ip->p', bra.real, ket.real)
rho += numpy.einsum('ip,ip->p', bra.imag, ket.imag)
return rho
示例13: so_by_shell
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def so_by_shell(mol, shls):
'''Spin-orbit coupling ECP in spinor basis
i/2 <Pauli_matrix dot l U(r)>
'''
li = mol.bas_angular(shls[0])
lj = mol.bas_angular(shls[1])
di = (li*4+2) * mol.bas_nctr(shls[0])
dj = (lj*4+2) * mol.bas_nctr(shls[1])
bas = numpy.vstack((mol._bas, mol._ecpbas))
mol._env[AS_ECPBAS_OFFSET] = len(mol._bas)
mol._env[AS_NECPBAS] = len(mol._ecpbas)
buf = numpy.empty((di,dj), order='F', dtype=numpy.complex128)
cache = numpy.empty(buf.size*48)
fn = libecp.ECPso_spinor
fn(buf.ctypes.data_as(ctypes.c_void_p),
(ctypes.c_int*2)(di, dj),
(ctypes.c_int*2)(*shls),
mol._atm.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(mol.natm),
bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(mol.nbas),
mol._env.ctypes.data_as(ctypes.c_void_p), lib.c_null_ptr(),
cache.ctypes.data_as(ctypes.c_void_p))
return buf
示例14: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def __init__(self, j):
self._j = j
self._c2r = np.zeros( (2*j+1, 2*j+1), dtype=np.complex128)
self._c2r[j,j]=1.0
for m in range(1,j+1):
self._c2r[m+j, m+j] = sgn[m] * np.sqrt(0.5)
self._c2r[m+j,-m+j] = np.sqrt(0.5)
self._c2r[-m+j,-m+j]= 1j*np.sqrt(0.5)
self._c2r[-m+j, m+j]= -sgn[m] * 1j * np.sqrt(0.5)
self._hc_c2r = np.conj(self._c2r).transpose()
self._conj_c2r = np.conjugate(self._c2r) # what is the difference ? conj and conjugate
self._tr_c2r = np.transpose(self._c2r)
#print(abs(self._hc_c2r.conj().transpose()-self._c2r).sum())
#
#
#
示例15: test_three_qubit_rotation_gates_on_simulator
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import complex128 [as 别名]
def test_three_qubit_rotation_gates_on_simulator(gate: cirq.Gate,
initial_state: np.ndarray,
correct_state: np.ndarray):
op = gate(*cirq.LineQubit.range(3))
result = cirq.Circuit(op).final_wavefunction(
initial_state, dtype=np.complex128)
cirq.testing.assert_allclose_up_to_global_phase(result,
correct_state,
atol=1e-8)