From 9f76efce80d9e1a873ca7bd32551eec206f6043d Mon Sep 17 00:00:00 2001 From: miha-q <> Date: Thu, 1 Aug 2024 19:06:16 -0400 Subject: [PATCH] Thu Aug 1 07:06:16 PM EDT 2024 --- examples/ghz.txt | 25 +-- src/bytecode.c | 14 +- src/bytecode.h | 2 +- src/gui.html | 304 +++++++++++++++++++++++++++-------- src/imports/istina-editor.js | 1 + src/imports/spinner.gif | Bin 0 -> 19236 bytes src/openqasm.c | 6 +- src/qansel.h | 7 +- 8 files changed, 268 insertions(+), 91 deletions(-) create mode 100644 src/imports/spinner.gif diff --git a/examples/ghz.txt b/examples/ghz.txt index d988daa..07e4689 100644 --- a/examples/ghz.txt +++ b/examples/ghz.txt @@ -1,21 +1,8 @@ -qreg q[3]; -creg c[3]; - -//Prepare GHZ state -h q[0]; -cx q[0], q[1]; -cx q[0], q[2]; - -h q[0]; +qreg q[2]; +creg c[2]; +x q[0]; +z q[1]; +swap q[0], q[1]; measure q[0] -> c[0]; - -sdg q[1]; -h q[1]; measure q[1] -> c[1]; - -sdg q[2]; -h q[2]; -measure q[2] -> c[2]; - -sample c; - +sample c; \ No newline at end of file diff --git a/src/bytecode.c b/src/bytecode.c index f694362..7327f7e 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -32,6 +32,7 @@ const char* qansel_instruction_to_string(unsigned char instr) case QANSEL_INSTRUCTION_IF_L: return "if<"; case QANSEL_INSTRUCTION_IF_LE: return "if<="; case QANSEL_INSTRUCTION_PRINT: return "print"; + case QANSEL_INSTRUCTION_SET: return "set"; case QANSEL_INSTRUCTION_RESET: return "reset"; case QANSEL_INSTRUCTION_BARRIER: return "barrier"; case QANSEL_INSTRUCTION_EXIT: return "exit"; @@ -522,6 +523,7 @@ int qansel_get_instruction_bitmax(unsigned char* ptr, int offset, int* bitmax, i if ((a0 > QANSEL_CBOUND_UPPER || a0 < QANSEL_CBOUND_LOWER) && a0 != QANSEL_ALL_CLASSIC) return 0; if (a0 != QANSEL_ALL_CLASSIC) *bitmax = (a0 - QANSEL_CBOUND_LOWER) + 1; return 1; + case QANSEL_INSTRUCTION_SET: case QANSEL_INSTRUCTION_RESET: case QANSEL_INSTRUCTION_PRINT: a0 = ptr[offset + 1]; @@ -598,6 +600,7 @@ int qansel_get_instruction_size(unsigned char instr) case QANSEL_INSTRUCTION_IF_GE: return 1 + 1 + sizeof(unsigned short); case QANSEL_INSTRUCTION_IF_L: return 1 + 1 + sizeof(unsigned short); case QANSEL_INSTRUCTION_IF_LE: return 1 + 1 + sizeof(unsigned short); + case QANSEL_INSTRUCTION_SET: return 1 + 1; case QANSEL_INSTRUCTION_RESET: return 1 + 1; case QANSEL_INSTRUCTION_PRINT: return 1 + 1; case QANSEL_INSTRUCTION_BARRIER: return 1 + 1; @@ -645,6 +648,7 @@ void qansel_get_barrier(QBytecode** qbc, int idx) case QANSEL_INSTRUCTION_BORN: case QANSEL_INSTRUCTION_BARRIER: case QANSEL_INSTRUCTION_PRINT: + case QANSEL_INSTRUCTION_SET: case QANSEL_INSTRUCTION_RESET: switch ((*qbc)[idx].bytes[1]) { @@ -835,7 +839,7 @@ int qansel_get_int(unsigned char* program, int offset) return ret; } -void qansel_reset(QAnselContext* ctx, cpx_mtx_t* stateVector, unsigned char* bitVector, int qubitCount, int bitCount, unsigned char q0) +void qansel_set(QAnselContext* ctx, cpx_mtx_t* stateVector, unsigned char* bitVector, int qubitCount, int bitCount, unsigned char q0, unsigned char value) { unsigned int qubitCountPow2 = (unsigned int)pow(2, qubitCount); if (q0 == QANSEL_ALL) @@ -868,7 +872,7 @@ void qansel_reset(QAnselContext* ctx, cpx_mtx_t* stateVector, unsigned char* bit else if (q0 <= QANSEL_QBOUND_UPPER) { unsigned char bit = qansel_measure(ctx, stateVector, qubitCount, q0); - if (bit) + if (bit != value) { qansel_instruction(ctx, stateVector, qubitCount, QANSEL_INSTRUCTION_X, q0, 0, 0, 0, NULL); } @@ -1410,9 +1414,13 @@ void qansel_run(QAnselContext* ctx, unsigned char* program, int programSize, int case QANSEL_INSTRUCTION_BARRIER: a0 = program[PC + 1]; break; + case QANSEL_INSTRUCTION_SET: + a0 = program[PC + 1]; + qansel_set(ctx, &stateVector, bitVector, qubitCount, bitCount, a0, 1); + break; case QANSEL_INSTRUCTION_RESET: a0 = program[PC + 1]; - qansel_reset(ctx, &stateVector, bitVector, qubitCount, bitCount, a0); + qansel_set(ctx, &stateVector, bitVector, qubitCount, bitCount, a0, 0); break; case QANSEL_INSTRUCTION_IF_E: a0 = program[PC + 1]; diff --git a/src/bytecode.h b/src/bytecode.h index 9a53a2f..a3da33f 100644 --- a/src/bytecode.h +++ b/src/bytecode.h @@ -134,7 +134,7 @@ void qansel_density_or_print(cpx_mtx_t* stateVector, unsigned char* bitVector, u float qansel_get_float(unsigned char* program, int offset); short qansel_get_short(unsigned char* program, int offset); int qansel_get_int(unsigned char* program, int offset); -void qansel_reset(QAnselContext* ctx, cpx_mtx_t* stateVector, unsigned char* bitVector, int qubitCount, int bitCount, unsigned char q0); +void qansel_set(QAnselContext* ctx, cpx_mtx_t* stateVector, unsigned char* bitVector, int qubitCount, int bitCount, unsigned char q0, unsigned char value); unsigned char qansel_compare(unsigned char* bitVector, int bitCount, int PC, unsigned char a0, short op); //computes program efficiency diff --git a/src/gui.html b/src/gui.html index bbc0159..5d45b2c 100644 --- a/src/gui.html +++ b/src/gui.html @@ -6,7 +6,7 @@ + .top-button-row td:hover + { + background-color: gray; + cursor: pointer; + } + + @keyframes animation-reveal + { + from { + clip-path: polygon(0% 0%, 0% 0%, 100% 0%, 100% 0%); + } + to { + clip-path: polygon(0% 0%, 0% 100%, 100% 100%, 100% 0%); + } + } + -