@@ -99,29 +99,47 @@ class Target
9999
100100bool Target::from_json (nlohmann::ordered_json &input)
101101{
102+ if (!input.contains (" configuration" )) {
103+ std::cerr << " Target Error : No configuration section found" << std::endl;
104+ return false ;
105+ }
102106 auto backend_configuration = input[" configuration" ];
107+ if (!input.contains (" properties" )) {
108+ std::cerr << " Target Error : No properties section found" << std::endl;
109+ return false ;
110+ }
103111 auto backend_properties = input[" properties" ];
112+
113+ if (!backend_configuration.contains (" n_qubits" )) {
114+ std::cerr << " Target Error : n_qubits not found in backend config" << std::endl;
115+ return false ;
116+ }
117+ num_qubits_ = backend_configuration[" n_qubits" ];
118+
104119 if (target_)
105120 {
106121 qk_target_free (target_);
107122 }
108123
109- num_qubits_ = backend_configuration[" n_qubits" ];
110-
111124 target_ = qk_target_new ((uint32_t )num_qubits_);
112125 if (target_ == nullptr )
113126 return false ;
114127
115- dt_ = backend_configuration[" dt" ];
116128 max_experiments_ = backend_configuration[" max_experiments" ];
117129 max_shots_ = backend_configuration[" max_shots" ];
118130
119131 // set target configs available in C-API
120- qk_target_set_dt (target_, dt_);
121- qk_target_set_granularity (target_, backend_configuration[" timing_constraints" ][" granularity" ]);
122- qk_target_set_min_length (target_, backend_configuration[" timing_constraints" ][" min_length" ]);
123- qk_target_set_pulse_alignment (target_, backend_configuration[" timing_constraints" ][" pulse_alignment" ]);
124- qk_target_set_acquire_alignment (target_, backend_configuration[" timing_constraints" ][" acquire_alignment" ]);
132+ if (backend_configuration.at (" dt" ).is_number ()) {
133+ dt_ = backend_configuration[" dt" ];
134+ qk_target_set_dt (target_, dt_);
135+ }
136+ if (backend_configuration.contains (" timing_constraints" )) {
137+ auto timing_constraints = backend_configuration[" timing_constraints" ];
138+ qk_target_set_granularity (target_, timing_constraints[" granularity" ]);
139+ qk_target_set_min_length (target_, timing_constraints[" min_length" ]);
140+ qk_target_set_pulse_alignment (target_, timing_constraints[" pulse_alignment" ]);
141+ qk_target_set_acquire_alignment (target_, timing_constraints[" acquire_alignment" ]);
142+ }
125143
126144 // get basis gates and make property entries
127145 auto name_map = Qiskit::circuit::get_standard_gate_name_mapping ();
0 commit comments