Exemple #1
0
 def test_get_random_int(self):
     bitgen = QiskitBitGenerator()
     qrng = Qrng(bitgen)
     cache = "001" * 1000
     bitgen.load_cache(cache)
     assert qrng.get_random_int() == -1
     assert qrng.get_random_int(-4, 4) == -2
Exemple #2
0
 def test_get_random_double(self):
     bitgen = QiskitBitGenerator()
     qrng = Qrng(bitgen)
     cache = "100" * 1000
     bitgen.load_cache(cache)
     assert qrng.get_random_double() == 0.1428571428571428
     assert qrng.get_random_double(-4, 4) == -2.8571428571428577
Exemple #3
0
 def test_get_random_float(self):
     bitgen = QiskitBitGenerator()
     qrng = Qrng(bitgen)
     cache = "100" * 1000
     bitgen.load_cache(cache)
     assert qrng.get_random_float() == 0.14285707473754883
     assert qrng.get_random_float(-4, 4) == -1.7142858505249023
Exemple #4
0
 def test_state(self):
     bitgen = QiskitBitGenerator()
     qrng = Qrng(bitgen)
     cache = "100" * 1000
     bitgen.load_cache(cache)
     job_config = {
         "max_bits_per_request": None,
         "bits_per_request": 1572864,
         "n_qubits": 24,
         "shots": 65536,
         "experiments": 1,
     }
     backend_config = {
         # "backend_name": "qasm_simulator",
         "credits_required": False,
         "local": True,
         "n_qubits": 24,
         "simulator": True,
     }
     bitcache = {
         "size": 3000,
     }
     bitgen_state = qrng.state["quantum_bit_generator"]
     assert bitgen_state["BITS"] == 64
     assert bitgen_state["job_config"] == job_config
     assert bitgen_state["backend_config"] == backend_config
     assert bitgen_state["bitcache"] == bitcache
Exemple #5
0
 def test_get_random_bitstring(self):
     bitgen = QiskitBitGenerator()
     bitgen32 = QiskitBitGenerator(ISRAW32=True)
     qrng = Qrng(bitgen)
     qrng32 = Qrng(bitgen32)
     cache = "100" * 1000
     bitgen.load_cache(cache)
     bitgen32.load_cache(cache)
     assert qrng.get_random_bitstring() == cache[:64]
     assert qrng32.get_random_bitstring() == cache[:32]
     assert qrng.get_random_bitstring(4) == cache[64:68]
Exemple #6
0
 def test_get_random_complex_rect(self):
     bitgen = QiskitBitGenerator()
     qrng = Qrng(bitgen)
     cache = "100" * 1000
     bitgen.load_cache(cache)
     assert (qrng.get_random_complex_rect() == 0.14285707473754883 -
             0.4285714626312256j)
     assert (qrng.get_random_complex_rect(-4, 4) == -2.8571434020996094 +
             0.5714282989501953j)
     assert (qrng.get_random_complex_rect(
         -4, 3, -2, 1) == -2.0000001192092896 - 1.5714287757873535j)
Exemple #7
0
 def test_get_random_complex_polar(self):
     bitgen = QiskitBitGenerator()
     qrng = Qrng(bitgen)
     cache = "100" * 1000
     bitgen.load_cache(cache)
     assert (qrng.get_random_complex_polar() == -0.16820993120165456 +
             0.7369762251347793j)
     assert (qrng.get_random_complex_polar(4) == -1.362136709039319 -
             0.6559701073130655j)
     assert (qrng.get_random_complex_polar(4, 3.14) == 1.926563627649004 +
             0.9272437045189929j)
Exemple #8
0
def test_QiskitBitGenerator():
    provider = IBMQ.load_account()
    bitgen = QiskitBitGenerator(provider)
    assert not bitgen.state["backend_config"]["simulator"]
    simulator = BasicAer.get_backend("qasm_simulator")
    bitgen = QiskitBitGenerator(backend=simulator)
    assert bitgen.state["backend_config"]["simulator"]
    gen = Generator(bitgen)
    cache = "100" * 1000
    assert bitgen.load_cache(cache)
    assert (
        bitgen.random_raw() == 10540996613548315209
        and bitgen.random_bitstring()
        == "0010010010010010010010010010010010010010010010010010010010010010"
        and bitgen.random_uint() == 5270498306774157604
        and bitgen.random_double() == 0.5714285714285714)
    assert (gen.binomial(4, 1 / 4) == 0
            and gen.exponential() == 0.18350170297843915
            and gen.logistic() == 0.28768207245178085 and gen.poisson() == 0
            and gen.standard_normal() == -0.24679872730094507
            and gen.triangular(-1, 0, 1) == 0.07417990022744847)
    assert bitgen.flush_cache()
    bitgen = QiskitBitGenerator(max_bits_per_request=128, ISRAW32=True)
    bitgen.random_raw()
    assert bitgen._fetch_random_bits()
Exemple #9
0
 def test_get_random_int64(self):
     bitgen = QiskitBitGenerator()
     qrng = Qrng(bitgen)
     cache = "100" * 1000
     bitgen.load_cache(cache)
     assert qrng.get_random_int64() == 10540996613548315209
Exemple #10
0
 def test_get_random_int32(self):
     bitgen = QiskitBitGenerator()
     qrng = Qrng(bitgen)
     cache = "100" * 1000
     bitgen.load_cache(cache)
     assert qrng.get_random_int32() == 2454267026