Skip to content
Merged
44 changes: 5 additions & 39 deletions cirq-core/cirq/contrib/quimb/mps_simulator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import cirq
import cirq.contrib.quimb as ccq
import cirq.experiments.google_v2_supremacy_circuit as supremacy_v2
import cirq.testing
from cirq import value

Expand Down Expand Up @@ -353,17 +352,17 @@ def test_state_equal():
assert state1a != state1b


def test_supremacy_equal_more_rows():
circuit = supremacy_v2.generate_boixo_2018_supremacy_circuits_v2_grid(
n_rows=3, n_cols=2, cz_depth=3, seed=0
def test_random_circuits_equal_more_rows():
circuit = cirq.testing.random_circuit(
qubits=cirq.GridQubit.rect(3, 2), n_moments=6, op_density=1.0
)
qubits = circuit.all_qubits()
assert_same_output_as_dense(circuit, qubits)


def test_supremacy_equal_more_cols():
circuit = supremacy_v2.generate_boixo_2018_supremacy_circuits_v2_grid(
n_rows=2, n_cols=3, cz_depth=3, seed=0
circuit = cirq.testing.random_circuit(
qubits=cirq.GridQubit.rect(2, 3), n_moments=6, op_density=1.0
)
qubits = circuit.all_qubits()
assert_same_output_as_dense(circuit, qubits)
Expand All @@ -380,39 +379,6 @@ def test_tensor_index_names():
assert state.mu_str(3, 0) == "mu_0_3"


def test_supremacy_big():
circuit = supremacy_v2.generate_boixo_2018_supremacy_circuits_v2_grid(
n_rows=7, n_cols=7, cz_depth=6, seed=0
)
qubit_order = circuit.all_qubits()
q0 = next(iter(qubit_order))
circuit.append(cirq.measure(q0))

mps_simulator_1 = ccq.mps_simulator.MPSSimulator(
simulation_options=ccq.mps_simulator.MPSOptions(cutoff=5e-5)
)
result_1 = mps_simulator_1.simulate(circuit, qubit_order=qubit_order, initial_state=0)

assert result_1.final_state.estimation_stats() == {
'estimated_fidelity': 0.997,
'memory_bytes': 11008,
'num_coefs_used': 688,
}

mps_simulator_2 = ccq.mps_simulator.MPSSimulator(
simulation_options=ccq.mps_simulator.MPSOptions(
method='isvd', max_bond=1, cutoff_mode='sum2'
)
)
result_2 = mps_simulator_2.simulate(circuit, qubit_order=qubit_order, initial_state=0)

assert result_2.final_state.estimation_stats() == {
'estimated_fidelity': 1.0,
'memory_bytes': 1568,
'num_coefs_used': 98,
}


def test_simulate_moment_steps_sample():
q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit(cirq.H(q0), cirq.CNOT(q0, q1))
Expand Down
22 changes: 21 additions & 1 deletion cirq-core/cirq/experiments/google_v2_supremacy_circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
from typing import Callable, Iterable, TypeVar, cast, Sequence

from cirq.circuits import InsertStrategy
from cirq import circuits, devices, ops
from cirq import _compat, circuits, devices, ops


@_compat.deprecated(
deadline='v0.16',
fix=(
'Install ReCirq and use ' 'recirq.beyond_classical.generate_boixo_2018_beyond_classical_v2'
),
)
def generate_boixo_2018_supremacy_circuits_v2(
qubits: Iterable[devices.GridQubit], cz_depth: int, seed: int
) -> circuits.Circuit:
Expand Down Expand Up @@ -81,6 +87,13 @@ def generate_boixo_2018_supremacy_circuits_v2(
return circuit


@_compat.deprecated(
deadline='v0.16',
fix=(
'Install ReCirq and use '
'recirq.beyond_classical.generate_boixo_2018_beyond_classical_v2_grid'
),
)
def generate_boixo_2018_supremacy_circuits_v2_grid(
n_rows: int, n_cols: int, cz_depth: int, seed: int
) -> circuits.Circuit:
Expand Down Expand Up @@ -183,6 +196,13 @@ def generate_boixo_2018_supremacy_circuits_v2_grid(
)


@_compat.deprecated(
deadline='v0.16',
fix=(
'Install ReCirq and use '
'recirq.beyond_classical.generate_boixo_2018_beyond_classical_v2_bristlecone'
),
)
def generate_boixo_2018_supremacy_circuits_v2_bristlecone(
n_rows: int, cz_depth: int, seed: int
) -> circuits.Circuit:
Expand Down
29 changes: 17 additions & 12 deletions cirq-core/cirq/experiments/google_v2_supremacy_circuit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@

import pytest

import cirq
from cirq import GridQubit
from cirq import ops
import cirq.experiments.google_v2_supremacy_circuit as supremacy_v2


def test_google_v2_supremacy_circuit():
circuit = supremacy_v2.generate_boixo_2018_supremacy_circuits_v2_grid(
n_rows=4, n_cols=5, cz_depth=9, seed=0
)
with cirq.testing.assert_deprecated('_beyond_classical_', deadline='v0.16', count=2):
circuit = supremacy_v2.generate_boixo_2018_supremacy_circuits_v2_grid(
n_rows=4, n_cols=5, cz_depth=9, seed=0
)
# We check that is exactly circuit inst_4x5_10_0
# in github.com/sboixo/GRCS cz_v2
assert len(circuit) == 11
Expand All @@ -47,9 +49,10 @@ def test_google_v2_supremacy_circuit():
def test_google_v2_supremacy_bristlecone():
pytest.importorskip("cirq_google")
# Check instance consistency
c = supremacy_v2.generate_boixo_2018_supremacy_circuits_v2_bristlecone(
n_rows=11, cz_depth=8, seed=0
)
with cirq.testing.assert_deprecated('_beyond_classical_', deadline='v0.16', count=2):
c = supremacy_v2.generate_boixo_2018_supremacy_circuits_v2_bristlecone(
n_rows=11, cz_depth=8, seed=0
)
assert len(c) == 10
assert len(c.all_qubits()) == 70
assert len(list(c.findall_operations_with_gate_type(ops.CZPowGate))) == 119
Expand All @@ -59,9 +62,10 @@ def test_google_v2_supremacy_bristlecone():
assert isinstance(c.operation_at(GridQubit(3, 2), 2).gate, ops.XPowGate)
assert isinstance(c.operation_at(GridQubit(1, 6), 3).gate, ops.XPowGate)
# test smaller subgraph
c = supremacy_v2.generate_boixo_2018_supremacy_circuits_v2_bristlecone(
n_rows=9, cz_depth=8, seed=0
)
with cirq.testing.assert_deprecated('_beyond_classical_', deadline='v0.16', count=2):
c = supremacy_v2.generate_boixo_2018_supremacy_circuits_v2_bristlecone(
n_rows=9, cz_depth=8, seed=0
)
qubits = list(c.all_qubits())
qubits.sort()
assert len(qubits) == 48
Expand All @@ -74,6 +78,7 @@ def test_google_v2_supremacy_bristlecone():
def test_n_rows_less_than_2():
pytest.importorskip("cirq_google")
with pytest.raises(AssertionError):
supremacy_v2.generate_boixo_2018_supremacy_circuits_v2_bristlecone(
n_rows=1, cz_depth=0, seed=0
)
with cirq.testing.assert_deprecated('_beyond_classical_', deadline='v0.16'):
supremacy_v2.generate_boixo_2018_supremacy_circuits_v2_bristlecone(
n_rows=1, cz_depth=0, seed=0
)