def test_qasm_auto_enable_parallel_experiments(self):
     """test default max memory configuration"""
     # Test circuit
     shots = 100
     experiments = multiprocessing.cpu_count()
     circuits = []
     for i in range(experiments):
         circuits.append(
             ref_qvolume.quantum_volume(4, depth=1, final_measure=True))
     qobj = compile(circuits, self.SIMULATOR, shots=shots)
     backend_opts = {
         'max_parallel_experiments': experiments,
         'max_memory_mb': 1024
     }
     result = self.SIMULATOR.run(qobj,
                                 backend_options=backend_opts).result()
     if result.metadata['omp_enabled']:
         self.assertEqual(
             result.metadata['parallel_experiments'],
             multiprocessing.cpu_count(),
             msg="parallel_experiments should be multiprocessing.cpu_count()"
         )
         self.assertEqual(
             result.to_dict()['results'][0]['metadata']['parallel_shots'],
             1,
             msg="parallel_shots must be 1")
         self.assertEqual(result.to_dict()['results'][0]['metadata']
                          ['parallel_state_update'],
                          1,
                          msg="parallel_state_update should be 1")
 def test_qasm_auto_disable_shot_parallelization_with_memory_shortage(self):
     """test auto-disabling max_parallel_shots because memory is short"""
     # Test circuit
     shots = multiprocessing.cpu_count()
     circuit = ref_qvolume.quantum_volume(16, depth=1, final_measure=True)
     qobj = compile(circuit, self.SIMULATOR, shots=shots)
     backend_opts = {
         'max_parallel_shots': shots,
         'noise_model': self.dummy_noise_model(),
         'max_memory_mb': 1
     }
     result = self.SIMULATOR.run(qobj,
                                 backend_options=backend_opts).result()
     if result.metadata['omp_enabled']:
         self.assertEqual(result.metadata['parallel_experiments'],
                          1,
                          msg="parallel_experiments should be 1")
         self.assertEqual(
             result.to_dict()['results'][0]['metadata']['parallel_shots'],
             1,
             msg="parallel_shots must be 1")
         self.assertEqual(result.to_dict()['results'][0]['metadata']
                          ['parallel_state_update'],
                          multiprocessing.cpu_count(),
                          msg="parallel_state_update should be " +
                          str(multiprocessing.cpu_count()))
 def test_qasm_auto_short_shot_parallelization(self):
     """test auto-disabling max_parallel_shots because a number of shots is few"""
     # Test circuit
     shots = multiprocessing.cpu_count() - 1
     if (shots == 0):
         return
     circuit = ref_qvolume.quantum_volume(4, depth=1, final_measure=True)
     qobj = compile(circuit, self.SIMULATOR, shots=shots)
     backend_opts = {
         'max_parallel_shots': multiprocessing.cpu_count(),
         'noise_model': self.dummy_noise_model()
     }
     result = self.SIMULATOR.run(qobj,
                                 backend_options=backend_opts).result()
     if result.metadata['omp_enabled']:
         self.assertEqual(result.metadata['parallel_experiments'],
                          1,
                          msg="parallel_experiments should be 1")
         self.assertEqual(
             result.to_dict()['results'][0]['metadata']['parallel_shots'],
             shots,
             msg="parallel_shots must be " + str(shots))
         self.assertEqual(result.to_dict()['results'][0]['metadata']
                          ['parallel_state_update'],
                          int(multiprocessing.cpu_count() / shots),
                          msg="parallel_state_update should be " +
                          str(int(multiprocessing.cpu_count() / shots)))
 def test_qasm_auto_short_parallel_experiments(self):
     """test auto-disabling max_parallel_experiments because a number of circuits is few"""
     # Test circuit
     shots = 1
     experiments = multiprocessing.cpu_count()
     if (experiments == 1):
         return
     circuits = []
     for i in range(experiments - 1):
         circuits.append(
             ref_qvolume.quantum_volume(
                 4, depth=1, final_measure=True))  # 2 MB for each
     qobj = compile(circuits, self.SIMULATOR, shots=shots)
     backend_opts = {
         'max_parallel_experiments': experiments,
         'max_memory_mb': 1024
     }
     result = self.SIMULATOR.run(qobj,
                                 backend_options=backend_opts).result()
     if result.metadata['omp_enabled']:
         self.assertEqual(result.metadata['parallel_experiments'],
                          multiprocessing.cpu_count() - 1,
                          msg="parallel_experiments should be " +
                          str(multiprocessing.cpu_count() - 1))
         self.assertEqual(
             result.to_dict()['results'][0]['metadata']['parallel_shots'],
             1,
             msg="parallel_shots must be 1")
 def test_qasm_max_memory_specified(self):
     """test default max memory configuration"""
     # Test circuit
     shots = 100
     experiments = multiprocessing.cpu_count()
     circuit = ref_qvolume.quantum_volume(4, depth=1, final_measure=True)
     qobj = compile(circuit, self.SIMULATOR, shots=shots)
     backend_opts = {'max_memory_mb': 128}
     result = self.SIMULATOR.run(qobj,
                                 backend_options=backend_opts).result()
     self.assertEqual(result.metadata['max_memory_mb'],
                      128,
                      msg="max_memory_mb is not configured correctly.")
 def test_qasm_max_memory_default(self):
     """test default max memory"""
     # Test circuit
     shots = 100
     experiments = multiprocessing.cpu_count()
     circuit = ref_qvolume.quantum_volume(4, depth=1, final_measure=True)
     qobj = compile(circuit, self.SIMULATOR, shots=shots)
     backend_opts = {}
     result = self.SIMULATOR.run(qobj,
                                 backend_options=backend_opts).result()
     system_memory = int(psutil.virtual_memory().total / 1024 / 1024)
     self.assertGreaterEqual(result.metadata['max_memory_mb'],
                             int(system_memory / 2),
                             msg="statevector_memory is too small.")
     self.assertLessEqual(result.metadata['max_memory_mb'],
                          system_memory,
                          msg="statevector_memory is too big.")
Exemple #7
0
 def test_qasm_shot_parallelization(self):
     """Test statevector method is used for Clifford circuit"""
     # Test circuit
     shots = multiprocessing.cpu_count()
     circuit = ref_qvolume.quantum_volume(4, final_measure=True)
     qobj = compile(circuit, self.SIMULATOR, shots=shots)
     backend_opts = {'max_parallel_shots': shots}
     result = self.SIMULATOR.run(qobj,
                                 backend_options=backend_opts).result()
     if result.metadata['omp_enabled']:
         self.assertEqual(result.metadata['parallel_experiments'],
                          1,
                          msg="default parallel_experiments should be 1")
         self.assertEqual(
             result.metadata['parallel_shots'],
             multiprocessing.cpu_count(),
             msg="parallel_shots must be multiprocessing.cpu_count()")
         self.assertEqual(result.metadata['parallel_state_update'],
                          1,
                          msg="parallel_state_update should be 1")
 def test_qasm_default_parallelization(self):
     """test default parallelization"""
     # Test circuit
     shots = 100
     circuit = ref_qvolume.quantum_volume(4, depth=1, final_measure=True)
     qobj = compile(circuit, self.SIMULATOR, shots=shots)
     backend_opts = {}
     result = self.SIMULATOR.run(qobj,
                                 backend_options=backend_opts).result()
     if result.metadata['omp_enabled']:
         self.assertEqual(result.metadata['parallel_experiments'],
                          1,
                          msg="parallel_experiments should be 1")
         self.assertEqual(
             result.to_dict()['results'][0]['metadata']['parallel_shots'],
             1,
             msg="parallel_shots must be 1")
         self.assertEqual(result.to_dict()['results'][0]['metadata']
                          ['parallel_state_update'],
                          multiprocessing.cpu_count(),
                          msg="parallel_state_update should be " +
                          str(multiprocessing.cpu_count()))