diff --git a/docs/tutorials/hello_many_worlds.ipynb b/docs/tutorials/hello_many_worlds.ipynb index 229136219..801d388de 100644 --- a/docs/tutorials/hello_many_worlds.ipynb +++ b/docs/tutorials/hello_many_worlds.ipynb @@ -255,7 +255,7 @@ "# Create a circuit on these qubits using the parameters you created above.\n", "circuit = cirq.Circuit(\n", " cirq.rx(a).on(q0),\n", - " cirq.ry(b).on(q1), cirq.CNOT(control=q0, target=q1))\n", + " cirq.ry(b).on(q1), cirq.CNOT(q0, q1))\n", "\n", "SVGCircuit(circuit)" ] diff --git a/docs/tutorials/qcnn.ipynb b/docs/tutorials/qcnn.ipynb index f53182701..abbb8c560 100644 --- a/docs/tutorials/qcnn.ipynb +++ b/docs/tutorials/qcnn.ipynb @@ -554,7 +554,7 @@ " source_basis_selector = one_qubit_unitary(source_qubit, symbols[3:6])\n", " pool_circuit.append(sink_basis_selector)\n", " pool_circuit.append(source_basis_selector)\n", - " pool_circuit.append(cirq.CNOT(control=source_qubit, target=sink_qubit))\n", + " pool_circuit.append(cirq.CNOT(source_qubit, sink_qubit))\n", " pool_circuit.append(sink_basis_selector**-1)\n", " return pool_circuit" ] diff --git a/docs/tutorials/research_tools.ipynb b/docs/tutorials/research_tools.ipynb index 538fcf46c..e7538ae75 100644 --- a/docs/tutorials/research_tools.ipynb +++ b/docs/tutorials/research_tools.ipynb @@ -83,7 +83,8 @@ }, "outputs": [], "source": [ - "!pip install tensorflow==2.7.0 tensorflow-quantum==0.7.2 tensorboard_plugin_profile==2.4.0" + "!pip install tensorflow==2.7.0 tensorflow-quantum==0.7.2 tensorboard_plugin_profile==2.4.0\n", + "!pip install --quiet git+https://github.com/quantumlib/ReCirq" ] }, { @@ -124,6 +125,7 @@ "import datetime\n", "import time\n", "import cirq\n", + "from recirq import beyond_classical\n", "import tensorflow as tf\n", "import tensorflow_quantum as tfq\n", "from tensorflow.keras import layers\n", @@ -155,7 +157,7 @@ "source": [ "def generate_circuit(qubits):\n", " \"\"\"Generate a random circuit on qubits.\"\"\"\n", - " random_circuit = cirq.generate_boixo_2018_supremacy_circuits_v2(\n", + " random_circuit = beyond_classical.generate_boixo_2018_beyond_classical_v2(\n", " qubits, cz_depth=2, seed=1234)\n", " return random_circuit\n", "\n", diff --git a/release/setup.py b/release/setup.py index 24424b613..766e29920 100644 --- a/release/setup.py +++ b/release/setup.py @@ -51,7 +51,7 @@ def finalize_options(self): REQUIRED_PACKAGES = [ - 'cirq-core==0.13.1', 'cirq-google>=0.13.1', 'sympy == 1.8', + 'cirq-core~=1.0', 'cirq-google~=1.0', 'sympy == 1.8', 'googleapis-common-protos==1.52.0', 'google-api-core==1.21.0', 'google-auth==1.18.0', 'protobuf==3.19.4' ] diff --git a/requirements.txt b/requirements.txt index ae8700878..c1abca840 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -cirq-core==0.13.1 -cirq-google==0.13.1 +cirq-core~=1.0 +cirq-google~=1.0 sympy==1.8 numpy==1.24.2 # TensorFlow can detect if it was built against other versions. nbformat==4.4.0 diff --git a/scripts/ci_validate_tutorials.sh b/scripts/ci_validate_tutorials.sh index e58355faf..e4375bdf0 100755 --- a/scripts/ci_validate_tutorials.sh +++ b/scripts/ci_validate_tutorials.sh @@ -24,6 +24,8 @@ pip install gym==0.24.1 pip install seaborn==0.12.0 # tf_docs pip package needed for noise tutorial. pip install -q git+https://github.com/tensorflow/docs +# ReCirq pip package needed for research tools. +pip install --quiet git+https://github.com/quantumlib/ReCirq # Leave the quantum directory, otherwise errors may occur cd .. examples_output=$(python3 quantum/scripts/test_tutorials.py) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops_test.py b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py index f94297cdc..f8948bfa3 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops_test.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py @@ -27,6 +27,7 @@ from scipy import stats import cirq import cirq_google +from cirq_google.engine.abstract_processor import AbstractProcessor from tensorflow_quantum.core.ops import batch_util, circuit_execution_ops from tensorflow_quantum.python import util @@ -97,11 +98,9 @@ def test_get_expectation_inputs(self): circuit_execution_ops.get_expectation_op() with self.assertRaisesRegex(NotImplementedError, expected_regex='Sample-based'): - mock_engine = mock.Mock() + mock_processor = mock.create_autospec(AbstractProcessor) circuit_execution_ops.get_expectation_op( - cirq_google.QuantumEngineSampler(engine=mock_engine, - processor_id='test', - gate_set=cirq_google.XMON)) + cirq_google.ProcessorSampler(processor=mock_processor)) with self.assertRaisesRegex( TypeError, expected_regex="cirq.sim.simulator.SimulatesExpectationValues"): @@ -118,11 +117,9 @@ def test_get_sampled_expectation_inputs(self): backend=cirq.Simulator()) circuit_execution_ops.get_sampled_expectation_op( backend=cirq.DensityMatrixSimulator()) - mock_engine = mock.Mock() + mock_processor = mock.create_autospec(AbstractProcessor) circuit_execution_ops.get_sampled_expectation_op( - cirq_google.QuantumEngineSampler(engine=mock_engine, - processor_id='test', - gate_set=cirq_google.XMON)) + cirq_google.ProcessorSampler(processor=mock_processor)) with self.assertRaisesRegex(TypeError, expected_regex="a Cirq.Sampler"): circuit_execution_ops.get_sampled_expectation_op(backend="junk") @@ -137,11 +134,9 @@ def test_get_samples_inputs(self): circuit_execution_ops.get_sampling_op(backend=cirq.Simulator()) circuit_execution_ops.get_sampling_op( backend=cirq.DensityMatrixSimulator()) - mock_engine = mock.Mock() + mock_processor = mock.create_autospec(AbstractProcessor) circuit_execution_ops.get_sampling_op( - backend=cirq_google.QuantumEngineSampler(engine=mock_engine, - processor_id='test', - gate_set=cirq_google.XMON)) + backend=cirq_google.ProcessorSampler(processor=mock_processor)) with self.assertRaisesRegex(TypeError, expected_regex="Expected a Cirq.Sampler"): circuit_execution_ops.get_sampling_op(backend="junk") @@ -161,12 +156,9 @@ def test_get_state_inputs(self): circuit_execution_ops.get_state_op(backend="junk") with self.assertRaisesRegex(TypeError, expected_regex="Cirq.SimulatesFinalState"): - mock_engine = mock.Mock() + mock_processor = mock.create_autospec(AbstractProcessor) circuit_execution_ops.get_state_op( - backend=cirq_google.QuantumEngineSampler( - engine=mock_engine, - processor_id='test', - gate_set=cirq_google.XMON)) + backend=cirq_google.ProcessorSampler(processor=mock_processor)) with self.assertRaisesRegex(TypeError, expected_regex="must be type bool."): diff --git a/tensorflow_quantum/core/ops/cirq_ops.py b/tensorflow_quantum/core/ops/cirq_ops.py index 2650e812b..884fe98d2 100644 --- a/tensorflow_quantum/core/ops/cirq_ops.py +++ b/tensorflow_quantum/core/ops/cirq_ops.py @@ -491,7 +491,7 @@ def _no_grad(grad): ] max_n_qubits = max(len(p.all_qubits()) for p in programs) - if isinstance(sampler, cirq_google.QuantumEngineSampler): + if isinstance(sampler, cirq_google.ProcessorSampler): # group samples from identical circuits to reduce communication # overhead. Have to keep track of the order in which things came # in to make sure the output is ordered correctly diff --git a/tensorflow_quantum/core/ops/cirq_ops_test.py b/tensorflow_quantum/core/ops/cirq_ops_test.py index 1b54771a9..55f0eeb8c 100644 --- a/tensorflow_quantum/core/ops/cirq_ops_test.py +++ b/tensorflow_quantum/core/ops/cirq_ops_test.py @@ -16,6 +16,7 @@ # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position import sys + NEW_PATH = [x for x in sys.path if 'com_google_protobuf' not in x] sys.path = NEW_PATH # pylint: enable=wrong-import-position @@ -26,6 +27,7 @@ from absl.testing import parameterized import cirq import cirq_google +from cirq_google.engine.abstract_processor import AbstractProcessor from tensorflow_quantum.core.ops import cirq_ops from tensorflow_quantum.core.serialize import serializer @@ -348,11 +350,9 @@ def test_get_cirq_sampling_op(self): cirq_ops._get_cirq_samples() cirq_ops._get_cirq_samples(cirq.Simulator()) cirq_ops._get_cirq_samples(cirq.DensityMatrixSimulator()) - mock_engine = mock.Mock() + mock_processor = mock.create_autospec(AbstractProcessor) cirq_ops._get_cirq_samples( - cirq_google.QuantumEngineSampler(engine=mock_engine, - processor_id='test', - gate_set=cirq_google.XMON)) + cirq_google.ProcessorSampler(processor=mock_processor)) def test_cirq_sampling_op_inputs(self): """test input checking in the cirq sampling op.""" @@ -451,7 +451,9 @@ class DummySampler(cirq.Sampler): def run_sweep(self, program, params, repetitions): """Returns all ones in the correct sample shape.""" return [ - cirq.Result( + cirq_google.EngineResult( + job_id="1", + job_finished_time="1", params=param, measurements={ 'tfq': diff --git a/tensorflow_quantum/core/serialize/op_deserializer_test.py b/tensorflow_quantum/core/serialize/op_deserializer_test.py index ce1748b65..e9762bd5c 100644 --- a/tensorflow_quantum/core/serialize/op_deserializer_test.py +++ b/tensorflow_quantum/core/serialize/op_deserializer_test.py @@ -38,7 +38,7 @@ def op_proto(json_dict): @cirq.value_equality -class GateWithAttribute(cirq.SingleQubitGate): +class GateWithAttribute(cirq.testing.SingleQubitGate): """GateAttribute helper class.""" def __init__(self, val, not_req=None): diff --git a/tensorflow_quantum/core/serialize/op_serializer_test.py b/tensorflow_quantum/core/serialize/op_serializer_test.py index a485091e7..ea3e11d73 100644 --- a/tensorflow_quantum/core/serialize/op_serializer_test.py +++ b/tensorflow_quantum/core/serialize/op_serializer_test.py @@ -38,14 +38,14 @@ def op_proto(json): return op -class GateWithAttribute(cirq.SingleQubitGate): +class GateWithAttribute(cirq.testing.SingleQubitGate): """GateAttribute helper class.""" def __init__(self, val): self.val = val -class GateWithProperty(cirq.SingleQubitGate): +class GateWithProperty(cirq.testing.SingleQubitGate): """GateProperty helper class.""" def __init__(self, val, not_req=None): @@ -58,7 +58,7 @@ def val(self): return self._val -class GateWithMethod(cirq.SingleQubitGate): +class GateWithMethod(cirq.testing.SingleQubitGate): """GateMethod helper class.""" def __init__(self, val): diff --git a/tensorflow_quantum/python/optimizers/rotosolve_minimizer_test.py b/tensorflow_quantum/python/optimizers/rotosolve_minimizer_test.py index 1d3a2965f..b7d8a454e 100755 --- a/tensorflow_quantum/python/optimizers/rotosolve_minimizer_test.py +++ b/tensorflow_quantum/python/optimizers/rotosolve_minimizer_test.py @@ -145,7 +145,7 @@ def convert_to_circuit(input_data): a, b = sympy.symbols('a b') # parameters for the circuit circuit = cirq.Circuit( cirq.rx(a).on(q0), - cirq.ry(b).on(q1), cirq.CNOT(control=q0, target=q1)) + cirq.ry(b).on(q1), cirq.CNOT(q0, q1)) # Build the Keras model. model = tf.keras.Sequential([ diff --git a/tensorflow_quantum/python/optimizers/spsa_minimizer_test.py b/tensorflow_quantum/python/optimizers/spsa_minimizer_test.py index 1de86d86c..a71f25101 100644 --- a/tensorflow_quantum/python/optimizers/spsa_minimizer_test.py +++ b/tensorflow_quantum/python/optimizers/spsa_minimizer_test.py @@ -248,7 +248,7 @@ def convert_to_circuit(input_data): a, b = sympy.symbols('a b') # parameters for the circuit circuit = cirq.Circuit( cirq.rx(a).on(q0), - cirq.ry(b).on(q1), cirq.CNOT(control=q0, target=q1)) + cirq.ry(b).on(q1), cirq.CNOT(q0, q1)) # Build the Keras model. model = tf.keras.Sequential([