From 6d4c8aaf191debf718838057f9b833de1aa999fe Mon Sep 17 00:00:00 2001 From: watkinsr Date: Sun, 29 Aug 2021 02:18:00 +0200 Subject: [PATCH] QuantumGate alias --- TODOS.txt | 27 +++++++++++++-------------- include/QReg.h | 22 +++++++++++++--------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/TODOS.txt b/TODOS.txt index 3336c0d..0c816f1 100644 --- a/TODOS.txt +++ b/TODOS.txt @@ -1,16 +1,15 @@ -x Implement tensor function -x Fix dot product amplitudes -x Verify we can reproduce a entanglement +[x] Implement tensor function +[x] Fix dot product amplitudes +[x] Verify we can reproduce a entanglement - support example1 - - FORMGATE U HAD ID - - APPLY U R - - - harder: - - SELECT S1 R2 0 1 (0-1 is a range, S1 is where it's saved and R2 is the register) - - MEASURE RES S1 (measure S1) (porbably hardest to support.) - + - [x] FORMGATE U HAD ID + - [x] need to form hashmap for storing variables + - [ ] APPLY U R + - [ ] harder: + - [ ] SELECT S1 R2 0 1 (0-1 is a range, S1 is where it's saved and R2 is the register) + - [ ] MEASURE RES S1 (measure S1) (porbably hardest to support.) +- [ ] REPL stuff: + - [ ] introspection of registers/gates + - [ ] help command +Notes; - we will drop ADD for now because too complex. - -- REPL stuff: - - introspection of registers/gates - - help command diff --git a/include/QReg.h b/include/QReg.h index 4ca8f34..8ea625f 100644 --- a/include/QReg.h +++ b/include/QReg.h @@ -1,3 +1,5 @@ +#pragma once + #include #include #include @@ -6,6 +8,8 @@ using namespace std; +using QuantumGate = vector>>; + class QReg { public: @@ -15,22 +19,22 @@ public: qubits = (int *)calloc(sizeof(int), numberOfQubits); numberOfAmplitudes = (1 << numberOfQubits); - vector>> matrix_(numberOfAmplitudes, vector>(1)); + QuantumGate matrix_(numberOfAmplitudes, vector>(1)); amplitude_matrix = matrix_; amplitude_matrix[init_bit][0] = 1; } - void applyGateToSystem(vector>> gate); - vector>> dot_product_amplitudes(vector>> gate); + void applyGateToSystem(QuantumGate gate); + QuantumGate dot_product_amplitudes(QuantumGate gate); void printAmplitudes(); - static vector>> tensor(vector>> A, vector>> B); - const static vector>> HAD_GATE; - const static vector>> ID_GATE; - const static vector>> CNOT_GATE; - static void printGate(vector>> gate); + static QuantumGate tensor(QuantumGate A, QuantumGate B); + const static QuantumGate HAD_GATE; + const static QuantumGate ID_GATE; + const static QuantumGate CNOT_GATE; + static void printGate(QuantumGate gate); - static vector>> getGateByString(const char* gate); + static QuantumGate getGateByString(const char* gate); private: int numberOfQubits;