From bdb723c7a51ac44d9943fa097d801e62cc25f813 Mon Sep 17 00:00:00 2001 From: WrathfulSpatula Date: Sat, 5 Oct 2024 10:56:12 -0400 Subject: [PATCH] Noise parameter and new Qrack --- Makefile | 2 +- pennylane_qrack/QrackDeviceConfig.toml | 4 ++-- pennylane_qrack/_version.py | 2 +- pennylane_qrack/qrack_device.cpp | 9 +++++++-- pennylane_qrack/qrack_device.py | 10 +++++----- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index c83ce78..336ff4d 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,7 @@ help: build-deps: ifneq ($(OS),Windows_NT) ifeq ($(QRACK_PRESENT),) - git clone https://github.com/unitaryfund/qrack.git; cd qrack; git checkout 4e42ae5d0780ad70e86669f01bf0b134f2c8da06; cd .. + git clone https://github.com/unitaryfund/qrack.git; cd qrack; git checkout 61a9f1e4694eab612b5032e884e6f1696842e47d; cd .. endif mkdir -p qrack/build ifeq ($(UNAME_S),Linux) diff --git a/pennylane_qrack/QrackDeviceConfig.toml b/pennylane_qrack/QrackDeviceConfig.toml index 6206958..507dedd 100644 --- a/pennylane_qrack/QrackDeviceConfig.toml +++ b/pennylane_qrack/QrackDeviceConfig.toml @@ -142,8 +142,8 @@ is_qbdd = "isBinaryDecisionTree" is_gpu = "isOpenCL" # Allocate GPU buffer from general host heap? (Default is "false"; "true" might improve performance or reliability in certain cases, like if using an Intel HD as accelerator) is_host_pointer = "isHostPointer" -# Use noisy simulation? (Default is "false"; depolarizing noise intensity can be controlled by "QRACK_GATE_DEPOLARIZATION" environment variable) -is_noisy = "isNoisy" +# Noise parameter. (Default is "0"; depolarizing noise intensity can also be controlled by "QRACK_GATE_DEPOLARIZATION" environment variable) +noise = "noise" # In the above example, a dictionary will be constructed at run time. # The dictionary will contain the string key "option_key" and its value diff --git a/pennylane_qrack/_version.py b/pennylane_qrack/_version.py index a7aca54..e4bf150 100644 --- a/pennylane_qrack/_version.py +++ b/pennylane_qrack/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.9.8" +__version__ = "0.10.0" diff --git a/pennylane_qrack/qrack_device.cpp b/pennylane_qrack/qrack_device.cpp index bbc79ed..8ac9928 100644 --- a/pennylane_qrack/qrack_device.cpp +++ b/pennylane_qrack/qrack_device.cpp @@ -406,9 +406,10 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice { keyMap["'is_qbdd'"] = 5; keyMap["'is_gpu'"] = 6; keyMap["'is_host_pointer'"] =7; - keyMap["'is_noisy'"] = 8; + keyMap["'noise'"] = 8; size_t pos; + real1_f noiseParam = 0; while ((pos = kwargs.find(":")) != std::string::npos) { std::string key = trim(kwargs.substr(0, pos)); kwargs.erase(0, pos + 1U); @@ -439,7 +440,8 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice { hp = val; break; case 8: - nw = val; + noiseParam = std::stof(value) + nw = noiseParam > ZERO_R1; break; default: break; @@ -447,6 +449,9 @@ struct QrackDevice final : public Catalyst::Runtime::QuantumDevice { } qsim = QSIM_CONFIG(0U); + if (noiseParam > ZERO_R1) { + qsim->SetNoiseParameter(noiseParam); + } } QrackDevice &operator=(const QuantumDevice &) = delete; diff --git a/pennylane_qrack/qrack_device.py b/pennylane_qrack/qrack_device.py index fb2718d..c452499 100644 --- a/pennylane_qrack/qrack_device.py +++ b/pennylane_qrack/qrack_device.py @@ -158,8 +158,8 @@ class QrackDevice(QubitDevice): isOpenCL = True # Allocate GPU buffer from general host heap? (Default is "false"; "true" might improve performance or reliability in certain cases, like if using an Intel HD as accelerator) isHostPointer = False - # Use noisy simulation? (Default is "false"; depolarizing noise intensity can be controlled by "QRACK_GATE_DEPOLARIZATION" environment variable) - isNoisy = False + # Noise parameter. (Default is "0"; depolarizing noise intensity can also be controlled by "QRACK_GATE_DEPOLARIZATION" environment variable) + noise = 0 @staticmethod def get_c_interface(): @@ -187,8 +187,8 @@ def __init__(self, wires=0, shots=None, **kwargs): self.isOpenCL = options['isOpenCL'] if 'isHostPointer' in options: self.isHostPointer = options['isHostPointer'] - if 'isNoisy' in options: - self.isNoisy = options['isNoisy'] + if 'noise' in options: + self.noise = options['noise'] super().__init__(wires=wires, shots=shots) self._state = QrackSimulator( self.num_wires, @@ -198,7 +198,7 @@ def __init__(self, wires=0, shots=None, **kwargs): isBinaryDecisionTree=self.isBinaryDecisionTree, isOpenCL=self.isOpenCL, isHostPointer=self.isHostPointer, - isNoisy=self.isNoisy + noise = self.noise ) def _reverse_state(self):