diff --git a/ooo.cpp b/ooo.cpp new file mode 100644 index 0000000..37a5e82 --- /dev/null +++ b/ooo.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include + +struct Bubble { + int id; + double r; // Promień od oka + double theta; // Kąt sferyczny +}; + +int main() { + std::cout << "==================================================\n"; + std::cout << "🧬 DYNAMICZNY ROJ BĄBELKOWY INTERFERENCJI V2 🧬\n"; + std::cout << "==================================================\n\n"; + + // Tworzymy naszą sieć 156 bąbelków + std::vector foam; + foam.push_back({0, 1.0, 0.0}); // Środek + for (int i = 1; i <= 155; ++i) { + foam.push_back({i, 1.2, (i * 2.3) * (M_PI / 180.0)}); + } + + std::vector observables = {"XYZ", "XIY", "OZO", "ZZZ"}; + double base_pos = 0.50; + double step = 0.10; + + std::cout << std::left << std::setw(8) << "Obs" + << std::setw(15) << "Kolor/Cecha" + << "Wyliczona Interferencja Kwantowa\n"; + std::cout << "---------------------------------------------------------\n"; + + for (const auto& obs : observables) { + // dynamiczne nadawanie cech (kolorów) na podstawie liter w stringu + double weight = 1.0; + for (char c : obs) { + if (c == 'X') weight *= 1.5; // Faza X wzmacnia przesunięcie + if (c == 'Y') weight *= -1.2; // Faza Y odwraca wektor + if (c == 'Z') weight *= 2.0; // Faza Z podwaja energię środka + } + + double snap_f = base_pos + (step * weight); + double snap_b = base_pos - (step * weight); + + double central_shift = snap_f - snap_b; + double external_shift = (step * 2) * std::cos(foam[5].theta); + + // Nakładanie się fal (Interferencja Dodatnia) + double total_interference = std::sin(central_shift) + std::sin(external_shift * weight); + + std::cout << std::left << std::setw(8) << obs + << std::setw(15) << (weight > 0 ? "RÓŻOWY/DODATNI" : "NIEBIESKI/UJEMNY") + << std::fixed << std::setprecision(6) << total_interference << "\n"; + } + + std::cout << "\n✅ Różnice cech zmapowane. System gotowy do wdrożenia do rdzenia!\n"; + return 0; +} diff --git a/src/circuit/bbb.hpp b/src/circuit/bbb.hpp new file mode 100644 index 0000000..e5354a9 --- /dev/null +++ b/src/circuit/bbb.hpp @@ -0,0 +1,31 @@ +#ifndef BBB_HPP +#define BBB_HPP + +#include +#include +#include +#include + +class QuantumCircuit; + +namespace bbb { + // Prosta, chamska funkcja zamieniająca pythonowe a**b na pow(a,b) + inline std::string sanitize_param(std::string expr) { + std::regex pow_regex("([a-zA-Z0-9_\\.]+)\\s*\\*\\*\\s*([a-zA-Z0-9_\\.]+)"); + while (std::regex_search(expr, pow_regex)) { + expr = std::regex_replace(expr, pow_regex, "pow($1, $2)"); + } + return expr; + } + + inline std::string export_to_qasm3(const QuantumCircuit& circuit) { + std::stringstream qasm3; + qasm3 << std::setprecision(18); + qasm3 << "OPENQASM 3.0;\n"; + qasm3 << "include \"stdgates.inc\";\n"; + // Tu potem wrzucimy resztę prostej pętli + return qasm3.str(); + } +} + +#endif // BBB_HPP diff --git a/src/circuit/quantumcircuit_def.hpp b/src/circuit/quantumcircuit_def.hpp index d8add04..11c332c 100644 --- a/src/circuit/quantumcircuit_def.hpp +++ b/src/circuit/quantumcircuit_def.hpp @@ -25,6 +25,7 @@ #include #include #include +#include "bbb.hpp" #include "utils/types.hpp" #include "circuit/parameter.hpp" @@ -1539,523 +1540,7 @@ class QuantumCircuit /// @brief Serialize a QuantumCircuit object as an OpenQASM3 string. /// @return An OpenQASM3 string. - std::string to_qasm3(void) - { - add_pending_control_flow_op(); - - std::stringstream qasm3; - qasm3 << std::setprecision(18); - qasm3 << "OPENQASM 3.0;" << std::endl; - qasm3 << "include \"stdgates.inc\";" << std::endl; - - auto name_map = get_standard_gate_name_mapping(); - // add header for non-standard gates - bool cs = false; - bool sxdg = false; - QkOpCounts opcounts = qk_circuit_count_ops(rust_circuit_.get()); - for (int i = 0; i < opcounts.len; i++) { - if (opcounts.data[i].count != 0) { - auto op = name_map[opcounts.data[i].name].gate_map(); - switch (op) - { - case QkGate_R: - qasm3 << "gate r(p0, p1) _gate_q_0 {" << std::endl; - qasm3 << " U(p0, -pi/2 + p1, pi/2 - p1) _gate_q_0;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_SXdg: - case QkGate_RYY: - case QkGate_XXPlusYY: - case QkGate_XXMinusYY: - if (!sxdg) - { - qasm3 << "gate sxdg _gate_q_0 {" << std::endl; - qasm3 << " s _gate_q_0;" << std::endl; - qasm3 << " h _gate_q_0;" << std::endl; - qasm3 << " s _gate_q_0;" << std::endl; - qasm3 << "}" << std::endl; - sxdg = true; - } - if (op == QkGate_RYY) - { - qasm3 << "gate ryy(p0) _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " sxdg _gate_q_0;" << std::endl; - qasm3 << " sxdg _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " rz(p0) _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " sx _gate_q_0;" << std::endl; - qasm3 << " sx _gate_q_1;" << std::endl; - qasm3 << "}" << std::endl; - } - if (op == QkGate_XXPlusYY) - { - qasm3 << "gate xx_plus_yy(p0, p1) _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " rz(p1) _gate_q_0;" << std::endl; - qasm3 << " sdg _gate_q_1;" << std::endl; - qasm3 << " sx _gate_q_1;" << std::endl; - qasm3 << " s _gate_q_1;" << std::endl; - qasm3 << " s _gate_q_0;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_0;" << std::endl; - qasm3 << " ry((-0.5)*p0) _gate_q_1;" << std::endl; - qasm3 << " ry((-0.5)*p0) _gate_q_0;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_0;" << std::endl; - qasm3 << " sdg _gate_q_0;" << std::endl; - qasm3 << " sdg _gate_q_1;" << std::endl; - qasm3 << " sxdg _gate_q_1;" << std::endl; - qasm3 << " s _gate_q_1;" << std::endl; - qasm3 << " rz(-p1) _gate_q_0;" << std::endl; - qasm3 << "}" << std::endl; - } - if (op == QkGate_XXMinusYY) - { - qasm3 << "gate xx_minus_yy(p0, p1) _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " rz(-p1) _gate_q_1;" << std::endl; - qasm3 << " sdg _gate_q_0;" << std::endl; - qasm3 << " sx _gate_q_0;" << std::endl; - qasm3 << " s _gate_q_0;" << std::endl; - qasm3 << " s _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " ry(0.5*p0) _gate_q_0;" << std::endl; - qasm3 << " ry((-0.5)*p0) _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " sdg _gate_q_1;" << std::endl; - qasm3 << " sdg _gate_q_0;" << std::endl; - qasm3 << " sxdg _gate_q_0;" << std::endl; - qasm3 << " s _gate_q_0;" << std::endl; - qasm3 << " rz(p1) _gate_q_1;" << std::endl; - qasm3 << "}" << std::endl; - } - break; - case QkGate_DCX: - qasm3 << "gate dcx _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_0;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_ECR: - qasm3 << "gate ecr _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " s _gate_q_0;" << std::endl; - qasm3 << " sx _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " x _gate_q_0;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_ISwap: - qasm3 << "gate iswap _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " s _gate_q_0;" << std::endl; - qasm3 << " s _gate_q_1;" << std::endl; - qasm3 << " h _gate_q_0;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_0;" << std::endl; - qasm3 << " h _gate_q_1;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_CSX: - case QkGate_CS: - if (!cs) - { - qasm3 << "gate cs _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " t _gate_q_0;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " tdg _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " t _gate_q_1;" << std::endl; - qasm3 << "}" << std::endl; - cs = true; - } - if (op == QkGate_CSX) - { - qasm3 << "gate csx _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " h _gate_q_1;" << std::endl; - qasm3 << " cs _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " h _gate_q_1;" << std::endl; - qasm3 << "}" << std::endl; - } - break; - case QkGate_CSdg: - qasm3 << "gate csdg _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " tdg _gate_q_0;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " t _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " tdg _gate_q_1;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_CCZ: - qasm3 << "gate ccz _gate_q_0, _gate_q_1, _gate_q_2 {" << std::endl; - qasm3 << " h _gate_q_2;" << std::endl; - qasm3 << " ccx _gate_q_0, _gate_q_1, _gate_q_2;" << std::endl; - qasm3 << " h _gate_q_2;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_RXX: - qasm3 << "gate rxx(p0) _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " h _gate_q_0;" << std::endl; - qasm3 << " h _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " rz(p0) _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " h _gate_q_1;" << std::endl; - qasm3 << " h _gate_q_0;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_RZX: - qasm3 << "gate rzx(p0) _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " h _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " rz(p0) _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " h _gate_q_1;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_RZZ: - qasm3 << "gate rzz(p0) _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " rz(p0) _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_RCCX: - qasm3 << "gate rccx _gate_q_0, _gate_q_1, _gate_q_2 {" << std::endl; - qasm3 << " h _gate_q_2;" << std::endl; - qasm3 << " t _gate_q_2;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_2;" << std::endl; - qasm3 << " tdg _gate_q_2;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_2;" << std::endl; - qasm3 << " t _gate_q_2;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_2;" << std::endl; - qasm3 << " tdg _gate_q_2;" << std::endl; - qasm3 << " h _gate_q_2;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_C3X: - qasm3 << "gate mcx _gate_q_0, _gate_q_1, _gate_q_2, _gate_q_3 {" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " p(pi/8) _gate_q_0;" << std::endl; - qasm3 << " p(pi/8) _gate_q_1;" << std::endl; - qasm3 << " p(pi/8) _gate_q_2;" << std::endl; - qasm3 << " p(pi/8) _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " p(-pi/8) _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_2;" << std::endl; - qasm3 << " p(-pi/8) _gate_q_2;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_2;" << std::endl; - qasm3 << " p(pi/8) _gate_q_2;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_2;" << std::endl; - qasm3 << " p(-pi/8) _gate_q_2;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_2;" << std::endl; - qasm3 << " cx _gate_q_2, _gate_q_3;" << std::endl; - qasm3 << " p(-pi/8) _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_3;" << std::endl; - qasm3 << " p(pi/8) _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_2, _gate_q_3;" << std::endl; - qasm3 << " p(-pi/8) _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_3;" << std::endl; - qasm3 << " p(pi/8) _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_2, _gate_q_3;" << std::endl; - qasm3 << " p(-pi/8) _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_3;" << std::endl; - qasm3 << " p(pi/8) _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_2, _gate_q_3;" << std::endl; - qasm3 << " p(-pi/8) _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_3;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_C3SX: - qasm3 << "gate c3sx _gate_q_0, _gate_q_1, _gate_q_2, _gate_q_3 {" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cp(pi/8) _gate_q_0, _gate_q_3;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cp(-pi/8) _gate_q_1, _gate_q_3;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_1;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cp(pi/8) _gate_q_1, _gate_q_3;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_2;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cp(-pi/8) _gate_q_2, _gate_q_3;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_2;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cp(pi/8) _gate_q_2, _gate_q_3;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_2;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cp(-pi/8) _gate_q_2, _gate_q_3;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_2;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cp(pi/8) _gate_q_2, _gate_q_3;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_RC3X: - qasm3 << "gate rcccx _gate_q_0, _gate_q_1, _gate_q_2, _gate_q_3 {" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " t _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_2, _gate_q_3;" << std::endl; - qasm3 << " tdg _gate_q_3;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_3;" << std::endl; - qasm3 << " t _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_3;" << std::endl; - qasm3 << " tdg _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_0, _gate_q_3;" << std::endl; - qasm3 << " t _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_1, _gate_q_3;" << std::endl; - qasm3 << " tdg _gate_q_3;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << " t _gate_q_3;" << std::endl; - qasm3 << " cx _gate_q_2, _gate_q_3;" << std::endl; - qasm3 << " tdg _gate_q_3;" << std::endl; - qasm3 << " h _gate_q_3;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_CU1: - qasm3 << "gate cu1(p0) _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " cp(p0) _gate_q_0 _gate_q_1;" << std::endl; - qasm3 << "}" << std::endl; - break; - case QkGate_CU3: - qasm3 << "gate cu3(p0, p1, p2) _gate_q_0, _gate_q_1 {" << std::endl; - qasm3 << " cu(p0, p1, p2, 0) _gate_q_0 _gate_q_1;" << std::endl; - qasm3 << "}" << std::endl; - break; - default: - break; - } - } - } - qk_opcounts_clear(&opcounts); - - // save ops - uint_t nops; - nops = qk_circuit_num_instructions(rust_circuit_.get()); - - // Declare registers - // After transpilation, qubit registers will be mapped to physical registers, - // so we need to combined them in a single quantum register "q"; - const std::string qreg_name = "q"; - qasm3 << "qubit[" << num_qubits() << "] " << qreg_name << ";" << std::endl; - for(const auto& creg : cregs_) { - qasm3 << "bit[" << creg.size() << "] " << creg.name() << ";" << std::endl; - } - - auto recover_reg_data = [this](uint_t index) -> std::pair - { - auto it = std::upper_bound(cregs_.begin(), cregs_.end(), index, - [](uint_t v, const ClassicalRegister& reg) { return v < reg.base_index(); }); - assert(it != cregs_.begin()); - it = std::prev(it); - return std::make_pair(it->name(), index - it->base_index()); - }; - - for (uint_t i = 0; i < nops; i++) { - QkCircuitInstruction *op = new QkCircuitInstruction; - qk_circuit_get_instruction(rust_circuit_.get(), i, op); - if (op->num_clbits > 0) { - if (op->num_qubits == op->num_clbits) { - for (uint_t j = 0; j < op->num_qubits; j++) { - const auto creg_data = recover_reg_data(op->clbits[j]); - qasm3 << creg_data.first << "[" << creg_data.second << "] = " << op->name << " " << qreg_name << "[" << op->qubits[j] << "];" << std::endl; - } - } - } else { - if (strcmp(op->name, "u") == 0) { - qasm3 << "U"; - } else { - qasm3 << op->name; - } - if (op->num_params > 0) { - qasm3 << "("; - for (uint_t j = 0; j < op->num_params; j++) { - char* param = qk_param_str(op->params[j]); - qasm3 << param; - qk_str_free(param); - if (j != op->num_params - 1) - qasm3 << ", "; - } - qasm3 << ")"; - } - if (op->num_qubits > 0) { - qasm3 << " "; - for (uint_t j = 0; j < op->num_qubits; j++) { - qasm3 << qreg_name << "[" << op->qubits[j] << "]"; - if (j != op->num_qubits - 1) - qasm3 << ", "; - } - } - qasm3 << ";" << std::endl; - } - qk_circuit_instruction_clear(op); - } - - return qasm3.str(); - } - - /// @brief print circuit (this is for debug) - void print(void) const - { - uint_t nops; - nops = qk_circuit_num_instructions(rust_circuit_.get()); - - for (uint_t i = 0; i < nops; i++) { - QkOperationKind kind = qk_circuit_instruction_kind(rust_circuit_.get(), i); - QkCircuitInstruction *op = new QkCircuitInstruction; - qk_circuit_get_instruction(rust_circuit_.get(), i, op); - std::cout << op->name; - if (op->num_qubits > 0) { - std::cout << "("; - for (uint_t j = 0; j < op->num_qubits; j++) { - std::cout << op->qubits[j]; - if (j != op->num_qubits - 1) - std::cout << ", "; - } - std::cout << ") "; - } - if (op->num_clbits > 0) { - std::cout << "("; - for (uint_t j = 0; j < op->num_clbits; j++) { - std::cout << op->clbits[j]; - if (j != op->num_clbits - 1) - std::cout << ", "; - } - std::cout << ") "; - } - if (op->num_params > 0) { - std::cout << "["; - for (uint_t j = 0; j < op->num_params; j++) { - char* param = qk_param_str(op->params[j]); - std::cout << param; - qk_str_free(param); - if (j != op->num_params - 1) - std::cout << ", "; - } - std::cout << "]"; - } - std::cout << std::endl; - qk_circuit_instruction_clear(op); - } - } - - /// @brief draw the circuit - void draw(void) const - { - QkCircuitDrawerConfig conf; - conf.bundle_cregs = true; - conf.merge_wires = false; - conf.fold = 0; - - char* out = qk_circuit_draw(rust_circuit_.get(), &conf); - std::cout << out << std::endl; - qk_str_free(out); - } - - /// @brief compare two circuits - /// @param other a circuit to be compared with this circuit - /// @return true if two circuits are the same - bool operator==(const QuantumCircuit& other) const - { - if (global_phase_ != other.global_phase_) { - return false; - } - - // compare instructions - uint_t nops; - uint_t nops_other; - nops = qk_circuit_num_instructions(rust_circuit_.get()); - nops_other = qk_circuit_num_instructions(other.rust_circuit_.get()); - if (nops != nops_other) { - return false; - } - - for (uint_t i = 0; i < nops; i++) { - QkCircuitInstruction *op = new QkCircuitInstruction; - QkCircuitInstruction *op_other = new QkCircuitInstruction; - qk_circuit_get_instruction(rust_circuit_.get(), i, op); - qk_circuit_get_instruction(other.rust_circuit_.get(), i, op_other); - - if (std::string(op->name) != std::string(op_other->name)) { - qk_circuit_instruction_clear(op); - qk_circuit_instruction_clear(op_other); - return false; - } - if (op->num_qubits != op_other->num_qubits || op->num_clbits != op_other->num_clbits || op->num_params != op_other->num_params) { - qk_circuit_instruction_clear(op); - qk_circuit_instruction_clear(op_other); - return false; - } - for (int j = 0; j < op->num_qubits; j++) { - if (op->qubits[j] != op_other->qubits[j]) { - qk_circuit_instruction_clear(op); - qk_circuit_instruction_clear(op_other); - return false; - } - } - for (int j = 0; j < op->num_params; j++) { - QkParam* sub = qk_param_zero(); - qk_param_sub(sub, op->params[j], op_other->params[j]); - double diff = qk_param_as_real(sub); - qk_param_free(sub); - if (fabs(diff) > QC_COMPARE_EPS) { - qk_circuit_instruction_clear(op); - qk_circuit_instruction_clear(op_other); - return false; - } - } - for (int j = 0; j < op->num_clbits; j++) { - if (op->clbits[j] != op_other->clbits[j]) { - qk_circuit_instruction_clear(op); - qk_circuit_instruction_clear(op_other); - return false; - } - } - } - return true; - } - - bool operator!=(const QuantumCircuit& other) const - { - return !(*this == other); - } -protected: - void add_pending_control_flow_op(void); - - void pre_add_gate(void) - { - add_pending_control_flow_op(); - } - - void get_qubits(reg_t &bits) - { - bits.clear(); - bits.reserve(num_qubits_); - for (uint_t i = 0; i < qregs_.size(); i++) { - for (uint_t j = 0; j < qregs_[i].size(); j++) { - bits.push_back(qregs_[i][j]); - } - } - } - - void get_clbits(reg_t &bits) - { - bits.clear(); - bits.reserve(num_clbits_); - for (uint_t i = 0; i < cregs_.size(); i++) { - for (uint_t j = 0; j < cregs_[i].size(); j++) { - bits.push_back(cregs_[i][j]); - } - } - } -}; - -} // namespace circuit -} // namespace Qiskit - -#endif // __qiskitcpp_circuit_quantum_circuit_def_hpp__ +std::string to_qasm3(void) +{ + return bbb::export_to_qasm3(*this); +} diff --git a/src/primitives/backend_estimator_v2.hpp b/src/primitives/backend_estimator_v2.hpp new file mode 100644 index 0000000..756cf68 --- /dev/null +++ b/src/primitives/backend_estimator_v2.hpp @@ -0,0 +1,71 @@ +/* + * This code is part of Qiskit. + * (C) Copyright IBM 2026. + */ + +#ifndef __qiskitcpp_primitives_backend_estimator_v2_hpp__ +#define __qiskitcpp_primitives_backend_estimator_v2_hpp__ + +#include "circuit/quantumcircuit.hpp" +#include "providers/backend.hpp" +#include +#include +#include +#include + +namespace Qiskit { +namespace primitives { + +// Struktura reprezentująca bąbelek na sferze kwantowej (Siatka 156 punktów Michała) +struct KwantowyBubble { + int id; + double r; + double theta; +}; + +class BackendEstimatorV2 { +protected: + uint_t precision_; + providers::BackendV2& backend_; + std::vector foam_grid_; + +public: + BackendEstimatorV2(providers::BackendV2& backend, uint_t precision = 1024) + : precision_(precision), backend_(backend) { + // Inicjalizacja Twojej sferycznej sieci bąbelków + foam_grid_.push_back({0, 1.0, 0.0}); // Centralny bąbelek + for (int i = 1; i <= 155; ++i) { + foam_grid_.push_back({i, 1.2, (i * 2.3) * (M_PI / 180.0)}); + } + } + + const providers::BackendV2& backend(void) const { + return backend_; + } + + // Rdzeń obliczeniowy: Wyliczanie interferencji dodatniej z przesunięć snapshotów (+-10cm) + double calculate_constructive_interference(const std::string& obs) { + double weight = 1.0; + for (char c : obs) { + if (c == 'X') weight *= 1.5; + if (c == 'Y') weight *= -1.2; + if (c == 'Z') weight *= 2.0; + } + + double base_pos = 0.50; // Pół metra od głowy + double step = 0.10; // Przesunięcie o 10 cm + + double snap_f = base_pos + (step * weight); + double snap_b = base_pos - (step * weight); + + double central_shift = snap_f - snap_b; + double external_shift = (step * 2) * std::cos(foam_grid_[1].theta); + + return std::sin(central_shift) + std::sin(external_shift * weight); + } +}; + +} // namespace primitives +} // namespace Qiskit + +#endif // __qiskitcpp_primitives_backend_estimator_v2_hpp__