File size: 3,700 Bytes
b84549f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
from dataclasses import dataclass
import json
from typing import List
@dataclass
class TrialResult:
"""
TrialResult stores the result information of a trial job.
Attributes
----------
parameter: dict
Hyper parameters for this trial.
value: serializable object, usually a number, or a dict with key "default" and other extra keys
Final result.
trialJobId: str
Trial job id.
"""
parameter: dict
value: dict
trialJobId: str
def __init__(self, parameter: dict, value: str, trialJobId: str):
self.parameter = parameter
self.value = json.loads(value)
self.trialJobId = trialJobId
@dataclass
class TrialMetricData:
"""
TrialMetricData stores the metric data of a trial job.
A trial job may have both intermediate metric and final metric.
Attributes
----------
timestamp: int
Time stamp.
trialJobId: str
Trial job id.
parameterId: int
Parameter id.
type: str
Metric type, `PERIODICAL` for intermediate result and `FINAL` for final result.
sequence: int
Sequence number in this trial.
data: serializable object, usually a number, or a dict with key "default" and other extra keys
Metric data.
"""
timestamp: int
trialJobId: str
parameterId: int
type: str
sequence: int
data: dict
def __init__(self, timestamp: int, trialJobId: str, parameterId: int, type: str, sequence: int, data: str): # pylint: disable=W0622
self.timestamp = timestamp
self.trialJobId = trialJobId
self.parameterId = parameterId
self.type = type
self.sequence = sequence
self.data = json.loads(json.loads(data))
@dataclass
class TrialHyperParameters:
"""
TrialHyperParameters stores the hyper parameters of a trial job.
Attributes
----------
parameter_id: int
Parameter id.
parameter_source: str
Parameter source.
parameters: dict
Hyper parameters.
parameter_index: int
Parameter index.
"""
parameter_id: int
parameter_source: str
parameters: dict
parameter_index: int
@dataclass
class TrialJob:
"""
TrialJob stores the information of a trial job.
Attributes
----------
trialJobId: str
Trial job id.
status: str
Job status.
hyperParameters: list of `nni.experiment.TrialHyperParameters`
See `nni.experiment.TrialHyperParameters`.
logPath: str
Log path.
startTime: int
Job start time (timestamp).
endTime: int
Job end time (timestamp).
finalMetricData: list of `nni.experiment.TrialMetricData`
See `nni.experiment.TrialMetricData`.
stderrPath: str
Stderr log path.
sequenceId: int
Sequence Id.
"""
trialJobId: str
status: str
hyperParameters: List[TrialHyperParameters]
logPath: str
startTime: int
endTime: int
finalMetricData: List[TrialMetricData]
stderrPath: str
sequenceId: int
def __init__(self, trialJobId: str, status: str, logPath: str, startTime: int, sequenceId: int,
endTime: int = -1, stderrPath: str = '', hyperParameters: List = [], finalMetricData: List = []):
self.trialJobId = trialJobId
self.status = status
self.hyperParameters = [TrialHyperParameters(**json.loads(e)) for e in hyperParameters]
self.logPath = logPath
self.startTime = startTime
self.endTime = endTime
self.finalMetricData = [TrialMetricData(**e) for e in finalMetricData]
self.stderrPath = stderrPath
self.sequenceId = sequenceId
|