本文整理匯總了Python中WaveBlocksND.BlockFactory.set_basis_shapes方法的典型用法代碼示例。如果您正苦於以下問題:Python BlockFactory.set_basis_shapes方法的具體用法?Python BlockFactory.set_basis_shapes怎麽用?Python BlockFactory.set_basis_shapes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WaveBlocksND.BlockFactory
的用法示例。
在下文中一共展示了BlockFactory.set_basis_shapes方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: read_data_inhomogeneous
# 需要導入模塊: from WaveBlocksND import BlockFactory [as 別名]
# 或者: from WaveBlocksND.BlockFactory import set_basis_shapes [as 別名]
def read_data_inhomogeneous(iom, blockid=0):
r"""
:param iom: An :py:class:`IOManager` instance providing the simulation data.
:param blockid: The data block from which the values are read.
"""
parameters = iom.load_parameters()
timegrid = iom.load_inhomogwavepacket_timegrid(blockid=blockid)
time = timegrid * parameters["dt"]
# The potential used
Potential = BlockFactory().create_potential(parameters)
# Basis transformator
BT = BasisTransformationHAWP(Potential)
# Basis shapes
BS_descr = iom.load_wavepacket_basisshapes(blockid=blockid)
BS = {}
for ahash, descr in BS_descr.iteritems():
BS[ahash] = BlockFactory().create_basis_shape(descr)
# Initialize a Hagedorn wavepacket with the data
descr = iom.load_inhomogwavepacket_description(blockid=blockid)
HAWP = BlockFactory().create_wavepacket(descr)
BT.set_matrix_builder(HAWP.get_quadrature())
# Store the resulting coefficients here
CI = [ [] for i in xrange(HAWP.get_number_components()) ]
# Iterate over all timesteps, this is an *expensive* transformation
for i, step in enumerate(timegrid):
print(" Computing eigentransformation at timestep "+str(step))
# Retrieve simulation data
params = iom.load_inhomogwavepacket_parameters(timestep=step, blockid=blockid)
hashes, coeffs = iom.load_inhomogwavepacket_coefficients(timestep=step, get_hashes=True, blockid=blockid)
# Configure the wavepacket
HAWP.set_parameters(params)
HAWP.set_basis_shapes([ BS[int(ha)] for ha in hashes ])
HAWP.set_coefficients(coeffs)
# Transform to the eigenbasis.
BT.transform_to_eigen(HAWP)
for index, item in enumerate(HAWP.get_coefficients()):
CI[index].append(item)
CI = [ transpose(hstack(item)) for item in CI ]
return time, CI
示例2: compute_autocorrelation_inhawp
# 需要導入模塊: from WaveBlocksND import BlockFactory [as 別名]
# 或者: from WaveBlocksND.BlockFactory import set_basis_shapes [as 別名]
def compute_autocorrelation_inhawp(iom, obsconfig, blockid=0, eigentrafo=True):
"""Compute the autocorrelation of a wavepacket timeseries.
This function is for inhomogeneous wavepackets.
:param iom: An :py:class:`IOManager` instance providing the simulation data.
:param obsconfig: Configuration parameters describing f.e. the inner product to use.
:type obsconfig: A :py:class:`ParameterProvider` instance.
:param blockid: The data block from which the values are read.
:type blockid: Integer, Default is ``0``
:param eigentrafo: Whether to make a transformation into the eigenbasis.
:type eigentrafo: Boolean, default is ``True``.
"""
parameters = iom.load_parameters()
# Number of time steps we saved
timesteps = iom.load_inhomogwavepacket_timegrid(blockid=blockid)
nrtimesteps = timesteps.shape[0]
# Basis transformator
if eigentrafo is True:
# The potential used
Potential = BlockFactory().create_potential(parameters)
BT = BasisTransformationHAWP(Potential)
# We want to save autocorrelations, thus add a data slot to the data file
iom.add_autocorrelation(parameters, timeslots=nrtimesteps, blockid=blockid)
# Initialize a Hagedorn wavepacket with the data
descr = iom.load_inhomogwavepacket_description(blockid=blockid)
HAWPo = BlockFactory().create_wavepacket(descr)
HAWPt = BlockFactory().create_wavepacket(descr)
if eigentrafo is True:
BT.set_matrix_builder(HAWPo.get_innerproduct())
# Basis shapes
BS_descr = iom.load_inhomogwavepacket_basisshapes(blockid=blockid)
BS = {}
for ahash, descr in BS_descr.iteritems():
BS[ahash] = BlockFactory().create_basis_shape(descr)
# Comfigure the original wavepacket
# Retrieve simulation data
params = iom.load_wavepacket_parameters(timestep=0, blockid=blockid)
hashes, coeffs = iom.load_wavepacket_coefficients(timestep=0, get_hashes=True, blockid=blockid)
# Configure the wavepacket
HAWPo.set_parameters(params)
HAWPo.set_basis_shapes([ BS[int(ha)] for ha in hashes ])
HAWPo.set_coefficients(coeffs)
# Set up the innerproduct for solving the integrals <phi_0 | phi_t>
IP = BlockFactory().create_inner_product(obsconfig["innerproduct"])
# Iterate over all timesteps
for i, step in enumerate(timesteps):
print(" Computing autocorrelations of timestep "+str(step))
# Retrieve simulation data
params = iom.load_inhomogwavepacket_parameters(timestep=step, blockid=blockid)
hashes, coeffs = iom.load_inhomogwavepacket_coefficients(timestep=step, get_hashes=True, blockid=blockid)
# Configure the wavepacket
HAWPt.set_parameters(params)
HAWPt.set_basis_shapes([ BS[int(ha)] for ha in hashes ])
HAWPt.set_coefficients(coeffs)
# Transform to the eigenbasis.
if eigentrafo is True:
BT.transform_to_eigen(HAWPt)
# Measure autocorrelations in the eigenbasis
acs = IP.quadrature(HAWPo, HAWPt, diagonal=True)
# Save the autocorrelations
iom.save_autocorrelation(acs, timestep=step, blockid=blockid)
示例3: compute_evaluate_wavepackets
# 需要導入模塊: from WaveBlocksND import BlockFactory [as 別名]
# 或者: from WaveBlocksND.BlockFactory import set_basis_shapes [as 別名]
def compute_evaluate_wavepackets(pp, iom, blockid=0, eigentrafo=True):
"""Evaluate a homogeneous Hagedorn wavepacket on a given grid for each timestep.
:param pp: An :py:class:`ParameterProvider` instance providing the grid data.
:param iom: An :py:class:`IOManager` instance providing the simulation data.
:param blockid: The data block from which the values are read.
:param eigentrafo: Whether or not do an eigentransformation before evaluation is done.
"""
parameters = iom.load_parameters()
if pp is None:
pp = parameters
# Number of time steps we saved
timesteps = iom.load_wavepacket_timegrid(blockid=blockid)
nrtimesteps = timesteps.shape[0]
# Prepare the potential for basis transformations
Potential = BlockFactory().create_potential(parameters)
grid = BlockFactory().create_grid(pp)
# We want to save wavefunctions, thus add a data slot to the data file
d = {"ncomponents": parameters["ncomponents"],
"number_nodes": pp["number_nodes"],
"dimension": parameters["dimension"]}
iom.add_grid(d, blockid=blockid)
iom.add_wavefunction(d, timeslots=nrtimesteps, flat=True, blockid=blockid)
iom.save_grid(grid.get_nodes(), blockid=blockid)
# Initialize a Hagedorn wavepacket with the data
descr = iom.load_wavepacket_description(blockid=blockid)
HAWP = BlockFactory().create_wavepacket(descr)
# Basis transformator
if eigentrafo is True:
BT = BasisTransformationHAWP(Potential)
BT.set_matrix_builder(HAWP.get_innerproduct())
# Basis shapes
BS_descr = iom.load_wavepacket_basisshapes(blockid=blockid)
BS = {}
for ahash, descr in BS_descr.items():
BS[ahash] = BlockFactory().create_basis_shape(descr)
WF = WaveFunction(parameters)
WF.set_grid(grid)
# Iterate over all timesteps
for i, step in enumerate(timesteps):
print(" Evaluating homogeneous wavepacket at timestep %d" % step)
# Retrieve simulation data
params = iom.load_wavepacket_parameters(timestep=step, blockid=blockid, key=("q", "p", "Q", "P", "S", "adQ"))
hashes, coeffs = iom.load_wavepacket_coefficients(timestep=step, get_hashes=True, blockid=blockid)
# Configure the wavepacket
HAWP.set_parameters(params, key=("q", "p", "Q", "P", "S", "adQ"))
HAWP.set_basis_shapes([BS[int(ha)] for ha in hashes])
HAWP.set_coefficients(coeffs)
# Transform to the eigenbasis.
if eigentrafo is True:
BT.transform_to_eigen(HAWP)
# Evaluate the wavepacket
values = HAWP.evaluate_at(grid, prefactor=True)
WF.set_values(values)
# Save the wave function
iom.save_wavefunction(WF.get_values(), timestep=step, blockid=blockid)
示例4: compute_energy_inhawp
# 需要導入模塊: from WaveBlocksND import BlockFactory [as 別名]
# 或者: from WaveBlocksND.BlockFactory import set_basis_shapes [as 別名]
def compute_energy_inhawp(iom, blockid=0, eigentrafo=True, iseigen=True):
"""Compute the energies of a wavepacket timeseries.
This function is for inhomogeneous wavepackets.
:param iom: An :py:class:`IOManager` instance providing the simulation data.
:param blockid: The data block from which the values are read.
:type blockid: Integer, Default is ``0``
:param eigentrafo: Whether to make a transformation into the eigenbasis.
:type eigentrafo: Boolean, default is ``True``.
:param iseigen: Whether the data is assumed to be in the eigenbasis.
:type iseigen: Boolean, default is ``True``
"""
parameters = iom.load_parameters()
# Number of time steps we saved
timesteps = iom.load_inhomogwavepacket_timegrid(blockid=blockid)
nrtimesteps = timesteps.shape[0]
# The potential used
Potential = BlockFactory().create_potential(parameters)
# Basis transformator
if eigentrafo is True:
BT = BasisTransformationHAWP(Potential)
# We want to save energies, thus add a data slot to the data file
iom.add_energy(parameters, timeslots=nrtimesteps, blockid=blockid)
# Initialize a Hagedorn wavepacket with the data
descr = iom.load_inhomogwavepacket_description(blockid=blockid)
HAWP = BlockFactory().create_wavepacket(descr)
if eigentrafo is True:
BT.set_matrix_builder(HAWP.get_innerproduct())
# Basis shapes
BS_descr = iom.load_inhomogwavepacket_basisshapes(blockid=blockid)
BS = {}
for ahash, descr in BS_descr.iteritems():
BS[ahash] = BlockFactory().create_basis_shape(descr)
O = ObservablesHAWP()
KEY = ("q","p","Q","P","S","adQ")
# Iterate over all timesteps
for i, step in enumerate(timesteps):
print(" Computing energies of timestep "+str(step))
# Retrieve simulation data
params = iom.load_inhomogwavepacket_parameters(timestep=step, blockid=blockid, key=KEY)
hashes, coeffs = iom.load_inhomogwavepacket_coefficients(timestep=step, get_hashes=True, blockid=blockid)
# Configure the wavepacket
HAWP.set_parameters(params, key=KEY)
HAWP.set_basis_shapes([ BS[int(ha)] for ha in hashes ])
HAWP.set_coefficients(coeffs)
# Transform to the eigenbasis.
if eigentrafo is True:
BT.transform_to_eigen(HAWP)
# Compute the energies
O.set_innerproduct(HAWP.get_innerproduct())
ekin = O.kinetic_energy(HAWP)
if iseigen is True:
epot = O.potential_energy(HAWP, Potential.evaluate_eigenvalues_at)
else:
epot = O.potential_energy(HAWP, Potential.evaluate_at)
iom.save_energy((ekin, epot), timestep=step, blockid=blockid)
示例5: compute_norm_hawp
# 需要導入模塊: from WaveBlocksND import BlockFactory [as 別名]
# 或者: from WaveBlocksND.BlockFactory import set_basis_shapes [as 別名]
def compute_norm_hawp(iom, blockid=0, eigentrafo=True):
"""Compute the norm of a wavepacket timeseries.
:param iom: An :py:class:`IOManager` instance providing the simulation data.
:param blockid: The data block from which the values are read.
:type blockid: Integer, Default is ``0``
:param eigentrafo: Whether to make a transformation into the eigenbasis.
:type eigentrafo: Boolean, default is ``True``.
"""
parameters = iom.load_parameters()
# Number of time steps we saved
timesteps = iom.load_wavepacket_timegrid(blockid=blockid)
nrtimesteps = timesteps.shape[0]
# Basis transformator
if eigentrafo is True:
# The potential used
Potential = BlockFactory().create_potential(parameters)
BT = BasisTransformationHAWP(Potential)
# We want to save norms, thus add a data slot to the data file
iom.add_norm(parameters, timeslots=nrtimesteps, blockid=blockid)
# Initialize a Hagedorn wavepacket with the data
descr = iom.load_wavepacket_description(blockid=blockid)
HAWP = BlockFactory().create_wavepacket(descr)
if eigentrafo is True:
BT.set_matrix_builder(HAWP.get_innerproduct())
# Basis shapes
BS_descr = iom.load_wavepacket_basisshapes(blockid=blockid)
BS = {}
for ahash, descr in BS_descr.iteritems():
BS[ahash] = BlockFactory().create_basis_shape(descr)
KEY = ("q", "p", "Q", "P", "S", "adQ")
# Iterate over all timesteps
for i, step in enumerate(timesteps):
print(" Computing norms of timestep " + str(step))
# Retrieve simulation data
params = iom.load_wavepacket_parameters(timestep=step, blockid=blockid, key=KEY)
hashes, coeffs = iom.load_wavepacket_coefficients(timestep=step, get_hashes=True, blockid=blockid)
# Configure the wavepacket
HAWP.set_parameters(params, key=KEY)
HAWP.set_basis_shapes([BS[int(ha)] for ha in hashes])
HAWP.set_coefficients(coeffs)
# Transform to the eigenbasis.
if eigentrafo is True:
BT.transform_to_eigen(HAWP)
# Measure norms in the eigenbasis
norm = HAWP.norm()
# Save the norms
iom.save_norm(norm, timestep=step, blockid=blockid)
示例6: transform_inhawp_to_eigen
# 需要導入模塊: from WaveBlocksND import BlockFactory [as 別名]
# 或者: from WaveBlocksND.BlockFactory import set_basis_shapes [as 別名]
def transform_inhawp_to_eigen(iomin, iomout, blockidin=0, blockidout=0):
"""Compute the transformation to the eigenbasis for a wavepacket.
Save the result back to a file.
:param iomin: An :py:class:`IOManager: instance providing the simulation data.
:param iomout: An :py:class:`IOManager: instance for saving the transformed data.
:param blockidin: The data block from which the values are read. Default is `0`.
:param blockidout: The data block to which the values are written. Default is `0`.
"""
parameters = iomin.load_parameters()
KEY = ("q","p","Q","P","S","adQ")
# Number of time steps we saved
timesteps = iomin.load_inhomogwavepacket_timegrid(blockid=blockidin)
nrtimesteps = timesteps.shape[0]
# The potential used
Potential = BlockFactory().create_potential(parameters)
# Basis transformator
BT = BasisTransformationHAWP(Potential)
# Initialize a Hagedorn wavepacket with the data
descr = iomin.load_inhomogwavepacket_description(blockid=blockidin)
HAWP = BlockFactory().create_wavepacket(descr)
iomout.add_inhomogwavepacket(descr, timeslots=nrtimesteps, blockid=blockidout, key=KEY)
iomout.save_inhomogwavepacket_description(HAWP.get_description(), blockid=blockidout)
BT.set_matrix_builder(HAWP.get_innerproduct())
# Basis shapes
BS_descr = iomin.load_inhomogwavepacket_basisshapes(blockid=blockidin)
BS = {}
for ahash, descr in BS_descr.iteritems():
BS[ahash] = BlockFactory().create_basis_shape(descr)
# Iterate over all timesteps
for i, step in enumerate(timesteps):
print(" Compute eigentransform at timestep # " + str(step))
# Retrieve simulation data
params = iomin.load_inhomogwavepacket_parameters(timestep=step, blockid=blockidin, key=KEY)
hashes, coeffs = iomin.load_inhomogwavepacket_coefficients(timestep=step, get_hashes=True, blockid=blockidin)
# Configure the wavepacket
HAWP.set_parameters(params, key=KEY)
HAWP.set_basis_shapes([ BS[int(ha)] for ha in hashes ])
HAWP.set_coefficients(coeffs)
# Transform to the eigenbasis.
BT.transform_to_eigen(HAWP)
# Save the transformed packet
# Pi
iomout.save_inhomogwavepacket_parameters(HAWP.get_parameters(key=KEY), timestep=step, blockid=blockidout, key=KEY)
# Basis shapes (in case they changed!)
for shape in HAWP.get_basis_shapes():
iomout.save_inhomogwavepacket_basisshapes(shape, blockid=blockidout)
# Coefficients
iomout.save_inhomogwavepacket_coefficients(HAWP.get_coefficients(), HAWP.get_basis_shapes(), timestep=step, blockid=blockidout)