Skip to content

Commit

Permalink
Pulled out Cirq proto dependency. (tensorflow#590)
Browse files Browse the repository at this point in the history
* Pulled out Cirq proto dependency.

* format.

* remove cirq from WORKSPACE.
  • Loading branch information
MichaelBroughton authored Jun 14, 2021
1 parent 859ba3a commit 534f65d
Show file tree
Hide file tree
Showing 40 changed files with 2,627 additions and 350 deletions.
7 changes: 0 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ http_archive(
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"],
)

http_archive(
name = "cirq",
sha256 = "9241bd0a31bfe294f76071884fcb053c63abf2b5d311e7b7f0f4e20537cc7c43",
strip_prefix = "Cirq-0.11.0/cirq-google",
urls = ["https://github.com/quantumlib/Cirq/archive/v0.11.0.zip"],
)

http_archive(
name = "qsim",
sha256 = "d39b9c48866ce4d6a095093ae8059444d649e851219497af99e937a74f1e9a45",
Expand Down
2 changes: 2 additions & 0 deletions tensorflow_quantum/core/ops/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ py_library(
srcs_version = "PY3",
deps = [
":batch_util",
"//tensorflow_quantum/core/proto:program_py_proto",
"//tensorflow_quantum/core/proto:pauli_sum_py_proto",
"//tensorflow_quantum/core/serialize:serializer",
],
)
Expand Down
3 changes: 2 additions & 1 deletion tensorflow_quantum/core/ops/cirq_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from tensorflow_quantum.core.ops import batch_util
from tensorflow_quantum.core.proto import pauli_sum_pb2
from tensorflow_quantum.core.proto import program_pb2
from tensorflow_quantum.core.serialize import serializer


Expand Down Expand Up @@ -108,7 +109,7 @@ def _batch_deserialize_helper(programs, symbol_names, symbol_values):
program = program.numpy()
values = values.numpy().astype(float)

circuit_proto = cirq.google.api.v2.program_pb2.Program()
circuit_proto = program_pb2.Program()
circuit_proto.ParseFromString(program)

circuit = serializer.deserialize_circuit(circuit_proto)
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ limitations under the License.
#include "../qsim/lib/gates_cirq.h"
#include "../qsim/lib/seqfor.h"
#include "../qsim/lib/simmux.h"
#include "cirq_google/api/v2/program.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/tensor_shape.h"
Expand All @@ -30,13 +29,14 @@ limitations under the License.
#include "tensorflow/core/lib/core/threadpool.h"
#include "tensorflow/core/platform/mutex.h"
#include "tensorflow_quantum/core/ops/parse_context.h"
#include "tensorflow_quantum/core/proto/program.pb.h"
#include "tensorflow_quantum/core/src/util_qsim.h"

namespace tfq {

using ::cirq::google::api::v2::Program;
using ::tensorflow::Status;
using ::tfq::proto::PauliSum;
using ::tfq::proto::Program;

typedef qsim::Cirq::GateCirq<float> QsimGate;
typedef qsim::Circuit<QsimGate> QsimCircuit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ limitations under the License.
#include "../qsim/lib/gates_cirq.h"
#include "../qsim/lib/seqfor.h"
#include "../qsim/lib/simmux.h"
#include "cirq_google/api/v2/program.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/tensor_shape.h"
Expand All @@ -30,14 +29,15 @@ limitations under the License.
#include "tensorflow/core/lib/core/threadpool.h"
#include "tensorflow/core/platform/mutex.h"
#include "tensorflow_quantum/core/ops/parse_context.h"
#include "tensorflow_quantum/core/proto/program.pb.h"
#include "tensorflow_quantum/core/src/adj_util.h"
#include "tensorflow_quantum/core/src/util_qsim.h"

namespace tfq {

using ::cirq::google::api::v2::Program;
using ::tensorflow::Status;
using ::tfq::proto::PauliSum;
using ::tfq::proto::Program;

typedef qsim::Cirq::GateCirq<float> QsimGate;
typedef qsim::Circuit<QsimGate> QsimCircuit;
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_quantum/core/ops/noise/tfq_noisy_expectation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ limitations under the License.
#include "../qsim/lib/qtrajectory.h"
#include "../qsim/lib/seqfor.h"
#include "../qsim/lib/simmux.h"
#include "cirq_google/api/v2/program.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/tensor_shape.h"
Expand All @@ -41,13 +40,14 @@ limitations under the License.
#include "tensorflow/core/util/guarded_philox_random.h"
#include "tensorflow_quantum/core/ops/parse_context.h"
#include "tensorflow_quantum/core/proto/pauli_sum.pb.h"
#include "tensorflow_quantum/core/proto/program.pb.h"
#include "tensorflow_quantum/core/src/util_qsim.h"

namespace tfq {

using ::cirq::google::api::v2::Program;
using ::tensorflow::Status;
using ::tfq::proto::PauliSum;
using ::tfq::proto::Program;

typedef qsim::Cirq::GateCirq<float> QsimGate;
typedef qsim::Circuit<QsimGate> QsimCircuit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ limitations under the License.
#include "../qsim/lib/qtrajectory.h"
#include "../qsim/lib/seqfor.h"
#include "../qsim/lib/simmux.h"
#include "cirq_google/api/v2/program.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/tensor_shape.h"
Expand All @@ -41,13 +40,14 @@ limitations under the License.
#include "tensorflow/core/util/guarded_philox_random.h"
#include "tensorflow_quantum/core/ops/parse_context.h"
#include "tensorflow_quantum/core/proto/pauli_sum.pb.h"
#include "tensorflow_quantum/core/proto/program.pb.h"
#include "tensorflow_quantum/core/src/util_qsim.h"

namespace tfq {

using ::cirq::google::api::v2::Program;
using ::tensorflow::Status;
using ::tfq::proto::PauliSum;
using ::tfq::proto::Program;

typedef qsim::Cirq::GateCirq<float> QsimGate;
typedef qsim::Circuit<QsimGate> QsimCircuit;
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_quantum/core/ops/noise/tfq_noisy_samples.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ limitations under the License.
#include "../qsim/lib/qtrajectory.h"
#include "../qsim/lib/seqfor.h"
#include "../qsim/lib/simmux.h"
#include "cirq_google/api/v2/program.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/tensor_shape.h"
Expand All @@ -39,13 +38,14 @@ limitations under the License.
#include "tensorflow/core/lib/random/simple_philox.h"
#include "tensorflow/core/util/guarded_philox_random.h"
#include "tensorflow_quantum/core/ops/parse_context.h"
#include "tensorflow_quantum/core/proto/program.pb.h"
#include "tensorflow_quantum/core/src/circuit_parser_qsim.h"
#include "tensorflow_quantum/core/src/util_qsim.h"

namespace tfq {

using ::cirq::google::api::v2::Program;
using ::tensorflow::Status;
using ::tfq::proto::Program;

typedef qsim::Cirq::GateCirq<float> QsimGate;
typedef qsim::Circuit<QsimGate> QsimCircuit;
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_quantum/core/ops/parse_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ limitations under the License.
#include <string>
#include <vector>

#include "cirq_google/api/v2/program.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/lib/core/error_codes.pb.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/threadpool.h"
#include "tensorflow_quantum/core/ops/tfq_simulate_utils.h"
#include "tensorflow_quantum/core/proto/pauli_sum.pb.h"
#include "tensorflow_quantum/core/proto/program.pb.h"
#include "tensorflow_quantum/core/src/program_resolution.h"

namespace tfq {
namespace {

using ::cirq::google::api::v2::Program;
using ::tensorflow::OpKernelContext;
using ::tensorflow::Status;
using ::tensorflow::Tensor;
using ::tfq::proto::PauliSum;
using ::tfq::proto::Program;

template <typename T>
Status ParseProto(const std::string& text, T* proto) {
Expand Down
22 changes: 10 additions & 12 deletions tensorflow_quantum/core/ops/parse_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ limitations under the License.
#include <vector>

#include "absl/container/flat_hash_map.h"
#include "cirq_google/api/v2/program.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow_quantum/core/proto/pauli_sum.pb.h"
#include "tensorflow_quantum/core/proto/program.pb.h"

namespace tfq {

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

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

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

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

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

// Parses PauliSum protos out of the 'pauli_sums' input tensor. Note this
// function does NOT resolve QubitID's as any paulisum needs a reference
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_quantum/core/ops/tfq_adj_grad_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ limitations under the License.
#include "../qsim/lib/gates_cirq.h"
#include "../qsim/lib/seqfor.h"
#include "../qsim/lib/simmux.h"
#include "cirq_google/api/v2/program.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/tensor_shape.h"
Expand All @@ -31,14 +30,15 @@ limitations under the License.
#include "tensorflow/core/platform/mutex.h"
#include "tensorflow_quantum/core/ops/parse_context.h"
#include "tensorflow_quantum/core/proto/pauli_sum.pb.h"
#include "tensorflow_quantum/core/proto/program.pb.h"
#include "tensorflow_quantum/core/src/adj_util.h"
#include "tensorflow_quantum/core/src/util_qsim.h"

namespace tfq {

using ::cirq::google::api::v2::Program;
using ::tensorflow::Status;
using ::tfq::proto::PauliSum;
using ::tfq::proto::Program;

typedef qsim::Cirq::GateCirq<float> QsimGate;
typedef qsim::Circuit<QsimGate> QsimCircuit;
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ limitations under the License.
#include "../qsim/lib/gate_appl.h"
#include "../qsim/lib/gates_cirq.h"
#include "../qsim/lib/umux.h"
#include "cirq_google/api/v2/program.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/tensor_shape.h"
Expand All @@ -28,13 +27,14 @@ limitations under the License.
#include "tensorflow/core/lib/core/threadpool.h"
#include "tensorflow/core/platform/mutex.h"
#include "tensorflow_quantum/core/ops/parse_context.h"
#include "tensorflow_quantum/core/proto/program.pb.h"
#include "tensorflow_quantum/core/src/circuit_parser_qsim.h"
#include "tensorflow_quantum/core/src/util_qsim.h"

namespace tfq {

using ::cirq::google::api::v2::Program;
using ::tensorflow::Status;
using ::tfq::proto::Program;

typedef qsim::Cirq::GateCirq<float> QsimGate;
typedef qsim::Circuit<QsimGate> QsimCircuit;
Expand Down
6 changes: 3 additions & 3 deletions tensorflow_quantum/core/ops/tfq_circuit_append_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ limitations under the License.

#include <string>

#include "cirq_google/api/v2/program.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/threadpool.h"
#include "tensorflow_quantum/core/ops/parse_context.h"
#include "tensorflow_quantum/core/ops/tfq_simulate_utils.h"
#include "tensorflow_quantum/core/proto/program.pb.h"

namespace tfq {

using ::cirq::google::api::v2::Moment;
using ::cirq::google::api::v2::Program;
using ::tfq::proto::Moment;
using ::tfq::proto::Program;

class TfqCircuitAppendOp : public tensorflow::OpKernel {
public:
Expand Down
12 changes: 6 additions & 6 deletions tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ limitations under the License.
#include <cmath>
#include <string>

#include "cirq_google/api/v2/program.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/threadpool.h"
#include "tensorflow_quantum/core/ops/parse_context.h"
#include "tensorflow_quantum/core/ops/tfq_simulate_utils.h"
#include "tensorflow_quantum/core/proto/program.pb.h"

namespace tfq {

using ::cirq::google::api::v2::Arg;
using ::cirq::google::api::v2::Circuit;
using ::cirq::google::api::v2::Moment;
using ::cirq::google::api::v2::Operation;
using ::cirq::google::api::v2::Program;
using ::tensorflow::Status;
using ::tensorflow::Tensor;
using ::tfq::proto::Arg;
using ::tfq::proto::Circuit;
using ::tfq::proto::Moment;
using ::tfq::proto::Operation;
using ::tfq::proto::Program;

class TfqPsDecomposeOp : public tensorflow::OpKernel {
public:
Expand Down
10 changes: 5 additions & 5 deletions tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ limitations under the License.

#include <string>

#include "cirq_google/api/v2/program.pb.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/shape_inference.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/core/threadpool.h"
#include "tensorflow_quantum/core/ops/parse_context.h"
#include "tensorflow_quantum/core/ops/tfq_simulate_utils.h"
#include "tensorflow_quantum/core/proto/program.pb.h"

namespace tfq {

using ::cirq::google::api::v2::Arg;
using ::cirq::google::api::v2::Moment;
using ::cirq::google::api::v2::Operation;
using ::cirq::google::api::v2::Program;
using ::tfq::proto::Arg;
using ::tfq::proto::Moment;
using ::tfq::proto::Operation;
using ::tfq::proto::Program;

using ::tensorflow::Status;
using ::tensorflow::Tensor;
Expand Down
Loading

0 comments on commit 534f65d

Please sign in to comment.