diff --git a/pennylane_qrack/qrack_device.cpp b/pennylane_qrack/qrack_device.cpp index 18a6dd8..7527369 100644 --- a/pennylane_qrack/qrack_device.cpp +++ b/pennylane_qrack/qrack_device.cpp @@ -6,6 +6,8 @@ #define CL_HPP_TARGET_OPENCL_VERSION 300 #include "qrack/qfactory.hpp" +#define QSIM_CONFIG(numQubits) CreateQuantumInterface(simulatorType, numQubits, Qrack::ZERO_BCI, nullptr, Qrack::CMPLX_DEFAULT_ARG, false, true, is_host_pointer) + std::string trim(std::string s) { // Cut leading, trailing, and extra spaces @@ -30,11 +32,14 @@ struct QrackObservable { struct QrackDevice final : public Catalyst::Runtime::QuantumDevice { bool tapeRecording; + bool is_host_pointer; bitLenInt allocated_qubits; + bitLenInt mapped_qubits; size_t shots; Qrack::QInterfacePtr qsim; std::map qubit_map; std::vector obs_cache; + std::vector simulatorType; // static constants for RESULT values static constexpr bool QRACK_RESULT_TRUE_CONST = true; @@ -369,7 +374,9 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice { QrackDevice([[maybe_unused]] std::string kwargs = "{}") : tapeRecording(false) + , is_host_pointer(false) , allocated_qubits(0U) + , mapped_qubits(0U) , shots(1U) , qsim(nullptr) { @@ -390,14 +397,12 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice { keyMap["'is_gpu'"] = 8; keyMap["'is_host_pointer'"] = 9; - bitLenInt wires = 0U; bool is_hybrid_stabilizer = true; - bool is_tensor_network = false; + bool is_tensor_network = true; bool is_schmidt_decomposed = true; bool is_schmidt_decomposition_parallel = true; bool is_qbdd = false; bool is_gpu = true; - bool is_host_pointer = false; size_t pos; while ((pos = kwargs.find(":")) != std::string::npos) { @@ -421,8 +426,8 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice { } } if (isInt) { - wires = stoi(trim(kwargs.substr(0, pos))); - for (size_t i = 0U; i < wires; ++i) { + mapped_qubits = stoi(trim(kwargs.substr(0, pos))); + for (size_t i = 0U; i < mapped_qubits; ++i) { qubit_map[i] = i; } kwargs.erase(0, pos + 1U); @@ -436,15 +441,14 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice { kwargs.erase(0, pos + 3U); size_t p = value.find("["); value.erase(0, p + 1U); - wires = 0U; size_t q; while ((q = value.find(",")) != std::string::npos) { - qubit_map[(QubitIdType)stoi(trim(value.substr(0, q)))] = wires; - ++wires; + qubit_map[(QubitIdType)stoi(trim(value.substr(0, q)))] = mapped_qubits; + ++mapped_qubits; value.erase(0, q + 1U); } - qubit_map[stoi(trim(value))] = wires; - ++wires; + qubit_map[stoi(trim(value))] = mapped_qubits; + ++mapped_qubits; continue; } @@ -486,8 +490,6 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice { } // Construct backwards, then reverse: - std::vector simulatorType; - if (!is_gpu) { simulatorType.push_back(Qrack::QINTERFACE_CPU); } @@ -515,7 +517,7 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice { simulatorType.push_back(Qrack::QINTERFACE_CPU); } - qsim = CreateQuantumInterface(simulatorType, wires, Qrack::ZERO_BCI, nullptr, Qrack::CMPLX_DEFAULT_ARG, false, true, is_host_pointer); + qsim = QSIM_CONFIG(mapped_qubits); } QrackDevice &operator=(const QuantumDevice &) = delete; @@ -607,7 +609,7 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice { void ReleaseAllQubits() override { // State vector is left empty - qsim->Dispose(0U, qsim->GetQubitCount()); + qsim = QSIM_CONFIG(0U); qubit_map.clear(); } [[nodiscard]] auto GetNumQubits() const -> size_t override diff --git a/pennylane_qrack/qrack_device.py b/pennylane_qrack/qrack_device.py index 5a1dd00..c511097 100644 --- a/pennylane_qrack/qrack_device.py +++ b/pennylane_qrack/qrack_device.py @@ -152,11 +152,7 @@ def get_c_interface(): def __init__(self, wires=0, shots=None, **kwargs): super().__init__(wires=wires, shots=shots) - - if "isTensorNetwork" in kwargs: - self._state = QrackSimulator(self.num_wires, **kwargs) - else: - self._state = QrackSimulator(self.num_wires, isTensorNetwork=False, **kwargs) + self._state = QrackSimulator(self.num_wires, **kwargs) def _reverse_state(self): end = self.num_wires - 1