{ "cells": [ { "cell_type": "markdown", "id": "5677b81c", "metadata": {}, "source": [ "# SOQCS Benchmark" ] }, { "cell_type": "markdown", "id": "1060dc45", "metadata": {}, "source": [ "
In this example various random circuits of N photons and 2N channels are generated. The N photons are assigned one by one to be initialized in the first N channels. The amplitude to find out those photons in the same configuration at the output is calculated. The calculation of this amplitude implies the calculation of a single permanent. The time required to calculate this permanent with different methods is registered and plotted as function of the number of photons and channels. The permanent is calculated using the \n", "the Balasubramanian–Bax–Franklin–Glynn formula \"Glynn\", the Ryser formula \"Ryser\" or the Ryser formula making use of parallelization in the way suggested in ref. [1] \"Ryser 10\". In the last case 10 processor cores are used.
\n", "The next piece of code performs the benchmark for the different methods mentioned above. Random circuits are generated to calculate these benchmarks from minph photons to maxnph photon doubling the number of channels with respect the number of photons.
" ] }, { "cell_type": "code", "execution_count": 3, "id": "a8f521f8", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " nph nch Glynn Ryser Ryser10\n", " 10 20 0.07 1.14 0.04\n", " 11 22 0.17 0.11 0.03\n", " 12 24 0.35 0.21 0.04\n", " 13 26 0.69 0.44 0.07\n", " 14 28 1.38 0.88 0.13\n", " 15 30 2.90 1.87 0.25\n", " 16 32 5.81 3.53 0.49\n", " 17 34 11.45 6.82 0.90\n", " 18 36 22.04 14.43 1.94\n", " 19 38 46.05 36.39 7.57\n", " 20 40 112.97 104.44 13.10\n" ] } ], "source": [ "print(\" nph nch Glynn Ryser Ryser10\")\n", "for nph in range (minnph,maxnph+1):\n", " nch=chf*nph;\n", "\n", " # Build circuit\n", " example = soqcs.qodev(nph,nch)\n", " for j in range (0,nph):\n", " example.add_photons(1,j)\n", " example.random_circuit()\n", " for j in range (0,nch):\n", " example.detector(j)\n", "\n", " # Set-up inital state\n", " inputst=example.input()\n", " # List of output amplitudes to be calcualted\n", " olist=example.input()\n", " # Set-up circuit\n", " circuit=example.circuit()\n", "\n", " # Simulate Glynn\n", " start = time.time()\n", " output=sim.run_st(inputst,circuit,2,st_list=olist);\n", " end = time.time()\n", " tglynn=(end-start)*1000\n", " \n", " # Simulate Ryser 1\n", " start = time.time()\n", " output=sim.run_st(inputst,circuit,4,nthreads=1,st_list=olist);\n", " end = time.time()\n", " tryser=(end-start)*1000 \n", "\n", " # Simulate Ryser 10\n", " start = time.time()\n", " output=sim.run_st(inputst,circuit,4,nthreads=10,st_list=olist);\n", " end = time.time()\n", " tryser10=(end-start)*1000 \n", "\n", " # Print results\n", " print(\"{:5d}\".format(nph),\"{:5d}\".format(nch),\"{:8.2f}\".format(tglynn),\"{:8.2f}\".format(tryser),\"{:8.2f}\".format(tryser10))" ] }, { "cell_type": "markdown", "id": "1ee62073", "metadata": {}, "source": [ "**THIS CODE IS PART OF SOQCS**