Skip to content

Commit a93f5fa

Browse files
committed
Merge branch 'evoxtorch-dev-xbq' of https://github.com/EMI-Group/evox into evoxtorch-dev-xbq
2 parents f35d893 + d7b362a commit a93f5fa

3 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/evox/algorithms/so/de_variants/shade.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ def step(self):
6969
device = self.pop.device
7070
indices = torch.arange(self.pop_size, device=device)
7171

72-
FCR_ids = torch.randperm(self.pop_size)
72+
# FCR_ids = torch.randperm(self.pop_size)
73+
# The above code does not support the torch.compile (at least up to Pytorch 2.9.0), see https://github.com/pytorch/pytorch/issues/158457.
74+
# Thus, use the following codes:
75+
FCR_ids = torch.argsort(torch.rand(self.pop_size, device=device))
7376
M_F_vect = self.Memory_FCR[0, FCR_ids]
7477
M_CR_vect = self.Memory_FCR[1, FCR_ids]
7578

src/evox/algorithms/so/es_variants/cma_es.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def _update_covariance_matrix(
125125
y = (population - old_mean) / self.sigma
126126
update = (
127127
(1 - self.c_1 - self.c_mu) * C
128-
+ self.c_1 * (p_c @ p_c.T + (1 - h_sigma) * self.c_c * (2 - self.c_c) * C)
129-
+ self.c_mu * (y.T * self.weights) @ y
128+
+ self.c_1 * (p_c.dot(p_c) + (1 - h_sigma) * self.c_c * (2 - self.c_c) * C)
129+
+ self.c_mu * (y.mT * self.weights) @ y
130130
)
131131
return update
132132

@@ -161,20 +161,22 @@ def _conditional_decomposition(self, iteration: torch.Tensor, C: torch.Tensor):
161161
return B, D, C_invsqrt
162162

163163
def _no_decomposition(self, C: torch.Tensor):
164-
return torch.stack([self.B, self.D, self.C_invsqrt], dim=0)
164+
return self.B.clone(), self.D.clone(), self.C_invsqrt.clone()
165165

166166
def _decomposition(
167167
self,
168168
C: torch.Tensor,
169169
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
170-
C = (C + C.T) / 2
171-
D, B = torch.linalg.eigh(C)
170+
# symC = (C + C.T) / 2 # This will fail to compile since PyTorch tries to in-place modify C
171+
symC = C.clone()
172+
symC = (symC + symC.mT) / 2
173+
D, B = torch.linalg.eigh(symC)
172174
D = torch.clamp(D, min=1e-8)
173-
C_invsqrt = B @ torch.diag(1.0 / torch.sqrt(D)) @ B.T
175+
C_invsqrt = B @ torch.diag(1.0 / torch.sqrt(D)) @ B.mT
174176
D = torch.diag(D)
175177
D = torch.sqrt(D)
176178
D = B @ D
177-
return torch.stack([B.T, D, C_invsqrt], dim=0)
179+
return B.mT, D, C_invsqrt
178180

179181
def record_step(self):
180182
return {

src/evox/metrics/hv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def hv(objs: torch.Tensor, ref: torch.Tensor, num_sample: int = 100000):
1414
points = torch.abs(objs - ref)
1515
bound = torch.max(points, dim=0).values
1616
max_vol = torch.prod(bound)
17-
samples = torch.rand(num_sample, points.size(1)) * bound
17+
samples = torch.rand(num_sample, points.size(1), device=objs.device) * bound
1818
in_hypercube = torch.any(torch.all(samples.unsqueeze(1) < points.unsqueeze(0), dim=2), dim=1)
1919
hv = in_hypercube.sum() / num_sample * max_vol
2020
return hv

0 commit comments

Comments
 (0)