From 2dae90efda318c111f6b675a27a3e1ecf2274d8a Mon Sep 17 00:00:00 2001 From: nathandelcid Date: Sat, 6 Jun 2026 13:37:39 -0500 Subject: [PATCH] feat: new lifecycle tutorial --- examples/tutorials/min_quest_lifecycle.c | 58 ++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 examples/tutorials/min_quest_lifecycle.c diff --git a/examples/tutorials/min_quest_lifecycle.c b/examples/tutorials/min_quest_lifecycle.c new file mode 100644 index 000000000..53863929e --- /dev/null +++ b/examples/tutorials/min_quest_lifecycle.c @@ -0,0 +1,58 @@ +/** @file + * Minimal end-to-end example of a standard QuEST simulation. + * + * This example demonstrates the typical lifecycle of a QuEST program: + * 1. initialise the QuEST environment, + * 2. create a quantum register, + * 3. initialise its state, + * 4. apply operations, + * 5. report or calculate results, + * 6. destroy allocated objects, + * 7. finalise the environment. + * + * @author Nathan Delcid + */ + +#include "quest.h" + +int main(void) { + + // Initialise the QuEST environment. This prepares available hardware + // backends such as MPI, GPU acceleration and multithreading if enabled. + initQuESTEnv(); + + // Create a 2-qubit statevector Qureg. + // + // Its amplitudes correspond to: + // alpha_0 |00> + // alpha_1 |01> + // alpha_2 |10> + // alpha_3 |11> + // + // Qubit 0 is the rightmost, least-significant qubit. + Qureg qureg = createQureg(2); + + // Initialise the register to |00>. + initZeroState(qureg); + + // Apply some example operations. + // + // Hadamard on qubit 0 prepares: + // (|00> + |01>) / sqrt(2) + // + // Pauli-X on qubit 1 then flips the left qubit, giving: + // (|10> + |11>) / sqrt(2) + applyHadamard(qureg, 0); + applyPauliX(qureg, 1); + + // Report the resulting statevector amplitudes. + reportQureg(qureg); + + // Free memory allocated for the Qureg. + destroyQureg(qureg); + + // Finalise the QuEST environment. + finalizeQuESTEnv(); + + return 0; +}