コード例 #1
0
def test_qubit_management_error():
    eng = MainEngine(backend=DummyEngine(), engine_list=[DummyEngine()])
    with _compute.Compute(eng):
        ancilla = eng.allocate_qubit()
    eng.active_qubits = weakref.WeakSet()
    with pytest.raises(_compute.QubitManagementError):
        _compute.Uncompute(eng)
コード例 #2
0
ファイル: _ionq_test.py プロジェクト: Takishima/ProjectQ
def test_ionq_no_midcircuit_measurement(monkeypatch, mapper_factory):
    """Test that attempts to measure mid-circuit raise exceptions."""
    def mock_send(*args, **kwargs):
        return {
            'nq': 1,
            'shots': 10,
            'output_probs': {
                '0': 0.4,
                '1': 0.6
            },
        }

    monkeypatch.setattr(_ionq_http_client, "send", mock_send)

    # Create a backend to use with an engine.
    backend = _ionq.IonQBackend(verbose=True, num_runs=10)
    eng = MainEngine(
        backend=backend,
        engine_list=[mapper_factory()],
        verbose=True,
    )
    qubit = eng.allocate_qubit()
    X | qubit
    Measure | qubit
    with pytest.raises(MidCircuitMeasurementError):
        X | qubit

    # atexit sends another FlushGate, therefore we remove the backend:
    dummy = DummyEngine()
    dummy.is_last_engine = True
    eng.active_qubits = []
    eng.next_engine = dummy