Maestro 0.1.0
Unified interface for quantum circuit simulation
Loading...
Searching...
No Matches
basic_simulation.cpp
Go to the documentation of this file.
1
13
15#include <iostream>
16#include <string>
17#include <vector>
18
24void PrintResults(const char *jsonResult) {
25 if (!jsonResult) {
26 std::cout << "No results returned." << std::endl;
27 return;
28 }
29 std::cout << "Simulation Results: " << jsonResult << std::endl;
30}
31
32int main() {
33 // 1. Initialize Maestro
34 // Get the singleton instance of the Maestro engine
35 void *maestro = GetMaestroObject();
36 if (!maestro) {
37 std::cerr << "Failed to initialize Maestro." << std::endl;
38 return 1;
39 }
40
41 // 2. Create a Simulator
42 // Create a simple simulator for 2 qubits.
43 // This returns a handle (ID) to the simulator.
44 unsigned long int simHandle = CreateSimpleSimulator(2);
45 if (simHandle == 0) {
46 std::cerr << "Failed to create simulator." << std::endl;
47 return 1;
48 }
49
50 std::cout << "Simulator created with handle: " << simHandle << std::endl;
51
52 // 3. Define a Circuit
53 // We'll use a simple Bell State circuit in OpenQASM 2.0 format.
54 const char *qasmCircuit = "OPENQASM 2.0;\n"
55 "include \"qelib1.inc\";\n"
56 "qreg q[2];\n"
57 "creg c[2];\n"
58 "h q[0];\n"
59 "cx q[0], q[1];\n"
60 "measure q -> c;\n";
61
62 // 4. Configure Execution
63 // Configuration is passed as a JSON string.
64 // Here we request 1024 shots.
65 const char *config = "{\"shots\": 1024}";
66
67 // 5. Execute the Circuit
68 // SimpleExecute takes the simulator handle, circuit string, and config.
69 // It returns a JSON string with the results.
70 char *result = SimpleExecute(simHandle, qasmCircuit, config);
71
72 // 6. Process Results
73 PrintResults(result);
74
75 // 7. Cleanup
76 // Free the result string memory
77 FreeResult(result);
78
79 // Destroy the simulator instance
80 DestroySimpleSimulator(simHandle);
81
82 return 0;
83}
void FreeResult(char *result)
char * SimpleExecute(unsigned long int simpleSim, const char *circuitStr, const char *jsonConfig)
Definition Interface.cpp:99
void * GetMaestroObject()
Definition Interface.cpp:32
void DestroySimpleSimulator(unsigned long int simHandle)
Definition Interface.cpp:71
unsigned long int CreateSimpleSimulator(int nrQubits)
Definition Interface.cpp:64
void PrintResults(const char *jsonResult)
Helper function to print the JSON result.
int main()