Skip to content

Commit 6b6132d

Browse files
committed
Rename hash_() -> hashfunc() and raise warning when using hash_()
1 parent 3554b13 commit 6b6132d

5 files changed

Lines changed: 24 additions & 13 deletions

notebooks/PyBroMo - 1. Simulate 3D trajectories - single core.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"source": [
7878
"# Initialize the random state\n",
7979
"rs = np.random.RandomState(seed=1)\n",
80-
"print('Initial random state:', pbm.hash_(rs.get_state()))\n",
80+
"print('Initial random state:', pbm.hashfunc(rs.get_state()))\n",
8181
"\n",
8282
"# Simulation time step (seconds)\n",
8383
"t_step = 0.5e-6\n",
@@ -107,7 +107,7 @@
107107
"S = pbm.ParticlesSimulation(t_step=t_step, t_max=t_max, \n",
108108
" particles=P, box=box, psf=psf)\n",
109109
"\n",
110-
"print('Current random state:', pbm.hash_(rs.get_state()))"
110+
"print('Current random state:', pbm.hashfunc(rs.get_state()))"
111111
]
112112
},
113113
{
@@ -214,7 +214,7 @@
214214
"metadata": {},
215215
"outputs": [],
216216
"source": [
217-
"print('Current random state:', pbm.hash_(rs.get_state()))"
217+
"print('Current random state:', pbm.hashfunc(rs.get_state()))"
218218
]
219219
},
220220
{
@@ -233,7 +233,7 @@
233233
"metadata": {},
234234
"outputs": [],
235235
"source": [
236-
"print('Current random state:', pbm.hash_(rs.get_state()))"
236+
"print('Current random state:', pbm.hashfunc(rs.get_state()))"
237237
]
238238
},
239239
{
@@ -367,7 +367,7 @@
367367
" plt.plot(t, em_ip, label='P%d' % ip)\n",
368368
" ax.set_xlabel('Time (ms)')\n",
369369
" \n",
370-
" rs_hash = pbm.hash_(S.traj_group._v_attrs['init_random_state'])[:3]\n",
370+
" rs_hash = pbm.hashfunc(S.traj_group._v_attrs['init_random_state'])[:3]\n",
371371
" ax.set_title('%ds ID-EID: %d-%d, sim rs = %s, part rs = %s' %\\\n",
372372
" (s, S.ID, S.EID, rs_hash, S.particles.rs_hash[:3]))\n",
373373
" ax.legend(bbox_to_anchor=(1.03, 1), loc=2, borderaxespad=0.)\n",

notebooks/PyBroMo - A1. Reference - Data format and internals.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@
580580
" print ('\\t%s' % attr)\n",
581581
" attr_data = repr(node._v_attrs[attr])\n",
582582
" if len(attr_data) > 300:\n",
583-
" attr_data = hash_(node._v_attrs[attr])\n",
583+
" attr_data = hashfunc(node._v_attrs[attr])\n",
584584
" print (\"\\t %s\" % attr_data)"
585585
]
586586
},
@@ -876,7 +876,7 @@
876876
" print ('\\t%s' % attr)\n",
877877
" attr_data = repr(node._v_attrs[attr])\n",
878878
" if len(attr_data) > 300:\n",
879-
" attr_data = pbm.hash_(node._v_attrs[attr])\n",
879+
" attr_data = pbm.hashfunc(node._v_attrs[attr])\n",
880880
" print (\"\\t %s\" % attr_data)\n",
881881
" \n",
882882
"print ('\\n>> Attributes in %s:\\n' % group)\n",

notebooks/PyBroMo - B.1 Disk-single-core - Generate photon timestamps.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"source": [
110110
"# Get the random state at the end of the diffusion simulation\n",
111111
"saved_rs_state = S.traj_group._v_attrs['last_random_state']\n",
112-
"pbm.hash_(saved_rs_state)"
112+
"pbm.hashfunc(saved_rs_state)"
113113
]
114114
},
115115
{

pybromo/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616

1717
from .utils import hdf5
1818

19-
from .diffusion import Box, Particles, ParticlesSimulation, hash_
19+
from .diffusion import Box, Particles, ParticlesSimulation, hashfunc
2020
from .psflib import GaussianPSF, NumericPSF
2121
from .timestamps import TimestampSimulation
22+
23+
import warnings
24+
25+
26+
def deprecation(message):
27+
warnings.warn(message, FutureWarning, stacklevel=2)
28+
29+
30+
def hash_(x):
31+
deprecation('The function `hash_` is deprecated, please use `hashfunc` instead.')
32+
return hashfunc(x)

pybromo/timestamps.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from pathlib import Path
1414
import phconvert as phc
1515

16-
from .diffusion import hash_
16+
from .diffusion import hashfunc
1717
from ._version import get_versions
1818
__version__ = get_versions()['version']
1919

@@ -268,7 +268,7 @@ def filepath(self):
268268
def _calc_hash_da(self, rs):
269269
"""Compute hash of D and A timestamps for single-step D+A case.
270270
"""
271-
self.hash_d = hash_(rs.get_state())[:6]
271+
self.hash_d = hashfunc(rs.get_state())[:6]
272272
self.hash_a = self.hash_d
273273

274274
def run(self, rs, overwrite=True, skip_existing=False, path=None,
@@ -291,7 +291,7 @@ def run(self, rs, overwrite=True, skip_existing=False, path=None,
291291
header = ' - Mixture Simulation:'
292292

293293
# Donor timestamps hash is from the input RandomState
294-
self.hash_d = hash_(rs.get_state())[:6] # needed by merge_da()
294+
self.hash_d = hashfunc(rs.get_state())[:6] # needed by merge_da()
295295
print('%s Donor timestamps - %s' % (header, ctime()), flush=True)
296296
self.S.simulate_timestamps_mix(
297297
populations=self.populations,
@@ -304,7 +304,7 @@ def run(self, rs, overwrite=True, skip_existing=False, path=None,
304304
# donor + acceptor timestamps given the input random state.
305305
ts_d, _, _ = self.S.get_timestamp_data(self.name_timestamps_d)
306306
rs.set_state(ts_d.attrs['last_random_state'])
307-
self.hash_a = hash_(rs.get_state())[:6] # needed by merge_da()
307+
self.hash_a = hashfunc(rs.get_state())[:6] # needed by merge_da()
308308
print('\n%s Acceptor timestamps - %s' % (header, ctime()), flush=True)
309309
self.S.simulate_timestamps_mix(
310310
populations=self.populations,

0 commit comments

Comments
 (0)