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

bin2hex(data)[source]

Convert binary string list to hex string list.

bin2hex_str(sbin)[source]

Convert binary string to hex string.

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.

dec2bin(idec, nbit=10, signed=False, name='')[source]

Convert dec array to binary string list.

extend_bin(slbin, nfull)[source]

Extend the element of list (slbin) to the length (nfull).

such as, when

slbin = [‘10010’,’10100’],
nfull = 6

extent to

[‘010010’,’010100’]

extend_hex(slhex, nfull)[source]

Extend the element of list (slhex) to the length (nfull).

extend_list(slbin, nfull)[source]

Extend the list (slbin) to the length (nfull) the attched element of list is 0.

such as, when

slbin = [‘10010’,’10100’],
nfull = 4

extent it to

[‘10010’,’10100’,’00000’,’00000]

find_max_expo(v, expo_min=-1000)[source]
flt2bin(data, nbit_expo, nbit_frac)[source]

Convert float into binary string list.

flt2bin_one(v, nbit_expo, nbit_frac)[source]
hex2bin(data)[source]

Convert hex string list to binary string list.

hex2bin_str(shex)[source]

Convert hex string to binary string.

merge_bin(slbin, nmerge)[source]

Merge binary string list per nmerge value.

norm_expo(v, nbit_frac=20, expo_min=-1000)[source]
qc(v, nbit: int = 14)[source]

Quantize value using ceil.

qf(v, nbit: int = 14)[source]

Quantize value using floor.

qr(v, nbit: int = 14)[source]

Quantize value using round.

reverse_bin(slbin, nreverse)[source]

Reverse binary string list per nreverse value.

split_bin(sbin, nbit: int)[source]

Split sbin into many segment with the length nbit.

split_expo_mant(v, min=-1000)[source]
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.

load(file_name='', default_value='')[source]

Load binary file into bytes value.

save(file_name: str, data: List[str])[source]

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

get(jdata, key, default_value)[source]
load(file_name='', default_value={})[source]
save(file_name='', dic={})[source]
update(jdata, jdata_o)[source]

Update key-value pair is key in jdata_o.keys().

Parameters
jdata

new jdata

jdata_o

origin jdata

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.

load(file_name='', default_value=[])[source]

Load .txt file into string list.

save(file_name: str = '', data: list = [])[source]

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.

Parameters
weightsdict

weights

spe_jint

special order of neighbor atom j 0~ntype-1

layer_l

layer order in embedding network 1~nlayer

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.

Parameters
weightsdict

weights

spe_iint

special order of central atom i 0~ntype-1

layer_lint

layer order in embedding network 0~nlayer-1

nlayerint

number of layers

deepmd.nvnmd.utils.map_nvnmd(x, map_y, map_dy, prec, nbit=None)[source]

Mapping function implemented by numpy.

deepmd.nvnmd.utils.nvnmd_args()[source]
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.argcheck.nvnmd_args()[source]

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

disp_message()

Display the log of NVNMD.

get_deepmd_jdata()

Generate input script with member element one by one.

get_dp_init_weights()

Build the weight dict for initialization of net.

get_dscp_jdata()

Generate model/descriptor in input script.

get_fitn_jdata()

Generate model/fitting_net in input script.

get_learning_rate_jdata()

Generate learning_rate in input script.

get_loss_jdata()

Generate loss in input script.

get_model_jdata()

Generate model in input script.

get_nvnmd_jdata()

Generate nvnmd in input script.

get_s_range(davg, dstd)

Get the range of switch function.

get_training_jdata()

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.

init_net_size()

Initialize net_size.

init_size(jdata[, jdata_parent])

Initialize members about ram capacity.

init_train_mode([mod])

Configure for taining cnn or qnn.

init_value()

Initialize member with dict.

save([file_name])

Save all configuration to file.

set_ntype(ntype)

Set the number of type.

update_config()

Update config from dict.

disp_message()[source]

Display the log of NVNMD.

get_deepmd_jdata()[source]

Generate input script with member element one by one.

get_dp_init_weights()[source]

Build the weight dict for initialization of net.

get_dscp_jdata()[source]

Generate model/descriptor in input script.

get_fitn_jdata()[source]

Generate model/fitting_net in input script.

get_learning_rate_jdata()[source]

Generate learning_rate in input script.

get_loss_jdata()[source]

Generate loss in input script.

get_model_jdata()[source]

Generate model in input script.

get_nvnmd_jdata()[source]

Generate nvnmd in input script.

get_s_range(davg, dstd)[source]

Get the range of switch function.

get_training_jdata()[source]

Generate training in input script.

init_config_by_version(version, max_nnei)[source]

Initialize version-dependent parameters.

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_dscp(jdata: dict, jdata_parent: dict = {}) dict[source]

Initialize members about descriptor.

init_fitn(jdata: dict, jdata_parent: dict = {}) dict[source]

Initialize members about fitting network.

init_from_config(jdata)[source]

Initialize member element one by one.

init_from_deepmd_input(jdata)[source]

Initialize members with input script of deepmd.

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.

init_net_size()[source]

Initialize net_size.

init_size(jdata: dict, jdata_parent: dict = {}) dict[source]

Initialize members about ram capacity.

init_train_mode(mod='cnn')[source]

Configure for taining cnn or qnn.

init_value()[source]

Initialize member with dict.

save(file_name=None)[source]

Save all configuration to file.

set_ntype(ntype)[source]

Set the number of type.

update_config()[source]

Update config from dict.

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

bin2hex(data)[source]

Convert binary string list to hex string list.

bin2hex_str(sbin)[source]

Convert binary string to hex string.

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.

dec2bin(idec, nbit=10, signed=False, name='')[source]

Convert dec array to binary string list.

extend_bin(slbin, nfull)[source]

Extend the element of list (slbin) to the length (nfull).

such as, when

slbin = [‘10010’,’10100’],
nfull = 6

extent to

[‘010010’,’010100’]

extend_hex(slhex, nfull)[source]

Extend the element of list (slhex) to the length (nfull).

extend_list(slbin, nfull)[source]

Extend the list (slbin) to the length (nfull) the attched element of list is 0.

such as, when

slbin = [‘10010’,’10100’],
nfull = 4

extent it to

[‘10010’,’10100’,’00000’,’00000]

find_max_expo(v, expo_min=-1000)[source]
flt2bin(data, nbit_expo, nbit_frac)[source]

Convert float into binary string list.

flt2bin_one(v, nbit_expo, nbit_frac)[source]
hex2bin(data)[source]

Convert hex string list to binary string list.

hex2bin_str(shex)[source]

Convert hex string to binary string.

merge_bin(slbin, nmerge)[source]

Merge binary string list per nmerge value.

norm_expo(v, nbit_frac=20, expo_min=-1000)[source]
qc(v, nbit: int = 14)[source]

Quantize value using ceil.

qf(v, nbit: int = 14)[source]

Quantize value using floor.

qr(v, nbit: int = 14)[source]

Quantize value using round.

reverse_bin(slbin, nreverse)[source]

Reverse binary string list per nreverse value.

split_bin(sbin, nbit: int)[source]

Split sbin into many segment with the length nbit.

split_expo_mant(v, min=-1000)[source]

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

create_file_path(file_name='')[source]
exits(file_name='')[source]
get_file_list(path) list[source]
is_file(file_name)[source]
is_path(path)[source]
mkdir(path_name='')[source]
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.

load(file_name='', default_value='')[source]

Load binary file into bytes value.

save(file_name: str, data: List[str])[source]

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

get(jdata, key, default_value)[source]
load(file_name='', default_value={})[source]
save(file_name='', dic={})[source]
update(jdata, jdata_o)[source]

Update key-value pair is key in jdata_o.keys().

Parameters
jdata

new jdata

jdata_o

origin jdata

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.

load(file_name='', default_value={})[source]

Load .json file into dict.

save(file_name='', dic={})[source]

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

load(file_name='', default_value={})[source]
save(file_name='', dic={})[source]
class deepmd.nvnmd.utils.fio.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.

load(file_name='', default_value=[])[source]

Load .txt file into string list.

save(file_name: str = '', data: list = [])[source]

Save string list into .txt file.

deepmd.nvnmd.utils.network module

deepmd.nvnmd.utils.network.get_sess()[source]
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.network.qr(x, nbit)[source]

Quantize and round tensor x with quantification precision nbit.

deepmd.nvnmd.utils.network.tanh4(x)[source]

deepmd.nvnmd.utils.op module

deepmd.nvnmd.utils.op.map_nvnmd(x, map_y, map_dy, prec, nbit=None)[source]

Mapping function implemented by numpy.

deepmd.nvnmd.utils.op.r2s(r, rmin, rmax)[source]

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
weightsdict

weights

layer_l

layer order in embedding network 1~nlayer

deepmd.nvnmd.utils.weight.get_filter_weight(weights: int, spe_j: int, layer_l: int)[source]

Get weight and bias of embedding network.

Parameters
weightsdict

weights

spe_jint

special order of neighbor atom j 0~ntype-1

layer_l

layer order in embedding network 1~nlayer

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.

Parameters
weightsdict

weights

spe_iint

special order of central atom i 0~ntype-1

layer_lint

layer order in embedding network 0~nlayer-1

nlayerint

number of layers

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
weightsdict

weights

layer_l

layer order in embedding network 1~nlayer

deepmd.nvnmd.utils.weight.get_type_weight(weights: dict, layer_l: int)[source]

Get weight and bias of fitting network.

Parameters
weightsdict

weights

layer_lint

layer order in embedding network 0~nlayer-1

deepmd.nvnmd.utils.weight.get_weight(weights, key)[source]

Get weight value according to key.