Skip to content

Commit 534f65d

Browse files
Pulled out Cirq proto dependency. (#590)
* Pulled out Cirq proto dependency. * format. * remove cirq from WORKSPACE.
1 parent 859ba3a commit 534f65d

40 files changed

+2627
-350
lines changed

WORKSPACE

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ http_archive(
5858
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"],
5959
)
6060

61-
http_archive(
62-
name = "cirq",
63-
sha256 = "9241bd0a31bfe294f76071884fcb053c63abf2b5d311e7b7f0f4e20537cc7c43",
64-
strip_prefix = "Cirq-0.11.0/cirq-google",
65-
urls = ["https://github.com/quantumlib/Cirq/archive/v0.11.0.zip"],
66-
)
67-
6861
http_archive(
6962
name = "qsim",
7063
sha256 = "d39b9c48866ce4d6a095093ae8059444d649e851219497af99e937a74f1e9a45",

tensorflow_quantum/core/ops/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ py_library(
461461
srcs_version = "PY3",
462462
deps = [
463463
":batch_util",
464+
"//tensorflow_quantum/core/proto:program_py_proto",
465+
"//tensorflow_quantum/core/proto:pauli_sum_py_proto",
464466
"//tensorflow_quantum/core/serialize:serializer",
465467
],
466468
)

tensorflow_quantum/core/ops/cirq_ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from tensorflow_quantum.core.ops import batch_util
2424
from tensorflow_quantum.core.proto import pauli_sum_pb2
25+
from tensorflow_quantum.core.proto import program_pb2
2526
from tensorflow_quantum.core.serialize import serializer
2627

2728

@@ -108,7 +109,7 @@ def _batch_deserialize_helper(programs, symbol_names, symbol_values):
108109
program = program.numpy()
109110
values = values.numpy().astype(float)
110111

111-
circuit_proto = cirq.google.api.v2.program_pb2.Program()
112+
circuit_proto = program_pb2.Program()
112113
circuit_proto.ParseFromString(program)
113114

114115
circuit = serializer.deserialize_circuit(circuit_proto)

tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ limitations under the License.
2121
#include "../qsim/lib/gates_cirq.h"
2222
#include "../qsim/lib/seqfor.h"
2323
#include "../qsim/lib/simmux.h"
24-
#include "cirq_google/api/v2/program.pb.h"
2524
#include "tensorflow/core/framework/op_kernel.h"
2625
#include "tensorflow/core/framework/shape_inference.h"
2726
#include "tensorflow/core/framework/tensor_shape.h"
@@ -30,13 +29,14 @@ limitations under the License.
3029
#include "tensorflow/core/lib/core/threadpool.h"
3130
#include "tensorflow/core/platform/mutex.h"
3231
#include "tensorflow_quantum/core/ops/parse_context.h"
32+
#include "tensorflow_quantum/core/proto/program.pb.h"
3333
#include "tensorflow_quantum/core/src/util_qsim.h"
3434

3535
namespace tfq {
3636

37-
using ::cirq::google::api::v2::Program;
3837
using ::tensorflow::Status;
3938
using ::tfq::proto::PauliSum;
39+
using ::tfq::proto::Program;
4040

4141
typedef qsim::Cirq::GateCirq<float> QsimGate;
4242
typedef qsim::Circuit<QsimGate> QsimCircuit;

tensorflow_quantum/core/ops/math_ops/tfq_inner_product_grad.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ limitations under the License.
2121
#include "../qsim/lib/gates_cirq.h"
2222
#include "../qsim/lib/seqfor.h"
2323
#include "../qsim/lib/simmux.h"
24-
#include "cirq_google/api/v2/program.pb.h"
2524
#include "tensorflow/core/framework/op_kernel.h"
2625
#include "tensorflow/core/framework/shape_inference.h"
2726
#include "tensorflow/core/framework/tensor_shape.h"
@@ -30,14 +29,15 @@ limitations under the License.
3029
#include "tensorflow/core/lib/core/threadpool.h"
3130
#include "tensorflow/core/platform/mutex.h"
3231
#include "tensorflow_quantum/core/ops/parse_context.h"
32+
#include "tensorflow_quantum/core/proto/program.pb.h"
3333
#include "tensorflow_quantum/core/src/adj_util.h"
3434
#include "tensorflow_quantum/core/src/util_qsim.h"
3535

3636
namespace tfq {
3737

38-
using ::cirq::google::api::v2::Program;
3938
using ::tensorflow::Status;
4039
using ::tfq::proto::PauliSum;
40+
using ::tfq::proto::Program;
4141

4242
typedef qsim::Cirq::GateCirq<float> QsimGate;
4343
typedef qsim::Circuit<QsimGate> QsimCircuit;

tensorflow_quantum/core/ops/noise/tfq_noisy_expectation.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ limitations under the License.
2828
#include "../qsim/lib/qtrajectory.h"
2929
#include "../qsim/lib/seqfor.h"
3030
#include "../qsim/lib/simmux.h"
31-
#include "cirq_google/api/v2/program.pb.h"
3231
#include "tensorflow/core/framework/op_kernel.h"
3332
#include "tensorflow/core/framework/shape_inference.h"
3433
#include "tensorflow/core/framework/tensor_shape.h"
@@ -41,13 +40,14 @@ limitations under the License.
4140
#include "tensorflow/core/util/guarded_philox_random.h"
4241
#include "tensorflow_quantum/core/ops/parse_context.h"
4342
#include "tensorflow_quantum/core/proto/pauli_sum.pb.h"
43+
#include "tensorflow_quantum/core/proto/program.pb.h"
4444
#include "tensorflow_quantum/core/src/util_qsim.h"
4545

4646
namespace tfq {
4747

48-
using ::cirq::google::api::v2::Program;
4948
using ::tensorflow::Status;
5049
using ::tfq::proto::PauliSum;
50+
using ::tfq::proto::Program;
5151

5252
typedef qsim::Cirq::GateCirq<float> QsimGate;
5353
typedef qsim::Circuit<QsimGate> QsimCircuit;

tensorflow_quantum/core/ops/noise/tfq_noisy_sampled_expectation.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ limitations under the License.
2828
#include "../qsim/lib/qtrajectory.h"
2929
#include "../qsim/lib/seqfor.h"
3030
#include "../qsim/lib/simmux.h"
31-
#include "cirq_google/api/v2/program.pb.h"
3231
#include "tensorflow/core/framework/op_kernel.h"
3332
#include "tensorflow/core/framework/shape_inference.h"
3433
#include "tensorflow/core/framework/tensor_shape.h"
@@ -41,13 +40,14 @@ limitations under the License.
4140
#include "tensorflow/core/util/guarded_philox_random.h"
4241
#include "tensorflow_quantum/core/ops/parse_context.h"
4342
#include "tensorflow_quantum/core/proto/pauli_sum.pb.h"
43+
#include "tensorflow_quantum/core/proto/program.pb.h"
4444
#include "tensorflow_quantum/core/src/util_qsim.h"
4545

4646
namespace tfq {
4747

48-
using ::cirq::google::api::v2::Program;
4948
using ::tensorflow::Status;
5049
using ::tfq::proto::PauliSum;
50+
using ::tfq::proto::Program;
5151

5252
typedef qsim::Cirq::GateCirq<float> QsimGate;
5353
typedef qsim::Circuit<QsimGate> QsimCircuit;

tensorflow_quantum/core/ops/noise/tfq_noisy_samples.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ limitations under the License.
2828
#include "../qsim/lib/qtrajectory.h"
2929
#include "../qsim/lib/seqfor.h"
3030
#include "../qsim/lib/simmux.h"
31-
#include "cirq_google/api/v2/program.pb.h"
3231
#include "tensorflow/core/framework/op_kernel.h"
3332
#include "tensorflow/core/framework/shape_inference.h"
3433
#include "tensorflow/core/framework/tensor_shape.h"
@@ -39,13 +38,14 @@ limitations under the License.
3938
#include "tensorflow/core/lib/random/simple_philox.h"
4039
#include "tensorflow/core/util/guarded_philox_random.h"
4140
#include "tensorflow_quantum/core/ops/parse_context.h"
41+
#include "tensorflow_quantum/core/proto/program.pb.h"
4242
#include "tensorflow_quantum/core/src/circuit_parser_qsim.h"
4343
#include "tensorflow_quantum/core/src/util_qsim.h"
4444

4545
namespace tfq {
4646

47-
using ::cirq::google::api::v2::Program;
4847
using ::tensorflow::Status;
48+
using ::tfq::proto::Program;
4949

5050
typedef qsim::Cirq::GateCirq<float> QsimGate;
5151
typedef qsim::Circuit<QsimGate> QsimCircuit;

tensorflow_quantum/core/ops/parse_context.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ limitations under the License.
2020
#include <string>
2121
#include <vector>
2222

23-
#include "cirq_google/api/v2/program.pb.h"
2423
#include "tensorflow/core/framework/op_kernel.h"
2524
#include "tensorflow/core/lib/core/error_codes.pb.h"
2625
#include "tensorflow/core/lib/core/status.h"
2726
#include "tensorflow/core/lib/core/threadpool.h"
2827
#include "tensorflow_quantum/core/ops/tfq_simulate_utils.h"
2928
#include "tensorflow_quantum/core/proto/pauli_sum.pb.h"
29+
#include "tensorflow_quantum/core/proto/program.pb.h"
3030
#include "tensorflow_quantum/core/src/program_resolution.h"
3131

3232
namespace tfq {
3333
namespace {
3434

35-
using ::cirq::google::api::v2::Program;
3635
using ::tensorflow::OpKernelContext;
3736
using ::tensorflow::Status;
3837
using ::tensorflow::Tensor;
3938
using ::tfq::proto::PauliSum;
39+
using ::tfq::proto::Program;
4040

4141
template <typename T>
4242
Status ParseProto(const std::string& text, T* proto) {

tensorflow_quantum/core/ops/parse_context.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,28 @@ limitations under the License.
2929
#include <vector>
3030

3131
#include "absl/container/flat_hash_map.h"
32-
#include "cirq_google/api/v2/program.pb.h"
3332
#include "tensorflow/core/framework/op_kernel.h"
3433
#include "tensorflow/core/lib/core/status.h"
3534
#include "tensorflow_quantum/core/proto/pauli_sum.pb.h"
35+
#include "tensorflow_quantum/core/proto/program.pb.h"
3636

3737
namespace tfq {
3838

3939
// Simplest Program proto parsing
40-
tensorflow::Status ParsePrograms(
41-
tensorflow::OpKernelContext* context, const std::string& input_name,
42-
std::vector<cirq::google::api::v2::Program>* programs);
40+
tensorflow::Status ParsePrograms(tensorflow::OpKernelContext* context,
41+
const std::string& input_name,
42+
std::vector<tfq::proto::Program>* programs);
4343

4444
// Simplest Program proto parsing in 2D.
4545
tensorflow::Status ParsePrograms2D(
4646
tensorflow::OpKernelContext* context, const std::string& input_name,
47-
std::vector<std::vector<cirq::google::api::v2::Program>>* programs);
47+
std::vector<std::vector<tfq::proto::Program>>* programs);
4848

4949
// Parses a vector of programs along with another vector of programs to append
5050
tensorflow::Status GetProgramsAndProgramsToAppend(
5151
tensorflow::OpKernelContext* context,
52-
std::vector<cirq::google::api::v2::Program>* programs,
53-
std::vector<cirq::google::api::v2::Program>* programs_to_append);
52+
std::vector<tfq::proto::Program>* programs,
53+
std::vector<tfq::proto::Program>* programs_to_append);
5454

5555
// A parameter map is a mapping from the name of the parameter to the index in
5656
// the input parameter value tensor (for gradient computations) and the value
@@ -63,8 +63,7 @@ typedef absl::flat_hash_map<std::string, std::pair<int, float>> SymbolMap;
6363
// and correct with the original programs.
6464
tensorflow::Status GetProgramsAndNumQubits(
6565
tensorflow::OpKernelContext* context,
66-
std::vector<cirq::google::api::v2::Program>* programs,
67-
std::vector<int>* num_qubits,
66+
std::vector<tfq::proto::Program>* programs, std::vector<int>* num_qubits,
6867
std::vector<std::vector<tfq::proto::PauliSum>>* p_sums = nullptr);
6968

7069
// Parses Cirq Program protos out of the 'circuit_specs' input Tensor. Also
@@ -73,9 +72,8 @@ tensorflow::Status GetProgramsAndNumQubits(
7372
// found in all programs[i][j] for all j.
7473
tensorflow::Status GetProgramsAndNumQubits(
7574
tensorflow::OpKernelContext* context,
76-
std::vector<cirq::google::api::v2::Program>* programs,
77-
std::vector<int>* num_qubits,
78-
std::vector<std::vector<cirq::google::api::v2::Program>>* other_programs);
75+
std::vector<tfq::proto::Program>* programs, std::vector<int>* num_qubits,
76+
std::vector<std::vector<tfq::proto::Program>>* other_programs);
7977

8078
// Parses PauliSum protos out of the 'pauli_sums' input tensor. Note this
8179
// function does NOT resolve QubitID's as any paulisum needs a reference

0 commit comments

Comments
 (0)