コード例 #1
0
def test_measurementresult_outcome(backend):
    import collections
    result = measurements.MeasurementResult((0, ))
    result.decimal = K.zeros(1, dtype='DTYPEINT')
    assert result.outcome() == 0
    result.decimal = K.ones(1, dtype='DTYPEINT')
    assert result.outcome() == 1
コード例 #2
0
ファイル: test_core_callbacks.py プロジェクト: mlazzarin/qibo
def test_entropy_product_state(backend):
    """Check that the |++> state has zero entropy."""
    entropy = callbacks.EntanglementEntropy()
    state = K.ones(4) / 2.0

    result = entropy(state)
    K.assert_allclose(result, 0, atol=_atol)
コード例 #3
0
 def plus_state(cls, circuit):
     """Creates ``|++...+>`` as a distributed state."""
     state = cls(circuit)
     with K.on_cpu():
         n = K.cast(2**state.nlocal, dtype=K.dtypes('DTYPEINT'))
         norm = K.cast(2**float(state.nqubits / 2.0))
         state.pieces = [
             K.cpu_tensor(K.ones(n) / norm) for _ in range(state.ndevices)
         ]
     return state
コード例 #4
0
ファイル: hamiltonians.py プロジェクト: rickyHong/qibo
 def ground_state():
     n = K.cast(2**nqubits, dtype='DTYPEINT')
     state = K.ones(n, dtype='DTYPECPX')
     return state / K.sqrt(K.cast(n, dtype=state.dtype))
コード例 #5
0
 def ground_state():
     n = K.cast(2**nqubits, dtype=DTYPES.get('DTYPEINT'))
     state = K.ones(n, dtype=DTYPES.get('DTYPECPX'))
     return state / K.math.sqrt(K.cast(n, dtype=state.dtype))
コード例 #6
0
 def plus_state(cls, nqubits):
     state = cls(nqubits)
     shape = K.cast((state.nstates, ), dtype='DTYPEINT')
     state.tensor = K.ones(shape) / K.cast(K.qnp.sqrt(state.nstates))
     return state