void demo() { printf("Demo: Stacked mode\n"); printf("- Multiple 2D CA are run as layers within a 3D CA\n"); if (info->matrix_depth == 1) { printf("ERROR: A matrix depth of 2 or greater is required\n"); return; } write_lut(lut_to_2D(LUT_XOR), 0); printf("Same init state for each layer:\n"); for (int z = 0; z < info->matrix_depth; z++) { for (int i = 0; i < 1; i++) { write_state(i,i,z, 1); } } swap_run_swap(); print_states(); printf("Different init state for each layer:\n"); for (int z = 0; z < info->matrix_depth; z++) { for (int i = 0; i < z; i++) { write_state(i,i,z, 1); } } swap_run_swap(); print_states(); }
int * Gates::vec2ampl(Complex * vec, int qb_count){ int kron_size = utils.custom_pow(2, qb_count); print_states(kron_size, vec, "3: After multiplying:\n"); if (qb_count>1) vec = reverse_kronecker(vec, kron_size); int* newthephi = new int[qb_count * 2]; for (int i = 0; i < qb_count * 2; i++) if (i % 2 == 0) newthephi[i] = (360 * acos(vec[i].re)) / M_PI; else newthephi[i] = (180 * vec[i].arg()) / M_PI; print_states((log(kron_size)/log(2))*2, vec, "4: After reverting kronecker:\n"); return newthephi; }
void read_s( StringT& str, void const* data, std::size_t const size ) { duct::IO::StreamContext ctx(FromU::id, duct::Endian::system); duct::IO::imemstream stream(data, size * FromU::char_size); std::printf( "stream size: %lu\n", static_cast<unsigned long>(duct::IO::size(stream)) ); DUCT_ASSERTE(stream.good()); ctx.read_string( stream, str, static_cast<std::streamsize>(size), duct::CHAR_NULL ); DUCT_ASSERTE(stream.good()); print_states(stream); std::printf( "String [size: %lu bsize: %lu len: %lu]: |", static_cast<unsigned long>(size), static_cast<unsigned long>(size*FromU::char_size), static_cast<unsigned long>(str.size()) ); std::cout << str << "|\n"; str.clear(); }
Complex * Gates::ampl2vec(int qb_count, int theta_list[6], int phi_list[6]){ Complex * vec = new Complex[qb_count * 2]; if (vec == NULL){ std::cout << "ERROR"; while (1); } int thephi_index = 0; for (int i = 0; i<qb_count * 2; i += 2){ vec[i].re = cos(theta_list[thephi_index] * M_PI / 360); // ALPHA RE (IM=0) vec[i].im = 0.0f; vec[i + 1].re = sin((theta_list[thephi_index] * M_PI) / 360)*cos((phi_list[thephi_index] * M_PI) / 180); // BETA RE vec[i + 1].im = sin((theta_list[thephi_index] * M_PI) / 360)*sin((phi_list[thephi_index] * M_PI) / 180); // BETA IM thephi_index++; } print_states(qb_count * 2, vec, "1: Before kronecker:\n"); return kronecker(vec, qb_count, true); // PUT VEC INTO KRONECKER AND RETURN THE RESULT }
int main(int argc, char** argv) { char * hostname = "localhost"; if(argc > 1) { hostname = argv[1]; } sqlights_light_initialize(hostname); light_t * light0 = sqlights_add_light("testlight_light0", SQ_ONOFF); light0->onoff_handler = &light0_onoff_handler; light_t * light1 = sqlights_add_light("testlight_light1", SQ_FADEABLE); light1->onoff_handler = &light1_onoff_handler; light1->brightness_handler = &light1_brightness_handler; print_states(); sqlights_lights_run(); }
Complex * Gates::kronecker(Complex * vec, int qb_count, int touch_enable){ if (qb_count == 1 || qb_count>KRON_MAX_SIZE) return vec; int kron_size = (int) utils.custom_pow(2,qb_count); Complex * kronvec = new Complex [kron_size]; init_vector(kronvec,kron_size); //SPLIT THE VECTOR INTO SEPARATE VECTORS OF SIZE 2 (EACH): Complex ** vecdims = new Complex*[qb_count]; for (int i = 0; i < qb_count; i++) vecdims[i] = get_subvector(vec, i + 1); //MAKE KRONECKER PRODUCT: int kron_i = 0; for (int i = 0; i < KRON_SIZE_EACH_VECTOR;i++) for (int j = 0; j < KRON_SIZE_EACH_VECTOR; j++) if (qb_count == 3)for (int k = 0; k < KRON_SIZE_EACH_VECTOR; k++) kronvec[kron_i++] = vecdims[0][i].mul(vecdims[1][j]).mul(vecdims[2][k]); else kronvec[kron_i++] = vecdims[0][i].mul(vecdims[1][j]); for (int i = 0; i < qb_count; i++) delete[]vecdims[i]; delete[] vecdims; print_states(kron_size, kronvec, "2: After kronecker:\n"); if (touch_enable){ //TOUCH THE ENTANGLED/SUPERPOSITIONED QUBIT BEFORE GIVING IT TO A MATRIX: int binary_touch = 0; int binary_touch_location = 0; while (true){ for (int i = 0; i < kron_size; i++){ if (touch(kronvec[i].re) == 1){ binary_touch++; binary_touch_location = i; } } if (binary_touch==1){ for (int j = 0; j < kron_size; j++){ kronvec[j].re = 0; kronvec[j].im = 0; } kronvec[binary_touch_location].re = 1; break; } else{ binary_touch = 0; binary_touch_location = 0; } } } delete []vec; return kronvec; }
void write_s( StringT& str, typename ToU::strict_char_type const* data, std::size_t const size ) { typename ToU::strict_char_type out_buffer[512u]; duct::IO::StreamContext ctx(ToU::id, duct::Endian::system); duct::IO::omemstream stream(out_buffer, sizeof(out_buffer)); DUCT_ASSERTE(stream.good()); std::size_t written_size = ctx.write_string(stream, str, duct::CHAR_NULL); std::printf( "size: %lu written_size: %lu\n", static_cast<unsigned long>(size), static_cast<unsigned long>(written_size) ); DUCT_ASSERTE(stream.good()); DUCT_ASSERTE(written_size == size); stream.flush(); print_states(stream); bool kosher = true; typename ToU::strict_char_type const *di = data, *wi = out_buffer; for (; data + size != di && out_buffer + written_size != wi; ++di, ++wi ) { if (*di != *wi) { std::printf( "di: %lu, %u 0x%X wi: %lu, %u 0x%X\n", static_cast<unsigned long>(di - data), *di, *di, static_cast<unsigned long>(wi - out_buffer), *wi, *wi ); kosher = false; } } if (kosher) { std::puts("She's kosher, cap'n."); } else { std::puts("Something has gone horribly wrong!"); } }
static int dump_states_ascii(int fd, int verbose, const char* filename) { FILE *f; if (strcmp(filename, "-") == 0) { f = stdout; } else { f = fopen(filename, "w"); if (f == NULL) err(EXIT_FAILURE, "Can't open %s", filename); } print_states(fd, verbose, f); if (f != stdout) fclose(f); return 0; }
void light1_brightness_handler(light_t * light, float brightness) { light1_brightness = (int)(254*brightness); print_states(); }
void light0_onoff_handler(light_t * light, char seton) { light0_state = seton; print_states(); }
//! You expected it: This routine is expected never to exit void main (void) { port_init(); watchdog_init(); timer_gpt3_init(); adc_init(); cursors_init(); power_init(); uart_init(); /* enable interrupts. */ EA = 1; get_board_id(); startup_message(); dump_xdata_sfr(); gpio_check_IO_direction(); dump_gpio(); dump_mcs51(); tx_drain(); // oops, UART routines seem not yet clean print_states_ruler(); print_states_enable = 1; print_states(); print_states_enable = 0; save_old_states(); states.number = 0; manufacturing_print_all(); ow_init(); timer1_init(); battery_charging_table_init(); LED_CHG_G_OFF(); LED_CHG_R_OFF(); LED_PWR_OFF(); /* The main loop contains several state machines handling various subsystems on the EC. The idea is to have each subroutine return as quickly as it can (no busy wait unless for a _very_ short delay). Also the subroutines should be pretty much self contained. Unless it is noted _here_ no state machine should need more than xxx microseconds before returning control. When a state machine returns control it is expected to have the variables it is working on in a consistent state. Period (just in case it was missed:^) If it helps: you may want to think of the main loop as a round-robin cooperative scheduler without the overhead this usually implies. This works well if, well, if _all_ routines within the main loop cooperate well. */ while(1) { STATES_TIMESTAMP(); busy = handle_command(); busy |= handle_cursors(); handle_leds(); handle_power(); handle_ds2756_requests(); handle_ds2756_readout(); busy |= handle_battery_charging_table(); watchdog_all_up_and_well |= WATCHDOG_MAIN_LOOP_IS_FINE; print_states(); monitor(); handle_debug(); sleep_if_allowed(); } }