Skip to content

Commit 0290dfd

Browse files
Merge pull request #223 from macrocosm-os/staging
Staging
2 parents fb0edd8 + 1dd3b12 commit 0290dfd

File tree

9 files changed

+52
-21
lines changed

9 files changed

+52
-21
lines changed

folding/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .protocol import JobSubmissionSynapse
22
from .validators.protein import Protein
33

4-
__version__ = "1.0.1"
4+
__version__ = "1.0.2"
55
version_split = __version__.split(".")
66
__spec_version__ = (
77
(10000 * int(version_split[0]))

folding/miners/folding_miner.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -395,17 +395,19 @@ def submit_simulation(
395395
with open(os.path.join(output_dir, f"{pdb_id}.pdb"), "w") as f:
396396
f.write(synapse.pdb_contents)
397397

398-
system_config = SimulationConfig(**synapse.system_config)
398+
system_config = copy.deepcopy(synapse.system_config)
399+
if system_config["seed"] is None:
400+
system_config["seed"] = self.generate_random_seed()
401+
402+
system_config = SimulationConfig(**system_config)
399403
write_pkl(system_config, system_config_filepath)
400404

401405
# Create the job and submit it to the executor
402406
simulation_manager = SimulationManager(
403407
pdb_id=pdb_id,
404408
output_dir=output_dir,
405409
system_config=system_config.to_dict(),
406-
seed=self.generate_random_seed()
407-
if system_config.seed is None
408-
else system_config.seed,
410+
seed=system_config.seed,
409411
)
410412

411413
future = self.executor.submit(

folding/store.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ class Job:
153153
gro_hash: str = None
154154
update_interval: pd.Timedelta = pd.Timedelta(minutes=10)
155155
updated_count: int = 0
156+
min_updates: int = 5
156157
max_time_no_improvement: pd.Timedelta = pd.Timedelta(minutes=25)
157-
min_updates: int = 10
158158
epsilon: float = 0.05 # percentage.
159159
event: dict = None
160160

@@ -185,14 +185,21 @@ def update(
185185
raise ValueError(f"Hotkey {hotkey!r} is not a valid choice")
186186

187187
percent_improvement = (
188-
(self.best_loss - loss) / self.best_loss
188+
(loss - self.best_loss) / self.best_loss
189189
if not np.isinf(self.best_loss) and not self.best_loss == 0
190-
else 1
190+
else np.nan
191191
)
192192
self.updated_at = pd.Timestamp.now().floor("s")
193193
self.updated_count += 1
194194

195-
if (np.isinf(self.best_loss)) or percent_improvement >= self.epsilon:
195+
never_updated_better_loss = (
196+
np.isnan(percent_improvement) and loss < self.best_loss
197+
) # only happens if best_loss is 0 or inf
198+
better_loss = (
199+
percent_improvement >= self.epsilon
200+
) # only happens if best_loss is not 0 or inf
201+
202+
if never_updated_better_loss or better_loss:
196203
self.best_loss = loss
197204
self.best_loss_at = pd.Timestamp.now().floor("s")
198205
self.best_hotkey = hotkey

folding/utils/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def add_args(cls, parser):
194194
"--neuron.events_retention_size",
195195
type=str,
196196
help="Events retention size.",
197-
default="2 GB",
197+
default="25 MB",
198198
)
199199

200200
parser.add_argument(

folding/utils/logging.py

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from loguru import logger
55
from dataclasses import asdict, dataclass
66
import datetime as dt
7+
import os
78

89
import folding
910
import bittensor as bt
@@ -113,6 +114,7 @@ def log_event(self, event, failed=False, pdb_location: str = None):
113114

114115
# Log the event to wandb.
115116
run.log(event)
117+
wandb.save(os.path.join(self.config.neuron.full_path, f"events.log"))
116118

117119
if pdb_location is not None:
118120
log_protein(run, pdb_id_path=pdb_location)

folding/validators/forward.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ def run_step(
6868
# Get the list of uids to query for this step.
6969
axons = [self.metagraph.axons[uid] for uid in uids]
7070

71+
system_config = protein.system_config.to_dict()
72+
system_config["seed"] = None # We don't want to pass the seed to miners.
73+
7174
synapse = JobSubmissionSynapse(
7275
pdb_id=protein.pdb_id,
7376
md_inputs=protein.md_inputs,
7477
pdb_contents=protein.pdb_contents,
75-
system_config=protein.system_config.to_dict(),
78+
system_config=system_config,
7679
)
7780

7881
# Make calls to the network with the prompt - this is synchronous.

folding/validators/protein.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(
6363
self.water: str = water
6464

6565
self.system_config = SimulationConfig(
66-
ff=self.ff, water=self.water, box=self.box, seed=25
66+
ff=self.ff, water=self.water, box=self.box, seed=1337
6767
)
6868

6969
self.config = config

folding/validators/reward.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import time
12
from typing import List
23

34
import bittensor as bt
@@ -10,45 +11,57 @@
1011
def get_energies(
1112
protein: Protein, responses: List[JobSubmissionSynapse], uids: List[int]
1213
):
13-
"""Takes all the data from reponse synapses, applies the reward pipeline, and aggregates the rewards
14-
into a single torch.FloatTensor. Also aggregates the RMSDs for logging.
14+
"""Takes all the data from reponse synapses, checks if the data is valid, and returns the energies.
15+
16+
Args:
17+
protein (Protein): instance of the Protein class
18+
responses (List[JobSubmissionSynapse]): list of JobSubmissionSynapse objects
19+
uids (List[int]): list of uids
1520
1621
Returns:
17-
tuple:
18-
torch.FloatTensor: A tensor of rewards for each miner.
19-
torch.FloatTensor: A tensor of RMSDs for each miner.
22+
Tuple: Tuple containing the energies and the event dictionary
2023
"""
2124
event = {}
2225
event["is_valid"] = [False] * len(uids)
2326
event["checked_energy"] = [0] * len(uids)
2427
event["reported_energy"] = [0] * len(uids)
2528
event["miner_energy"] = [0] * len(uids)
2629
event["rmsds"] = [0] * len(uids)
30+
event["process_md_output_time"] = [0] * len(uids)
31+
event["is_run_valid"] = [0] * len(uids)
32+
2733
energies = np.zeros(len(uids))
34+
2835
for i, (uid, resp) in enumerate(zip(uids, responses)):
2936
# Ensures that the md_outputs from the miners are parsed correctly
3037
try:
31-
if not protein.process_md_output(
38+
start_time = time.time()
39+
can_process = protein.process_md_output(
3240
md_output=resp.md_output,
3341
hotkey=resp.axon.hotkey,
3442
state=resp.miner_state,
3543
seed=resp.miner_seed,
36-
):
44+
)
45+
event["process_md_output_time"][i] = time.time() - start_time
46+
47+
if not can_process:
3748
continue
3849

3950
if resp.dendrite.status_code != 200:
4051
bt.logging.info(
4152
f"uid {uid} responded with status code {resp.dendrite.status_code}"
4253
)
4354
continue
55+
4456
energy = protein.get_energy()
45-
# rmsd = protein.get_rmsd().iloc[-1]["rmsd"]
4657
rmsd = protein.get_rmsd()
4758

4859
if energy == 0:
4960
continue
5061

62+
start_time = time.time()
5163
is_valid, checked_energy, miner_energy = protein.is_run_valid()
64+
event["is_run_valid"][i] = time.time() - start_time
5265

5366
energies[i] = energy if is_valid else 0
5467

neurons/validator.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ def prepare_event_for_logging(event: Dict):
304304
rewards.numpy()
305305
) # add the rewards to the logging event.
306306

307-
bt.logging.success(f"Event information: {merged_events}")
308307
event = prepare_event_for_logging(merged_events)
309308

310309
# If the job is finished, remove the pdb directory
@@ -319,6 +318,11 @@ def prepare_event_for_logging(event: Dict):
319318
else:
320319
bt.logging.error(f"Protein.from_job returns NONE for protein {job.pdb}")
321320

321+
# Remove these keys from the log because they polute the terminal.
322+
merged_events.pop("checked_energy")
323+
merged_events.pop("miner_energy")
324+
325+
bt.logging.success(f"Event information: {merged_events}")
322326
log_event(self, event=event, pdb_location=pdb_location)
323327

324328

0 commit comments

Comments
 (0)