Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR1/? from #774] Upgrade Cirq to >=1.0 #784

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/tutorials/hello_many_worlds.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/qcnn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down
6 changes: 4 additions & 2 deletions docs/tutorials/research_tools.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion release/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci_validate_tutorials.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 9 additions & 17 deletions tensorflow_quantum/core/ops/circuit_execution_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"):
Expand All @@ -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")

Expand All @@ -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")
Expand All @@ -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."):
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_quantum/core/ops/cirq_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions tensorflow_quantum/core/ops/cirq_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion tensorflow_quantum/core/serialize/op_deserializer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_quantum/core/serialize/op_serializer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down