deepmd.nvnmd.utils package
- class deepmd.nvnmd.utils.Encode[source]
Bases:
object
Encoding value as hex, bin, and dec format.
Methods
bin2hex
(data)Convert binary string list to hex string list.
bin2hex_str
(sbin)Convert binary string to hex string.
byte2hex
(bs, nbyte)Convert byte into hex bs: low byte in the first hex: low byte in the right.
check_dec
(idec, nbit[, signed, name])Check whether the data (idec) is in the range range is \([0, 2^nbit-1]\) for unsigned range is \([-2^{nbit-1}, 2^{nbit-1}-1]\) for signed.
dec2bin
(idec[, nbit, signed, name])Convert dec array to binary string list.
extend_bin
(slbin, nfull)Extend the element of list (slbin) to the length (nfull).
extend_hex
(slhex, nfull)Extend the element of list (slhex) to the length (nfull).
extend_list
(slbin, nfull)Extend the list (slbin) to the length (nfull) the attched element of list is 0.
flt2bin
(data, nbit_expo, nbit_frac)Convert float into binary string list.
hex2bin
(data)Convert hex string list to binary string list.
hex2bin_str
(shex)Convert hex string to binary string.
merge_bin
(slbin, nmerge)Merge binary string list per nmerge value.
qc
(v[, nbit])Quantize value using ceil.
qf
(v[, nbit])Quantize value using floor.
qr
(v[, nbit])Quantize value using round.
reverse_bin
(slbin, nreverse)Reverse binary string list per nreverse value.
split_bin
(sbin, nbit)Split sbin into many segment with the length nbit.
find_max_expo
flt2bin_one
norm_expo
split_expo_mant
- byte2hex(bs, nbyte)[source]
Convert byte into hex bs: low byte in the first hex: low byte in the right.
- check_dec(idec, nbit, signed=False, name='')[source]
Check whether the data (idec) is in the range range is \([0, 2^nbit-1]\) for unsigned range is \([-2^{nbit-1}, 2^{nbit-1}-1]\) for signed.
- extend_bin(slbin, nfull)[source]
Extend the element of list (slbin) to the length (nfull).
such as, when
slbin = [‘10010’,’10100’],nfull = 6extent to
[‘010010’,’010100’]
- class deepmd.nvnmd.utils.FioBin[source]
Bases:
object
Input and output for binary file.
Methods
load
([file_name, default_value])Load binary file into bytes value.
save
(file_name, data)Save hex string into binary file.
- class deepmd.nvnmd.utils.FioDic[source]
Bases:
object
Input and output for dict class data the file can be .json or .npy file containing a dictionary.
Methods
update
(jdata, jdata_o)Update key-value pair is key in jdata_o.keys().
get
load
save
- class deepmd.nvnmd.utils.FioTxt[source]
Bases:
object
Input and output for .txt file with string.
Methods
load
([file_name, default_value])Load .txt file into string list.
save
([file_name, data])Save string list into .txt file.
- deepmd.nvnmd.utils.get_filter_weight(weights: int, spe_j: int, layer_l: int)[source]
Get weight and bias of embedding network.
- deepmd.nvnmd.utils.get_fitnet_weight(weights: dict, spe_i: int, layer_l: int, nlayer: int = 10)[source]
Get weight and bias of fitting network.
- deepmd.nvnmd.utils.map_nvnmd(x, map_y, map_dy, prec, nbit=None)[source]
Mapping function implemented by numpy.
- deepmd.nvnmd.utils.one_layer(inputs, outputs_size, activation_fn=<function tanh>, precision=tf.float64, stddev=1.0, bavg=0.0, name='linear', reuse=None, seed=None, use_timestep=False, trainable=True, useBN=False, uniform_seed=False, initial_variables=None, mixed_prec=None, final_layer=False)[source]
Build one layer with continuous or quantized value. Its weight and bias can be initialed with random or constant value.
Submodules
deepmd.nvnmd.utils.argcheck module
Alias for backward compatibility.
deepmd.nvnmd.utils.config module
- class deepmd.nvnmd.utils.config.NvnmdConfig(jdata: dict)[source]
Bases:
object
Configuration for NVNMD record the message of model such as size, using nvnmd or not.
- Parameters
- jdata
a dictionary of input script
References
DOI: 10.1038/s41524-022-00773-z
Methods
Display the log of NVNMD.
Generate input script with member element one by one.
Build the weight dict for initialization of net.
Generate model/descriptor in input script.
Generate model/fitting_net in input script.
Generate learning_rate in input script.
Generate loss in input script.
Generate model in input script.
Generate nvnmd in input script.
get_s_range
(davg, dstd)Get the range of switch function.
Generate training in input script.
init_config_by_version
(version, max_nnei)Initialize version-dependent parameters.
init_ctrl
(jdata[, jdata_parent])Initialize members about control signal.
init_dpin
(jdata[, jdata_parent])Initialize members about other deepmd input.
init_dscp
(jdata[, jdata_parent])Initialize members about descriptor.
init_fitn
(jdata[, jdata_parent])Initialize members about fitting network.
init_from_config
(jdata)Initialize member element one by one.
init_from_deepmd_input
(jdata)Initialize members with input script of deepmd.
init_from_jdata
([jdata])Initialize this class with jdata loaded from input script.
init_nbit
(jdata[, jdata_parent])Initialize members about quantification precision.
Initialize net_size.
init_size
(jdata[, jdata_parent])Initialize members about ram capacity.
init_train_mode
([mod])Configure for taining cnn or qnn.
Initialize member with dict.
save
([file_name])Save all configuration to file.
set_ntype
(ntype)Set the number of type.
Update config from dict.
- init_ctrl(jdata: dict, jdata_parent: dict = {}) dict [source]
Initialize members about control signal.
- init_dpin(jdata: dict, jdata_parent: dict = {}) dict [source]
Initialize members about other deepmd input.
- init_fitn(jdata: dict, jdata_parent: dict = {}) dict [source]
Initialize members about fitting network.
- init_from_jdata(jdata: dict = {})[source]
Initialize this class with jdata loaded from input script.
- init_nbit(jdata: dict, jdata_parent: dict = {}) dict [source]
Initialize members about quantification precision.
deepmd.nvnmd.utils.encode module
- class deepmd.nvnmd.utils.encode.Encode[source]
Bases:
object
Encoding value as hex, bin, and dec format.
Methods
bin2hex
(data)Convert binary string list to hex string list.
bin2hex_str
(sbin)Convert binary string to hex string.
byte2hex
(bs, nbyte)Convert byte into hex bs: low byte in the first hex: low byte in the right.
check_dec
(idec, nbit[, signed, name])Check whether the data (idec) is in the range range is \([0, 2^nbit-1]\) for unsigned range is \([-2^{nbit-1}, 2^{nbit-1}-1]\) for signed.
dec2bin
(idec[, nbit, signed, name])Convert dec array to binary string list.
extend_bin
(slbin, nfull)Extend the element of list (slbin) to the length (nfull).
extend_hex
(slhex, nfull)Extend the element of list (slhex) to the length (nfull).
extend_list
(slbin, nfull)Extend the list (slbin) to the length (nfull) the attched element of list is 0.
flt2bin
(data, nbit_expo, nbit_frac)Convert float into binary string list.
hex2bin
(data)Convert hex string list to binary string list.
hex2bin_str
(shex)Convert hex string to binary string.
merge_bin
(slbin, nmerge)Merge binary string list per nmerge value.
qc
(v[, nbit])Quantize value using ceil.
qf
(v[, nbit])Quantize value using floor.
qr
(v[, nbit])Quantize value using round.
reverse_bin
(slbin, nreverse)Reverse binary string list per nreverse value.
split_bin
(sbin, nbit)Split sbin into many segment with the length nbit.
find_max_expo
flt2bin_one
norm_expo
split_expo_mant
- byte2hex(bs, nbyte)[source]
Convert byte into hex bs: low byte in the first hex: low byte in the right.
- check_dec(idec, nbit, signed=False, name='')[source]
Check whether the data (idec) is in the range range is \([0, 2^nbit-1]\) for unsigned range is \([-2^{nbit-1}, 2^{nbit-1}-1]\) for signed.
- extend_bin(slbin, nfull)[source]
Extend the element of list (slbin) to the length (nfull).
such as, when
slbin = [‘10010’,’10100’],nfull = 6extent to
[‘010010’,’010100’]
deepmd.nvnmd.utils.fio module
- class deepmd.nvnmd.utils.fio.Fio[source]
Bases:
object
Basic class for FIO.
Methods
create_file_path
exits
get_file_list
is_file
is_path
mkdir
- class deepmd.nvnmd.utils.fio.FioBin[source]
Bases:
object
Input and output for binary file.
Methods
load
([file_name, default_value])Load binary file into bytes value.
save
(file_name, data)Save hex string into binary file.
- class deepmd.nvnmd.utils.fio.FioDic[source]
Bases:
object
Input and output for dict class data the file can be .json or .npy file containing a dictionary.
Methods
update
(jdata, jdata_o)Update key-value pair is key in jdata_o.keys().
get
load
save
- class deepmd.nvnmd.utils.fio.FioJsonDic[source]
Bases:
object
Input and output for .json file containing dictionary.
Methods
load
([file_name, default_value])Load .json file into dict.
save
([file_name, dic])Save dict into .json file.
- class deepmd.nvnmd.utils.fio.FioNpyDic[source]
Bases:
object
Input and output for .npy file containing dictionary.
Methods
load
save
deepmd.nvnmd.utils.network module
- deepmd.nvnmd.utils.network.matmul2_qq(a, b, nbit)[source]
Quantized matmul operation for 2d tensor. a and b is input tensor, nbit represent quantification precision.
- deepmd.nvnmd.utils.network.matmul3_qq(a, b, nbit)[source]
Quantized matmul operation for 3d tensor. a and b is input tensor, nbit represent quantification precision.
- deepmd.nvnmd.utils.network.one_layer(inputs, outputs_size, activation_fn=<function tanh>, precision=tf.float64, stddev=1.0, bavg=0.0, name='linear', reuse=None, seed=None, use_timestep=False, trainable=True, useBN=False, uniform_seed=False, initial_variables=None, mixed_prec=None, final_layer=False)[source]
Build one layer with continuous or quantized value. Its weight and bias can be initialed with random or constant value.
- deepmd.nvnmd.utils.network.one_layer_t(shape, outputs_size, bavg, stddev, precision, trainable, initial_variables, seed, uniform_seed, name)[source]
- deepmd.nvnmd.utils.network.one_layer_wb(shape, outputs_size, bavg, stddev, precision, trainable, initial_variables, seed, uniform_seed, name)[source]
- deepmd.nvnmd.utils.network.qf(x, nbit)[source]
Quantize and floor tensor x with quantification precision nbit.
deepmd.nvnmd.utils.op module
deepmd.nvnmd.utils.weight module
- deepmd.nvnmd.utils.weight.get_constant_initializer(weights, name)[source]
Get initial value by name and create a initializer.
- deepmd.nvnmd.utils.weight.get_filter_type_weight(weights: dict, layer_l: int)[source]
Get weight and bias of two_side_type_embedding network.
- Parameters
- weights
dict
weights
- layer_l
layer order in embedding network 1~nlayer
- weights
- deepmd.nvnmd.utils.weight.get_filter_weight(weights: int, spe_j: int, layer_l: int)[source]
Get weight and bias of embedding network.
- deepmd.nvnmd.utils.weight.get_fitnet_weight(weights: dict, spe_i: int, layer_l: int, nlayer: int = 10)[source]
Get weight and bias of fitting network.
- deepmd.nvnmd.utils.weight.get_normalize(weights: dict)[source]
Get normalize parameter (avg and std) of \(s_{ji}\).
- deepmd.nvnmd.utils.weight.get_type_embedding_weight(weights: dict, layer_l: int)[source]
Get weight and bias of type_embedding network.
- Parameters
- weights
dict
weights
- layer_l
layer order in embedding network 1~nlayer
- weights