def test_memory(self): ds = pygsti.objects.DataSet(fileToLoadFrom=compare_files + "/analysis.dataset") gateset = pygsti.io.load_gateset(compare_files + "/analysis.gateset") with self.assertRaises(MemoryError): pygsti.logl_hessian(gateset, ds, probClipInterval=(-1e6,1e6), poissonPicture=True, check=False, memLimit=0) # No memory for you L = pygsti.logl_hessian(gateset, ds, probClipInterval=(-1e6,1e6), poissonPicture=True, check=False, memLimit=None, verbosity=10) # Reference: no mem limit L1 = pygsti.logl_hessian(gateset, ds, probClipInterval=(-1e6,1e6), poissonPicture=True, check=False, memLimit=370000000, verbosity=10) # Limit memory a bit L2 = pygsti.logl_hessian(gateset, ds,probClipInterval=(-1e6,1e6), poissonPicture=True, check=False, memLimit=1000000, verbosity=10) # Limit memory a bit more L3 = pygsti.logl_hessian(gateset, ds, probClipInterval=(-1e6,1e6), poissonPicture=True, check=False, memLimit=300000, verbosity=10) # Very low memory (splits tree) with self.assertRaises(MemoryError): pygsti.logl_hessian(gateset, ds, probClipInterval=(-1e6,1e6), poissonPicture=True, check=False, memLimit=100000) # Splitting unproductive #print("****DEBUG LOGL HESSIAN L****") #print("shape = ",L.shape) #to_check = L #for i in range(L.shape[0]): # for j in range(L.shape[1]): # diff = abs(L3[i,j]-L[i,j]) # if diff > 1e-6: # print("[%d,%d] diff = %g - %g = %g" % (i,j,L3[i,j],L[i,j],L3[i,j]-L[i,j])) self.assertArraysAlmostEqual(L, L1) self.assertArraysAlmostEqual(L, L2) self.assertArraysAlmostEqual(L, L3)
def test_memory(self): ds = pygsti.objects.DataSet(fileToLoadFrom=compare_files + "/analysis.dataset") with self.assertRaises(MemoryError): pygsti.logl_hessian(std.gs_target, ds, probClipInterval=(-1e6, 1e6), countVecMx=None, poissonPicture=True, check=False, memLimit=0) # No memory for you L = pygsti.logl_hessian(std.gs_target, ds, probClipInterval=(-1e6, 1e6), countVecMx=None, poissonPicture=True, check=False, memLimit=370000000) # Limit memory a bit pygsti.logl_hessian(std.gs_target, ds, probClipInterval=(-1e6, 1e6), countVecMx=None, poissonPicture=True, check=False, memLimit=25000000) # Limit memory a bit more with self.assertRaises(MemoryError): pygsti.logl_hessian( std.gs_target, ds, probClipInterval=(-1e6, 1e6), countVecMx=None, poissonPicture=True, check=False, memLimit=30000) # Until another error is thrown
def test_hessian_mpi(self): from mpi4py import MPI comm = MPI.COMM_WORLD ds = pygsti.objects.DataSet(fileToLoadFrom=compare_files + "/analysis.dataset") L = pygsti.logl_hessian(std.gs_target, ds, probClipInterval=(-1e6,1e6), countVecMx=None, memLimit=25000000, poissonPicture=True, check=False, comm=comm) print(L)
def test_logl_fn(self): ds = pygsti.objects.DataSet(fileToLoadFrom=compare_files + "/analysis.dataset") gatestrings = pygsti.construction.gatestring_list( [ ('Gx',), ('Gy',), ('Gx','Gx') ] ) spam_labels = std.gs_target.get_spam_labels() pygsti.create_count_vec_dict( spam_labels, ds, gatestrings ) gateset = pygsti.io.load_gateset(compare_files + "/analysis.gateset") L1 = pygsti.logl(gateset, ds, gatestrings, probClipInterval=(-1e6,1e6), countVecMx=None, poissonPicture=True, check=False) L2 = pygsti.logl(gateset, ds, gatestrings, probClipInterval=(-1e6,1e6), countVecMx=None, poissonPicture=False, check=False) #Non-poisson-picture dL1 = pygsti.logl_jacobian(gateset, ds, gatestrings, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=True, check=False) dL2 = pygsti.logl_jacobian(gateset, ds, gatestrings, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=False, check=False) dL2b = pygsti.logl_jacobian(gateset, ds, None, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=False, check=False) #test None as gs list hL1 = pygsti.logl_hessian(gateset, ds, gatestrings, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=True, check=False) hL2 = pygsti.logl_hessian(gateset, ds, gatestrings, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=False, check=False) hL2b = pygsti.logl_hessian(gateset, ds, None, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=False, check=False) #test None as gs list maxL1 = pygsti.logl_max(ds, gatestrings, poissonPicture=True, check=True) maxL2 = pygsti.logl_max(ds, gatestrings, poissonPicture=False, check=True) pygsti.cptp_penalty(gateset, include_spam_penalty=True) twoDelta1 = pygsti.two_delta_loglfn(N=100, p=0.5, f=0.6, minProbClip=1e-6, poissonPicture=True) twoDelta2 = pygsti.two_delta_loglfn(N=100, p=0.5, f=0.6, minProbClip=1e-6, poissonPicture=False)
def test_hessian_mpi(self): from mpi4py import MPI comm = MPI.COMM_WORLD ds = pygsti.objects.DataSet(fileToLoadFrom=compare_files + "/analysis.dataset") gateset = pygsti.io.load_gateset(compare_files + "/analysis.gateset") L = pygsti.logl_hessian(gateset, ds, probClipInterval=(-1e6,1e6), memLimit=25000000, poissonPicture=True, check=False, comm=comm) print(L)
def test_logl_fn(self): ds = pygsti.objects.DataSet(fileToLoadFrom=compare_files + "/analysis.dataset%s" % self.versionsuffix) circuits = pygsti.construction.circuit_list( [ ('Gx',), ('Gy',), ('Gx','Gx') ] ) #OLD spam_labels = std.target_model().get_spam_labels() #OLD pygsti.create_count_vec_dict( spam_labels, ds, circuits ) model = pygsti.io.load_model(compare_files + "/analysis.model") L1 = pygsti.logl(model, ds, circuits, probClipInterval=(-1e6,1e6), poissonPicture=True, check=False) L2 = pygsti.logl(model, ds, circuits, probClipInterval=(-1e6,1e6), poissonPicture=False, check=False) #Non-poisson-picture dL1 = pygsti.logl_jacobian(model, ds, circuits, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=True, check=False) dL2 = pygsti.logl_jacobian(model, ds, circuits, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=False, check=False) dL2b = pygsti.logl_jacobian(model, ds, None, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=False, check=False) #test None as mdl list hL1 = pygsti.logl_hessian(model, ds, circuits, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=True, check=False) hL2 = pygsti.logl_hessian(model, ds, circuits, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=False, check=False) hL2b = pygsti.logl_hessian(model, ds, None, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=False, check=False) #test None as mdl list maxL1 = pygsti.logl_max(model, ds, circuits, poissonPicture=True, check=True) maxL2 = pygsti.logl_max(model, ds, circuits, poissonPicture=False, check=True) pygsti.cptp_penalty(model, include_spam_penalty=True) twoDelta1 = pygsti.two_delta_loglfn(N=100, p=0.5, f=0.6, minProbClip=1e-6, poissonPicture=True) twoDelta2 = pygsti.two_delta_loglfn(N=100, p=0.5, f=0.6, minProbClip=1e-6, poissonPicture=False)
def test_hessian_mpi(self): from mpi4py import MPI comm = MPI.COMM_WORLD ds = pygsti.objects.DataSet(fileToLoadFrom=compare_files + "/analysis.dataset%s" % self.versionsuffix) model = pygsti.io.load_model(compare_files + "/analysis.model") L = pygsti.logl_hessian(model, ds, probClipInterval=(-1e6,1e6), memLimit=25000000, poissonPicture=True, check=False, comm=comm) print(L)
def test_logl_fn(self): ds = pygsti.objects.DataSet(fileToLoadFrom=compare_files + "/analysis.dataset") gatestrings = pygsti.construction.gatestring_list( [ ('Gx',), ('Gy',), ('Gx','Gx') ] ) spam_labels = std.gs_target.get_spam_labels() pygsti.create_count_vec_dict( spam_labels, ds, gatestrings ) L1 = pygsti.logl(std.gs_target, ds, gatestrings, probClipInterval=(-1e6,1e6), countVecMx=None, poissonPicture=True, check=False) L2 = pygsti.logl(std.gs_target, ds, gatestrings, probClipInterval=(-1e6,1e6), countVecMx=None, poissonPicture=False, check=False) #Non-poisson-picture dL1 = pygsti.logl_jacobian(std.gs_target, ds, gatestrings, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=True, check=False) dL2 = pygsti.logl_jacobian(std.gs_target, ds, gatestrings, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=False, check=False) dL2b = pygsti.logl_jacobian(std.gs_target, ds, None, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=False, check=False) #test None as gs list hL1 = pygsti.logl_hessian(std.gs_target, ds, gatestrings, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=True, check=False) hL2 = pygsti.logl_hessian(std.gs_target, ds, gatestrings, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=False, check=False) hL2b = pygsti.logl_hessian(std.gs_target, ds, None, probClipInterval=(-1e6,1e6), radius=1e-4, poissonPicture=False, check=False) #test None as gs list maxL1 = pygsti.logl_max(ds, gatestrings, poissonPicture=True, check=True) maxL2 = pygsti.logl_max(ds, gatestrings, poissonPicture=False, check=True) pygsti.cptp_penalty(std.gs_target, include_spam_penalty=True) twoDelta1 = pygsti.two_delta_loglfn(N=100, p=0.5, f=0.6, minProbClip=1e-6, poissonPicture=True) twoDelta2 = pygsti.two_delta_loglfn(N=100, p=0.5, f=0.6, minProbClip=1e-6, poissonPicture=False)
def test_memory(self): def musage(prefix): p = psutil.Process(os.getpid()) print(prefix, p.memory_info()[0]) current_mem = pygsti.baseobjs.profiler._get_mem_usage musage("Initial") ds = pygsti.data.DataSet(file_to_load_from=compare_files + "/analysis.dataset") model = pygsti.io.load_model(compare_files + "/analysis.model") musage("Pt1") with self.assertRaises(MemoryError): pygsti.logl_hessian(model, ds, prob_clip_interval=(-1e6, 1e6), poisson_picture=True, mem_limit=0) # No memory for you musage("Pt2") L = pygsti.logl_hessian(model, ds, prob_clip_interval=(-1e6, 1e6), poisson_picture=True, mem_limit=None, verbosity=10) # Reference: no mem limit musage("Pt3") L1 = pygsti.logl_hessian(model, ds, prob_clip_interval=(-1e6, 1e6), poisson_picture=True, mem_limit=1024.0**3, verbosity=10) # Limit memory (1GB) musage("Pt4") #L2 = pygsti.logl_hessian(model, ds,prob_clip_interval=(-1e6,1e6), # poisson_picture=True, mem_limit=current_mem()+1000000, verbosity=10) # Limit memory a bit more #musage("Pt5") #L3 = pygsti.logl_hessian(model, ds, prob_clip_interval=(-1e6,1e6), # poisson_picture=True, mem_limit=current_mem()+300000, verbosity=10) # Very low memory (splits tree) #We've currently disabled memory errors - re-enable this after we get memory checks working again. #with self.assertRaises(MemoryError): pygsti.logl_hessian(model, ds, prob_clip_interval=(-1e6, 1e6), poisson_picture=True, mem_limit=1024.0**3) #print("****DEBUG LOGL HESSIAN L****") #print("shape = ",L.shape) #to_check = L #for i in range(L.shape[0]): # for j in range(L.shape[1]): # diff = abs(L3[i,j]-L[i,j]) # if diff > 1e-6: # print("[%d,%d] diff = %g - %g = %g" % (i,j,L3[i,j],L[i,j],L3[i,j]-L[i,j])) self.assertArraysAlmostEqual(L, L1)
def test_hessian_mpi(self): try: from mpi4py import MPI comm = MPI.COMM_WORLD current_mem = pygsti.baseobjs.profiler._get_mem_usage ds = pygsti.data.DataSet(file_to_load_from=compare_files + "/analysis.dataset") model = pygsti.io.load_model(compare_files + "/analysis.model") L = pygsti.logl_hessian(model, ds, prob_clip_interval=(-1e6, 1e6), mem_limit=500 * 1024**2 + current_mem(), poisson_picture=True, comm=comm) print(L) except ImportError: self.skipTest('Skipping because failed to import MPI')
def test_memory(self): ds = pygsti.objects.DataSet(fileToLoadFrom=compare_files + "/analysis.dataset") with self.assertRaises(MemoryError): pygsti.logl_hessian(std.gs_target, ds, probClipInterval=(-1e6,1e6), countVecMx=None, poissonPicture=True, check=False, memLimit=0) # No memory for you L = pygsti.logl_hessian(std.gs_target, ds, probClipInterval=(-1e6,1e6), countVecMx=None, poissonPicture=True, check=False, memLimit=370000000) # Limit memory a bit pygsti.logl_hessian(std.gs_target, ds, probClipInterval=(-1e6,1e6), countVecMx=None, poissonPicture=True, check=False, memLimit=25000000) # Limit memory a bit more with self.assertRaises(MemoryError): pygsti.logl_hessian(std.gs_target, ds, probClipInterval=(-1e6,1e6), countVecMx=None, poissonPicture=True, check=False, memLimit=30000) # Until another error is thrown