|
| 1 | +import time |
1 | 2 | from typing import List
|
2 | 3 |
|
3 | 4 | import bittensor as bt
|
|
10 | 11 | def get_energies(
|
11 | 12 | protein: Protein, responses: List[JobSubmissionSynapse], uids: List[int]
|
12 | 13 | ):
|
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 |
15 | 20 |
|
16 | 21 | 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 |
20 | 23 | """
|
21 | 24 | event = {}
|
22 | 25 | event["is_valid"] = [False] * len(uids)
|
23 | 26 | event["checked_energy"] = [0] * len(uids)
|
24 | 27 | event["reported_energy"] = [0] * len(uids)
|
25 | 28 | event["miner_energy"] = [0] * len(uids)
|
26 | 29 | event["rmsds"] = [0] * len(uids)
|
| 30 | + event["process_md_output_time"] = [0] * len(uids) |
| 31 | + event["is_run_valid"] = [0] * len(uids) |
| 32 | + |
27 | 33 | energies = np.zeros(len(uids))
|
| 34 | + |
28 | 35 | for i, (uid, resp) in enumerate(zip(uids, responses)):
|
29 | 36 | # Ensures that the md_outputs from the miners are parsed correctly
|
30 | 37 | try:
|
31 |
| - if not protein.process_md_output( |
| 38 | + start_time = time.time() |
| 39 | + can_process = protein.process_md_output( |
32 | 40 | md_output=resp.md_output,
|
33 | 41 | hotkey=resp.axon.hotkey,
|
34 | 42 | state=resp.miner_state,
|
35 | 43 | seed=resp.miner_seed,
|
36 |
| - ): |
| 44 | + ) |
| 45 | + event["process_md_output_time"][i] = time.time() - start_time |
| 46 | + |
| 47 | + if not can_process: |
37 | 48 | continue
|
38 | 49 |
|
39 | 50 | if resp.dendrite.status_code != 200:
|
40 | 51 | bt.logging.info(
|
41 | 52 | f"uid {uid} responded with status code {resp.dendrite.status_code}"
|
42 | 53 | )
|
43 | 54 | continue
|
| 55 | + |
44 | 56 | energy = protein.get_energy()
|
45 |
| - # rmsd = protein.get_rmsd().iloc[-1]["rmsd"] |
46 | 57 | rmsd = protein.get_rmsd()
|
47 | 58 |
|
48 | 59 | if energy == 0:
|
49 | 60 | continue
|
50 | 61 |
|
| 62 | + start_time = time.time() |
51 | 63 | is_valid, checked_energy, miner_energy = protein.is_run_valid()
|
| 64 | + event["is_run_valid"][i] = time.time() - start_time |
52 | 65 |
|
53 | 66 | energies[i] = energy if is_valid else 0
|
54 | 67 |
|
|
0 commit comments