free(reordered[i]);
}
- int copyloc = 0;
- for (int i = 0; i < ramInstrLen; i++)
+ if (best > efficiency)
{
- int next;
- if (ramInstr[i].use_ifop)
+ int copyloc = 0;
+ besti = head[besti];
+ for (int i = 0; i < ramInstrLen; i++)
{
- next = qansel_get_instruction_size(ramInstr[i].ifop[0]);
- memcpy(program + copyloc, ramInstr[i].ifop, next);
+ int next;
+ if (ramInstr[besti].use_ifop)
+ {
+ next = qansel_get_instruction_size(ramInstr[besti].ifop[0]);
+ memcpy(program + copyloc, ramInstr[besti].ifop, next);
+ copyloc += next;
+ }
+ next = qansel_get_instruction_size(ramInstr[besti].op);
+ memcpy(program + copyloc, ramInstr[besti].bytes, next);
+ besti = ramInstr[besti].next;
copyloc += next;
}
- next = qansel_get_instruction_size(ramInstr[i].op);
- memcpy(program + copyloc, ramInstr[i].bytes, next);
- copyloc += next;
}
-
+
if (ctx->verbose)
{
if (best > efficiency)
void qansel_run(QAnselContext* ctx, unsigned char* program, int programSize, int qubitCount, int bitCount, unsigned char* outputBitVector)
{
- int useQueue = ((ctx->optimization_level) & QANSEL_MODE_QUEUE) ? 1 : 0;
+ int useQueue = ((ctx->optimization_level) & QANSEL_MODE_SMART) ? 1 : 0;
int PC = 0;
unsigned int qubitCountPow2 = (unsigned int)pow(2, qubitCount);
unsigned char bitVector[bitCount];
else
{
unsigned char instr = program[PC];
- //printf("-----------------------------------\n");
- //qansel_density_or_print(&stateVector, bitVector, 0, bitCount, qubitCount, QANSEL_ALL_QUANTUM);
- //qansel_density_or_print(&stateVector, bitVector, 0, bitCount, qubitCount, QANSEL_ALL_CLASSIC);
- //printf("%s(%i, %i, %i)(%f, %f, %f)\n", qansel_instruction_to_string(instr), program[PC+1], program[PC+2], program[PC], qansel_get_float(program, PC + 2), qansel_get_float(program, PC + 2 + sizeof(float)), qansel_get_float(program, PC + 2) + sizeof(float) * 2);
//flush the queue if any non-single qubit instructions are called
if (useQueue)
case QANSEL_INSTRUCTION_IF_LE:
break;
default:
- qansel_instruction(ctx, &stateVector, qubitCount, instr, 0, 0, 0, 0, &queueVector);
- for (int i = 0; i < qubitCount; i++)
+ if (!queueFlushed)
{
- memcpy(queueVector[i].ptr, Identity, sizeof(Identity));
+ qansel_instruction(ctx, &stateVector, qubitCount, instr, 0, 0, 0, 0, &queueVector);
+ for (int i = 0; i < qubitCount; i++)
+ {
+ memcpy(queueVector[i].ptr, Identity, sizeof(Identity));
+ }
+ queueFlushed = 1;
}
- queueFlushed = 1;
break;
}
}
fprintf(stderr, "QAnsel: Invalid display settings.\n");
return 0;
}
- if (ctx->optimization_level < QANSEL_MODE_BARE || ctx->optimization_level > (QANSEL_MODE_THREADED | QANSEL_MODE_METAL | QANSEL_MODE_QUEUE))
+ if (ctx->optimization_level < QANSEL_MODE_BARE || ctx->optimization_level > (QANSEL_MODE_THREADED | QANSEL_MODE_METAL | QANSEL_MODE_SMART))
{
fprintf(stderr, "QAnsel: Invalid optimization settings.\n");
return 0;
fprintf(stderr, "QAnsel: Invalid display settings.\n");
return 0;
}
- if (ctx->optimization_level < QANSEL_MODE_BARE || ctx->optimization_level > (QANSEL_MODE_THREADED | QANSEL_MODE_METAL | QANSEL_MODE_QUEUE))
+ if (ctx->optimization_level < QANSEL_MODE_BARE || ctx->optimization_level > (QANSEL_MODE_THREADED | QANSEL_MODE_METAL | QANSEL_MODE_SMART))
{
fprintf(stderr, "QAnsel: Invalid optimization settings.\n");
return 0;
printf(" -o1 Enables multithreading.\n");
printf(" -o2 Enables hardware acceleration (GPU).\n");
printf(" -o3 Combines -o1 and -o2.\n");
- printf(" -o4 Enables instruction queueing.\n");
+ printf(" -o4 Enables smart optimizations.\n");
printf(" -o5 Combines -o1 and -o4.\n");
printf(" -o6 Combines -o2 and -o4.\n");
printf(" -o7 Combines -o3 and -o4.\n");
if (!qanselContextBegin(&ctx)) exit(1);
if (qanselBuildFromSource(script, &bytecode, &bytecodeSize, &ctx))
{
+ for (int i = 0; i < bytecodeSize; i += qansel_get_instruction_size(bytecode[i]))
+ {
+ printf("%s(%i,%i)\n", qansel_instruction_to_string(bytecode[i]), bytecode[i + 1], bytecode[i + 2]);
+ }
qanselExecuteBytecode(bytecode, bytecodeSize, &ctx);
free(bytecode);
}
}
if (instr == 0x00) //sample
{
- if (a0 == QANSEL_ALL_QUANTUM) a0 = QANSEL_ALL;
+ if (a0 == QANSEL_ALL_CLASSIC) a0 = QANSEL_ALL;
else a0 = a0 - QANSEL_CBOUND_LOWER;
ctx->sampling_bit = a0;
ctx->sampling_shots = samplingshots;
if (regcomp(®ex, regexes[j], REG_EXTENDED | REG_ICASE))
{
printf("QAnsel: Regex fatal error.\n");
+ free(binary);
return 0;
}
ret = regexec(®ex, chunks[i], 10, regmatches, 0);
{
regerror(ret, ®ex, errbuf, sizeof(errbuf));
fprintf(stderr, "QAnsel: %s.\n", errbuf);
+ free(binary);
return 0;
}
}
if (!found)
{
fprintf(stderr, "QAnsel on line %i: Invalid syntax.\n", associatedLines[i]);
+ free(binary);
return 0;
}
}
if (!status)
{
*binarySize = 0;
- free(*binary);
return 0;
}
-
- //qansel_reorder(ctx, *binary, *binarySize);
+ if (ctx->optimization_level & QANSEL_MODE_SMART)
+ {
+ qansel_reorder(ctx, *binary, *binarySize);
+ }
return 1;
}