Resolve "Pruning functionality"
Features
- Added pruning functionality for cluster expansions
- Pruning will only remove parameters and orbits if possible which is mostly an issue with e.g. ternaries where one orbit links to several ECI's
- Pruning without arguments remove all orbits with zero ECIs if possible
- Pruning can also be done with indices (try to remove the orbits corresponding to the ECIs) or tolerances (tries to prune all orbits with ECIs that have abs values smaller than tol
- Reading a written CE that's been pruned will return the pruned CE
- The CE calc will automatically call the prune function to remove all orbits with zero ECI, i.e. when running the MC the user will not have to do anything special.
- Zerolet will never be pruned
DEMO Running the below script:
from icet import ClusterSpace, ClusterExpansion
from ase.build import bulk
import numpy as np
from time import time
def get_predict_timings(ce, atoms):
t0 = time()
for _ in range(100):
ce.predict(atoms)
t1 = time()
return t1-t0
atoms = bulk('Au')
cutoffs = [5.0] * 3
chemical_symbols = ['Au', 'Pd']
cs = ClusterSpace(atoms, cutoffs, chemical_symbols)
parameters = np.array([0] * len(cs))
parameters[np.array([2, 4, 7, 5, 22])] = 10
ce = ClusterExpansion(cs, parameters)
t_before_prune = get_predict_timings(ce, atoms.repeat(5))
print(ce)
ce.prune()
t_after_prune = get_predict_timings(ce, atoms.repeat(5))
print(ce)
ce.prune(tol=11)
print(ce)
print(
f"\n\ntime before prune {t_before_prune:.2f}s, time after prune {t_after_prune:.2f}s. Speedup: {t_before_prune/t_after_prune:.2f}")
Will yield the following output
=================================== Cluster Expansion ====================================
chemical species: ['Au', 'Pd']
cutoffs: 5.0000 5.0000 5.0000
total number of orbits: 28
number of orbits by order: 0= 1 1= 1 2= 3 3= 7 4= 16
------------------------------------------------------------------------------------------
index | order | radius | multiplicity | orbit_index | multi_component_vector | ECI
------------------------------------------------------------------------------------------
0 | 0 | 0.0000 | 1 | -1 | . | 0
1 | 1 | 0.0000 | 1 | 0 | [0] | 0
2 | 2 | 1.4425 | 6 | 1 | [0, 0] | 10
3 | 2 | 2.0400 | 3 | 2 | [0, 0] | 0
4 | 2 | 2.4985 | 12 | 3 | [0, 0] | 10
5 | 3 | 1.6657 | 8 | 4 | [0, 0, 0] | 10
6 | 3 | 1.8869 | 12 | 5 | [0, 0, 0] | 0
7 | 3 | 2.0168 | 24 | 6 | [0, 0, 0] | 10
8 | 3 | 2.3021 | 24 | 7 | [0, 0, 0] | 0
9 | 3 | 2.4967 | 24 | 8 | [0, 0, 0] | 0
10 | 3 | 2.7099 | 24 | 9 | [0, 0, 0] | 0
11 | 3 | 2.8850 | 8 | 10 | [0, 0, 0] | 0
12 | 4 | 1.7667 | 2 | 11 | [0, 0, 0, 0] | 0
13 | 4 | 1.8883 | 12 | 12 | [0, 0, 0, 0] | 0
14 | 4 | 1.9705 | 12 | 13 | [0, 0, 0, 0] | 0
15 | 4 | 2.0400 | 3 | 14 | [0, 0, 0, 0] | 0
16 | 4 | 2.0857 | 48 | 15 | [0, 0, 0, 0] | 0
17 | 4 | 2.1604 | 24 | 16 | [0, 0, 0, 0] | 0
18 | 4 | 2.1637 | 8 | 17 | [0, 0, 0, 0] | 0
19 | 4 | 2.2240 | 24 | 18 | [0, 0, 0, 0] | 0
20 | 4 | 2.3377 | 48 | 19 | [0, 0, 0, 0] | 0
21 | 4 | 2.4133 | 8 | 20 | [0, 0, 0, 0] | 0
22 | 4 | 2.4162 | 24 | 21 | [0, 0, 0, 0] | 10
23 | 4 | 2.4985 | 6 | 22 | [0, 0, 0, 0] | 0
24 | 4 | 2.5594 | 48 | 23 | [0, 0, 0, 0] | 0
25 | 4 | 2.7608 | 48 | 24 | [0, 0, 0, 0] | 0
26 | 4 | 2.7871 | 12 | 25 | [0, 0, 0, 0] | 0
27 | 4 | 2.8850 | 6 | 26 | [0, 0, 0, 0] | 0
==========================================================================================
=================================== Cluster Expansion ====================================
chemical species: ['Au', 'Pd']
cutoffs: 5.0000 5.0000 5.0000
total number of orbits: 6
number of orbits by order: 0= 1 2= 2 3= 2 4= 1
------------------------------------------------------------------------------------------
index | order | radius | multiplicity | orbit_index | multi_component_vector | ECI
------------------------------------------------------------------------------------------
0 | 0 | 0.0000 | 1 | -1 | . | 0
1 | 2 | 1.4425 | 6 | 0 | [0, 0] | 10
2 | 2 | 2.4985 | 12 | 1 | [0, 0] | 10
3 | 3 | 1.6657 | 8 | 2 | [0, 0, 0] | 10
4 | 3 | 2.0168 | 24 | 3 | [0, 0, 0] | 10
5 | 4 | 2.4162 | 24 | 4 | [0, 0, 0, 0] | 10
==========================================================================================
=================================== Cluster Expansion ====================================
chemical species: ['Au', 'Pd']
cutoffs: 5.0000 5.0000 5.0000
total number of orbits: 1
number of orbits by order: 0= 1
------------------------------------------------------------------------------------------
index | order | radius | multiplicity | orbit_index | multi_component_vector | ECI
------------------------------------------------------------------------------------------
0 | 0 | 0.0000 | 1 | -1 | . | 0
==========================================================================================
time before prune 3.85s, time after prune 0.52s. Speedup: 7.44
Closes #88 (closed)
Edited by Mattias Ångqvist