Maestro 0.1.0
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
advanced_simulation.cpp
Go to the documentation of this file.
1
13
15#include <iostream>
16#include <vector>
17
18int main() {
19 // 1. Initialize Maestro
20 void *maestro = GetMaestroObject();
21 if (!maestro) {
22 std::cerr << "Failed to initialize Maestro." << std::endl;
23 return 1;
24 }
25
26 // 2. Create a Simulator
27 // Create a Statevector simulator.
28 // Simulators::SimulatorType::Statevector is typically 0 (check
29 // Simulators/Simulator.h or documentation).
30 // Simulators::SimulationType::QiskitAer is typically 0.
31 // We use 0, 0 here for demonstration.
32 unsigned long int simHandle = CreateSimulator(0, 0);
33 if (simHandle == 0) {
34 std::cerr << "Failed to create simulator." << std::endl;
35 return 1;
36 }
37
38 void *sim = GetSimulator(simHandle);
39 if (!sim) {
40 std::cerr << "Failed to get simulator instance." << std::endl;
41 DestroySimulator(simHandle);
42 return 1;
43 }
44
45 std::cout << "Simulator created with handle: " << simHandle << std::endl;
46
47 // 3. Apply Gates Manually
48 // We will create a Bell state: |00> -> H(0) -> |+0> -> CX(0,1) -> (|00> +
49 // |11>) / sqrt(2)
50
51 // Apply Hadamard on qubit 0
52 ApplyH(sim, 0);
53 std::cout << "Applied H on qubit 0" << std::endl;
54
55 // Apply CNOT with control 0 and target 1
56 ApplyCX(sim, 0, 1);
57 std::cout << "Applied CX on 0 -> 1" << std::endl;
58
59 // 4. Measure
60 // MeasureNoCollapse returns the outcome without collapsing the state vector
61 // (useful for debugging/inspection) Note: This might not be supported by all
62 // backends.
63 unsigned long long int outcome = MeasureNoCollapse(sim);
64 std::cout << "Measurement outcome (no collapse): " << outcome << std::endl;
65
66 // Standard Measure (collapses state)
67 // We need to specify which qubits to measure.
68 unsigned long int qubits[] = {0, 1};
69 unsigned long long int measurement = Measure(sim, qubits, 2);
70 std::cout << "Measurement outcome (collapsed): " << measurement << std::endl;
71
72 // 5. Cleanup
73 DestroySimulator(simHandle);
74
75 return 0;
76}
unsigned long int CreateSimulator(int simType, int simExecType)
int ApplyCX(void *sim, int controlQubit, int targetQubit)
unsigned long long int MeasureNoCollapse(void *sim)
void * GetMaestroObject()
Definition Interface.cpp:32
unsigned long long int Measure(void *sim, const unsigned long int *qubits, unsigned long int nrQubits)
int ApplyH(void *sim, int qubit)
void DestroySimulator(unsigned long int simHandle)
void * GetSimulator(unsigned long int simHandle)
int main()