Loading...
Searching...
No Matches
factory.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * create_provenance_record — pick the provenance record a Q3 run produces.
5 *
6 * The records under provenance/ each describe one level of what a run was:
7 * a quantum system that was solved (QuantumSystemProvenanceRecord), solved in a
8 * plane-wave basis (PlanewaveProvenanceRecord), whose potentials are
9 * pseudopotentials (PseudopotentialProvenanceRecord). Which of them a given run
10 * needs is a question about the run, and this is the single place that answers
11 * it -- the same shape as create_input_parser() and create_mean_field_exporter().
12 *
13 * Today the answer is unconditional, because a Q3 calculation is a plane-wave
14 * pseudopotential calculation and there is nothing yet to choose between. That
15 * is deliberately still expressed as a factory rather than a hard-coded
16 * construction at the call sites: when a second representation arrives, the
17 * choice is made here, once, and Flavor::run(), the bindings and every other
18 * caller keep working through build_provenance_json() without knowing that a
19 * choice exists at all.
20 *
21 * A record borrows the InputData it reports on rather than copying it, so it
22 * must not outlive that input -- which is why the common case has a function of
23 * its own that builds the JSON and lets the record go.
24 */
25
26#include <memory>
27
28#include <nlohmann/json.hpp>
29
30#include "io/input/data.hpp"
34
35namespace q3 {
36
37/// The provenance record for a run of this input. Borrows `input`.
38[[nodiscard]] inline std::unique_ptr<QuantumSystemProvenanceRecord>
40 return std::make_unique<PseudopotentialProvenanceRecord>(input);
41}
42
43/// Build the provenance block for a completed run, from the input it consumed.
44[[nodiscard]] inline nlohmann::json build_provenance_json(const InputData& input) {
45 return create_provenance_record(input)->to_json();
46}
47
48} // namespace q3
std::unique_ptr< QuantumSystemProvenanceRecord > create_provenance_record(const InputData &input)
The provenance record for a run of this input. Borrows input.
Definition factory.hpp:39
nlohmann::json build_provenance_json(const InputData &input)
Build the provenance block for a completed run, from the input it consumed.
Definition factory.hpp:44
Parsed input data — holds raw values read from input files.
Definition data.hpp:27