def test(nphotons, nmodes, accelerate, explicit, mode='quantum'): '''test the simulator''' # build a basis, device and simulator basis=lo.basis(nphotons, nmodes) device=lo.random_unitary(basis.nmodes) simulator=lo.simulator(basis, device) simulator.configure_perm(accelerate, explicit) mode='quantum' if not mode else 'classical' simulator.set_mode(mode) # put photons in the top modes state=basis.get_state(['m'] + range(basis.nphotons)) #print str(state).strip() simulator.set_input_state(state) # how long does it take to work over the full hilbert space t=clock() for i in range(basis.hilbert_space_dimension): simulator.get_probability(i) util.progress_bar(i/float(basis.hilbert_space_dimension-1)) hilbert_space_time=clock()-t return hilbert_space_time
# Now let's make a simulator, and link it to the device simulator=lo.simulator(device, nphotons=2) # Let's have a look at the basis print simulator.basis # Set the input state to two photons in the top mode, and look at # the output probabilities and output state simulator.set_input_state([0, 0]) print simulator.input_state print simulator.get_probabilities().round(2) print simulator.get_output_state() # Superposition input states, and classical statistics state=simulator.basis.get_state() state[0,1]=1/np.sqrt(2) state[3,4]=1/np.sqrt(2) print state simulator.set_input_state(state) simulator.set_visibility(0.5) print simulator.get_probabilities() # Now let's test the speed/performance of the code. # Let's do 4 photons in 16 modes of a Haar-random U # Hilbert space dimension is now 3876 device=lo.random_unitary(16) simulator=lo.simulator(device, nphotons=4) simulator.set_input_state(range(4)) # Photons go in the top 4 modes probs=simulator.get_probabilities(label=True)
# Now let's make a simulator, and link it to the device simulator = lo.simulator(device, nphotons=2) # Let's have a look at the basis print simulator.basis # Set the input state to two photons in the top mode, and look at # the output probabilities and output state simulator.set_input_state([0, 0]) print simulator.input_state print simulator.get_probabilities().round(2) print simulator.get_output_state() # Superposition input states, and classical statistics state = simulator.basis.get_state() state[0, 1] = 1 / np.sqrt(2) state[3, 4] = 1 / np.sqrt(2) print state simulator.set_input_state(state) simulator.set_visibility(0.5) print simulator.get_probabilities() # Now let's test the speed/performance of the code. # Let's do 4 photons in 16 modes of a Haar-random U # Hilbert space dimension is now 3876 device = lo.random_unitary(16) simulator = lo.simulator(device, nphotons=4) simulator.set_input_state(range(4)) # Photons go in the top 4 modes probs = simulator.get_probabilities(label=True)