Beispiel #1
0
 def from_basis(self):
     ''' generate all probabilities relevant to a given detection model'''
     probabilities={}
     for index in range(self.basis.hilbert_space_dimension):
         modes=self.basis.mode(index)
         probabilities[tuple(modes)]=self.get_probability(index)
         util.progress_bar(index, self.basis.hilbert_space_dimension)
     return probabilities
Beispiel #2
0
 def from_detection_model(self, detection_model):
     ''' generate all probabilities relevant to a given detection model'''
     patterns=list(detection_model.iterate_over_mode_events(self.nphotons))
     probabilities={}
     for index, pattern in enumerate(patterns):
         probabilities[pattern]=self.get_probability(['m']+list(pattern))
         util.progress_bar(index, len(patterns))
     return probabilities
Beispiel #3
0
 def load(self, patterns, callback=None, trim=True):
     ''' load all data in the file without a callback or anything '''
     self.set_patterns(patterns)
     if not self.silent: print 'loading %s (%d kB)...' % (os.path.split(self.filename)[-1], self.filesize/1024.)
     chunks_read=1
     total=0
     while chunks_read>0:
         chunks_read=self.read_chunk() 
         if callback!=None: callback(total)
         if not self.silent: util.progress_bar(self.progress)
         total+=1
     if trim: self.trim()
     if not self.silent: print
     return total
Beispiel #4
0
 def load(self, patterns, callback=None, trim=True):
     ''' load all data in the file without a callback or anything '''
     self.set_patterns(patterns)
     loading_messsage = 'loading %s (%d kB)...' % (os.path.split(
         self.filename)[-1], self.filesize / 1024.)
     chunks_read = 1
     total = 0
     while chunks_read > 0:
         chunks_read = self.read_chunk()
         if callback != None: callback(total)
         util.progress_bar(self.progress * 100, 100, loading_messsage)
         total += 1
     if trim: self.trim()
     if not self.silent: print
     return total
Beispiel #5
0
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