Quantum 3xplorer (Q3)
An AI-native quantum simulation engine
Loading...
Searching...
No Matches
factory.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * Top-level iterator factory — dispatches by theory.
5 *
6 * create_iterator(InputData) is the main entry point for production use.
7 * Reads input.theory to select the method (default: "kohn_sham") and
8 * delegates to the appropriate sub-factory.
9 *
10 * Uses PlanewaveSerialExecutionPolicy by default (serial, single-process).
11 * For MPI runs, use io/iterator/kohn_sham/planewave/factory_mpi.hpp which supplies
12 * PlanewaveMPIExecutionPolicy.
13 */
14
15#include <functional>
16#include <memory>
17#include <stdexcept>
18#include <string>
19
20#include "io/input/data.hpp"
23
24namespace q3 {
25
26/**
27 * Create a serial SCF iterator from parsed InputData.
28 *
29 * Dispatches by input.theory:
30 * - "kohn_sham" (default): delegates to create_kohn_sham_iterator(input, policy).
31 *
32 * Returns a PlanewaveKohnShamSCFIterator so callers can access result()
33 * without knowing the concrete subclass.
34 *
35 * Ownership of the execution policy is transferred into the returned iterator.
36 */
37inline std::unique_ptr<PlanewaveKohnShamSCFIterator> create_iterator(const InputData& input) {
38 if (input.theory == "kohn_sham") {
39 auto policy = std::make_unique<execution::PlanewaveSerialExecutionPolicy>();
40 const execution::PlanewaveSerialExecutionPolicy& policy_ref = *policy;
41 auto iterator = create_kohn_sham_iterator(input, policy_ref);
42 iterator->set_owned_execution_policy(std::move(policy));
43 return iterator;
44 }
45 throw std::runtime_error("Unsupported theory: " + input.theory);
46}
47
48/**
49 * Builds the iterator a flavor runs, from the input that flavor prepared.
50 *
51 * The seam through which an entry point hands every flavor its execution environment
52 * -- an MPI execution policy and its topology, a GPU diagonalizer -- without
53 * the flavor naming either. A flavor that adjusts its input first (a
54 * non-self-consistent pass caps the iterations and tightens the solver) still
55 * gets the entry point's setup, because it is the adjusted input that is
56 * passed in. Empty means create_iterator(): serial, on the CPU.
57 */
59 std::function<std::unique_ptr<PlanewaveKohnShamSCFIterator>(const InputData&)>;
60
61/// The iterator `factory` builds for `input`, or the serial one when it is empty.
62inline std::unique_ptr<PlanewaveKohnShamSCFIterator>
63create_iterator(const InputData& input, const IteratorFactory& factory) {
64 return factory ? factory(input) : create_iterator(input);
65}
66
67} // namespace q3
std::function< std::unique_ptr< PlanewaveKohnShamSCFIterator >(const InputData &)> IteratorFactory
Definition factory.hpp:59
std::unique_ptr< PlanewaveKohnShamSCFIterator > create_iterator(const InputData &input)
Definition factory.hpp:37
std::unique_ptr< PlanewaveKohnShamSCFIterator > create_kohn_sham_iterator(const InputData &input, const execution::PlanewaveExecutionPolicy &execution_policy)
Definition factory.hpp:64
Parsed input data — holds raw values read from input files.
Definition data.hpp:27
std::string theory
Definition data.hpp:29