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

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

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

bin2hex(data)[source]

Convert binary string list to hex string list

bin2hex_str(sbin)[source]

Convert binary string to hex string

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]

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

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

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: 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()

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: dict, spe_i: int, spe_j: int, layer_l: int)[source]

Get weight and bias of embedding network

Parameters
spe_i(int)

special order of central atom i 0~ntype-1

spe_j(int)

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
spe_i(int)

special order of central atom i 0~ntype-1

layer_l(int)

layer order in embedding network 0~nlayer-1

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

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_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_training_jdata()

Generate training in input script

init_ctrl(jdata[, jdata_parent])

Initial members about control signal

init_dscp(jdata[, jdata_parent])

Initial members about descriptor

init_fitn(jdata[, jdata_parent])

Initial members about fitting network

init_from_config(jdata)

Initial member element one by one

init_from_deepmd_input(jdata)

Initial members with input script of deepmd

init_from_jdata([jdata])

Initial this class with jdata loaded from input script

init_nbit(jdata[, jdata_parent])

Initial members about quantification precision

init_net_size()

Initial net_size

init_size(jdata[, jdata_parent])

Initial members about ram capacity

init_train_mode([mod])

Configure for taining cnn or qnn

init_value()

Initial member with dict

save([file_name])

Save all configuration to file

disp_message()[source]

Display the log of NVNMD

get_deepmd_jdata()[source]

Generate input script with member element one by one

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_training_jdata()[source]

Generate training in input script

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

Initial members about control signal

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

Initial members about descriptor

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

Initial members about fitting network

init_from_config(jdata)[source]

Initial member element one by one

init_from_deepmd_input(jdata)[source]

Initial members with input script of deepmd

init_from_jdata(jdata: dict = {})[source]

Initial this class with jdata loaded from input script

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

Initial members about quantification precision

init_net_size()[source]

Initial net_size

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

Initial members about ram capacity

init_train_mode(mod='cnn')[source]

Configure for taining cnn or qnn

init_value()[source]

Initial member with dict

save(file_name=None)[source]

Save all configuration to file

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

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

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

bin2hex(data)[source]

Convert binary string list to hex string list

bin2hex_str(sbin)[source]

Convert binary string to hex string

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]

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

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

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: 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()

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_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.tanh2(x, nbit=- 1, nbit2=- 1)[source]

User-defined activation function tanh2

deepmd.nvnmd.utils.network.tanh4(x, nbit=- 1, nbit2=- 1)[source]

User-defined activation function tanh4

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.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_weight(weights: dict, spe_i: int, spe_j: int, layer_l: int)[source]

Get weight and bias of embedding network

Parameters
spe_i(int)

special order of central atom i 0~ntype-1

spe_j(int)

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
spe_i(int)

special order of central atom i 0~ntype-1

layer_l(int)

layer order in embedding network 0~nlayer-1

deepmd.nvnmd.utils.weight.get_normalize(weights: dict)[source]

Get normalize parameter (avg and std) of \(s_{ji}\)

deepmd.nvnmd.utils.weight.get_rng_s(weights: dict)[source]

Guess the range of \(s_{ji}\)

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

Get weight value according to key