How to use blueqat - 10 common examples

To help you get started, we’ve selected a few blueqat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Blueqat / Blueqat / tests / test_circuit.py View on Github external
def test_copy_empty_numba():
    c = Circuit()
    c.run(backend='numba')
    # copy_history: deprecated.
    cc = c.copy(copy_backends=True)
    assert c.ops == cc.ops and c.ops is not cc.ops
    assert c._backends['numba'].cache is None and cc._backends['numba'].cache is None
    assert c._backends['numba'].cache_idx == cc._backends['numba'].cache_idx == -1
github Blueqat / Blueqat / tests / test_circuit.py View on Github external
def test_u3_gate(backend):
    assert is_vec_same(Circuit().u3(1.23, 4.56, -5.43)[1].run(backend=backend),
                       Circuit().rz(-5.43)[1].ry(1.23)[1].rz(4.56)[1].run(backend=backend))
github Blueqat / Blueqat / tests / test_sympy.py View on Github external
def test_sympy_cx_cz():
    assert Circuit().cx[1, 2].run(backend="sympy_unitary") == Circuit().h[2].cz[2, 1].h[2].run(backend="sympy_unitary")
    assert Circuit().cx[2, 1].run(backend="sympy_unitary") == Circuit().h[1].cz[2, 1].h[1].run(backend="sympy_unitary")
github Blueqat / Blueqat / tests / test_circuit.py View on Github external
def test_measurement1(backend):
    c = Circuit().m[0]
    cnt = c.run(backend=backend, shots=10000)
    assert cnt.most_common(1) == [("0", 10000)]
github Blueqat / Blueqat / tests / test_toqasm.py View on Github external
def test_qasm_noprologue():
    correct_qasm = "x q[0];\ny q[0];\nz q[0];"
    c = Circuit().x[0].y[0].z[0]
    qasm = c.to_qasm(output_prologue=False)
    assert qasm == correct_qasm
github Blueqat / Blueqat / tests / test_circuit.py View on Github external
def test_concat_circuit3(backend):
    c1 = Circuit()
    c1.x[0]
    c2 = Circuit()
    c2.h[0]
    c1 += c2
    assert is_vec_same(c1.run(backend=backend), Circuit().x[0].h[0].run(backend=backend))
    c1 = Circuit()
    c1.h[0]
    c2 = Circuit()
    c2.x[0]
    c1 += c2
    assert is_vec_same(c1.run(backend=backend), Circuit().h[0].x[0].run(backend=backend))
github Blueqat / Blueqat / tests / test_circuit.py View on Github external
def test_measurement_after_qubits1(backend):
    for _ in range(50):
        c = Circuit().h[0].m[0]
        a, cnt = c.run(backend=backend, shots=1, returns="statevector_and_shots")
        if cnt.most_common(1)[0] == ('0', 1):
            assert is_vec_same(a, np.array([1, 0]))
        else:
            assert is_vec_same(a, np.array([0, 1]))
github Blueqat / Blueqat / tests / test_sympy.py View on Github external
def test_u2():
    phi, lambd = symbols("phi lambd")

    actual_1 = Circuit().u2(phi, lambd)[0].run(backend="sympy_unitary")
    expected_1 = Circuit().rz(lambd)[0].ry(pi / 2)[0].rz(phi)[0].run_with_sympy_unitary()
    assert simplify(actual_1 - expected_1) == zeros(2)
github Blueqat / Blueqat / tests / test_sympy.py View on Github external
def test_cu1():
    E = eye(2)
    UPPER = Matrix([[1, 0], [0, 0]])
    LOWER = Matrix([[0, 0], [0, 1]])
    lambd = symbols("lambd")
    U = Circuit().rz(lambd)[0].run_with_sympy_unitary()
    U /= U[0, 0]

    actual_1 = Circuit().cu1(lambd)[0, 1].run(backend="sympy_unitary")
    actual_1 /= actual_1[0, 0]
    expected_1 = reduce(TensorProduct, [UPPER, E]) + reduce(TensorProduct, [LOWER, U])
    assert simplify(actual_1 - expected_1) == zeros(4)
github Blueqat / Blueqat / tests / test_circuit.py View on Github external
def test_concat_circuit2(backend):
    c1 = Circuit()
    c1.h[1]
    c1.run()
    c2 = Circuit()
    c2.h[0]
    c2.run()
    c1 += c2
    assert is_vec_same(c1.run(backend=backend), Circuit().h[1].h[0].run(backend=backend))