Example #1
0
def test_compute_heavy_set():
    """Test that the heavy set can be computed from a given circuit."""
    a, b, c = cirq.LineQubit.range(3)
    model_circuit = cirq.Circuit([
        cirq.Moment([]),
        cirq.Moment([cirq.X(a), cirq.Y(b)]),
        cirq.Moment([]),
        cirq.Moment([cirq.CNOT(a, c)]),
        cirq.Moment([cirq.Z(a), cirq.H(b)])
    ])
    assert quantum_volume.compute_heavy_set(model_circuit) == [5, 7]
Example #2
0
def test_calculate_quantum_volume_result():
    """Test that running the main loop returns the desired result"""
    results = quantum_volume.calculate_quantum_volume(
        num_qubits=3,
        depth=3,
        num_repetitions=1,
        device=cirq.google.Bristlecone,
        samplers=[cirq.Simulator()],
        seed=1)

    model_circuit = quantum_volume.generate_model_circuit(
        3, 3, random_state=np.random.RandomState(1))
    assert len(results) == 1
    assert results[0].model_circuit == model_circuit
    assert results[0].heavy_set == quantum_volume.compute_heavy_set(
        model_circuit)
    assert len(results[0].sampler_result) == 1
    # Ensure that calling to_json on the results does not err.
    buffer = io.StringIO()
    cirq.to_json(results, buffer)