Browse Source

parser: implement APPLY gate register

master
watkinsr 1 year ago
parent
commit
75f7493420
  1. 12
      TODOS.txt
  2. 3
      include/parse.h
  3. 20
      src/parse.cpp

12
TODOS.txt

@ -4,12 +4,10 @@
- support example1
- [x] FORMGATE U HAD ID
- [x] need to form hashmap for storing variables
- [ ] APPLY U R
- [x] 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.
- [ ] MEASURE RES S1 (measure S1) (probably hardest to support.)
- [x] REPL stuff:
- [x] introspection of registers
- [x] help command

3
include/parse.h

@ -15,6 +15,7 @@ int execute_cmd(char **args);
int sqint_init(char **args);
int sqint_formgate(char **args);
int sqint_peek(char **args);
int sqint_apply(char **args);
int shell_help(char **args);
unordered_map<string, QuantumGate> gateHashmap;
@ -24,6 +25,7 @@ const char *tokens[] = {
"INIT",
"FORMGATE",
"PEEK",
"APPLY",
"help",
};
@ -31,5 +33,6 @@ int (*builtin_func[])(char **) = {
&sqint_init,
&sqint_formgate,
&sqint_peek,
&sqint_apply,
&shell_help,
};

20
src/parse.cpp

@ -116,6 +116,25 @@ int sqint_peek(char **args) {
}
}
int sqint_apply(char **args) {
if (args[1] == NULL || args[2] == NULL) {
fprintf(stderr, "bad input");
return 1;
} else {
auto gateIter = gateHashmap.find(args[1]);
if (gateIter == gateHashmap.end()) {
printf("Couldn't find gate variable.\n");
}
auto registerIter = quantumRegisterHashmap.find(args[2]);
if (registerIter == quantumRegisterHashmap.end()) {
printf("Couldn't find register variable.\n");
}
registerIter->second.applyGateToSystem(gateIter->second);
registerIter->second.printAmplitudes();
return 1;
}
}
int sqint_formgate(char **args) {
if (args[1] == NULL || args[2] == NULL || args[3] == NULL) {
fprintf(stderr, "bad input");
@ -141,6 +160,7 @@ int shell_help(char **args) {
printf("To initialize a register use INIT REG QUBITSIZE INITBIT\n");
printf("To form a gate use FORMGATE VAR GATE1 GATE2\n");
printf("To peek at a register use PEEK REGISTERNAME\n");
printf("To apply a register to a register use APPLY GATE REGISTER\n");
return 1;
}

Loading…
Cancel
Save