ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_Provenance.H
Go to the documentation of this file.
1 /**
2  * \file ERF_Provenance.H
3  */
4 #ifndef ERF_PROVENANCE_H_
5 #define ERF_PROVENANCE_H_
6 
7 #include <array>
8 #include <cstdint>
9 #include <ctime>
10 #include <string>
11 #include <string_view>
12 #include <vector>
13 
14 namespace erf_provenance
15 {
16 
17 constexpr int schema_version = 1;
18 constexpr const char* provenance_begin = "ERF_PROVENANCE_BEGIN";
19 constexpr const char* provenance_end = "ERF_PROVENANCE_END";
20 
21 /**
22  * The reason a lineage is incomplete is part of the persisted contract.
23  * Missing or invalid metadata never prevents ERF from reading physical state.
24  */
25 enum class LineageStatus
26 {
27  Complete,
34 };
35 
36 enum class ArtifactType
37 {
38  Checkpoint,
39  Plotfile2D,
41 };
42 
44 {
45  Valid,
51 };
52 
53 /**
54  * Identity and known ancestry for one ERF process invocation.
55  *
56  * Simulation identity names one rooted restart family, which may branch.
57  * Execution identity names one invocation. Artifact identity is kept separate
58  * because one invocation can write many checkpoints and plotfiles. The known
59  * ancestry path is stored in every artifact so old directories are not needed
60  * to reconstruct repeated restarts. The parent UUID gives the immediate edge;
61  * the source checkpoint UUID selects the exact checkpoint artifact. These UUIDs
62  * identify records; they do not authenticate contents or provide cryptographic
63  * proof.
64  */
66 {
68  std::string simulation_uuid;
69  std::string execution_uuid;
70  std::string parent_execution_uuid;
71  std::vector<std::string> execution_lineage;
73  bool lineage_complete = true;
77  std::string execution_start_utc;
78 };
79 
81 {
82  std::string artifact_uuid;
84  int artifact_step = -1;
85  double artifact_time_seconds = 0.0;
86  std::string artifact_created_utc;
87 };
88 
90 {
93 };
94 
96 {
99  std::string diagnostic;
100 
101  [[nodiscard]] bool valid () const noexcept
102  {
104  }
105 };
106 
108 
109 /** Format supplied bytes as a lowercase canonical RFC UUIDv4 string. */
110 std::string uuid_v4_from_bytes (const std::array<std::uint8_t, 16>& bytes);
111 
112 /** Validate a lowercase or uppercase canonical RFC UUIDv4 string. */
113 bool is_valid_uuid_v4 (std::string_view uuid);
114 
115 /** Generate a UUID without using AMReX's scientific random-number stream. */
116 std::string generate_uuid_v4 ();
117 
118 /** Format a supplied clock value as an ISO 8601 UTC timestamp. */
119 std::string format_utc (std::time_t time_value);
120 
121 /** Return the current time in the persisted UTC format. */
122 std::string current_utc ();
123 
124 /** Serialize exactly one schema-1 machine-readable block. */
125 std::string serialize_provenance_block (const ProvenanceRecord& record);
126 
127 /** Parse only delimited provenance markers from a human-readable job_info. */
128 ProvenanceParseResult parse_provenance_block (std::string_view job_info_text);
129 
130 /** Read and broadcast one job_info before parsing the same bytes on every rank. */
131 ProvenanceReadResult read_job_info_file (const std::string& job_info_path);
132 
133 /** Create the root record for one cold-start invocation. */
134 ExecutionProvenance make_cold_start_provenance (const std::string& execution_uuid,
135  const std::string& execution_start_utc);
136 
137 /** Create a child record from a valid checkpoint record, including its artifact UUID. */
139  const ProvenanceRecord& parent_checkpoint,
140  const std::string& checkpoint_path);
141 
142 /** Start a new known lineage segment after a nonfatal provenance read failure. */
144  ProvenanceReadStatus failure,
145  const std::string& checkpoint_path);
146 
147 /** Return the stable persisted token for a lineage status. */
148 const char* lineage_status_token (LineageStatus status) noexcept;
149 
150 /** Return the stable persisted token for an artifact type. */
151 const char* artifact_type_token (ArtifactType type) noexcept;
152 
153 /** Initialize one process-wide invocation record and share it across multiblock ERF objects. */
155 
156 } // namespace erf_provenance
157 
158 #endif
Definition: ERF_Provenance.cpp:250
std::string uuid_v4_from_bytes(const std::array< std::uint8_t, 16 > &bytes)
Definition: ERF_Provenance.cpp:252
ProvenanceReadResult read_job_info_file(const std::string &path)
Definition: ERF_Provenance.cpp:485
std::string current_utc()
Definition: ERF_Provenance.cpp:318
constexpr int schema_version
Definition: ERF_Provenance.H:17
std::string serialize_provenance_block(const ProvenanceRecord &record)
Definition: ERF_Provenance.cpp:347
ExecutionProvenance initialize_execution_provenance()
Definition: ERF_Provenance.cpp:562
ProvenanceParseResult parse_provenance_block(std::string_view text)
Definition: ERF_Provenance.cpp:377
ExecutionProvenance make_restart_provenance(const ExecutionProvenance &current_invocation, const ProvenanceRecord &parent_checkpoint, const std::string &checkpoint_path)
Definition: ERF_Provenance.cpp:522
const char * lineage_status_token(LineageStatus status) noexcept
Definition: ERF_Provenance.cpp:323
LineageStatus
Definition: ERF_Provenance.H:26
std::string format_utc(std::time_t time_value)
Definition: ERF_Provenance.cpp:305
constexpr const char * provenance_end
Definition: ERF_Provenance.H:19
ExecutionProvenance make_incomplete_restart_provenance(const ExecutionProvenance &current_invocation, ProvenanceReadStatus failure_status, const std::string &checkpoint_path)
Definition: ERF_Provenance.cpp:546
const char * artifact_type_token(ArtifactType type) noexcept
Definition: ERF_Provenance.cpp:337
bool is_valid_uuid_v4(std::string_view uuid)
Definition: ERF_Provenance.cpp:265
ProvenanceReadStatus
Definition: ERF_Provenance.H:44
std::string generate_uuid_v4()
Definition: ERF_Provenance.cpp:273
ExecutionProvenance make_cold_start_provenance(const std::string &execution_uuid, const std::string &execution_start_utc)
Definition: ERF_Provenance.cpp:511
constexpr const char * provenance_begin
Definition: ERF_Provenance.H:18
ArtifactType
Definition: ERF_Provenance.H:37
Definition: ERF_Provenance.H:81
int artifact_step
Definition: ERF_Provenance.H:84
std::string artifact_uuid
Definition: ERF_Provenance.H:82
double artifact_time_seconds
Definition: ERF_Provenance.H:85
std::string artifact_created_utc
Definition: ERF_Provenance.H:86
ArtifactType artifact_type
Definition: ERF_Provenance.H:83
Definition: ERF_Provenance.H:66
int schema_version
Definition: ERF_Provenance.H:67
std::string source_checkpoint_uuid
Definition: ERF_Provenance.H:75
std::string execution_uuid
Definition: ERF_Provenance.H:69
std::vector< std::string > execution_lineage
Definition: ERF_Provenance.H:71
LineageStatus lineage_status
Definition: ERF_Provenance.H:74
bool lineage_complete
Definition: ERF_Provenance.H:73
std::string parent_execution_uuid
Definition: ERF_Provenance.H:70
std::string execution_start_utc
Definition: ERF_Provenance.H:77
std::string source_checkpoint_path
Definition: ERF_Provenance.H:76
int restart_generation
Definition: ERF_Provenance.H:72
std::string simulation_uuid
Definition: ERF_Provenance.H:68
Definition: ERF_Provenance.H:96
ProvenanceRecord record
Definition: ERF_Provenance.H:98
bool valid() const noexcept
Definition: ERF_Provenance.H:101
std::string diagnostic
Definition: ERF_Provenance.H:99
ProvenanceReadStatus status
Definition: ERF_Provenance.H:97
Definition: ERF_Provenance.H:90
ArtifactProvenance artifact
Definition: ERF_Provenance.H:92
ExecutionProvenance execution
Definition: ERF_Provenance.H:91