Beispiel #1
0
def test_sample_heavy_set_with_parity():
    """Test that we correctly sample a circuit's heavy set with a parity map"""

    sampler = Mock(spec=cirq.Simulator)
    # Construct a result that returns [1, 0, 1, 0] for the physical qubit
    # measurement, and [0, 1, 1, 0] for the ancilla qubit measurement. The first
    # bitstring "10" is valid and heavy. The second "01" is valid and not
    # heavy. The third and fourth bitstraings "11" and "00" are not valid and
    # dropped.
    result = cirq.TrialResult.from_single_parameter_set(
        params=cirq.ParamResolver({}),
        measurements={
            '0': np.array([[1], [0]]),
            '1': np.array([[0], [1]]),
            '2': np.array([[1], [1]]),
            '3': np.array([[0], [0]])
        })
    sampler.run = MagicMock(return_value=result)
    circuit = cirq.Circuit(cirq.measure(*cirq.LineQubit.range(4)))
    compilation_result = CompilationResult(
        circuit=circuit,
        mapping={q: q
                 for q in cirq.LineQubit.range(4)},
        parity_map={
            cirq.LineQubit(0): cirq.LineQubit(1),
            cirq.LineQubit(2): cirq.LineQubit(3)
        })
    probability = cirq.contrib.quantum_volume.sample_heavy_set(
        compilation_result, [1], sampler=sampler, repetitions=1)
    # The first output is in the heavy set. The second one isn't, but it is
    # dropped.
    assert probability == .5
Beispiel #2
0
def test_sample_heavy_set():
    """Test that we correctly sample a circuit's heavy set"""

    sampler = Mock(spec=cirq.Simulator)
    # Construct a result that returns "1", "2", "3", "0"
    result = cirq.TrialResult.from_single_parameter_set(
        params=cirq.ParamResolver({}),
        measurements={'mock': np.array([[0, 1], [1, 0], [1, 1], [0, 0]])})
    sampler.run = MagicMock(return_value=result)
    circuit = cirq.Circuit(cirq.measure(*cirq.LineQubit.range(2)))
    compilation_result = CompilationResult(circuit=circuit,
                                           mapping={},
                                           parity_map={})
    probability = cirq.contrib.quantum_volume.sample_heavy_set(
        compilation_result, [1, 2, 3], sampler=sampler, repetitions=10)
    # The first 3 of our outputs are in the heavy set, and then the rest are
    # not.
    assert probability == .75