|
436 | 436 | "\n",
|
437 | 437 | "# 64 total runs \n",
|
438 | 438 | "for idx, window_size in enumerate(all_window_sizes):\n",
|
| 439 | + " X_train_val = np.load(x_train_path) # need to load data again to avoid memory issues \n", |
| 440 | + " X_test = np.load(x_test_path)\n", |
439 | 441 | " for jdx, start_location in enumerate(all_window_start_locations):\n",
|
440 | 442 | " #########################\n",
|
441 | 443 | " # 0. prep data \n",
|
442 | 444 | " #########################\n",
|
443 | 445 | " # check if window size is too big for start location\n",
|
444 | 446 | " if start_location+window_size > 770:\n",
|
445 |
| - " all_fidelity[idx, jdx] = -1\n", |
| 447 | + " all_fidelity[idx, jdx] = np.nan\n", |
446 | 448 | " print(f'Skipping start location={start_location}, window size={window_size}')\n",
|
447 | 449 | " continue\n",
|
448 |
| - " X_train_val = np.load(x_train_path) # need to load data again to avoid memory issues \n", |
449 |
| - " X_test = np.load(x_test_path)\n", |
450 |
| - " X_train_val = X_train_val[:,start_location*2:(start_location+window_size)*2]\n", |
451 |
| - " X_test = X_test[:,start_location*2:(start_location+window_size)*2]\n", |
| 450 | + " X_train_val_window = X_train_val[:,start_location*2:(start_location+window_size)*2]\n", |
| 451 | + " X_test_window = X_test[:,start_location*2:(start_location+window_size)*2]\n", |
452 | 452 | "\n",
|
453 | 453 | " #########################\n",
|
454 | 454 | " # 1. init callbacks\n",
|
|
487 | 487 | " # 3. train \n",
|
488 | 488 | " #########################\n",
|
489 | 489 | " history = model.fit(\n",
|
490 |
| - " X_train_val, \n", |
| 490 | + " X_train_val_window, \n", |
491 | 491 | " y_train_val, \n",
|
492 | 492 | " batch_size=batch_size,\n",
|
493 | 493 | " epochs=epochs, \n",
|
|
507 | 507 | " #########################\n",
|
508 | 508 | " # 4. compute fidelity \n",
|
509 | 509 | " #########################\n",
|
510 |
| - " y_pred = model.predict(X_test)\n", |
| 510 | + " y_pred = model.predict(X_test_window)\n", |
511 | 511 | " test_acc = accuracy_score(np.argmax(y_test, axis=1), np.argmax(y_pred, axis=1))\n",
|
512 | 512 | " all_accuracy[idx, jdx] = test_acc\n",
|
513 | 513 | " all_fidelity[idx, jdx] = test_acc*2-1\n",
|
514 | 514 | " \n",
|
515 |
| - " # # get ground and excited indices \n", |
516 |
| - " # e_indices = np.where(np.argmax(y_test, axis=1) == 1)[0]\n", |
517 |
| - " # g_indices = np.where(np.argmax(y_test, axis=1) == 0)[0]\n", |
518 |
| - "\n", |
519 |
| - " # # separate ground and excited samples \n", |
520 |
| - " # Xe_test = X_test_window[e_indices]\n", |
521 |
| - " # ye_test = np.argmax(y_test, axis=1)[e_indices]\n", |
522 |
| - "\n", |
523 |
| - " # Xg_test = X_test_window[g_indices]\n", |
524 |
| - " # yg_test = np.argmax(y_test, axis=1)[g_indices]\n", |
525 |
| - "\n", |
526 |
| - " # # compute total correct for excited state \n", |
527 |
| - " # ye_pred = model.predict(Xe_test)\n", |
528 |
| - " # e_accuracy = accuracy_score(ye_test, np.argmax(ye_pred, axis=1))\n", |
529 |
| - "\n", |
530 |
| - " # total_correct = (ye_test==np.argmax(ye_pred, axis=1)).astype(np.int8).sum()\n", |
531 |
| - " # total_incorrect = (ye_test!=np.argmax(ye_pred, axis=1)).astype(np.int8).sum()\n", |
532 |
| - "\n", |
533 |
| - " # # compute total correct for ground state \n", |
534 |
| - " # yg_pred = model.predict(Xg_test)\n", |
535 |
| - " # g_accuracy = accuracy_score(yg_test, np.argmax(yg_pred, axis=1))\n", |
536 |
| - "\n", |
537 |
| - " # total_correct = (yg_test==np.argmax(yg_pred, axis=1)).astype(np.int8).sum()\n", |
538 |
| - " # total_incorrect = (yg_test!=np.argmax(yg_pred, axis=1)).astype(np.int8).sum()\n", |
539 |
| - "\n", |
540 |
| - " # all_e_accuracy.append(e_accuracy)\n", |
541 |
| - " # all_g_accuracy.append(g_accuracy)\n", |
542 |
| - "\n", |
543 |
| - " # compute fidelity \n", |
544 |
| - " # fidelity = 0.5*(e_accuracy + g_accuracy)\n", |
545 |
| - " # all_fidelity[jdx, idx] = fidelity\n", |
546 | 515 | " print('\\n===================================')\n",
|
547 | 516 | " print(f'Start location = {start_location}, Window size = {window_size}')\n",
|
548 | 517 | " print(' Accuracy', test_acc)\n",
|
|
555 | 524 | "metadata": {},
|
556 | 525 | "outputs": [],
|
557 | 526 | "source": [
|
558 |
| - "outfile = '_2-layer_scan_window_size_and_location_window_size_600_770.npz'\n", |
| 527 | + "outfile = '_2-layer_scan_window_size_and_location_window_size_0_770.npz'\n", |
559 | 528 | "note = f'Training data on 0528, readout fidelity with 2-layer NN, scanned window size and location, window size 770'\n",
|
560 | 529 | "\n",
|
561 | 530 | "np.savez(\n",
|
|
0 commit comments