Exemplo n.º 1
0
 def test_state_setter(self):
     provider = IBMQ.load_account()
     backend = QiskitBitGenerator.get_best_backend(provider)
     bitgen = QiskitBitGenerator()
     bitgen.state = {}
     assert bitgen.state == QiskitBitGenerator().state
     bitgen.state = {"backend_filter": lambda b: True}
     bitgen.state = {"max_bits_per_request": 400}
     assert bitgen.state["job_config"]["max_bits_per_request"] == 400
     bitgen.state = {"backend": backend}
     assert not bitgen.state["backend_config"]["simulator"]
     bitgen.state = {"provider": provider}
     assert not bitgen.state["backend_config"]["simulator"]
Exemplo n.º 2
0
 def test_random_uint(self):
     bitgen = QiskitBitGenerator()
     cache = "100" * 100
     n_bits = 4
     bitgen.load_cache(cache)
     assert (bitgen.random_uint(-1) == 10540996613548315209
             and bitgen.random_uint(0) == 2635249153387078802
             and bitgen.random_uint(n_bits) == 4)
     bitgen = QiskitBitGenerator(ISRAW32=True)
     cache = "100" * 100
     n_bits = 4
     bitgen.load_cache(cache)
     assert (bitgen.random_uint(-1) == 2454267026
             and bitgen.random_uint(0) == 1227133513
             and bitgen.random_uint(n_bits) == 2)
Exemplo n.º 3
0
 def test_random_double(self):
     bitgen = QiskitBitGenerator()
     cache = "100" * 100
     n = 4
     bitgen.load_cache(cache)
     assert (bitgen.random_double(-1) == -0.5714285714285714
             and bitgen.random_double(0) == 0.0
             and bitgen.random_double(n) == 1.1428571428571423)
     bitgen = QiskitBitGenerator(ISRAW32=True)
     cache = "100" * 100
     n = 4
     bitgen.load_cache(cache)
     assert (bitgen.random_double(-1) == -0.5714285714285714
             and bitgen.random_double(0) == 0.0
             and bitgen.random_double(n) == 1.1428571428571423)
Exemplo n.º 4
0
 def test_dump_cache(self):
     bitgen = QiskitBitGenerator()
     cache = "100" * 100
     bitgen.load_cache(cache)
     assert bitgen.dump_cache() == cache
     assert (bitgen.dump_cache(flush=True) == cache
             and bitgen._bitcache.size == 0
             and bitgen._bitcache._cache == "")
Exemplo n.º 5
0
 def test_set_state(self):
     provider = IBMQ.load_account()
     simulator = BasicAer.get_backend("qasm_simulator")
     bitgen = QiskitBitGenerator()
     assert not bitgen.set_state()
     assert bitgen.set_state(backend_filter=lambda b: True)
     assert bitgen.set_state(max_bits_per_request=400)
     assert bitgen.set_state(backend=simulator)
     assert bitgen.set_state(provider=provider)
Exemplo n.º 6
0
 def test_random_bitstring(self):
     bitgen = QiskitBitGenerator()
     cache = "100" * 100
     n_bits = 4
     bitgen.load_cache(cache)
     assert (bitgen.random_bitstring(-1) == cache[:bitgen.BITS]
             and bitgen.random_bitstring(0)
             == cache[bitgen.BITS:bitgen.BITS * 2]
             and bitgen.random_bitstring(n_bits)
             == cache[bitgen.BITS * 2:bitgen.BITS * 2 + n_bits])
     bitgen = QiskitBitGenerator(ISRAW32=True)
     cache = "100" * 100
     n_bits = 4
     bitgen.load_cache(cache)
     assert (bitgen.random_bitstring(-1) == cache[:bitgen.BITS]
             and bitgen.random_bitstring(0)
             == cache[bitgen.BITS:bitgen.BITS * 2]
             and bitgen.random_bitstring(n_bits)
             == cache[bitgen.BITS * 2:bitgen.BITS * 2 + n_bits])
Exemplo n.º 7
0
 def test_load_cache(self):
     bitgen = QiskitBitGenerator()
     cache = "100" * 100
     with pytest.raises(TypeError):
         bitgen.load_cache(0)
     with pytest.raises(ValueError):
         bitgen.load_cache("abc")
     assert (bitgen.load_cache(cache) and bitgen.load_cache(cache)
             and bitgen._bitcache.size == 2 * len(cache)
             and bitgen._bitcache._cache == cache + cache)
     assert (bitgen.load_cache(cache, flush=True)
             and bitgen._bitcache.size == len(cache)
             and bitgen._bitcache._cache == cache)
Exemplo n.º 8
0
 def test_job_config(self):
     bitgen = QiskitBitGenerator()
     bjc = bitgen._job_config
     jc = {
         "experiments": 1,
         "max_bits_per_request": None,
         "n_qubits": 24,
         "shots": 65536,
     }
     jc["bits_per_request"] = (jc["experiments"] * jc["shots"] *
                               jc["n_qubits"])
     assert bjc == jc and (
         not bjc["max_bits_per_request"]
         or bjc["max_bits_per_request"] >= bjc["bits_per_request"])
Exemplo n.º 9
0
 def test_parse_backend_config(self):
     bitgen = QiskitBitGenerator()
     MASK = bitgen._BACKEND_CONFIG_MASK
     backend_config = {
         "backend_name": "TEST",
         "simulator": True,
         "dummy_1": True,
         "dummy_2": 2,
         "dummy_3": 0.4,
         "dummy_4": "test",
         "dummy_5": None,
     }
     parsed_bc = bitgen._parse_backend_config(backend_config)
     MASK.pop("backend_name")
     assert parsed_bc.pop("backend_name") == "TEST" and parsed_bc == MASK
Exemplo n.º 10
0
 def test_state(self):
     bitgen = QiskitBitGenerator()
     state = {
         "BITS": 64,
         "backend_config": {
             # "backend_name": "qasm_simulator",
             "credits_required": False,
             "local": True,
             "n_qubits": 24,
             "simulator": True,
         },
         "bitcache": {
             "size": 0
         },
         "job_config": {
             "bits_per_request": 1572864,
             "experiments": 1,
             "max_bits_per_request": None,
             "n_qubits": 24,
             "shots": 65536,
         },
     }
     assert bitgen.state == state
Exemplo n.º 11
0
 def test_memory(self):
     bitgen = QiskitBitGenerator()
     assert bitgen._backend_config["memory"] or not bitgen._memory
     memory = True if bitgen._n_qubits > 1 else False
     assert bitgen._memory == memory
Exemplo n.º 12
0
 def test_job_partition(self):
     bitgen = QiskitBitGenerator()
     assert bitgen._job_partition == (24, 65536, 1)
     bitgen.state = {"max_bits_per_request": 4}
     assert bitgen._job_partition == (4, 1, 1)
Exemplo n.º 13
0
 def test_flush_cache(self):
     bitgen = QiskitBitGenerator()
     cache = "100" * 100
     bitgen.load_cache(cache)
     bitgen.flush_cache()
     assert bitgen._bitcache.size == 0 and bitgen._bitcache._cache == ""
Exemplo n.º 14
0
 def test_circuit(self):
     bitgen = QiskitBitGenerator()
     bc = bitgen._circuit
     n_qubits = bitgen._n_qubits
     assert (bc.num_qubits == n_qubits and bc.num_clbits == n_qubits
             and bc.size() == 2 * n_qubits)
Exemplo n.º 15
0
 def test_backend_config(self):
     bitgen = QiskitBitGenerator()
     bc = BasicAer.get_backend("qasm_simulator").configuration().to_dict()
     assert bitgen._backend_config == bc
Exemplo n.º 16
0
 def test_BITS(self):
     bitgen64 = QiskitBitGenerator()
     bitgen32 = QiskitBitGenerator(ISRAW32=True)
     assert bitgen32.BITS == 32 and bitgen64.BITS == 64
Exemplo n.º 17
0
 def test_set_mbpr(self):
     bitgen = QiskitBitGenerator()
     assert bitgen._set_mbpr(-1) and bitgen._max_bits_per_request == 0
     assert bitgen._set_mbpr(0) and bitgen._max_bits_per_request == 0
     assert bitgen._set_mbpr(1) and bitgen._max_bits_per_request == 1