void quantum_sigma_x_ft( int target, quantum_reg *reg ) { int tmp = type; float lambda; type = 0; lambda = quantum_get_decoherence( ); quantum_set_decoherence( 0.0 ); quantum_sigma_x( target, reg ); quantum_sigma_x( width + target, reg ); quantum_set_decoherence( lambda ); quantum_sigma_x( target + ( width * 2 ), reg ); quantum_qec_counter( 1, 0, reg ); type = tmp; return; }
void muxfa_inv(int a,int b_in,int c_in,int c_out, int xlt_l,int L,int total,quantum_reg *reg){//a, if(a==0){//00 quantum_cnot(b_in,c_in, reg); quantum_toffoli(b_in,c_in,c_out, reg); } if(a==3){//11 quantum_cnot(b_in,c_in, reg); quantum_toffoli(b_in,c_in,c_out, reg); quantum_cnot(L,c_in, reg); quantum_toffoli(L,c_in,c_out, reg); } if(a==1){//01 quantum_cnot(b_in,c_in, reg); quantum_toffoli(b_in,c_in,c_out, reg); quantum_toffoli(L,xlt_l,c_in, reg); quantum_toffoli(b_in,c_in,c_out, reg); quantum_toffoli(L,xlt_l,b_in, reg); quantum_toffoli(b_in,c_in,c_out, reg); quantum_toffoli(L,xlt_l,b_in, reg); } if(a==2){//10 quantum_sigma_x(xlt_l, reg); quantum_cnot(b_in,c_in, reg); quantum_toffoli(b_in,c_in,c_out, reg); quantum_toffoli(L,xlt_l,c_in, reg); quantum_toffoli(b_in,c_in,c_out, reg); quantum_toffoli(L,xlt_l,b_in, reg); quantum_toffoli(b_in,c_in,c_out, reg); quantum_toffoli(L,xlt_l,b_in, reg); quantum_sigma_x(xlt_l, reg); } }
/* Reverce Sum 2 qbits */ void sum_1bit_r( quantum_reg * reg, int s1_bit, int s2_bit, int p_bit, int zero_bit ) { quantum_cnot( zero_bit, p_bit, reg ); quantum_cnot( s1_bit, s2_bit, reg ); quantum_cnot( p_bit, s2_bit, reg ); quantum_sigma_x( s1_bit, reg); quantum_sigma_x( s2_bit, reg); quantum_unbounded_toffoli( 3, reg, s1_bit, s2_bit, p_bit, zero_bit ); quantum_sigma_x( s1_bit, reg); quantum_sigma_x( s2_bit, reg); quantum_sigma_x( p_bit, reg); quantum_unbounded_toffoli( 3, reg, s1_bit, s2_bit, p_bit, zero_bit ); quantum_sigma_x( p_bit, reg); /* sigmaX i.e. NOT */ }
void quantum_exp_mod_n( int N, int x, int width_input, int width, quantum_reg *reg ) { int i, j, f; quantum_sigma_x( ( width * 2 ) + 2, reg ); i = 1; for ( ; i <= width_input; i++ ) { f = x % N; j = 1; for ( ; j < i; j++ ) { f *= f; f = f % N; //j++; } mul_mod_n( N, f, i + ( width * 3 ) + 1, width, reg ); //i++; } return; }
void quantum_objcode_run(char *file, quantum_reg *reg) { int i, j, k, l; FILE *fhd; unsigned char operation; unsigned char buf[OBJBUF_SIZE]; MAX_UNSIGNED mu; double d; fhd = fopen(file, "r"); if(!fhd) { fprintf(stderr, "quantum_objcode_run: Could not open %s: ", file); perror(0); return; } for(i=0; !feof(fhd); i++) { for(j=0; j<OBJBUF_SIZE; j++) buf[j] = 0; operation = fgetc(fhd); switch(operation) { case INIT: if(!fread(buf, sizeof(MAX_UNSIGNED), 1, fhd)) { quantum_error(QUANTUM_FAILURE); break; } mu = quantum_char2mu(buf); *reg = quantum_new_qureg(mu, 12); break; case CNOT: case COND_PHASE: if(!fread(buf, sizeof(int), 1, fhd)) { quantum_error(QUANTUM_FAILURE); break; } j = quantum_char2int(buf); if(!fread(buf, sizeof(int), 1, fhd)) { quantum_error(QUANTUM_FAILURE); break; } k = quantum_char2int(buf); switch(operation) { case CNOT: quantum_cnot(j, k, reg); break; case COND_PHASE: quantum_cond_phase(j, k, reg); break; } break; case TOFFOLI: if(!fread(buf, sizeof(int), 1, fhd)) { quantum_error(QUANTUM_FAILURE); break; } j = quantum_char2int(buf); if(!fread(buf, sizeof(int), 1, fhd)) { quantum_error(QUANTUM_FAILURE); break; } k = quantum_char2int(buf); if(!fread(buf, sizeof(int), 1, fhd)) { quantum_error(QUANTUM_FAILURE); break; } l = quantum_char2int(buf); quantum_toffoli(j, k, l, reg); break; case SIGMA_X: case SIGMA_Y: case SIGMA_Z: case HADAMARD: case BMEASURE: case BMEASURE_P: case SWAPLEADS: if(!fread(buf, sizeof(int), 1, fhd)) { quantum_error(QUANTUM_FAILURE); break; } j = quantum_char2int(buf); switch(operation) { case SIGMA_X: quantum_sigma_x(j, reg); break; case SIGMA_Y: quantum_sigma_y(j, reg); break; case SIGMA_Z: quantum_sigma_z(j, reg); break; case HADAMARD: quantum_hadamard(j, reg); break; case BMEASURE: quantum_bmeasure(j, reg); break; case BMEASURE_P: quantum_bmeasure_bitpreserve(j, reg); break; case SWAPLEADS: quantum_swaptheleads(j, reg); break; } break; case ROT_X: case ROT_Y: case ROT_Z: case PHASE_KICK: case PHASE_SCALE: if(!fread(buf, sizeof(int), 1, fhd)) { quantum_error(QUANTUM_FAILURE); break; } j = quantum_char2int(buf); if(!fread(buf, sizeof(double), 1, fhd)) { quantum_error(QUANTUM_FAILURE); break; } d = quantum_char2double(buf); switch(operation) { case ROT_X: quantum_r_x(j, d, reg); break; case ROT_Y: quantum_r_y(j, d, reg); break; case ROT_Z: quantum_r_z(j, d, reg); break; case PHASE_KICK: quantum_phase_kick(j, d, reg); break; case PHASE_SCALE: quantum_phase_scale(j, d, reg); break; } break; case CPHASE_KICK: if(!fread(buf, sizeof(int), 1, fhd)) { quantum_error(QUANTUM_FAILURE); break; } j = quantum_char2int(buf); if(!fread(buf, sizeof(int), 1, fhd)) { quantum_error(QUANTUM_FAILURE); break; } k = quantum_char2int(buf); if(!fread(buf, sizeof(double), 1, fhd)) { quantum_error(QUANTUM_FAILURE); break; } d = quantum_char2double(buf); quantum_cond_phase_kick(j, k, d, reg); break; case MEASURE: quantum_measure(*reg); break; case NOP: break; default: fprintf(stderr, "%i: Unknown opcode 0x(%X)!\n", i, operation); return; } } fclose(fhd); }
void test_sum(int compare, int width, quantum_reg *reg) { int i; if (compare & ((MAX_UNSIGNED) 1 << (width - 1))) { quantum_cnot(2*width-1, width-1, reg); quantum_sigma_x(2*width-1, reg); quantum_cnot(2*width-1, 0, reg); } else { quantum_sigma_x(2*width-1, reg); quantum_cnot(2*width-1,width-1, reg); } for (i = (width-2);i>0;i--) { if (compare & (1<<i)) {//is bit i set in compare? quantum_toffoli(i+1,width+i,i, reg); quantum_sigma_x(width+i, reg); quantum_toffoli(i+1,width+i,0, reg); } else { quantum_sigma_x(width+i, reg); quantum_toffoli(i+1,width+i,i, reg); } } if (compare & 1) { quantum_sigma_x(width, reg); quantum_toffoli(width,1,0, reg); } quantum_toffoli(2*width+1,0,2*width, reg);//set output to 1 if enabled and b < compare if (compare & 1) { quantum_toffoli(width,1,0, reg); quantum_sigma_x(width, reg); } for (i = 1;i<=(width-2);i++) { if (compare & (1<<i)) {//is bit i set in compare? quantum_toffoli(i+1,width+i,0, reg); quantum_sigma_x(width+i, reg); quantum_toffoli(i+1,width+i,i, reg); } else { quantum_toffoli(i+1,width+i,i, reg); quantum_sigma_x(width+i, reg); } } if (compare & (1<<(width-1))) { quantum_cnot(2*width-1,0, reg); quantum_sigma_x(2*width-1, reg); quantum_cnot(2*width-1,width-1, reg); } else { quantum_cnot(2*width-1,width-1, reg); quantum_sigma_x(2*width-1, reg); } }