Exemplo n.º 1
0
def test_nqubits_getter_and_setter():
    from qibo.abstractions import abstract_gates
    gate = abstract_gates.Gate()
    gate.target_qubits = (0, 1)
    gate.control_qubits = (2,)
    gate.nqubits = 10
    assert gate.nqubits == 10
    assert gate.nstates == 1024
Exemplo n.º 2
0
def test_qubit_getter_and_setter():
    from qibo.abstractions import abstract_gates
    gate = abstract_gates.Gate()
    gate.target_qubits = (0, 3)
    gate.control_qubits = (1, 4, 2)
    assert gate.qubits == (1, 2, 4, 0, 3)

    gate = abstract_gates.Gate()
    with pytest.raises(ValueError):
        gate.target_qubits = (1, 1)
    gate = abstract_gates.Gate()
    with pytest.raises(ValueError):
        gate.control_qubits = (1, 1)
    gate = abstract_gates.Gate()
    gate.target_qubits = (0, 1)
    with pytest.raises(ValueError):
        gate.control_qubits = (1,)
Exemplo n.º 3
0
def test_nqubits_getter_and_setter_errors():
    from qibo.abstractions import abstract_gates
    gate = abstract_gates.Gate()
    with pytest.raises(ValueError):
        nqubits = gate.nqubits
    with pytest.raises(ValueError):
        nstates = gate.nstates
    gate.nqubits = 4
    with pytest.raises(ValueError):
        gate.nqubits = 5
Exemplo n.º 4
0
def test_density_matrix_getter_and_setter():
    from qibo.abstractions import abstract_gates
    gate = abstract_gates.Gate()
    gate.target_qubits = (0, 1)
    gate.control_qubits = (2,)
    assert gate._active_call == "_state_vector_call"
    gate.density_matrix = True
    assert gate._active_call == "_density_matrix_call"

    gate.nqubits = 4
    gate.is_prepared = True
    with pytest.raises(RuntimeError):
        gate.density_matrix = False