sys-sage
Loading...
Searching...
No Matches
qdmi-parser.hpp
Go to the documentation of this file.
1
6#ifndef QDMIParser_HPP
7#define QDMIParser_HPP
8
9#ifdef QDMI
10
11#include <iostream>
12#include <string.h>
13#include <vector>
14#include <map>
15#include "Component.hpp"
16#include <ibm.h>
17
18#define CHECK_ERR(a,b) { if (a!=QDMI_SUCCESS) { printf("\n[Error]: %i at %s",a,b); return 1; }}
19
20extern "C"
21{
22
23 class QdmiParser
24 {
25 public:
26 QdmiParser();
27
32 std::vector<QDMI_Device> get_available_backends();
33
34 int get_num_qubits(QDMI_Device dev);
39 void createAllQcTopo(Topology *topo);
40
46 Topology createAllQcTopo();
47
54 void createQcTopo(QuantumBackend *backend, QDMI_Device dev);
55
64 QuantumBackend createQcTopo(QDMI_Device dev, int device_index = 0, std::string device_name="");
65
66 static void refreshQubitProperties(QDMI_Device dev, Qubit *q)
67 {
68 //Refresh Qubit properties
69 QDMI_Qubit qubits;
70 int err;
71
72 err = QDMI_query_all_qubits(dev, &qubits);
73
74 if (err != QDMI_SUCCESS || qubits == NULL)
75 {
76 std::cout << " [sys-sage]...............Could not obtain available "
77 << "qubits via QDMI\n";
78 return;
79 }
80 int qubit_index = q->GetId();
81
82 // Refreshing Qubit coupling map
83 int coupling_map_size;
84 std::vector<int> coupling_mapping;
85 coupling_map_size = (&qubits[qubit_index])->size_coupling_mapping;
86 coupling_mapping.resize(coupling_map_size);
87 std::copy(qubits[qubit_index].coupling_mapping, qubits[qubit_index].coupling_mapping + coupling_map_size, coupling_mapping.begin());
88 q->SetCouplingMapping(coupling_mapping, coupling_map_size);
89
90
91 // Set all the qubit properties
92 int scope;
93 // Declare prop as a vector
94 std::vector<int> prop{QDMI_T1_TIME, QDMI_T2_TIME, QDMI_READOUT_ERROR, QDMI_READOUT_LENGTH};
95 std::array<std::string, 4> properties{"T1", "T2", "readout_error", "readout_length"};
96 double value;
97 for (size_t i = 0; i < 4; ++i)
98 {
99 // QDMI_Qubit_property prop_index;
100 QDMI_Qubit_property prop_index = new (QDMI_Qubit_property_impl_t);
101 prop_index->name = prop[i];
102 int err = QDMI_query_qubit_property_exists(dev, &qubits[qubit_index], prop_index, &scope);
103 if(err)
104 {
105 std::cout << " [sys-sage]...............Queried property doesn't exist: " << i <<"\n";
106 continue;
107 }
108 err = QDMI_query_qubit_property_type(dev, &qubits[qubit_index], prop_index);
109 if(prop_index->type == QDMI_DOUBLE){
110 err = QDMI_query_qubit_property_d(dev, &qubits[qubit_index], prop_index, &value);
111 if(err)
112 {
113 std::cout << " [sys-sage]...............Unable to query property: " << i <<"\n";
114 continue;
115 }
116 //std::cout << " [sys-sage]...............Value of " << properties[i] << ": " << value << "\n";
117 }
118 delete prop_index;
119
120 }
121
122 q->SetProperties(qubits[qubit_index].t1, qubits[qubit_index].t2, qubits[qubit_index].readout_error, qubits[qubit_index].readout_length);
123 }
124 private:
125 int initiateSession();
126 static QInfo info;
127 static QDMI_Session session;
128 void getCouplingMapping(QDMI_Device dev, QDMI_Qubit qubit, std::vector<int> &coupling_mapping, int &coupling_map_size);
129 void getQubitProperties(QDMI_Device dev, QDMI_Qubit qubit);
130 void setQubits(QuantumBackend *backend, QDMI_Device dev);
131 void setGateSets(QuantumBackend *backend, QDMI_Device dev);
132
133 };
134
135}
136
137#endif //QDMI
138#endif // QDMIParser_HPP