Ejemplo n.º 1
0
def test_estimate_run_batch_time_average_depths():
    qubits = cirq.GridQubit.rect(4, 5)
    circuit_depth_20 = cirq.testing.random_circuit(qubits,
                                                   n_moments=20,
                                                   op_density=1.0)
    circuit_depth_30 = cirq.testing.random_circuit(qubits,
                                                   n_moments=30,
                                                   op_density=1.0)
    circuit_depth_40 = cirq.testing.random_circuit(qubits,
                                                   n_moments=40,
                                                   op_density=1.0)
    sweeps_10 = cirq.Linspace('t', 0, 1, 10)
    sweeps_20 = cirq.Linspace('t', 0, 1, 20)

    depth_20_and_40 = runtime_estimator.estimate_run_batch_time(
        [circuit_depth_20, circuit_depth_40], [sweeps_10, sweeps_10],
        repetitions=1000)
    depth_30 = runtime_estimator.estimate_run_sweep_time(circuit_depth_30,
                                                         sweeps_20,
                                                         repetitions=1000)
    depth_40 = runtime_estimator.estimate_run_sweep_time(circuit_depth_40,
                                                         sweeps_20,
                                                         repetitions=1000)
    assert depth_20_and_40 == depth_30
    assert depth_20_and_40 < depth_40
Ejemplo n.º 2
0
def test_estimate_run_batch_time():
    qubits = cirq.GridQubit.rect(4, 5)
    circuit = cirq.testing.random_circuit(qubits[:19], n_moments=40, op_density=1.0)
    circuit2 = cirq.testing.random_circuit(qubits[:19], n_moments=40, op_density=1.0)
    circuit3 = cirq.testing.random_circuit(qubits, n_moments=40, op_density=1.0)
    sweeps_10 = cirq.Linspace('t', 0, 1, 10)
    sweeps_20 = cirq.Linspace('t', 0, 1, 20)
    sweeps_30 = cirq.Linspace('t', 0, 1, 30)
    sweeps_40 = cirq.Linspace('t', 0, 1, 40)

    # 2 batches with same qubits is the same time as a combined sweep
    sweep_runtime = runtime_estimator.estimate_run_sweep_time(circuit, sweeps_30, repetitions=1000)
    batch_runtime = runtime_estimator.estimate_run_batch_time(
        [circuit, circuit2], [sweeps_10, sweeps_20], repetitions=1000
    )
    assert sweep_runtime == batch_runtime

    # 2 batches with same qubits and 1 batch with different qubits
    # Should be equal to combining the first two batches
    three_batches = runtime_estimator.estimate_run_batch_time(
        [circuit, circuit2, circuit3], [sweeps_10, sweeps_20, sweeps_10], repetitions=1000
    )
    two_batches = runtime_estimator.estimate_run_batch_time(
        [circuit, circuit3], [sweeps_30, sweeps_10], repetitions=1000
    )
    assert three_batches == two_batches
    # The last batch cannot be combined since it has different qubits
    sweep_runtime = runtime_estimator.estimate_run_sweep_time(circuit, sweeps_40, repetitions=1000)
    assert three_batches > sweep_runtime
Ejemplo n.º 3
0
def test_estimate_run_sweep_time(depth, width, sweeps, reps, expected):
    """Test various run times.
    Values taken from Weber November 2021."""
    qubits = cirq.GridQubit.rect(8, 8)
    circuit = cirq.testing.random_circuit(qubits[:depth], n_moments=width, op_density=1.0)
    params = cirq.Linspace('t', 0, 1, sweeps)
    runtime = runtime_estimator.estimate_run_sweep_time(circuit, params, repetitions=reps)
    _assert_about_equal(runtime, expected)
Ejemplo n.º 4
0
def test_many_qubits(num_qubits: int) -> None:
    """Regression test

    Make sure that high numbers of qubits do not
    slow the rep rate down to below zero.
    """
    qubits = cirq.LineQubit.range(num_qubits)
    sweeps_10 = cirq.Linspace('t', 0, 1, 10)
    circuit = cirq.Circuit(*[cirq.X(q)**sympy.Symbol('t') for q in qubits],
                           cirq.measure(*qubits))
    sweep_runtime = runtime_estimator.estimate_run_sweep_time(
        circuit, sweeps_10, repetitions=10000)
    assert sweep_runtime > 0