@@ -1240,6 +1240,59 @@ class QuantumCircuit
12401240 return qk_circuit_num_param_symbols (rust_circuit_.get ());
12411241 }
12421242
1243+ // / @brief Return a list of parameter symbol names used in the circuit.
1244+ // / @details It will be replaced by a C-API call when the API becomes available.
1245+ // / This is a stub function that collects unique parameter symbol names
1246+ // / by iterating through circuit instructions and extracting identifiers
1247+ // / from parameter string representations.
1248+ // / @note Duplicate symbol names are not accepted in Qiskit C++ because we do not
1249+ // / have a C-API to identify Parameters by UUID. Each symbol name must be unique.
1250+ // / @return A sorted list of unique parameter symbol names.
1251+ std::vector<std::string> parameter_symbols (void ) const
1252+ {
1253+ std::set<std::string> symbol_names;
1254+
1255+ // Reserved identifiers that should not be treated as parameter symbols
1256+ static const std::set<std::string> reserved = {
1257+ " sin" , " cos" , " tan" , " asin" , " acos" , " atan" , " exp" , " log" ,
1258+ " abs" , " sign" , " conjugate" , " pi" , " sqrt" , " ceil" , " floor" , " conj" };
1259+
1260+ uint_t nops = qk_circuit_num_instructions (rust_circuit_.get ());
1261+ for (uint_t i = 0 ; i < nops; i++) {
1262+ QkCircuitInstruction inst;
1263+ qk_circuit_get_instruction (rust_circuit_.get (), i, &inst);
1264+
1265+ for (uint_t j = 0 ; j < inst.num_params ; j++) {
1266+ char *param_str = qk_param_str (inst.params [j]);
1267+ std::string s (param_str);
1268+ qk_str_free (param_str);
1269+
1270+ size_t pos = 0 ;
1271+ while (pos < s.size ()) {
1272+ const char c = s[pos];
1273+ if ((c >= ' a' && c <= ' z' ) || (c >= ' A' && c <= ' Z' ) || c == ' _' ) {
1274+ const size_t start = pos++;
1275+ while (pos < s.size () &&
1276+ ((s[pos] >= ' a' && s[pos] <= ' z' ) ||
1277+ (s[pos] >= ' A' && s[pos] <= ' Z' ) ||
1278+ (s[pos] >= ' 0' && s[pos] <= ' 9' ) || s[pos] == ' _' )) {
1279+ pos++;
1280+ }
1281+ const std::string token = s.substr (start, pos - start);
1282+ if (reserved.find (token) == reserved.end ()) {
1283+ symbol_names.insert (token);
1284+ }
1285+ continue ;
1286+ }
1287+ pos++;
1288+ }
1289+ }
1290+ qk_circuit_instruction_clear (&inst);
1291+ }
1292+
1293+ return std::vector<std::string>(symbol_names.begin (), symbol_names.end ());
1294+ }
1295+
12431296 // / @brief Assign parameters to new parameters or values.
12441297 // / @param keys a list of keys
12451298 // / @param values a list of values
0 commit comments