From bd2b612fc56a4cd2d8491b54894d9661d6a9f03b Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Wed, 29 Mar 2023 06:18:38 +0000 Subject: [PATCH 001/106] broken version of ops --- tensorflow_quantum/core/ops/BUILD | 3 + ...ate_sampled_expectation_op_cuquantum.cu.cc | 350 ++++++++++++++++++ .../tfq_simulate_samples_op_cuquantum.cu.cc | 299 +++++++++++++++ .../ops/tfq_simulate_state_op_cuquantum.cu.cc | 256 +++++++++++++ 4 files changed, 908 insertions(+) create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index 84361cef1..d4a6e9477 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -759,6 +759,9 @@ cc_binary( name = "_tfq_simulate_ops_cuquantum.so", srcs = [ "tfq_simulate_expectation_op_cuquantum.cu.cc", + # "tfq_simulate_sampled_expectation_op_cuquantum.cu.cc", + # "tfq_simulate_state_op_cuquantum.cu.cc", + "tfq_simulate_samples_op_cuquantum.cu.cc", ], linkshared = 1, features = select({ diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc new file mode 100644 index 000000000..979ec1da2 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -0,0 +1,350 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include + +#include "../cuquantum_libs/include/custatevec.h" +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.h" +#include "../qsim/lib/simulator_custatevec.h" +#include "../qsim/lib/statespace_custatevec.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#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/pauli_sum.pb.h" +#include "tensorflow_quantum/core/proto/program.pb.h" +#include "tensorflow_quantum/core/src/util_qsim.h" + +#include "tensorflow/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/util/guarded_philox_random.h" + +namespace tfq { + +using ::tensorflow::Status; +using ::tfq::proto::PauliSum; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateSampledExpectationGpuOp : public tensorflow::OpKernel { + public: + explicit TfqSimulateSampledExpectationGpuOp( + tensorflow::OpKernelConstruction* context) + : OpKernel(context) {} + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + const int num_inputs = context->num_inputs(); + OP_REQUIRES(context, num_inputs == 5, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Expected 5 inputs, got ", num_inputs, " inputs."))); + + // Create the output Tensor. + const int output_dim_batch_size = context->input(0).dim_size(0); + const int output_dim_op_size = context->input(3).dim_size(1); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_batch_size); + output_shape.AddDim(output_dim_op_size); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->matrix(); + + std::vector programs; + std::vector num_qubits; + std::vector> pauli_sums; + OP_REQUIRES_OK(context, GetProgramsAndNumQubits(context, &programs, + &num_qubits, &pauli_sums)); + + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + + OP_REQUIRES(context, programs.size() == maps.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and symbol_values do not match. Got ", + programs.size(), " circuits and ", maps.size(), + " symbol values."))); + + std::vector> num_samples; + OP_REQUIRES_OK(context, GetNumSamples(context, &num_samples)); + + OP_REQUIRES(context, num_samples.size() == pauli_sums.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Dimension 0 of num_samples and pauli_sums do not match.", + "Got ", num_samples.size(), " lists of sample sizes and ", + pauli_sums.size(), " lists of pauli sums."))); + + OP_REQUIRES( + context, context->input(4).dim_size(1) == context->input(3).dim_size(1), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Dimension 1 of num_samples and pauli_sums do not match.", "Got ", + context->input(4).dim_size(1), " lists of sample sizes and ", + context->input(3).dim_size(1), " lists of pauli sums."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> fused_circuits( + programs.size(), std::vector>({})); + + Status parse_status = Status::OK(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + // Cross reference with standard google cloud compute instances + // Memory ~= 2 * num_threads * (2 * 64 * 2 ** num_qubits in circuits) + // e2s2 = 2 CPU, 8GB -> Can safely do 25 since Memory = 4GB + // e2s4 = 4 CPU, 16GB -> Can safely do 25 since Memory = 8GB + // ... + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + if (max_num_qubits >= 26 || programs.size() == 1) { + ComputeLarge(num_qubits, fused_circuits, pauli_sums, num_samples, context, + &output_tensor); + } else { + ComputeSmall(num_qubits, max_num_qubits, fused_circuits, pauli_sums, + num_samples, context, &output_tensor); + } + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } + + private: + cublasHandle_t cublas_handle_; + custatevecHandle_t custatevec_handle_; + + void ComputeLarge( + const std::vector& num_qubits, + const std::vector>>& fused_circuits, + const std::vector>& pauli_sums, + const std::vector>& num_samples, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + auto scratch = ss.Create(largest_nq); + + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + int largest_sum = -1; + for (const auto& sums : pauli_sums) { + for (const auto& sum : sums) { + largest_sum = std::max(largest_sum, sum.terms().size()); + } + } + auto local_gen = random_gen.ReserveSamples32( + largest_sum * pauli_sums[0].size() * fused_circuits.size() + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as necessary. + for (int i = 0; i < fused_circuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + } + // TODO: add heuristic here so that we do not always recompute + // the state if there is a possibility that circuit[i] and + // circuit[i + 1] produce the same state. + ss.SetStateZero(sv); + for (int j = 0; j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + for (int j = 0; j < pauli_sums[i].size(); j++) { + // (#679) Just ignore empty program + if (fused_circuits[i].size() == 0) { + (*output_tensor)(i, j) = -2.0; + continue; + } + float exp_v = 0.0; + OP_REQUIRES_OK(context, ComputeSampledExpectationQsim( + pauli_sums[i][j], sim, ss, sv, scratch, + num_samples[i][j], rand_source, &exp_v)); + (*output_tensor)(i, j) = exp_v; + } + } + } + + void ComputeSmall( + const std::vector& num_qubits, const int max_num_qubits, + const std::vector>>& fused_circuits, + const std::vector>& pauli_sums, + const std::vector>& num_samples, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + const int output_dim_op_size = output_tensor->dimension(1); + + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + int largest_sum = -1; + for (const auto& sums : pauli_sums) { + for (const auto& sum : sums) { + largest_sum = std::max(largest_sum, sum.terms().size()); + } + } + const int num_threads = context->device() + ->tensorflow_cpu_worker_threads() + ->workers->NumThreads(); + + Status compute_status = Status::OK(); + auto c_lock = tensorflow::mutex(); + auto DoWork = [&](int start, int end) { + int old_batch_index = -2; + int cur_batch_index = -1; + int largest_nq = 1; + int cur_op_index; + + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + auto scratch = ss.Create(largest_nq); + + int n_random = largest_sum * output_dim_op_size * fused_circuits.size(); + n_random /= num_threads; + n_random += 1; + auto local_gen = random_gen.ReserveSamples32(n_random); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + for (int i = start; i < end; i++) { + cur_batch_index = i / output_dim_op_size; + cur_op_index = i % output_dim_op_size; + + const int nq = num_qubits[cur_batch_index]; + + // (#679) Just ignore empty program + if (fused_circuits[cur_batch_index].size() == 0) { + (*output_tensor)(cur_batch_index, cur_op_index) = -2.0; + continue; + } + + if (cur_batch_index != old_batch_index) { + // We've run into a new state vector we must compute. + // Only compute a new state vector when we have to. + if (nq > largest_nq) { + largest_nq = nq; + sv = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + } + // no need to update scratch_state since ComputeExpectation + // will take care of things for us. + ss.SetStateZero(sv); + for (int j = 0; j < fused_circuits[cur_batch_index].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[cur_batch_index][j], sv); + } + } + + float exp_v = 0.0; + NESTED_FN_STATUS_SYNC( + compute_status, + ComputeSampledExpectationQsim( + pauli_sums[cur_batch_index][cur_op_index], sim, ss, sv, scratch, + num_samples[cur_batch_index][cur_op_index], rand_source, + &exp_v), + c_lock); + + (*output_tensor)(cur_batch_index, cur_op_index) = exp_v; + old_batch_index = cur_batch_index; + } + }; + + const int64_t num_cycles = + 200 * (int64_t(1) << static_cast(max_num_qubits)); + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + fused_circuits.size() * output_dim_op_size, num_cycles, DoWork); + OP_REQUIRES_OK(context, compute_status); + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqSimulateSampledExpectationGpu").Device(tensorflow::DEVICE_CPU), + TfqSimulateSampledExpectationGpuOp); + +REGISTER_OP("TfqSimulateSampledExpectationGpu") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("pauli_sums: string") + .Input("num_samples: int32") + .Output("expectations: float") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle pauli_sums_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 2, &pauli_sums_shape)); + + tensorflow::shape_inference::ShapeHandle num_samples_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(4), 2, &num_samples_shape)); + + tensorflow::shape_inference::DimensionHandle output_rows = + c->Dim(programs_shape, 0); + tensorflow::shape_inference::DimensionHandle output_cols = + c->Dim(pauli_sums_shape, 1); + c->set_output(0, c->Matrix(output_rows, output_cols)); + + return tensorflow::Status::OK(); + }); + +} // namespace tfq \ No newline at end of file diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc new file mode 100644 index 000000000..245b2f5a8 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -0,0 +1,299 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include +#include + +#include "../cuquantum_libs/include/custatevec.h" +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simulator_custatevec.h" +#include "../qsim/lib/statespace_custatevec.h" +#include "../qsim/lib/simmux.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/platform/mutex.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 ::tensorflow::Status; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateSamplesGpuOp : public tensorflow::OpKernel { + public: + explicit TfqSimulateSamplesGpuOp(tensorflow::OpKernelConstruction* context) + : OpKernel(context) {} + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + DCHECK_EQ(4, context->num_inputs()); + + // Parse to Program Proto and num_qubits. + std::vector programs; + std::vector num_qubits; + OP_REQUIRES_OK(context, + GetProgramsAndNumQubits(context, &programs, &num_qubits)); + + // Parse symbol maps for parameter resolution in the circuits. + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + OP_REQUIRES( + context, maps.size() == programs.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and values do not match. Got ", programs.size(), + " circuits and ", maps.size(), " values."))); + + int num_samples = 0; + OP_REQUIRES_OK(context, GetIndividualSample(context, &num_samples)); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> fused_circuits( + programs.size(), std::vector>({})); + + Status parse_status = Status::OK(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + // Find largest circuit for tensor size padding and allocate + // the output tensor. + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + const int output_dim_size = maps.size(); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_size); + output_shape.AddDim(num_samples); + output_shape.AddDim(max_num_qubits); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->tensor(); + + if (num_samples == 0) { + return; // bug in qsim dependency we can't control. + } + + // Cross reference with standard google cloud compute instances + // Memory ~= 2 * num_threads * (2 * 64 * 2 ** num_qubits in circuits) + // e2s2 = 2 CPU, 8GB -> Can safely do 25 since Memory = 4GB + // e2s4 = 4 CPU, 16GB -> Can safely do 25 since Memory = 8GB + // ... + + // create handles for simulator + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + if (max_num_qubits >= 26 || programs.size() == 1) { + ComputeLarge(num_qubits, max_num_qubits, num_samples, fused_circuits, + context, &output_tensor); + } else { + ComputeSmall(num_qubits, max_num_qubits, num_samples, fused_circuits, + context, &output_tensor); + } + // destroy handles in sync with simulator lifetime + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } + + private: + cublasHandle_t cublas_handle_; + custatevecHandle_t custatevec_handle_; + + void ComputeLarge( + const std::vector& num_qubits, const int max_num_qubits, + const int num_samples, + const std::vector>>& fused_circuits, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Tensor* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + auto local_gen = random_gen.ReserveSamples32(fused_circuits.size() + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as nescessary. + for (int i = 0; i < fused_circuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + } + ss.SetStateZero(sv); + for (int j = 0; j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + + auto samples = ss.Sample(sv, num_samples, rand_source.Rand32()); + for (int j = 0; j < num_samples; j++) { + uint64_t q_ind = 0; + uint64_t mask = 1; + bool val = 0; + while (q_ind < nq) { + val = samples[j] & mask; + (*output_tensor)( + i, j, static_cast(max_num_qubits - q_ind - 1)) = val; + q_ind++; + mask <<= 1; + } + while (q_ind < max_num_qubits) { + (*output_tensor)( + i, j, static_cast(max_num_qubits - q_ind - 1)) = -2; + q_ind++; + } + } + } + } + + void ComputeSmall( + const std::vector& num_qubits, const int max_num_qubits, + const int num_samples, + const std::vector>>& fused_circuits, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Tensor* output_tensor) { + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + + auto DoWork = [&](int start, int end) { + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + + auto local_gen = random_gen.ReserveSamples32(fused_circuits.size() + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + for (int i = start; i < end; i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + } + ss.SetStateZero(sv); + for (int j = 0; j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + + auto samples = ss.Sample(sv, num_samples, rand_source.Rand32()); + for (int j = 0; j < num_samples; j++) { + uint64_t q_ind = 0; + uint64_t mask = 1; + bool val = 0; + while (q_ind < nq) { + val = samples[j] & mask; + (*output_tensor)( + i, j, static_cast(max_num_qubits - q_ind - 1)) = val; + q_ind++; + mask <<= 1; + } + while (q_ind < max_num_qubits) { + (*output_tensor)( + i, j, static_cast(max_num_qubits - q_ind - 1)) = -2; + q_ind++; + } + } + } + }; + + const int64_t num_cycles = + 200 * (int64_t(1) << static_cast(max_num_qubits)); + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + fused_circuits.size(), num_cycles, DoWork); + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqSimulateSamplesGpu").Device(tensorflow::DEVICE_CPU), + TfqSimulateSamplesGpuOp); + +REGISTER_OP("TfqSimulateSamplesGpu") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("num_samples: int32") + .Output("samples: int8") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle num_samples_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 1, &num_samples_shape)); + + // [batch_size, n_samples, largest_n_qubits] + c->set_output( + 0, c->MakeShape( + {c->Dim(programs_shape, 0), + tensorflow::shape_inference::InferenceContext::kUnknownDim, + tensorflow::shape_inference::InferenceContext::kUnknownDim})); + + return tensorflow::Status::OK(); + }); + +} // namespace tfq \ No newline at end of file diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc new file mode 100644 index 000000000..8e0d3b7d4 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc @@ -0,0 +1,256 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include + +#include "../cuquantum_libs/include/custatevec.h" +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.h" +#include "../qsim/lib/simulator_custatevec.h" +#include "../qsim/lib/statespace_custatevec.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#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 ::tensorflow::Status; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateStateGpuOp : public tensorflow::OpKernel { + public: + explicit TfqSimulateStateGpuOp(tensorflow::OpKernelConstruction* context) + : OpKernel(context) {} + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + DCHECK_EQ(3, context->num_inputs()); + + // Parse to Program Proto and num_qubits. + std::vector programs; + std::vector num_qubits; + OP_REQUIRES_OK(context, + GetProgramsAndNumQubits(context, &programs, &num_qubits)); + + // Parse symbol maps for parameter resolution in the circuits. + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + OP_REQUIRES( + context, maps.size() == programs.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and values do not match. Got ", programs.size(), + " circuits and ", maps.size(), " values."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> fused_circuits( + programs.size(), std::vector>({})); + + Status parse_status = Status::OK(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + // Find largest circuit for tensor size padding and allocate + // the output tensor. + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + const int output_dim_size = maps.size(); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_size); + output_shape.AddDim(1 << max_num_qubits); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + tensorflow::TTypes, 1>::Matrix output_tensor = + output->matrix>(); + + // Cross reference with standard google cloud compute instances + // Memory ~= 2 * num_threads * (2 * 64 * 2 ** num_qubits in circuits) + // e2s2 = 2 CPU, 8GB -> Can safely do 25 since Memory = 4GB + // e2s4 = 4 CPU, 16GB -> Can safely do 25 since Memory = 8GB + // ... + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + if (max_num_qubits >= 26 || programs.size() == 1) { + ComputeLarge(num_qubits, max_num_qubits, fused_circuits, context, + &output_tensor); + } else { + ComputeSmall(num_qubits, max_num_qubits, fused_circuits, context, + &output_tensor); + } + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + + } + + private: + cublasHandle_t cublas_handle_; + custatevecHandle_t custatevec_handle_; + + void ComputeLarge( + const std::vector& num_qubits, const int max_num_qubits, + const std::vector>>& fused_circuits, + tensorflow::OpKernelContext* context, + tensorflow::TTypes, 1>::Matrix* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as nescessary. + for (int i = 0; i < fused_circuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + } + ss.SetStateZero(sv); + for (int j = 0; j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + + // Parallel copy state vector information from qsim into tensorflow + // tensors. + auto copy_f = [i, nq, max_num_qubits, &output_tensor, &ss, &sv]( + uint64_t start, uint64_t end) { + uint64_t crossover = uint64_t(1) << nq; + uint64_t upper = std::min(end, crossover); + + if (start < crossover) { + for (uint64_t j = 0; j < upper; j++) { + (*output_tensor)(i, j) = ss.GetAmpl(sv, j); + } + } + for (uint64_t j = upper; j < end; j++) { + (*output_tensor)(i, j) = std::complex(-2, 0); + } + }; + const int num_cycles_copy = 50; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + uint64_t(1) << max_num_qubits, num_cycles_copy, copy_f); + } + } + + void ComputeSmall( + const std::vector& num_qubits, const int max_num_qubits, + const std::vector>>& fused_circuits, + tensorflow::OpKernelContext* context, + tensorflow::TTypes, 1>::Matrix* output_tensor) { + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + auto DoWork = [&](int start, int end) { + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + for (int i = start; i < end; i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + } + ss.SetStateZero(sv); + for (int j = 0; j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + + for (uint64_t j = 0; j < (uint64_t(1) << nq); j++) { + (*output_tensor)(i, j) = ss.GetAmpl(sv, j); + } + for (uint64_t j = (uint64_t(1) << nq); + j < (uint64_t(1) << max_num_qubits); j++) { + (*output_tensor)(i, j) = std::complex(-2, 0); + } + } + }; + + const int64_t num_cycles = + 200 * (int64_t(1) << static_cast(max_num_qubits)); + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + fused_circuits.size(), num_cycles, DoWork); + } +}; + +REGISTER_KERNEL_BUILDER(Name("TfqSimulateStateGpu").Device(tensorflow::DEVICE_CPU), + TfqSimulateStateGpuOp); + +REGISTER_OP("TfqSimulateStateGpu") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Output("state_vector: complex64") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + c->set_output( + 0, c->MakeShape( + {c->Dim(programs_shape, 0), + tensorflow::shape_inference::InferenceContext::kUnknownDim})); + + return tensorflow::Status::OK(); + }); + +} // namespace tfq \ No newline at end of file From d749b058eedaaf3cb0c80f33fe65857dc14dc1b2 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 29 Mar 2023 18:02:40 -0700 Subject: [PATCH 002/106] Add cuquantum_configure() --- .bazelversion | 2 +- WORKSPACE | 19 +- tensorflow_quantum/core/ops/BUILD | 4 +- third_party/cuquantum/BUILD | 0 third_party/cuquantum/BUILD.tpl | 21 ++ third_party/cuquantum/cuquantum_configure.bzl | 210 ++++++++++++++++++ 6 files changed, 236 insertions(+), 20 deletions(-) create mode 100644 third_party/cuquantum/BUILD create mode 100644 third_party/cuquantum/BUILD.tpl create mode 100644 third_party/cuquantum/cuquantum_configure.bzl diff --git a/.bazelversion b/.bazelversion index 831446cbd..03f488b07 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -5.1.0 +5.3.0 diff --git a/WORKSPACE b/WORKSPACE index 6a29d598b..e2e82e2b5 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -81,21 +81,6 @@ bind( actual = "@six_archive//:six", ) -new_local_repository( - name = "cuquantum_libs", - path = "/usr/local/google/home/jaeyoo/workspace/cuquantum-linux-x86_64-22.11.0.13-archive", - build_file_content = """ -cc_library( - name = "custatevec_headers", - srcs = ["include/custatevec.h"], - visibility = ["//visibility:public"], -) - -cc_library( - name = "custatevec", - srcs = ["lib/libcustatevec.so"], - visibility = ["//visibility:public"], -) -""", -) +load("//third_party/cuquantum:cuquantum_configure.bzl", "cuquantum_configure") +cuquantum_configure(name = "local_config_cuquantum") diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index 4beb66954..e9c99744b 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -823,9 +823,9 @@ cc_binary( # tensorflow core protos ] + if_cuda_is_configured([ ":cuda", - "@cuquantum_libs//:custatevec", - "@cuquantum_libs//:custatevec_headers", "@local_config_cuda//cuda:cuda_headers", + "@local_config_cuquantum//:cuquantum_headers", + "@local_config_cuquantum//:libcuquantum", "@qsim//lib:qsim_cuquantum_lib", ]), # alwayslink=1, diff --git a/third_party/cuquantum/BUILD b/third_party/cuquantum/BUILD new file mode 100644 index 000000000..e69de29bb diff --git a/third_party/cuquantum/BUILD.tpl b/third_party/cuquantum/BUILD.tpl new file mode 100644 index 000000000..462b83631 --- /dev/null +++ b/third_party/cuquantum/BUILD.tpl @@ -0,0 +1,21 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "cuquantum_headers", + linkstatic = 1, + srcs = [":cuquantum_header_include"], + visibility = ["//visibility:public"], +) + +cc_library( + name = "libcuquantum", + srcs = [ + ":libcustatevec.so", + ":libcutensornet.so", + ], + visibility = ["//visibility:public"], +) + +%{CUQUANTUM_HEADER_GENRULE} +%{CUSTATEVEC_SHARED_LIBRARY_GENRULE} +%{CUTENSORNET_SHARED_LIBRARY_GENRULE} \ No newline at end of file diff --git a/third_party/cuquantum/cuquantum_configure.bzl b/third_party/cuquantum/cuquantum_configure.bzl new file mode 100644 index 000000000..81bc82ebb --- /dev/null +++ b/third_party/cuquantum/cuquantum_configure.bzl @@ -0,0 +1,210 @@ +"""Setup cuQuantum as external dependency""" +_CUQUANTUM_ROOT = "CUQUANTUM_ROOT" + + +def _tpl(repository_ctx, tpl, substitutions = {}, out = None): + if not out: + out = tpl + repository_ctx.template( + out, + Label("//third_party/cuquantum:%s.tpl" % tpl), + substitutions, + ) + + +def _fail(msg): + """Output failure message when auto configuration fails.""" + red = "\033[0;31m" + no_color = "\033[0m" + fail("%sPython Configuration Error:%s %s\n" % (red, no_color, msg)) + + +def _execute( + repository_ctx, + cmdline, + error_msg = None, + error_details = None, + empty_stdout_fine = False): + """Executes an arbitrary shell command. + Args: + repository_ctx: the repository_ctx object + cmdline: list of strings, the command to execute + error_msg: string, a summary of the error if the command fails + error_details: string, details about the error or steps to fix it + empty_stdout_fine: bool, if True, an empty stdout result is fine, otherwise + it's an error + Return: + the result of repository_ctx.execute(cmdline) + """ + result = repository_ctx.execute(cmdline) + if result.stderr or not (empty_stdout_fine or result.stdout): + _fail("\n".join([ + error_msg.strip() if error_msg else "Repository command failed", + result.stderr.strip(), + error_details if error_details else "", + ])) + return result + + +def _read_dir(repository_ctx, src_dir): + """Returns a string with all files in a directory. + Finds all files inside a directory, traversing subfolders and following + symlinks. The returned string contains the full path of all files + separated by line breaks. + """ + find_result = _execute( + repository_ctx, + ["find", src_dir, "-follow", "-type", "f"], + empty_stdout_fine = True, + ) + result = find_result.stdout + return result + +def _genrule(genrule_name, command, outs): + """Returns a string with a genrule. + + Genrule executes the given command and produces the given outputs. + + Args: + genrule_name: A unique name for genrule target. + command: The command to run. + outs: A list of files generated by this rule. + + Returns: + A genrule target. + """ + return ( + "genrule(\n" + + ' name = "' + + genrule_name + '",\n' + + " outs = [\n" + + outs + + "\n ],\n" + + ' cmd = """\n' + + command + + '\n """,\n' + + ")\n" + ) + +def _norm_path(path): + """Returns a path with '/' and remove the trailing slash.""" + path = path.replace("\\", "/") + if path[-1] == "/": + path = path[:-1] + return path + + +def _symlink_genrule_for_dir( + repository_ctx, + src_dir, + dest_dir, + genrule_name, + src_files = [], + dest_files = [], + is_empty_genrule = False): + """Returns a genrule to symlink(or copy if on Windows) a set of files. + + If src_dir is passed, files will be read from the given directory; otherwise + we assume files are in src_files and dest_files. + + Args: + repository_ctx: the repository_ctx object. + src_dir: source directory. + dest_dir: directory to create symlink in. + genrule_name: genrule name. + src_files: list of source files instead of src_dir. + dest_files: list of corresonding destination files. + is_empty_genrule: True if CUQUANTUM_ROOT is not set. + + Returns: + genrule target that creates the symlinks. + """ + if is_empty_genrule: + genrule = _genrule( + genrule_name, + "echo 'this genrule is empty because CUQUANTUM_ROOT is not set.' && touch %s.h" % genrule_name, + "'%s.h'" % genrule_name, + ) + return genrule + + if src_dir != None: + src_dir = _norm_path(src_dir) + dest_dir = _norm_path(dest_dir) + files = "\n".join(sorted(_read_dir(repository_ctx, src_dir).splitlines())) + + dest_files = files.replace(src_dir, "").splitlines() + src_files = files.splitlines() + command = [] + outs = [] + + for i in range(len(dest_files)): + if dest_files[i] != "": + # If we have only one file to link we do not want to use the dest_dir, as + # $(@D) will include the full path to the file. + dest = "$(@D)/" + dest_dir + dest_files[i] if len(dest_files) != 1 else "$(@D)/" + dest_files[i] + + # Copy the headers to create a sandboxable setup. + cmd = "cp -f" + command.append(cmd + ' "%s" "%s"' % (src_files[i], dest)) + outs.append(' "' + dest_dir + dest_files[i] + '",') + + genrule = _genrule( + genrule_name, + " && ".join(command), + "\n".join(outs), + ) + return genrule + + +def _cuquantum_pip_imple(repository_ctx): + cuquantum_root = repository_ctx.os.environ[_CUQUANTUM_ROOT] + + is_empty_genrule = cuquantum_root == "" + + cuquantum_header_path = "%s/include" % cuquantum_root + + cuquantum_header_rule = _symlink_genrule_for_dir( + repository_ctx, + cuquantum_header_path, + "include", + "cuquantum_header_include", + is_empty_genrule=is_empty_genrule, + ) + custatevec_shared_library_path = "%s/lib/libcustatevec.so" % (cuquantum_root) + + custatevec_shared_library_rule = _symlink_genrule_for_dir( + repository_ctx, + None, + "", + "libcustatevec.so", + [custatevec_shared_library_path], + ["libcustatevec.so"], + is_empty_genrule=is_empty_genrule, + ) + + cutensornet_shared_library_path = "%s/lib/libcutensornet.so" % (cuquantum_root) + + cutensornet_shared_library_rule = _symlink_genrule_for_dir( + repository_ctx, + None, + "", + "libcutensornet.so", + [cutensornet_shared_library_path], + ["libcutensornet.so"], + is_empty_genrule=is_empty_genrule, + ) + + _tpl(repository_ctx, "BUILD", { + "%{CUQUANTUM_HEADER_GENRULE}": cuquantum_header_rule, + "%{CUSTATEVEC_SHARED_LIBRARY_GENRULE}": custatevec_shared_library_rule, + "%{CUTENSORNET_SHARED_LIBRARY_GENRULE}": cutensornet_shared_library_rule, + }) + + + +cuquantum_configure = repository_rule( + implementation = _cuquantum_pip_imple, + environ = [ + _CUQUANTUM_ROOT, + ], +) From 9ae4fd00b3759eb3198b687bc81962b4cca8820f Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 29 Mar 2023 18:18:25 -0700 Subject: [PATCH 003/106] Add CUQUANTUM_ROOT detection for automatic setup in configure.sh --- configure.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/configure.sh b/configure.sh index c1ec9d2c5..651da5fcf 100755 --- a/configure.sh +++ b/configure.sh @@ -71,6 +71,17 @@ while [[ "$TF_CUDA_VERSION" == "" ]]; do esac done +# Check if we are building cuQuantum ops on top of CUDA. +if [[ "$TF_NEED_CUDA" == "1" ]]; then + echo "GPU is selected, default acceleration is CUDA for TFQuantum." + echo "Searching cuQuantum library from environment variable CUQUANTUM_ROOT..." + if [[ "$CUQUANTUM_ROOT" != "" ]]; then + echo " [*] cuQuantum library is detected here: CUQUANTUM_ROOT=$CUQUANTUM_ROOT." + write_action_env_to_bazelrc "CUQUANTUM_ROOT" ${CUQUANTUM_ROOT} + else + echo " [*] cuQuantum library is NOT detected. Using general CUDA ops..." + fi +fi # Check if it's installed if [[ $(pip show tensorflow) == *tensorflow* ]] || [[ $(pip show tf-nightly) == *tf-nightly* ]]; then From 2e29308fce31769259bd466cec59ecc3f579cf51 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 29 Mar 2023 18:39:38 -0700 Subject: [PATCH 004/106] Fix errors --- WORKSPACE | 6 +++--- .../core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc | 2 +- third_party/cuquantum/cuquantum_configure.bzl | 8 ++++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index e2e82e2b5..79fdbb846 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -34,9 +34,9 @@ cc_library( # TODO: After merging this patch later into qsim mainstream, remove this and uncomment the above. http_archive( name = "qsim", - sha256 = "", - strip_prefix = "qsim-0.15.0-dev20230327_v3", - urls = ["https://github.com/jaeyoo/qsim/archive/refs/tags/v0.15.0+dev20230327_v3.tar.gz"], + sha256 = "7d031865c1959c20ae12337b5c3b9420c54c25aac12a1bcf886f61be52b6e347", + strip_prefix = "qsim-0.15.0-dev20230330", + urls = ["https://github.com/jaeyoo/qsim/archive/refs/tags/v0.15.0+dev20230330.tar.gz"], ) http_archive( diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc index 61ba96d79..7119dafab 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc @@ -14,8 +14,8 @@ limitations under the License. #include #include +#include -#include "../cuquantum_libs/include/custatevec.h" #include "../qsim/lib/circuit.h" #include "../qsim/lib/gate_appl.h" #include "../qsim/lib/gates_cirq.h" diff --git a/third_party/cuquantum/cuquantum_configure.bzl b/third_party/cuquantum/cuquantum_configure.bzl index 81bc82ebb..bfe9abe2b 100644 --- a/third_party/cuquantum/cuquantum_configure.bzl +++ b/third_party/cuquantum/cuquantum_configure.bzl @@ -120,10 +120,14 @@ def _symlink_genrule_for_dir( genrule target that creates the symlinks. """ if is_empty_genrule: + if dest_dir != "": + target_path = "%s/%s.h" % (dest_dir, genrule_name) + else: + target_path = genrule_name genrule = _genrule( genrule_name, - "echo 'this genrule is empty because CUQUANTUM_ROOT is not set.' && touch %s.h" % genrule_name, - "'%s.h'" % genrule_name, + "echo 'this genrule %s is empty because CUQUANTUM_ROOT is not set.' && touch %s" % (genrule_name, target_path), + "'%s'" % (target_path), ) return genrule From 67b8e81196d3e535a298b9f1e218b6f5c6f7f8e0 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 29 Mar 2023 21:22:20 -0700 Subject: [PATCH 005/106] Split cuda/cuquantum and fix cuquantum_configure error --- WORKSPACE | 6 +- release/setup.py | 2 +- tensorflow_quantum/core/ops/BUILD | 18 +++- ..._test.py => tfq_simulate_ops_cuda_test.py} | 45 --------- .../ops/tfq_simulate_ops_cuquantum_test.py | 92 +++++++++++++++++++ third_party/cuquantum/BUILD.tpl | 3 +- third_party/cuquantum/cuquantum_configure.bzl | 16 +--- 7 files changed, 113 insertions(+), 69 deletions(-) rename tensorflow_quantum/core/ops/{tfq_simulate_ops_gpu_test.py => tfq_simulate_ops_cuda_test.py} (64%) create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py diff --git a/WORKSPACE b/WORKSPACE index 79fdbb846..e2312c905 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -34,9 +34,9 @@ cc_library( # TODO: After merging this patch later into qsim mainstream, remove this and uncomment the above. http_archive( name = "qsim", - sha256 = "7d031865c1959c20ae12337b5c3b9420c54c25aac12a1bcf886f61be52b6e347", - strip_prefix = "qsim-0.15.0-dev20230330", - urls = ["https://github.com/jaeyoo/qsim/archive/refs/tags/v0.15.0+dev20230330.tar.gz"], + sha256 = "", + strip_prefix = "qsim-0.15.0-dev-20230330_v2", + urls = ["https://github.com/jaeyoo/qsim/archive/refs/tags/v0.15.0-dev+20230330_v2.tar.gz"], ) http_archive( diff --git a/release/setup.py b/release/setup.py index b3ff0ded7..191981565 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==0.13.1', 'cirq-google==0.13.1', 'sympy == 1.8', 'googleapis-common-protos==1.52.0', 'google-api-core==1.21.0', 'google-auth==1.18.0', 'protobuf==3.19.5' ] diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index 3aee6286c..a9b054039 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -668,15 +668,15 @@ py_library( ) py_test( - name = "tfq_simulate_ops_gpu_test", - srcs = ["tfq_simulate_ops_gpu_test.py"], + name = "tfq_simulate_ops_cuda_test", + srcs = ["tfq_simulate_ops_cuda_test.py"], deps = [ ":tfq_simulate_ops_cuda_py", - ":tfq_simulate_ops_cuquantum_py", ":tfq_simulate_ops_py", "//tensorflow_quantum/python:util", ], srcs_version = "PY3", + tags = ["cuda"], ) cc_binary( @@ -755,6 +755,18 @@ cc_binary( # alwayslink=1, ) +py_test( + name = "tfq_simulate_ops_cuquantum_test", + srcs = ["tfq_simulate_ops_cuquantum_test.py"], + deps = [ + ":tfq_simulate_ops_cuquantum_py", + ":tfq_simulate_ops_py", + "//tensorflow_quantum/python:util", + ], + srcs_version = "PY3", + tags = ["cuquantum"], +) + cc_binary( name = "_tfq_simulate_ops_cuquantum.so", srcs = [ diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py similarity index 64% rename from tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py rename to tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py index 62517be22..c5bc6086b 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py @@ -22,7 +22,6 @@ from tensorflow_quantum.core.ops import tfq_simulate_ops from tensorflow_quantum.core.ops import tfq_simulate_ops_cuda -from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum from tensorflow_quantum.python import util def measure_average_runtime(fn, tag, num_samples=10): @@ -84,50 +83,6 @@ def test_simulate_expectation_cpu_vs_cuda(self): # CUDA op should be faster than CPU op. self.assertGreater(cpu_avg_time, cuda_avg_time) - def test_simulate_expectation_cpu_vs_cuquantum(self): - """Make sure that cpu & gpu(cuquantum) ops have the same results.""" - n_qubits = 20 - batch_size = 5 - symbol_names = ['alpha'] - qubits = cirq.GridQubit.rect(1, n_qubits) - circuit_batch, resolver_batch = \ - util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, batch_size) - - circuit_batch_tensor = util.convert_to_tensor(circuit_batch) - - symbol_values_array = np.array( - [[resolver[symbol] - for symbol in symbol_names] - for resolver in resolver_batch]) - - pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) - pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) - - cpu_avg_time, res_cpu = measure_average_runtime( - lambda: tfq_simulate_ops.tfq_simulate_expectation( - circuit_batch_tensor, - symbol_names, symbol_values_array.astype(np.float64), - pauli_sums_tensor), - "CPU", - num_samples=100, - - ) - - cuda_avg_time, res_cuda = measure_average_runtime( - lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( - circuit_batch_tensor, - symbol_names, symbol_values_array.astype(np.float64), - pauli_sums_tensor), - "cuQuantum", - num_samples=100, - ) - - # The result should be the similar within a tolerance. - np.testing.assert_allclose(res_cpu, res_cuda, atol=1e-4) - - # cuQuantum op should be faster than CPU op. - self.assertGreater(cpu_avg_time, cuda_avg_time) if __name__ == "__main__": tf.test.main() \ No newline at end of file diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py new file mode 100644 index 000000000..79cae3a45 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -0,0 +1,92 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +"""Tests that specifically target tfq_simulate_ops_cu*.""" +import os +import time +import numpy as np +from absl.testing import parameterized +import tensorflow as tf +import cirq + +from tensorflow_quantum.core.ops import tfq_simulate_ops +from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum +from tensorflow_quantum.python import util + +def measure_average_runtime(fn, tag, num_samples=10): + avg_time = [] + for _ in range(num_samples): + begin_time = time.time() + result = fn() + duration = time.time() - begin_time + avg_time.append(duration) + avg_time = sum(avg_time) / float(num_samples) + print(f"\n\t{tag} time: {avg_time}\n") + return avg_time, result + + +class SimulateExpectationCuquantumTest(tf.test.TestCase): + """Tests tfq_simulate_expectation.""" + + def test_simulate_expectation_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + cpu_avg_time, res_cpu = measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_expectation( + circuit_batch_tensor, + symbol_names, symbol_values_array.astype(np.float64), + pauli_sums_tensor), + "CPU", + num_samples=100, + ) + + cuquantum_avg_time, res_cuquantum = measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + circuit_batch_tensor, + symbol_names, symbol_values_array.astype(np.float64), + pauli_sums_tensor), + "cuQuantum", + num_samples=100, + ) + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, res_cuquantum, atol=1e-4, err_msg=""" + # If failed, the GPU architecture in this system may be unsupported. + # Please refer to the supported architectures here. + # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec + """) + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuquantum_avg_time) + + +if __name__ == "__main__": + tf.test.main() \ No newline at end of file diff --git a/third_party/cuquantum/BUILD.tpl b/third_party/cuquantum/BUILD.tpl index 462b83631..1081bba8f 100644 --- a/third_party/cuquantum/BUILD.tpl +++ b/third_party/cuquantum/BUILD.tpl @@ -4,6 +4,7 @@ cc_library( name = "cuquantum_headers", linkstatic = 1, srcs = [":cuquantum_header_include"], + includes = ["include"], visibility = ["//visibility:public"], ) @@ -11,11 +12,9 @@ cc_library( name = "libcuquantum", srcs = [ ":libcustatevec.so", - ":libcutensornet.so", ], visibility = ["//visibility:public"], ) %{CUQUANTUM_HEADER_GENRULE} %{CUSTATEVEC_SHARED_LIBRARY_GENRULE} -%{CUTENSORNET_SHARED_LIBRARY_GENRULE} \ No newline at end of file diff --git a/third_party/cuquantum/cuquantum_configure.bzl b/third_party/cuquantum/cuquantum_configure.bzl index bfe9abe2b..2eb1fb11b 100644 --- a/third_party/cuquantum/cuquantum_configure.bzl +++ b/third_party/cuquantum/cuquantum_configure.bzl @@ -126,7 +126,7 @@ def _symlink_genrule_for_dir( target_path = genrule_name genrule = _genrule( genrule_name, - "echo 'this genrule %s is empty because CUQUANTUM_ROOT is not set.' && touch %s" % (genrule_name, target_path), + "touch $(OUTS)", "'%s'" % (target_path), ) return genrule @@ -185,25 +185,11 @@ def _cuquantum_pip_imple(repository_ctx): ["libcustatevec.so"], is_empty_genrule=is_empty_genrule, ) - - cutensornet_shared_library_path = "%s/lib/libcutensornet.so" % (cuquantum_root) - - cutensornet_shared_library_rule = _symlink_genrule_for_dir( - repository_ctx, - None, - "", - "libcutensornet.so", - [cutensornet_shared_library_path], - ["libcutensornet.so"], - is_empty_genrule=is_empty_genrule, - ) _tpl(repository_ctx, "BUILD", { "%{CUQUANTUM_HEADER_GENRULE}": cuquantum_header_rule, "%{CUSTATEVEC_SHARED_LIBRARY_GENRULE}": custatevec_shared_library_rule, - "%{CUTENSORNET_SHARED_LIBRARY_GENRULE}": cutensornet_shared_library_rule, }) - cuquantum_configure = repository_rule( From dcf189f0f34972ad4dcf8989aaecfcc1fd91e1af Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Thu, 30 Mar 2023 04:58:05 +0000 Subject: [PATCH 006/106] modify kernels and add python wrapper file --- .../core/ops/tfq_simulate_ops_cuquantum.py | 91 ++++++++++++++++++- ...ate_sampled_expectation_op_cuquantum.cu.cc | 10 +- .../tfq_simulate_samples_op_cuquantum.cu.cc | 4 +- .../ops/tfq_simulate_state_op_cuquantum.cu.cc | 10 +- 4 files changed, 102 insertions(+), 13 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py index 127d4f56b..16daa16d7 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py @@ -42,4 +42,93 @@ def tfq_simulate_expectation(programs, symbol_names, symbol_values, pauli_sums): (after resolving the corresponding parameters in). """ return SIM_OP_MODULE.tfq_simulate_expectation_cuquantum( - programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums) \ No newline at end of file + programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums) + +def tfq_simulate_state(programs, symbol_names, symbol_values): + """Returns the state of the programs using the C++ state vector simulator. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + Returns: + A `tf.Tensor` containing the final state of each circuit in `programs`. + """ + return SIM_OP_MODULE.tfq_simulate_state_cuquantum(programs, symbol_names, + tf.cast(symbol_values, tf.float32)) + + +def tfq_simulate_samples(programs, symbol_names, symbol_values, num_samples): + """Generate samples using the C++ state vector simulator. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + From there we will then sample from the final state using native tensorflow + operations. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specified by programs, following the ordering + dictated by `symbol_names`. + num_samples: `tf.Tensor` with one element indicating the number of + samples to draw. + Returns: + A `tf.Tensor` containing the samples taken from each circuit in + `programs`. + """ + return SIM_OP_MODULE.tfq_simulate_samples_cuquantum( + programs, symbol_names, tf.cast(symbol_values, tf.float32), num_samples) + + +def tfq_simulate_sampled_expectation(programs, symbol_names, symbol_values, + pauli_sums, num_samples): + """Calculate the expectation value of circuits using samples. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + Them, sample the resulting state `num_samples` times and use these samples + to compute expectation values of the given `pauli_sums`. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] + containing the string representation of the operators that will + be used on all of the circuits in the expectation calculations. + num_samples: `tf.Tensor` with `num_samples[i][j]` is equal to the + number of samples to draw in each term of `pauli_sums[i][j]` + when estimating the expectation. Therefore, `num_samples` must + have the same shape as `pauli_sums`. + Returns: + `tf.Tensor` with shape [batch_size, n_ops] that holds the + expectation value for each circuit with each op applied to it + (after resolving the corresponding parameters in). + """ + return SIM_OP_MODULE.tfq_simulate_sampled_expectation_cuquantum( + programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums, + tf.cast(num_samples, dtype=tf.int32)) \ No newline at end of file diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index 979ec1da2..3643319af 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -51,9 +51,9 @@ using ::tfq::proto::Program; typedef qsim::Cirq::GateCirq QsimGate; typedef qsim::Circuit QsimCircuit; -class TfqSimulateSampledExpectationGpuOp : public tensorflow::OpKernel { +class TfqSimulateSampledExpectationCuquantumOp : public tensorflow::OpKernel { public: - explicit TfqSimulateSampledExpectationGpuOp( + explicit TfqSimulateSampledExpectationCuquantumOp( tensorflow::OpKernelConstruction* context) : OpKernel(context) {} @@ -312,10 +312,10 @@ class TfqSimulateSampledExpectationGpuOp : public tensorflow::OpKernel { }; REGISTER_KERNEL_BUILDER( - Name("TfqSimulateSampledExpectationGpu").Device(tensorflow::DEVICE_CPU), - TfqSimulateSampledExpectationGpuOp); + Name("TfqSimulateSampledExpectationCuquantum").Device(tensorflow::DEVICE_CPU), + TfqSimulateSampledExpectationCuquantumOp); -REGISTER_OP("TfqSimulateSampledExpectationGpu") +REGISTER_OP("TfqSimulateSampledExpectationCuquantum") .Input("programs: string") .Input("symbol_names: string") .Input("symbol_values: float") diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc index 245b2f5a8..7157b5582 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -264,10 +264,10 @@ class TfqSimulateSamplesGpuOp : public tensorflow::OpKernel { }; REGISTER_KERNEL_BUILDER( - Name("TfqSimulateSamplesGpu").Device(tensorflow::DEVICE_CPU), + Name("TfqSimulateSamplesCuquantum").Device(tensorflow::DEVICE_CPU), TfqSimulateSamplesGpuOp); -REGISTER_OP("TfqSimulateSamplesGpu") +REGISTER_OP("TfqSimulateSamplesCuquantum") .Input("programs: string") .Input("symbol_names: string") .Input("symbol_values: float") diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc index 8e0d3b7d4..cd56dbde6 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc @@ -46,9 +46,9 @@ using ::tfq::proto::Program; typedef qsim::Cirq::GateCirq QsimGate; typedef qsim::Circuit QsimCircuit; -class TfqSimulateStateGpuOp : public tensorflow::OpKernel { +class TfqSimulateStateCuquantumOp : public tensorflow::OpKernel { public: - explicit TfqSimulateStateGpuOp(tensorflow::OpKernelConstruction* context) + explicit TfqSimulateStateCuquantumOp(tensorflow::OpKernelConstruction* context) : OpKernel(context) {} void Compute(tensorflow::OpKernelContext* context) override { @@ -227,10 +227,10 @@ class TfqSimulateStateGpuOp : public tensorflow::OpKernel { } }; -REGISTER_KERNEL_BUILDER(Name("TfqSimulateStateGpu").Device(tensorflow::DEVICE_CPU), - TfqSimulateStateGpuOp); +REGISTER_KERNEL_BUILDER(Name("TfqSimulateStateCuquantum").Device(tensorflow::DEVICE_CPU), + TfqSimulateStateCuquantumOp); -REGISTER_OP("TfqSimulateStateGpu") +REGISTER_OP("TfqSimulateStateCuquantum") .Input("programs: string") .Input("symbol_names: string") .Input("symbol_values: float") From 3eae118c2aa9a1f27f92353f5e29c645bd9e2bcd Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Thu, 30 Mar 2023 05:09:45 +0000 Subject: [PATCH 007/106] linting --- tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py | 1 - .../core/ops/tfq_simulate_ops_cuquantum.py | 1 - tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py | 9 +++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py index e6860b028..3c5e9057b 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py @@ -13,7 +13,6 @@ # limitations under the License. # ============================================================================== """Module to register cuda simulation python op.""" -import os import tensorflow as tf from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py index 16daa16d7..bb74319a5 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py @@ -13,7 +13,6 @@ # limitations under the License. # ============================================================================== """Module to register cuQuantum simulation python op.""" -import os import tensorflow as tf from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py index 62517be22..af9022678 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py @@ -13,10 +13,8 @@ # limitations under the License. # ============================================================================== """Tests that specifically target tfq_simulate_ops_cu*.""" -import os import time import numpy as np -from absl.testing import parameterized import tensorflow as tf import cirq @@ -26,6 +24,10 @@ from tensorflow_quantum.python import util def measure_average_runtime(fn, tag, num_samples=10): + """ + Measures the average runtime of a function and returns the result + and average runtime in seconds. + """ avg_time = [] for _ in range(num_samples): begin_time = time.time() @@ -111,9 +113,8 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): pauli_sums_tensor), "CPU", num_samples=100, - ) - + cuda_avg_time, res_cuda = measure_average_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( circuit_batch_tensor, From c5e023527444bebf82f6fd28f48963a3d7c7c2d4 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 29 Mar 2023 22:44:28 -0700 Subject: [PATCH 008/106] Add simulate cuquantum ops --- WORKSPACE | 2 +- tensorflow_quantum/core/ops/BUILD | 23 +- .../tfq_simulate_expectation_op_cuda.cu.cc | 3 +- ...fq_simulate_expectation_op_cuquantum.cu.cc | 3 +- .../core/ops/tfq_simulate_ops_cuquantum.py | 92 ++++++- .../ops/tfq_simulate_ops_cuquantum_test.py | 169 +++++++++++- ...ate_sampled_expectation_op_cuquantum.cu.cc | 246 ++++++++++++++++++ .../tfq_simulate_samples_op_cuquantum.cu.cc | 224 ++++++++++++++++ .../ops/tfq_simulate_state_op_cuquantum.cu.cc | 207 +++++++++++++++ 9 files changed, 958 insertions(+), 11 deletions(-) create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc diff --git a/WORKSPACE b/WORKSPACE index e2312c905..7a6cdd229 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -34,7 +34,7 @@ cc_library( # TODO: After merging this patch later into qsim mainstream, remove this and uncomment the above. http_archive( name = "qsim", - sha256 = "", + sha256 = "75d62843020f8a70cf2aac85aca5e25fa6c1cea0945323afd06c3b7fcf3ee2b7", strip_prefix = "qsim-0.15.0-dev-20230330_v2", urls = ["https://github.com/jaeyoo/qsim/archive/refs/tags/v0.15.0-dev+20230330_v2.tar.gz"], ) diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index a9b054039..bbf17d2a4 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -717,6 +717,7 @@ cc_binary( "/wd4577", "/DNOGDI", "/UTF_COMPILE_LIBRARY", + "/D__CUDA__", ], "//conditions:default": [ "-Iexternal/local_cuda/cuda/include", @@ -733,7 +734,14 @@ cc_binary( "-DNV_CUDNN_DISABLE_EXCEPTION", # "-fpermissive", ], - }) + if_cuda_is_configured(["-DTENSORFLOW_USE_NVCC=1", "-DGOOGLE_CUDA=1", "-x cuda", "-nvcc_options=relaxed-constexpr", "-nvcc_options=ftz=true"]), + }) + if_cuda_is_configured([ + "-DTENSORFLOW_USE_NVCC=1", + "-DGOOGLE_CUDA=1", + "-x cuda", + "-nvcc_options=relaxed-constexpr", + "-nvcc_options=ftz=true", + "-D__CUDA__", + ]), deps = [ # cirq cc proto "//tensorflow_quantum/core/ops:parse_context", @@ -771,6 +779,9 @@ cc_binary( name = "_tfq_simulate_ops_cuquantum.so", srcs = [ "tfq_simulate_expectation_op_cuquantum.cu.cc", + "tfq_simulate_sampled_expectation_op_cuquantum.cu.cc", + "tfq_simulate_samples_op_cuquantum.cu.cc", + "tfq_simulate_state_op_cuquantum.cu.cc", ], linkshared = 1, features = select({ @@ -805,6 +816,7 @@ cc_binary( "/wd4577", "/DNOGDI", "/UTF_COMPILE_LIBRARY", + "/D__CUSTATEVEC__", ], "//conditions:default": [ "-Iexternal/local_cuda/cuda/include", @@ -821,7 +833,14 @@ cc_binary( "-DNV_CUDNN_DISABLE_EXCEPTION", # "-fpermissive", ], - }) + if_cuda_is_configured(["-DTENSORFLOW_USE_NVCC=1", "-DGOOGLE_CUDA=1", "-x cuda", "-nvcc_options=relaxed-constexpr", "-nvcc_options=ftz=true"]), + }) + if_cuda_is_configured([ + "-DTENSORFLOW_USE_NVCC=1", + "-DGOOGLE_CUDA=1", + "-x cuda", + "-nvcc_options=relaxed-constexpr", + "-nvcc_options=ftz=true", + "-D__CUSTATEVEC__", + ]), deps = [ # cirq cc proto "//tensorflow_quantum/core/ops:parse_context", diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuda.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuda.cu.cc index 271df7f5c..75f05d88f 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuda.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuda.cu.cc @@ -20,8 +20,7 @@ limitations under the License. #include "../qsim/lib/gates_cirq.h" #include "../qsim/lib/gates_qsim.h" #include "../qsim/lib/seqfor.h" -#include "../qsim/lib/simulator_cuda.h" -#include "../qsim/lib/statespace_cuda.h" +#include "../qsim/lib/simmux.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/shape_inference.h" #include "tensorflow/core/framework/tensor_shape.h" diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc index 35b288414..cbd3b3b53 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc @@ -21,8 +21,7 @@ limitations under the License. #include "../qsim/lib/gates_cirq.h" #include "../qsim/lib/gates_qsim.h" #include "../qsim/lib/seqfor.h" -#include "../qsim/lib/simulator_custatevec.h" -#include "../qsim/lib/statespace_custatevec.h" +#include "../qsim/lib/simmux.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/shape_inference.h" #include "tensorflow/core/framework/tensor_shape.h" diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py index 127d4f56b..e1596d4be 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py @@ -42,4 +42,94 @@ def tfq_simulate_expectation(programs, symbol_names, symbol_values, pauli_sums): (after resolving the corresponding parameters in). """ return SIM_OP_MODULE.tfq_simulate_expectation_cuquantum( - programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums) \ No newline at end of file + programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums) + + +def tfq_simulate_state(programs, symbol_names, symbol_values): + """Returns the state of the programs using the C++ state vector simulator. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + Returns: + A `tf.Tensor` containing the final state of each circuit in `programs`. + """ + return SIM_OP_MODULE.tfq_simulate_state_cuquantum(programs, symbol_names, + tf.cast(symbol_values, tf.float32)) + + +def tfq_simulate_samples(programs, symbol_names, symbol_values, num_samples): + """Generate samples using the C++ state vector simulator. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + From there we will then sample from the final state using native tensorflow + operations. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specified by programs, following the ordering + dictated by `symbol_names`. + num_samples: `tf.Tensor` with one element indicating the number of + samples to draw. + Returns: + A `tf.Tensor` containing the samples taken from each circuit in + `programs`. + """ + return SIM_OP_MODULE.tfq_simulate_samples_cuquantum( + programs, symbol_names, tf.cast(symbol_values, tf.float32), num_samples) + + +def tfq_simulate_sampled_expectation(programs, symbol_names, symbol_values, + pauli_sums, num_samples): + """Calculate the expectation value of circuits using samples. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + Them, sample the resulting state `num_samples` times and use these samples + to compute expectation values of the given `pauli_sums`. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] + containing the string representation of the operators that will + be used on all of the circuits in the expectation calculations. + num_samples: `tf.Tensor` with `num_samples[i][j]` is equal to the + number of samples to draw in each term of `pauli_sums[i][j]` + when estimating the expectation. Therefore, `num_samples` must + have the same shape as `pauli_sums`. + Returns: + `tf.Tensor` with shape [batch_size, n_ops] that holds the + expectation value for each circuit with each op applied to it + (after resolving the corresponding parameters in). + """ + return SIM_OP_MODULE.tfq_simulate_sampled_expectation_cuquantum( + programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums, + tf.cast(num_samples, dtype=tf.int32)) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 79cae3a45..2e8363a35 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -24,15 +24,25 @@ from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum from tensorflow_quantum.python import util -def measure_average_runtime(fn, tag, num_samples=10): +def measure_average_runtime( + fn, + tag, + num_samples=10, + result_avg=False, + ): avg_time = [] + avg_res = [] for _ in range(num_samples): begin_time = time.time() result = fn() duration = time.time() - begin_time avg_time.append(duration) + if result_avg: + avg_res.append(result) avg_time = sum(avg_time) / float(num_samples) print(f"\n\t{tag} time: {avg_time}\n") + if result_avg: + result = np.average(avg_res, axis=0) return avg_time, result @@ -65,7 +75,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor), "CPU", - num_samples=100, + num_samples=10, ) cuquantum_avg_time, res_cuquantum = measure_average_runtime( @@ -74,9 +84,12 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor), "cuQuantum", - num_samples=100, + num_samples=10, ) + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuquantum_avg_time) + # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, res_cuquantum, atol=1e-4, err_msg=""" # If failed, the GPU architecture in this system may be unsupported. @@ -84,9 +97,159 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec """) + +class SimulateSampledExpectationCuquantumTest(tf.test.TestCase): + """Tests tfq_simulate_sampled_expectation.""" + + def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + n_samples = [[100]] * batch_size + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + cpu_avg_time, res_cpu = measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_sampled_expectation( + circuit_batch_tensor, + symbol_names, symbol_values_array.astype(np.float64), + pauli_sums_tensor, n_samples), + "CPU", + num_samples=10, + ) + + cuquantum_avg_time, res_cuquantum = measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + circuit_batch_tensor, + symbol_names, symbol_values_array.astype(np.float64), + pauli_sums_tensor, n_samples), + "cuQuantum", + num_samples=10, + ) + # cuQuantum op should be faster than CPU op. self.assertGreater(cpu_avg_time, cuquantum_avg_time) + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, res_cuquantum, atol=1e-4, err_msg=""" + # If failed, the GPU architecture in this system may be unsupported. + # Please refer to the supported architectures here. + # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec + """) + + +class SimulateSamplesCuquantumTest(tf.test.TestCase): + """Tests tfq_simulate_samples.""" + + def test_simulate_samples_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + n_samples = [100] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cpu_avg_time, res_cpu = measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_samples( + circuit_batch_tensor, + symbol_names, symbol_values_array.astype(np.float64), + n_samples), + "CPU", + num_samples=10, + result_avg=True, + ) + + cuquantum_avg_time, res_cuquantum = measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_samples( + circuit_batch_tensor, + symbol_names, symbol_values_array.astype(np.float64), + n_samples), + "cuQuantum", + num_samples=10, + result_avg=True, + ) + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuquantum_avg_time) + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, res_cuquantum, atol=1e-4, err_msg=""" + # If failed, the GPU architecture in this system may be unsupported. + # Please refer to the supported architectures here. + # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec + """) + + +class SimulateStateCuquantumTest(tf.test.TestCase): + """Tests tfq_simulate_samples.""" + + def test_simulate_state_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 10 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cpu_avg_time, res_cpu = measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_state( + circuit_batch_tensor, + symbol_names, symbol_values_array.astype(np.float64)), + "CPU", + num_samples=10, + ) + + cuquantum_avg_time, res_cuquantum = measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_state( + circuit_batch_tensor, + symbol_names, symbol_values_array.astype(np.float64)), + "cuQuantum", + num_samples=10, + ) + + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuquantum_avg_time) + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, res_cuquantum, atol=1e-4, err_msg=""" + # If failed, the GPU architecture in this system may be unsupported. + # Please refer to the supported architectures here. + # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec + """) + if __name__ == "__main__": tf.test.main() \ No newline at end of file diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc new file mode 100644 index 000000000..cb656a48b --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -0,0 +1,246 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#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/pauli_sum.pb.h" +#include "tensorflow_quantum/core/proto/program.pb.h" +#include "tensorflow_quantum/core/src/util_qsim.h" + +#include "tensorflow/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/util/guarded_philox_random.h" + +namespace tfq { + +using ::tensorflow::Status; +using ::tfq::proto::PauliSum; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { + public: + explicit TfqSimulateSampledExpectationOpCuQuantum( + tensorflow::OpKernelConstruction* context) + : OpKernel(context) {} + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + const int num_inputs = context->num_inputs(); + OP_REQUIRES(context, num_inputs == 5, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Expected 5 inputs, got ", num_inputs, " inputs."))); + + // Create the output Tensor. + const int output_dim_batch_size = context->input(0).dim_size(0); + const int output_dim_op_size = context->input(3).dim_size(1); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_batch_size); + output_shape.AddDim(output_dim_op_size); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->matrix(); + + std::vector programs; + std::vector num_qubits; + std::vector> pauli_sums; + OP_REQUIRES_OK(context, GetProgramsAndNumQubits(context, &programs, + &num_qubits, &pauli_sums)); + + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + + OP_REQUIRES(context, programs.size() == maps.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and symbol_values do not match. Got ", + programs.size(), " circuits and ", maps.size(), + " symbol values."))); + + std::vector> num_samples; + OP_REQUIRES_OK(context, GetNumSamples(context, &num_samples)); + + OP_REQUIRES(context, num_samples.size() == pauli_sums.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Dimension 0 of num_samples and pauli_sums do not match.", + "Got ", num_samples.size(), " lists of sample sizes and ", + pauli_sums.size(), " lists of pauli sums."))); + + OP_REQUIRES( + context, context->input(4).dim_size(1) == context->input(3).dim_size(1), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Dimension 1 of num_samples and pauli_sums do not match.", "Got ", + context->input(4).dim_size(1), " lists of sample sizes and ", + context->input(3).dim_size(1), " lists of pauli sums."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> fused_circuits( + programs.size(), std::vector>({})); + + Status parse_status = Status::OK(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + ComputeLarge(num_qubits, fused_circuits, pauli_sums, num_samples, context, + &output_tensor); + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } + + private: + cublasHandle_t cublas_handle_; + custatevecHandle_t custatevec_handle_; + + void ComputeLarge( + const std::vector& num_qubits, + const std::vector>>& fused_circuits, + const std::vector>& pauli_sums, + const std::vector>& num_samples, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + auto scratch = ss.Create(largest_nq); + + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + int largest_sum = -1; + for (const auto& sums : pauli_sums) { + for (const auto& sum : sums) { + largest_sum = std::max(largest_sum, sum.terms().size()); + } + } + auto local_gen = random_gen.ReserveSamples32( + largest_sum * pauli_sums[0].size() * fused_circuits.size() + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as necessary. + for (int i = 0; i < fused_circuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + } + // TODO: add heuristic here so that we do not always recompute + // the state if there is a possibility that circuit[i] and + // circuit[i + 1] produce the same state. + ss.SetStateZero(sv); + for (int j = 0; j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + for (int j = 0; j < pauli_sums[i].size(); j++) { + // (#679) Just ignore empty program + if (fused_circuits[i].size() == 0) { + (*output_tensor)(i, j) = -2.0; + continue; + } + float exp_v = 0.0; + OP_REQUIRES_OK(context, ComputeSampledExpectationQsim( + pauli_sums[i][j], sim, ss, sv, scratch, + num_samples[i][j], rand_source, &exp_v)); + (*output_tensor)(i, j) = exp_v; + } + } + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqSimulateSampledExpectationCuquantum").Device(tensorflow::DEVICE_CPU), + TfqSimulateSampledExpectationOpCuQuantum); + +REGISTER_OP("TfqSimulateSampledExpectationCuquantum") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("pauli_sums: string") + .Input("num_samples: int32") + .Output("expectations: float") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle pauli_sums_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 2, &pauli_sums_shape)); + + tensorflow::shape_inference::ShapeHandle num_samples_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(4), 2, &num_samples_shape)); + + tensorflow::shape_inference::DimensionHandle output_rows = + c->Dim(programs_shape, 0); + tensorflow::shape_inference::DimensionHandle output_cols = + c->Dim(pauli_sums_shape, 1); + c->set_output(0, c->Matrix(output_rows, output_cols)); + + return tensorflow::Status::OK(); + }); + +} // namespace tfq \ No newline at end of file diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc new file mode 100644 index 000000000..f2e2b15b8 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -0,0 +1,224 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include +#include +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/platform/mutex.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 ::tensorflow::Status; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { + public: + explicit TfqSimulateSamplesOpCuQuantum(tensorflow::OpKernelConstruction* context) + : OpKernel(context) {} + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + DCHECK_EQ(4, context->num_inputs()); + + // Parse to Program Proto and num_qubits. + std::vector programs; + std::vector num_qubits; + OP_REQUIRES_OK(context, + GetProgramsAndNumQubits(context, &programs, &num_qubits)); + + // Parse symbol maps for parameter resolution in the circuits. + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + OP_REQUIRES( + context, maps.size() == programs.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and values do not match. Got ", programs.size(), + " circuits and ", maps.size(), " values."))); + + int num_samples = 0; + OP_REQUIRES_OK(context, GetIndividualSample(context, &num_samples)); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> fused_circuits( + programs.size(), std::vector>({})); + + Status parse_status = Status::OK(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + // Find largest circuit for tensor size padding and allocate + // the output tensor. + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + const int output_dim_size = maps.size(); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_size); + output_shape.AddDim(num_samples); + output_shape.AddDim(max_num_qubits); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->tensor(); + + if (num_samples == 0) { + return; // bug in qsim dependency we can't control. + } + + // create handles for simulator + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + ComputeLarge(num_qubits, max_num_qubits, num_samples, fused_circuits, + context, &output_tensor); + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } + + private: + cublasHandle_t cublas_handle_; + custatevecHandle_t custatevec_handle_; + + void ComputeLarge( + const std::vector& num_qubits, const int max_num_qubits, + const int num_samples, + const std::vector>>& fused_circuits, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Tensor* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + auto local_gen = random_gen.ReserveSamples32(fused_circuits.size() + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as nescessary. + for (int i = 0; i < fused_circuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + } + ss.SetStateZero(sv); + for (int j = 0; j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + + auto samples = ss.Sample(sv, num_samples, rand_source.Rand32()); + for (int j = 0; j < num_samples; j++) { + uint64_t q_ind = 0; + uint64_t mask = 1; + bool val = 0; + while (q_ind < nq) { + val = samples[j] & mask; + (*output_tensor)( + i, j, static_cast(max_num_qubits - q_ind - 1)) = val; + q_ind++; + mask <<= 1; + } + while (q_ind < max_num_qubits) { + (*output_tensor)( + i, j, static_cast(max_num_qubits - q_ind - 1)) = -2; + q_ind++; + } + } + } + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqSimulateSamplesCuquantum").Device(tensorflow::DEVICE_CPU), + TfqSimulateSamplesOpCuQuantum); + +REGISTER_OP("TfqSimulateSamplesCuquantum") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("num_samples: int32") + .Output("samples: int8") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle num_samples_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 1, &num_samples_shape)); + + // [batch_size, n_samples, largest_n_qubits] + c->set_output( + 0, c->MakeShape( + {c->Dim(programs_shape, 0), + tensorflow::shape_inference::InferenceContext::kUnknownDim, + tensorflow::shape_inference::InferenceContext::kUnknownDim})); + + return tensorflow::Status::OK(); + }); + +} // namespace tfq \ No newline at end of file diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc new file mode 100644 index 000000000..7a9e0264a --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc @@ -0,0 +1,207 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#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 ::tensorflow::Status; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { + public: + explicit TfqSimulateStateOpCuQuantum(tensorflow::OpKernelConstruction* context) + : OpKernel(context) {} + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + DCHECK_EQ(3, context->num_inputs()); + + // Parse to Program Proto and num_qubits. + std::vector programs; + std::vector num_qubits; + OP_REQUIRES_OK(context, + GetProgramsAndNumQubits(context, &programs, &num_qubits)); + + // Parse symbol maps for parameter resolution in the circuits. + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + OP_REQUIRES( + context, maps.size() == programs.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and values do not match. Got ", programs.size(), + " circuits and ", maps.size(), " values."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> fused_circuits( + programs.size(), std::vector>({})); + + Status parse_status = Status::OK(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + // Find largest circuit for tensor size padding and allocate + // the output tensor. + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + const int output_dim_size = maps.size(); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_size); + output_shape.AddDim(1 << max_num_qubits); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + tensorflow::TTypes, 1>::Matrix output_tensor = + output->matrix>(); + + // Cross reference with standard google cloud compute instances + // Memory ~= 2 * num_threads * (2 * 64 * 2 ** num_qubits in circuits) + // e2s2 = 2 CPU, 8GB -> Can safely do 25 since Memory = 4GB + // e2s4 = 4 CPU, 16GB -> Can safely do 25 since Memory = 8GB + // ... + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + ComputeLarge(num_qubits, max_num_qubits, fused_circuits, context, + &output_tensor); + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + + } + + private: + cublasHandle_t cublas_handle_; + custatevecHandle_t custatevec_handle_; + + void ComputeLarge( + const std::vector& num_qubits, const int max_num_qubits, + const std::vector>>& fused_circuits, + tensorflow::OpKernelContext* context, + tensorflow::TTypes, 1>::Matrix* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as nescessary. + for (int i = 0; i < fused_circuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + } + ss.SetStateZero(sv); + for (int j = 0; j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + + // Parallel copy state vector information from qsim into tensorflow + // tensors. + auto copy_f = [i, nq, max_num_qubits, &output_tensor, &ss, &sv]( + uint64_t start, uint64_t end) { + uint64_t crossover = uint64_t(1) << nq; + uint64_t upper = std::min(end, crossover); + + if (start < crossover) { + for (uint64_t j = 0; j < upper; j++) { + (*output_tensor)(i, j) = ss.GetAmpl(sv, j); + } + } + for (uint64_t j = upper; j < end; j++) { + (*output_tensor)(i, j) = std::complex(-2, 0); + } + }; + const int num_cycles_copy = 50; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + uint64_t(1) << max_num_qubits, num_cycles_copy, copy_f); + } + } +}; + +REGISTER_KERNEL_BUILDER(Name("TfqSimulateStateCuquantum").Device(tensorflow::DEVICE_CPU), + TfqSimulateStateOpCuQuantum); + +REGISTER_OP("TfqSimulateStateCuquantum") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Output("state_vector: complex64") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + c->set_output( + 0, c->MakeShape( + {c->Dim(programs_shape, 0), + tensorflow::shape_inference::InferenceContext::kUnknownDim})); + + return tensorflow::Status::OK(); + }); + +} // namespace tfq \ No newline at end of file From 41c18394c962d6dfba22c6f9a3623b468d07203e Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 29 Mar 2023 22:49:22 -0700 Subject: [PATCH 009/106] Fix lint and format --- .../tfq_simulate_expectation_op_cuda.cu.cc | 8 +- ...fq_simulate_expectation_op_cuquantum.cu.cc | 17 ++-- .../core/ops/tfq_simulate_ops_cuda.py | 1 - .../core/ops/tfq_simulate_ops_cuda_test.py | 15 ++- .../core/ops/tfq_simulate_ops_cuquantum.py | 5 +- .../ops/tfq_simulate_ops_cuquantum_test.py | 91 +++++++++++-------- ...ate_sampled_expectation_op_cuquantum.cu.cc | 19 ++-- .../tfq_simulate_samples_op_cuquantum.cu.cc | 5 +- .../ops/tfq_simulate_state_op_cuquantum.cu.cc | 17 ++-- 9 files changed, 94 insertions(+), 84 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuda.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuda.cu.cc index 75f05d88f..5fa048227 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuda.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuda.cu.cc @@ -10,11 +10,10 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ +#include #include #include -#include - #include "../qsim/lib/circuit.h" #include "../qsim/lib/gate_appl.h" #include "../qsim/lib/gates_cirq.h" @@ -42,10 +41,10 @@ using ::tfq::proto::Program; typedef qsim::Cirq::GateCirq QsimGate; typedef qsim::Circuit QsimCircuit; - class TfqSimulateExpectationOpCuda : public tensorflow::OpKernel { public: - explicit TfqSimulateExpectationOpCuda(tensorflow::OpKernelConstruction* context) + explicit TfqSimulateExpectationOpCuda( + tensorflow::OpKernelConstruction* context) : OpKernel(context) {} void Compute(tensorflow::OpKernelContext* context) override { @@ -168,7 +167,6 @@ class TfqSimulateExpectationOpCuda : public tensorflow::OpKernel { } } } - }; REGISTER_KERNEL_BUILDER( diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc index cbd3b3b53..1052dd0d1 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc @@ -10,11 +10,11 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include -#include +#include #include -#include +#include +#include #include "../qsim/lib/circuit.h" #include "../qsim/lib/gate_appl.h" @@ -43,14 +43,13 @@ using ::tfq::proto::Program; typedef qsim::Cirq::GateCirq QsimGate; typedef qsim::Circuit QsimCircuit; - class TfqSimulateExpectationOpCuQuantum : public tensorflow::OpKernel { public: - explicit TfqSimulateExpectationOpCuQuantum(tensorflow::OpKernelConstruction* context) + explicit TfqSimulateExpectationOpCuQuantum( + tensorflow::OpKernelConstruction* context) : OpKernel(context) {} void Compute(tensorflow::OpKernelContext* context) override { - // TODO (mbbrough): add more dimension checks for other inputs here. const int num_inputs = context->num_inputs(); OP_REQUIRES(context, num_inputs == 4, @@ -66,7 +65,7 @@ class TfqSimulateExpectationOpCuQuantum : public tensorflow::OpKernel { tensorflow::Tensor* output = nullptr; tensorflow::AllocatorAttributes alloc_attr; - alloc_attr.set_on_host(true); // why?? + alloc_attr.set_on_host(true); // why?? alloc_attr.set_gpu_compatible(true); OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output, alloc_attr)); @@ -74,7 +73,8 @@ class TfqSimulateExpectationOpCuQuantum : public tensorflow::OpKernel { // Parse program protos. std::vector programs; std::vector num_qubits; - std::vector> pauli_sums; // why is this a vector of vectors?? + std::vector> + pauli_sums; // why is this a vector of vectors?? OP_REQUIRES_OK(context, GetProgramsAndNumQubits(context, &programs, &num_qubits, &pauli_sums)); @@ -140,7 +140,6 @@ class TfqSimulateExpectationOpCuQuantum : public tensorflow::OpKernel { using Simulator = qsim::SimulatorCuStateVec; using StateSpace = Simulator::StateSpace; - // Launch the cuda kernel. // Begin simulation. int largest_nq = 1; diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py index e6860b028..3c5e9057b 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py @@ -13,7 +13,6 @@ # limitations under the License. # ============================================================================== """Module to register cuda simulation python op.""" -import os import tensorflow as tf from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py index c5bc6086b..fa0eda2e1 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py @@ -13,10 +13,8 @@ # limitations under the License. # ============================================================================== """Tests that specifically target tfq_simulate_ops_cu*.""" -import os import time import numpy as np -from absl.testing import parameterized import tensorflow as tf import cirq @@ -24,6 +22,7 @@ from tensorflow_quantum.core.ops import tfq_simulate_ops_cuda from tensorflow_quantum.python import util + def measure_average_runtime(fn, tag, num_samples=10): avg_time = [] for _ in range(num_samples): @@ -61,18 +60,16 @@ def test_simulate_expectation_cpu_vs_cuda(self): cpu_avg_time, res_cpu = measure_average_runtime( lambda: tfq_simulate_ops.tfq_simulate_expectation( - circuit_batch_tensor, - symbol_names, symbol_values_array.astype(np.float64), - pauli_sums_tensor), + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), "CPU", num_samples=100, ) cuda_avg_time, res_cuda = measure_average_runtime( lambda: tfq_simulate_ops_cuda.tfq_simulate_expectation( - circuit_batch_tensor, - symbol_names, symbol_values_array.astype(np.float64), - pauli_sums_tensor), + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), "CUDA", num_samples=100, ) @@ -85,4 +82,4 @@ def test_simulate_expectation_cpu_vs_cuda(self): if __name__ == "__main__": - tf.test.main() \ No newline at end of file + tf.test.main() diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py index e1596d4be..ba448d27e 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py @@ -13,7 +13,6 @@ # limitations under the License. # ============================================================================== """Module to register cuQuantum simulation python op.""" -import os import tensorflow as tf from tensorflow_quantum.core.ops.load_module import load_module @@ -65,8 +64,8 @@ def tfq_simulate_state(programs, symbol_names, symbol_values): Returns: A `tf.Tensor` containing the final state of each circuit in `programs`. """ - return SIM_OP_MODULE.tfq_simulate_state_cuquantum(programs, symbol_names, - tf.cast(symbol_values, tf.float32)) + return SIM_OP_MODULE.tfq_simulate_state_cuquantum( + programs, symbol_names, tf.cast(symbol_values, tf.float32)) def tfq_simulate_samples(programs, symbol_names, symbol_values, num_samples): diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 2e8363a35..6ead96a65 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -13,10 +13,8 @@ # limitations under the License. # ============================================================================== """Tests that specifically target tfq_simulate_ops_cu*.""" -import os import time import numpy as np -from absl.testing import parameterized import tensorflow as tf import cirq @@ -24,12 +22,24 @@ from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum from tensorflow_quantum.python import util + def measure_average_runtime( fn, tag, num_samples=10, result_avg=False, - ): +): + """Measures average runtime for given function. + + Args: + fn: function. + tag: The message title. + num_samples: The number of measurements. + result_avg: True if the results are all averaged. + + Returns: + The average time and the (averaged) result. + """ avg_time = [] avg_res = [] for _ in range(num_samples): @@ -38,11 +48,11 @@ def measure_average_runtime( duration = time.time() - begin_time avg_time.append(duration) if result_avg: - avg_res.append(result) + avg_res.append(result) avg_time = sum(avg_time) / float(num_samples) print(f"\n\t{tag} time: {avg_time}\n") if result_avg: - result = np.average(avg_res, axis=0) + result = np.average(avg_res, axis=0) return avg_time, result @@ -71,18 +81,16 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): cpu_avg_time, res_cpu = measure_average_runtime( lambda: tfq_simulate_ops.tfq_simulate_expectation( - circuit_batch_tensor, - symbol_names, symbol_values_array.astype(np.float64), - pauli_sums_tensor), + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), "CPU", num_samples=10, ) - + cuquantum_avg_time, res_cuquantum = measure_average_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( - circuit_batch_tensor, - symbol_names, symbol_values_array.astype(np.float64), - pauli_sums_tensor), + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), "cuQuantum", num_samples=10, ) @@ -91,7 +99,10 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): self.assertGreater(cpu_avg_time, cuquantum_avg_time) # The result should be the similar within a tolerance. - np.testing.assert_allclose(res_cpu, res_cuquantum, atol=1e-4, err_msg=""" + np.testing.assert_allclose(res_cpu, + res_cuquantum, + atol=1e-4, + err_msg=""" # If failed, the GPU architecture in this system may be unsupported. # Please refer to the supported architectures here. # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec @@ -124,18 +135,18 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): cpu_avg_time, res_cpu = measure_average_runtime( lambda: tfq_simulate_ops.tfq_simulate_sampled_expectation( - circuit_batch_tensor, - symbol_names, symbol_values_array.astype(np.float64), - pauli_sums_tensor, n_samples), + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor, + n_samples), "CPU", num_samples=10, ) - + cuquantum_avg_time, res_cuquantum = measure_average_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( - circuit_batch_tensor, - symbol_names, symbol_values_array.astype(np.float64), - pauli_sums_tensor, n_samples), + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor, + n_samples), "cuQuantum", num_samples=10, ) @@ -144,7 +155,10 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): self.assertGreater(cpu_avg_time, cuquantum_avg_time) # The result should be the similar within a tolerance. - np.testing.assert_allclose(res_cpu, res_cuquantum, atol=1e-4, err_msg=""" + np.testing.assert_allclose(res_cpu, + res_cuquantum, + atol=1e-4, + err_msg=""" # If failed, the GPU architecture in this system may be unsupported. # Please refer to the supported architectures here. # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec @@ -174,19 +188,17 @@ def test_simulate_samples_cpu_vs_cuquantum(self): cpu_avg_time, res_cpu = measure_average_runtime( lambda: tfq_simulate_ops.tfq_simulate_samples( - circuit_batch_tensor, - symbol_names, symbol_values_array.astype(np.float64), - n_samples), + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), n_samples), "CPU", num_samples=10, result_avg=True, ) - + cuquantum_avg_time, res_cuquantum = measure_average_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_samples( - circuit_batch_tensor, - symbol_names, symbol_values_array.astype(np.float64), - n_samples), + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), n_samples), "cuQuantum", num_samples=10, result_avg=True, @@ -196,7 +208,10 @@ def test_simulate_samples_cpu_vs_cuquantum(self): self.assertGreater(cpu_avg_time, cuquantum_avg_time) # The result should be the similar within a tolerance. - np.testing.assert_allclose(res_cpu, res_cuquantum, atol=1e-4, err_msg=""" + np.testing.assert_allclose(res_cpu, + res_cuquantum, + atol=1e-4, + err_msg=""" # If failed, the GPU architecture in this system may be unsupported. # Please refer to the supported architectures here. # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec @@ -225,26 +240,28 @@ def test_simulate_state_cpu_vs_cuquantum(self): cpu_avg_time, res_cpu = measure_average_runtime( lambda: tfq_simulate_ops.tfq_simulate_state( - circuit_batch_tensor, - symbol_names, symbol_values_array.astype(np.float64)), + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64)), "CPU", num_samples=10, ) - + cuquantum_avg_time, res_cuquantum = measure_average_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_state( - circuit_batch_tensor, - symbol_names, symbol_values_array.astype(np.float64)), + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64)), "cuQuantum", num_samples=10, ) - # cuQuantum op should be faster than CPU op. self.assertGreater(cpu_avg_time, cuquantum_avg_time) # The result should be the similar within a tolerance. - np.testing.assert_allclose(res_cpu, res_cuquantum, atol=1e-4, err_msg=""" + np.testing.assert_allclose(res_cpu, + res_cuquantum, + atol=1e-4, + err_msg=""" # If failed, the GPU architecture in this system may be unsupported. # Please refer to the supported architectures here. # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec @@ -252,4 +269,4 @@ def test_simulate_state_cpu_vs_cuquantum(self): if __name__ == "__main__": - tf.test.main() \ No newline at end of file + tf.test.main() diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index cb656a48b..1e31a62cc 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -13,11 +13,11 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include -#include +#include #include -#include +#include +#include #include "../qsim/lib/circuit.h" #include "../qsim/lib/gate_appl.h" @@ -30,16 +30,15 @@ limitations under the License. #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/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" #include "tensorflow/core/platform/mutex.h" +#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" -#include "tensorflow/core/lib/random/random.h" -#include "tensorflow/core/lib/random/simple_philox.h" -#include "tensorflow/core/util/guarded_philox_random.h" - namespace tfq { using ::tensorflow::Status; @@ -207,9 +206,9 @@ class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { } }; -REGISTER_KERNEL_BUILDER( - Name("TfqSimulateSampledExpectationCuquantum").Device(tensorflow::DEVICE_CPU), - TfqSimulateSampledExpectationOpCuQuantum); +REGISTER_KERNEL_BUILDER(Name("TfqSimulateSampledExpectationCuquantum") + .Device(tensorflow::DEVICE_CPU), + TfqSimulateSampledExpectationOpCuQuantum); REGISTER_OP("TfqSimulateSampledExpectationCuquantum") .Input("programs: string") diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc index f2e2b15b8..0e487fefd 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -13,10 +13,10 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ +#include #include #include -#include #include #include "../qsim/lib/circuit.h" @@ -49,7 +49,8 @@ typedef qsim::Circuit QsimCircuit; class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { public: - explicit TfqSimulateSamplesOpCuQuantum(tensorflow::OpKernelConstruction* context) + explicit TfqSimulateSamplesOpCuQuantum( + tensorflow::OpKernelConstruction* context) : OpKernel(context) {} void Compute(tensorflow::OpKernelContext* context) override { diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc index 7a9e0264a..a7f45acf5 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc @@ -13,11 +13,11 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include -#include +#include #include -#include +#include +#include #include "../qsim/lib/circuit.h" #include "../qsim/lib/gate_appl.h" @@ -46,7 +46,8 @@ typedef qsim::Circuit QsimCircuit; class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { public: - explicit TfqSimulateStateOpCuQuantum(tensorflow::OpKernelConstruction* context) + explicit TfqSimulateStateOpCuQuantum( + tensorflow::OpKernelConstruction* context) : OpKernel(context) {} void Compute(tensorflow::OpKernelContext* context) override { @@ -117,13 +118,12 @@ class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { &output_tensor); cublasDestroy(cublas_handle_); custatevecDestroy(custatevec_handle_); - } private: cublasHandle_t cublas_handle_; custatevecHandle_t custatevec_handle_; - + void ComputeLarge( const std::vector& num_qubits, const int max_num_qubits, const std::vector>>& fused_circuits, @@ -178,8 +178,9 @@ class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { } }; -REGISTER_KERNEL_BUILDER(Name("TfqSimulateStateCuquantum").Device(tensorflow::DEVICE_CPU), - TfqSimulateStateOpCuQuantum); +REGISTER_KERNEL_BUILDER( + Name("TfqSimulateStateCuquantum").Device(tensorflow::DEVICE_CPU), + TfqSimulateStateOpCuQuantum); REGISTER_OP("TfqSimulateStateCuquantum") .Input("programs: string") From 7189efc9c02d477045ad296e2bba23f55bce6048 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 29 Mar 2023 22:51:12 -0700 Subject: [PATCH 010/106] Fix lint --- .../core/ops/tfq_simulate_ops_cuda_test.py | 23 ++++++++++++++++++- .../ops/tfq_simulate_ops_cuquantum_test.py | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py index fa0eda2e1..b21141a75 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py @@ -23,15 +23,36 @@ from tensorflow_quantum.python import util -def measure_average_runtime(fn, tag, num_samples=10): +def measure_average_runtime( + fn, + tag, + num_samples=10, + result_avg=False, +): + """Measures average runtime for given function. + + Args: + fn: function. + tag: The message title. + num_samples: The number of measurements. + result_avg: True if the results are all averaged. + + Returns: + The average time and the (averaged) result. + """ avg_time = [] + avg_res = [] for _ in range(num_samples): begin_time = time.time() result = fn() duration = time.time() - begin_time avg_time.append(duration) + if result_avg: + avg_res.append(result) avg_time = sum(avg_time) / float(num_samples) print(f"\n\t{tag} time: {avg_time}\n") + if result_avg: + result = np.average(avg_res, axis=0) return avg_time, result diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 6ead96a65..f9f7aa180 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -30,7 +30,7 @@ def measure_average_runtime( result_avg=False, ): """Measures average runtime for given function. - + Args: fn: function. tag: The message title. From e9dfeb43d3a481973e45c52a22f291f3654960ad Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Fri, 31 Mar 2023 16:49:59 +0000 Subject: [PATCH 011/106] merge master ops BUILD file --- tensorflow_quantum/core/ops/BUILD | 50 +++++-------------------------- 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index 2e28f55f0..bd953da40 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -668,15 +668,15 @@ py_library( ) py_test( - name = "tfq_simulate_ops_cuda_test", - srcs = ["tfq_simulate_ops_cuda_test.py"], + name = "tfq_simulate_ops_gpu_test", + srcs = ["tfq_simulate_ops_gpu_test.py"], deps = [ ":tfq_simulate_ops_cuda_py", + ":tfq_simulate_ops_cuquantum_py", ":tfq_simulate_ops_py", "//tensorflow_quantum/python:util", ], srcs_version = "PY3", - tags = ["cuda"], ) cc_binary( @@ -717,7 +717,6 @@ cc_binary( "/wd4577", "/DNOGDI", "/UTF_COMPILE_LIBRARY", - "/D__CUDA__", ], "//conditions:default": [ "-Iexternal/local_cuda/cuda/include", @@ -734,14 +733,7 @@ cc_binary( "-DNV_CUDNN_DISABLE_EXCEPTION", # "-fpermissive", ], - }) + if_cuda_is_configured([ - "-DTENSORFLOW_USE_NVCC=1", - "-DGOOGLE_CUDA=1", - "-x cuda", - "-nvcc_options=relaxed-constexpr", - "-nvcc_options=ftz=true", - "-D__CUDA__", - ]), + }) + if_cuda_is_configured(["-DTENSORFLOW_USE_NVCC=1", "-DGOOGLE_CUDA=1", "-x cuda", "-nvcc_options=relaxed-constexpr", "-nvcc_options=ftz=true"]), deps = [ # cirq cc proto "//tensorflow_quantum/core/ops:parse_context", @@ -763,32 +755,14 @@ cc_binary( # alwayslink=1, ) -py_test( - name = "tfq_simulate_ops_cuquantum_test", - srcs = ["tfq_simulate_ops_cuquantum_test.py"], - deps = [ - ":tfq_simulate_ops_cuquantum_py", - ":tfq_simulate_ops_py", - "//tensorflow_quantum/python:util", - ], - srcs_version = "PY3", - tags = ["cuquantum"], -) - cc_binary( name = "_tfq_simulate_ops_cuquantum.so", srcs = [ "tfq_simulate_expectation_op_cuquantum.cu.cc", -<<<<<<< HEAD # "tfq_simulate_sampled_expectation_op_cuquantum.cu.cc", # "tfq_simulate_state_op_cuquantum.cu.cc", "tfq_simulate_samples_op_cuquantum.cu.cc", -======= - "tfq_simulate_sampled_expectation_op_cuquantum.cu.cc", - "tfq_simulate_samples_op_cuquantum.cu.cc", - "tfq_simulate_state_op_cuquantum.cu.cc", ->>>>>>> master - ], + ], linkshared = 1, features = select({ ":windows": ["windows_export_all_symbols"], @@ -822,7 +796,6 @@ cc_binary( "/wd4577", "/DNOGDI", "/UTF_COMPILE_LIBRARY", - "/D__CUSTATEVEC__", ], "//conditions:default": [ "-Iexternal/local_cuda/cuda/include", @@ -839,14 +812,7 @@ cc_binary( "-DNV_CUDNN_DISABLE_EXCEPTION", # "-fpermissive", ], - }) + if_cuda_is_configured([ - "-DTENSORFLOW_USE_NVCC=1", - "-DGOOGLE_CUDA=1", - "-x cuda", - "-nvcc_options=relaxed-constexpr", - "-nvcc_options=ftz=true", - "-D__CUSTATEVEC__", - ]), + }) + if_cuda_is_configured(["-DTENSORFLOW_USE_NVCC=1", "-DGOOGLE_CUDA=1", "-x cuda", "-nvcc_options=relaxed-constexpr", "-nvcc_options=ftz=true"]), deps = [ # cirq cc proto "//tensorflow_quantum/core/ops:parse_context", @@ -862,9 +828,9 @@ cc_binary( # tensorflow core protos ] + if_cuda_is_configured([ ":cuda", + "@cuquantum_libs//:custatevec", + "@cuquantum_libs//:custatevec_headers", "@local_config_cuda//cuda:cuda_headers", - "@local_config_cuquantum//:cuquantum_headers", - "@local_config_cuquantum//:libcuquantum", "@qsim//lib:qsim_cuquantum_lib", ]), # alwayslink=1, From 80861ae34e7425cb239580116d9a79bc91dedbe9 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Sat, 1 Apr 2023 22:55:33 +0000 Subject: [PATCH 012/106] cuquantum support for gpu ops, need to add CUDA support tho --- .../core/ops/circuit_execution_ops.py | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index 1158e98e4..36c2ad42d 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -18,16 +18,24 @@ import cirq from tensorflow_quantum.core.ops import (cirq_ops, tfq_simulate_ops, - tfq_utility_ops) + tfq_utility_ops, + tfq_simulate_ops_cuquantum) from tensorflow_quantum.python import quantum_context class TFQStateVectorSimulator(enum.Enum): """Enum to make specifying TFQ simulators user-friendly.""" expectation = tfq_simulate_ops.tfq_simulate_expectation + expectation_gpu_cpu = tfq_simulate_ops_cuquantum.tfq_simulate_expectation + samples = tfq_simulate_ops.tfq_simulate_samples + samples_gpu_cpu = tfq_simulate_ops_cuquantum.tfq_simulate_samples + state = tfq_simulate_ops.tfq_simulate_state + state_gpu_cpu = tfq_simulate_ops_cuquantum.tfq_simulate_state + sampled_expectation = tfq_simulate_ops.tfq_simulate_sampled_expectation + sampled_expectation_gpu_cpu = tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation def _check_quantum_concurrent(quantum_concurrent): @@ -38,6 +46,7 @@ def _check_quantum_concurrent(quantum_concurrent): def get_expectation_op( backend=None, + use_gpu=False, *, quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): """Get a TensorFlow op that will calculate batches of expectation values. @@ -121,7 +130,10 @@ def get_expectation_op( op = None if backend is None: - op = TFQStateVectorSimulator.expectation + if use_gpu: + op = TFQStateVectorSimulator.expectation_gpu_cpu + else: + op = TFQStateVectorSimulator.expectation # TODO(zaqqwerty): remove DM check after cirq #3964 if isinstance(backend, (cirq.sim.simulator.SimulatesExpectationValues, @@ -151,6 +163,7 @@ def get_expectation_op( def get_sampling_op( backend=None, + use_gpu=False, *, quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): """Get a Tensorflow op that produces samples from given quantum circuits. @@ -220,7 +233,10 @@ def get_sampling_op( op = None if backend is None: - op = TFQStateVectorSimulator.samples + if use_gpu: + op = TFQStateVectorSimulator.samples_gpu_cpu + else: + op = TFQStateVectorSimulator.samples if isinstance(backend, cirq.Sampler): op = cirq_ops._get_cirq_samples(backend) @@ -243,6 +259,7 @@ def get_sampling_op( def get_state_op( backend=None, + use_gpu=False, *, quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): """Get a TensorFlow op that produces states from given quantum circuits. @@ -309,7 +326,10 @@ def get_state_op( op = None if backend is None: - op = TFQStateVectorSimulator.state + if use_gpu: + op = TFQStateVectorSimulator.state_gpu_cpu + else: + op = TFQStateVectorSimulator.state if isinstance(backend, (cirq.SimulatesFinalState)): op = cirq_ops._get_cirq_simulate_state(backend) @@ -333,6 +353,7 @@ def get_state_op( def get_sampled_expectation_op( backend=None, + use_gpu=False, *, quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): """Get a TensorFlow op that will calculate sampled expectation values. @@ -420,7 +441,10 @@ def get_sampled_expectation_op( op = None if backend is None: - op = TFQStateVectorSimulator.sampled_expectation + if use_gpu: + op = TFQStateVectorSimulator.sampled_expectation_gpu_cpu + else: + op = TFQStateVectorSimulator.sampled_expectation if isinstance(backend, cirq.Sampler): op = cirq_ops._get_cirq_sampled_expectation(backend) @@ -446,4 +470,4 @@ def get_sampled_expectation_op( raise TypeError( "Backend {} is invalid. Expected a Cirq.Sampler or None.".format( - backend)) + backend)) \ No newline at end of file From ae9cac57e3fd3456a706b9fe2d191fd1822d9b5e Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Sat, 1 Apr 2023 22:56:45 +0000 Subject: [PATCH 013/106] python support for adj grad cuqantum op (needs to be merged WIP) --- .../python/differentiators/adjoint.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index 95ff5554e..af78fe0b3 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -15,7 +15,7 @@ """Compute gradients by combining function values linearly.""" import tensorflow as tf -from tensorflow_quantum.core.ops import tfq_adj_grad_op +from tensorflow_quantum.core.ops import tfq_adj_grad_op, tfq_adj_grad_op_cuquantum from tensorflow_quantum.python.differentiators import differentiator @@ -98,13 +98,17 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values): @differentiator.catch_empty_inputs @tf.function def differentiate_analytic(self, programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad): - return tfq_adj_grad_op.tfq_adj_grad(programs, symbol_names, - symbol_values, pauli_sums, grad) + pauli_sums, forward_pass_vals, grad, use_gpu=False): + if use_gpu: + return tfq_adj_grad_op_cuquantum.tfq_adj_grad(programs, symbol_names, + symbol_values, pauli_sums, grad) + else: + return tfq_adj_grad_op.tfq_adj_grad(programs, symbol_names, + symbol_values, pauli_sums, grad) def differentiate_sampled(self, programs, symbol_names, symbol_values, pauli_sums, num_samples, forward_pass_vals, grad): raise NotImplementedError( "Adjoint state methods are not supported in sample based settings." " Please use analytic expectation calculation or a different " - "tfq.differentiator.") + "tfq.differentiator.") \ No newline at end of file From d830a3b908962d7d4e0a08ebf58d21b86a06e094 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Sat, 1 Apr 2023 22:58:43 +0000 Subject: [PATCH 014/106] cuquantum support for circuit executor ops --- .../layers/circuit_executors/expectation.py | 11 ++++++++--- .../python/layers/circuit_executors/sample.py | 9 ++++++--- .../circuit_executors/sampled_expectation.py | 16 ++++++++++------ .../python/layers/circuit_executors/state.py | 7 ++++--- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation.py b/tensorflow_quantum/python/layers/circuit_executors/expectation.py index c3b1d913e..bce5c7d91 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation.py @@ -205,7 +205,8 @@ class Expectation(tf.keras.layers.Layer): """ - def __init__(self, backend='noiseless', differentiator=None, **kwargs): + def __init__(self, backend='noiseless', differentiator=None, use_gpu=False, + **kwargs): """Instantiate this Layer. Create a layer that will output expectation values gained from @@ -225,6 +226,7 @@ def __init__(self, backend='noiseless', differentiator=None, **kwargs): which uses `tfq.differentiators.ParameterShift()`. If `backend` is also 'noiseless' then default is `tfq.differentiators.Adjoint`. + use_gpu: Calls TFQ GPU version op. """ super().__init__(**kwargs) @@ -252,12 +254,15 @@ def __init__(self, backend='noiseless', differentiator=None, **kwargs): "tfq.differentiators.Differentiator") if backend == 'noisy': + if use_gpu: + raise ValueError('noisy backend does not currently support GPU') used_op = noisy_expectation_op.expectation self._expectation_op = differentiator.generate_differentiable_op( sampled_op=used_op) self.noisy = True else: - used_op = circuit_execution_ops.get_expectation_op(backend=backend) + used_op = circuit_execution_ops.get_expectation_op(backend=backend, + use_gpu=use_gpu) self._expectation_op = differentiator.generate_differentiable_op( analytic_op=used_op) @@ -355,4 +360,4 @@ def call(self, else: return self._expectation_op(inputs, symbol_names, symbol_values, operators) - # pylint: enable=no-else-return + # pylint: enable=no-else-return \ No newline at end of file diff --git a/tensorflow_quantum/python/layers/circuit_executors/sample.py b/tensorflow_quantum/python/layers/circuit_executors/sample.py index 616d811bc..026fb74df 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample.py @@ -139,7 +139,7 @@ class Sample(tf.keras.layers.Layer): """ - def __init__(self, backend='noiseless', **kwargs): + def __init__(self, backend='noiseless', use_gpu=False, **kwargs): """Instantiate this Layer. Create a layer that will output bitstring samples taken from either a @@ -150,12 +150,15 @@ def __init__(self, backend='noiseless', **kwargs): to the noiseless simulator. Options are {'noisy', 'noiseless'}, however users may also specify a preconfigured cirq execution object to use instead, which must inherit `cirq.Sampler`. + use_gpu: Calls TFQ GPU version op. """ super().__init__(**kwargs) used_op = None if backend == 'noiseless': - used_op = circuit_execution_ops.get_sampling_op(None) + used_op = circuit_execution_ops.get_sampling_op(None, use_gpu=use_gpu) elif backend == 'noisy': + if use_gpu: + raise ValueError('noisy backend does not currently support GPU') used_op = noisy_samples_op.samples else: used_op = circuit_execution_ops.get_sampling_op(backend) @@ -198,4 +201,4 @@ def call(self, inputs, symbol_names, symbol_values = input_checks.expand_circuits( inputs, symbol_names, symbol_values) - return self.sample_op(inputs, symbol_names, symbol_values, repetitions) + return self.sample_op(inputs, symbol_names, symbol_values, repetitions) \ No newline at end of file diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py index ebc750e59..436180fee 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py @@ -213,7 +213,8 @@ class SampledExpectation(tf.keras.layers.Layer): """ - def __init__(self, backend='noiseless', differentiator=None, **kwargs): + def __init__(self, backend='noiseless', differentiator=None, use_gpu=False, + **kwargs): """Instantiate this Layer. Create a layer that will output expectation values gained from @@ -227,6 +228,7 @@ def __init__(self, backend='noiseless', differentiator=None, **kwargs): derivative values of given operators_to_measure and circuit, which must inherit `tfq.differentiators.Differentiator`. Defaults to `parameter_shift.ParameterShift()` (None argument). + use_gpu: Calls TFQ GPU version op. """ super().__init__(**kwargs) @@ -247,13 +249,15 @@ def __init__(self, backend='noiseless', differentiator=None, **kwargs): used_op = None if backend == 'noiseless': - backend = None - - if backend == 'noisy': + used_op = circuit_execution_ops.get_sampled_expectation_op( + use_gpu=use_gpu) + elif backend == 'noisy': + if use_gpu: + raise ValueError('noisy backend does not currently support GPU') used_op = noisy_sampled_expectation_op.sampled_expectation else: used_op = circuit_execution_ops.get_sampled_expectation_op( - backend=backend) + backend=backend, use_gpu=use_gpu) self._expectation_op = differentiator.generate_differentiable_op( sampled_op=used_op) @@ -339,4 +343,4 @@ def call(self, num_samples = repetitions return self._expectation_op(inputs, symbol_names, symbol_values, - operators, num_samples) + operators, num_samples) \ No newline at end of file diff --git a/tensorflow_quantum/python/layers/circuit_executors/state.py b/tensorflow_quantum/python/layers/circuit_executors/state.py index 6f979139a..f59c67333 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/state.py +++ b/tensorflow_quantum/python/layers/circuit_executors/state.py @@ -112,7 +112,7 @@ class State(tf.keras.layers.Layer): """ - def __init__(self, backend=None, **kwargs): + def __init__(self, backend=None, use_gpu=False, **kwargs): """Instantiate a State Layer. Create a layer that will simulate a quantum state and output it into @@ -126,9 +126,10 @@ def __init__(self, backend=None, **kwargs): `cirq.SimulatesFinalState`. Note that C++ Density Matrix simulation is not yet supported so to do Density Matrix simulation please use `cirq.DensityMatrixSimulator`. + use_gpu: Calls TFQ GPU version op. """ super().__init__(**kwargs) - self.state_op = circuit_execution_ops.get_state_op(backend) + self.state_op = circuit_execution_ops.get_state_op(backend, use_gpu=use_gpu) def call(self, inputs, *, symbol_names=None, symbol_values=None): """Keras call function. @@ -145,4 +146,4 @@ def call(self, inputs, *, symbol_names=None, symbol_values=None): """ inputs, symbol_names, symbol_values = input_checks.expand_circuits( inputs, symbol_names, symbol_values) - return self.state_op(inputs, symbol_names, symbol_values) + return self.state_op(inputs, symbol_names, symbol_values) \ No newline at end of file From c97fa3acc6f9cc704a2840c7c1380274bf57892c Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Sat, 1 Apr 2023 23:00:08 +0000 Subject: [PATCH 015/106] keras layers cuquantum support --- .../python/layers/high_level/noisy_controlled_pqc.py | 10 +++++++++- .../python/layers/high_level/noisy_pqc.py | 9 ++++++++- tensorflow_quantum/python/layers/high_level/pqc.py | 8 +++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py index f3239e443..98b314990 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py @@ -142,6 +142,7 @@ def __init__(self, repetitions=None, sample_based=None, differentiator=None, + use_gpu=False, **kwargs): """Instantiate this layer. @@ -163,6 +164,8 @@ def __init__(self, trajectory. differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. + use_gpu: Optional `bool` indicating whether to use GPU for simulation + or not. Defaults to `False`. NOT IMPLEMENTED YET. """ super().__init__(**kwargs) # Ingest model_circuit. @@ -218,6 +221,11 @@ def __init__(self, if differentiator is None: differentiator = parameter_shift.ParameterShift() + # Use gpu not supported yet. + if use_gpu: + raise NotImplementedError("GPU support for noisy controlled PQC \ + is not yet implemented.") + # Ingest and promote sample based. if sample_based is None: raise ValueError("Please specify sample_based=False for analytic " @@ -256,4 +264,4 @@ def call(self, inputs): tiled_up_repetitions = tf.tile(self._repetitions, [circuit_batch_dim, 1]) return self._executor(model_appended, self._symbols, inputs[1], - tiled_up_operators, tiled_up_repetitions) + tiled_up_operators, tiled_up_repetitions) \ No newline at end of file diff --git a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py index 05cb535e8..bfc4a4463 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py @@ -139,6 +139,7 @@ def __init__( repetitions=None, sample_based=None, differentiator=None, + use_gpu=False, initializer=tf.keras.initializers.RandomUniform(0, 2 * np.pi), regularizer=None, constraint=None, @@ -164,6 +165,8 @@ def __init__( trajectory. differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. + use_gpu: Python `bool` indicating whether to use GPU ops (currently + not supported/implemented). initializer: Optional `tf.keras.initializer` object to specify how the symbols in `model_circuit` should be initialized when creating the managed variables. @@ -220,6 +223,10 @@ def __init__( [[repetitions for _ in range(len(operators))]], dtype=tf.dtypes.int32) + # Use gpu not supported yet. + if use_gpu: + raise NotImplementedError("GPU support for noisy PQC is not yet implemented.") + # Ingest differentiator. if differentiator is None: differentiator = parameter_shift.ParameterShift() @@ -292,4 +299,4 @@ def call(self, inputs): [circuit_batch_dim, 1]) return self._executor(model_appended, self._symbols, tiled_up_parameters, tiled_up_operators, - tiled_up_repetitions) + tiled_up_repetitions) \ No newline at end of file diff --git a/tensorflow_quantum/python/layers/high_level/pqc.py b/tensorflow_quantum/python/layers/high_level/pqc.py index e370be294..c4e1a5676 100644 --- a/tensorflow_quantum/python/layers/high_level/pqc.py +++ b/tensorflow_quantum/python/layers/high_level/pqc.py @@ -137,6 +137,7 @@ def __init__( *, repetitions=None, backend='noiseless', + use_gpu=False, differentiator=None, initializer=tf.keras.initializers.RandomUniform(0, 2 * np.pi), regularizer=None, @@ -166,6 +167,7 @@ def __init__( `cirq.sim.simulator.SimulatesExpectationValues` if analytic expectations are desired or `cirq.Sampler` if sampled expectations are desired. + use_gpu: Optional Python `bool` indicating whether or not to use GPU ops differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. initializer: Optional `tf.keras.initializer` object to specify how the @@ -248,10 +250,10 @@ def __init__( "cirq.sim.simulator.SimulatesExpectationValues.") if self._analytic: self._executor = expectation.Expectation( - backend=backend, differentiator=differentiator) + backend=backend, differentiator=differentiator, use_gpu=use_gpu) else: self._executor = sampled_expectation.SampledExpectation( - backend=backend, differentiator=differentiator) + backend=backend, differentiator=differentiator, use_gpu=use_gpu) self._append_layer = elementary.AddCircuit() @@ -315,4 +317,4 @@ def call(self, inputs): symbol_values=tiled_up_parameters, operators=tiled_up_operators, repetitions=tiled_up_repetitions) - # pylint: enable=no-else-return + # pylint: enable=no-else-return \ No newline at end of file From 6aec6dd98bd2221a287c17269df7f26f24176294 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Mon, 3 Apr 2023 21:12:50 +0000 Subject: [PATCH 016/106] adj grad cuquantum op kernel v0 --- .../core/ops/tfq_adj_grad_op_cuquantum.cu.cc | 312 ++++++++++++++++++ 1 file changed, 312 insertions(+) create mode 100644 tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc new file mode 100644 index 000000000..6347d6f5c --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc @@ -0,0 +1,312 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#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/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 ::tensorflow::Status; +using ::tfq::proto::PauliSum; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { + public: + explicit TfqAdjointGradientCuquantumOp(tensorflow::OpKernelConstruction* context) + : OpKernel(context) {} + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + const int num_inputs = context->num_inputs(); + OP_REQUIRES(context, num_inputs == 5, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Expected 5 inputs, got ", num_inputs, " inputs."))); + + // Create the output Tensor. + const int output_dim_batch_size = context->input(0).dim_size(0); + const int output_dim_param_size = context->input(2).dim_size(1); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_batch_size); + output_shape.AddDim(output_dim_param_size); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->matrix(); + + // Parse program protos. + std::vector programs; + std::vector num_qubits; + std::vector> pauli_sums; + OP_REQUIRES_OK(context, GetProgramsAndNumQubits(context, &programs, + &num_qubits, &pauli_sums)); + + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + + OP_REQUIRES(context, programs.size() == maps.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and symbol_values do not match. Got ", + programs.size(), " circuits and ", maps.size(), + " symbol values."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> full_fuse( + programs.size(), std::vector>({})); + std::vector>>> + partial_fused_circuits( + programs.size(), + std::vector>>({})); + + // track metadata. + std::vector> gate_meta( + programs.size(), std::vector({})); + + // track gradients + std::vector> gradient_gates( + programs.size(), std::vector({})); + + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = QsimCircuitFromProgram(programs[i], maps[i], + num_qubits[i], &qsim_circuits[i], + &full_fuse[i], &gate_meta[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + CreateGradientCircuit(qsim_circuits[i], gate_meta[i], + &partial_fused_circuits[i], &gradient_gates[i]); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + // Get downstream gradients. + std::vector> downstream_grads; + OP_REQUIRES_OK(context, GetPrevGrads(context, &downstream_grads)); + + OP_REQUIRES(context, downstream_grads.size() == programs.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of gradients and circuits do not match. Got ", + downstream_grads.size(), " gradients and ", programs.size(), + " circuits."))); + + OP_REQUIRES( + context, context->input(4).dim_size(1) == context->input(3).dim_size(1), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of gradients and pauli sum dimension do not match. Got ", + context->input(4).dim_size(1), " gradient entries and ", + context->input(3).dim_size(1), " paulis per circuit."))); + + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + output_tensor.setZero(); + + // create handles for simulator + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + // Cross reference with standard google cloud compute instances + // Memory ~= 2 * num_threads * (2 * 64 * 2 ** num_qubits in circuits) + // e2s2 = 2 CPU, 8GB -> Can safely do 25 since Memory = 4GB + // e2s4 = 4 CPU, 16GB -> Can safely do 25 since Memory = 8GB + // ... + // This method creates 3 big state vectors per thread so reducing size + // here slightly. + + ComputeLarge(num_qubits, qsim_circuits, maps, full_fuse, + partial_fused_circuits, pauli_sums, gradient_gates, + downstream_grads, context, &output_tensor); + + // destroy handles in sync with simulator lifetime + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } + + private: + cublasHandle_t cublas_handle_; + custatevecHandle_t custatevec_handle_; + + void ComputeLarge( + const std::vector& num_qubits, + const std::vector& qsim_circuits, + const std::vector& maps, + const std::vector>>& full_fuse, + const std::vector>>>& + partial_fused_circuits, + const std::vector>& pauli_sums, + const std::vector>& gradient_gates, + const std::vector>& downstream_grads, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + // Instantiate qsim objects. + const auto tfq_for = tfq::QsimFor(context); + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + auto scratch = ss.Create(largest_nq); + auto scratch2 = ss.Create(largest_nq); + + for (int i = 0; i < partial_fused_circuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + scratch2 = ss.Create(largest_nq); + } + + // (#679) Just ignore empty program + if (qsim_circuits[i].gates.size() == 0) { + continue; + } + + ss.SetStateZero(sv); + for (int j = 0; j < full_fuse[i].size(); j++) { + qsim::ApplyFusedGate(sim, full_fuse[i][j], sv); + } + + // sv now contains psi + // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> + // scratch2 now contains psi as well. + Status unused = AccumulateOperators(pauli_sums[i], downstream_grads[i], + sim, ss, sv, scratch2, scratch); + + for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { + for (int k = partial_fused_circuits[i][j].size() - 1; k >= 0; k--) { + ApplyFusedGateDagger(sim, partial_fused_circuits[i][j][k], sv); + ApplyFusedGateDagger(sim, partial_fused_circuits[i][j][k], scratch); + } + if (j == 0) { + // last layer will have no parametrized gates so can break. + break; + } + + // Hit a parameterized gate. + // todo fix this copy. + auto cur_gate = qsim_circuits[i].gates[gradient_gates[i][j - 1].index]; + ApplyGateDagger(sim, cur_gate, sv); + + // if applicable compute control qubit mask and control value bits. + uint64_t mask = 0; + uint64_t cbits = 0; + for (int k = 0; k < cur_gate.controlled_by.size(); k++) { + uint64_t control_loc = cur_gate.controlled_by[k]; + mask |= uint64_t{1} << control_loc; + cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; + } + + for (int k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); k++) { + // Copy sv onto scratch2 in anticipation of non-unitary "gradient + // gate". + ss.Copy(sv, scratch2); + if (!cur_gate.controlled_by.empty()) { + // Gradient of controlled gates puts zeros on diagonal which is + // the same as collapsing the state and then applying the + // non-controlled version of the gradient gate. + ss.BulkSetAmpl(scratch2, mask, cbits, 0, 0, true); + } + qsim::ApplyGate(sim, gradient_gates[i][j - 1].grad_gates[k], + scratch2); + + // don't need not-found check since this is done upstream already. + const auto it = maps[i].find(gradient_gates[i][j - 1].params[k]); + const int loc = it->second.first; + // Apply finite differencing for adjoint gradients. + // Finite differencing enables applying multiple `gradient_gate` + // of a symbol at the same circuit. For analytic methods like + // parameter-shift we need to apply a single `gradient_gate` + // per a symbol. + (*output_tensor)(i, loc) += ss.RealInnerProduct(scratch2, scratch) + + ss.RealInnerProduct(scratch, scratch2); + } + ApplyGateDagger(sim, cur_gate, scratch); + } + } + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqAdjointGradientCuquantum").Device(tensorflow::DEVICE_CPU), + TfqAdjointGradientCuquantumOp); + +REGISTER_OP("TfqAdjointGradientCuquantum") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("pauli_sums: string") + .Input("downstream_grads: float") + .Output("grads: float") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle pauli_sums_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 2, &pauli_sums_shape)); + + tensorflow::shape_inference::ShapeHandle downstream_grads_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(4), 2, &downstream_grads_shape)); + + tensorflow::shape_inference::DimensionHandle output_rows = + c->Dim(programs_shape, 0); + tensorflow::shape_inference::DimensionHandle output_cols = + c->Dim(symbol_names_shape, 0); + c->set_output(0, c->Matrix(output_rows, output_cols)); + + return ::tensorflow::Status(); + }); + +} // namespace tfq From 19717bf6de36dc2067da5fa728bfb7b204fc42fd Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Tue, 4 Apr 2023 02:57:24 +0000 Subject: [PATCH 017/106] update BUILD to master version --- tensorflow_quantum/core/ops/BUILD | 48 ++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index bd953da40..bbf17d2a4 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -668,15 +668,15 @@ py_library( ) py_test( - name = "tfq_simulate_ops_gpu_test", - srcs = ["tfq_simulate_ops_gpu_test.py"], + name = "tfq_simulate_ops_cuda_test", + srcs = ["tfq_simulate_ops_cuda_test.py"], deps = [ ":tfq_simulate_ops_cuda_py", - ":tfq_simulate_ops_cuquantum_py", ":tfq_simulate_ops_py", "//tensorflow_quantum/python:util", ], srcs_version = "PY3", + tags = ["cuda"], ) cc_binary( @@ -717,6 +717,7 @@ cc_binary( "/wd4577", "/DNOGDI", "/UTF_COMPILE_LIBRARY", + "/D__CUDA__", ], "//conditions:default": [ "-Iexternal/local_cuda/cuda/include", @@ -733,7 +734,14 @@ cc_binary( "-DNV_CUDNN_DISABLE_EXCEPTION", # "-fpermissive", ], - }) + if_cuda_is_configured(["-DTENSORFLOW_USE_NVCC=1", "-DGOOGLE_CUDA=1", "-x cuda", "-nvcc_options=relaxed-constexpr", "-nvcc_options=ftz=true"]), + }) + if_cuda_is_configured([ + "-DTENSORFLOW_USE_NVCC=1", + "-DGOOGLE_CUDA=1", + "-x cuda", + "-nvcc_options=relaxed-constexpr", + "-nvcc_options=ftz=true", + "-D__CUDA__", + ]), deps = [ # cirq cc proto "//tensorflow_quantum/core/ops:parse_context", @@ -755,14 +763,26 @@ cc_binary( # alwayslink=1, ) +py_test( + name = "tfq_simulate_ops_cuquantum_test", + srcs = ["tfq_simulate_ops_cuquantum_test.py"], + deps = [ + ":tfq_simulate_ops_cuquantum_py", + ":tfq_simulate_ops_py", + "//tensorflow_quantum/python:util", + ], + srcs_version = "PY3", + tags = ["cuquantum"], +) + cc_binary( name = "_tfq_simulate_ops_cuquantum.so", srcs = [ "tfq_simulate_expectation_op_cuquantum.cu.cc", - # "tfq_simulate_sampled_expectation_op_cuquantum.cu.cc", - # "tfq_simulate_state_op_cuquantum.cu.cc", + "tfq_simulate_sampled_expectation_op_cuquantum.cu.cc", "tfq_simulate_samples_op_cuquantum.cu.cc", - ], + "tfq_simulate_state_op_cuquantum.cu.cc", + ], linkshared = 1, features = select({ ":windows": ["windows_export_all_symbols"], @@ -796,6 +816,7 @@ cc_binary( "/wd4577", "/DNOGDI", "/UTF_COMPILE_LIBRARY", + "/D__CUSTATEVEC__", ], "//conditions:default": [ "-Iexternal/local_cuda/cuda/include", @@ -812,7 +833,14 @@ cc_binary( "-DNV_CUDNN_DISABLE_EXCEPTION", # "-fpermissive", ], - }) + if_cuda_is_configured(["-DTENSORFLOW_USE_NVCC=1", "-DGOOGLE_CUDA=1", "-x cuda", "-nvcc_options=relaxed-constexpr", "-nvcc_options=ftz=true"]), + }) + if_cuda_is_configured([ + "-DTENSORFLOW_USE_NVCC=1", + "-DGOOGLE_CUDA=1", + "-x cuda", + "-nvcc_options=relaxed-constexpr", + "-nvcc_options=ftz=true", + "-D__CUSTATEVEC__", + ]), deps = [ # cirq cc proto "//tensorflow_quantum/core/ops:parse_context", @@ -828,9 +856,9 @@ cc_binary( # tensorflow core protos ] + if_cuda_is_configured([ ":cuda", - "@cuquantum_libs//:custatevec", - "@cuquantum_libs//:custatevec_headers", "@local_config_cuda//cuda:cuda_headers", + "@local_config_cuquantum//:cuquantum_headers", + "@local_config_cuquantum//:libcuquantum", "@qsim//lib:qsim_cuquantum_lib", ]), # alwayslink=1, From 249e2eb09e5ababf08097179dae8cba95b397e9a Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Tue, 4 Apr 2023 04:51:07 +0000 Subject: [PATCH 018/106] added build targets and initial tests --- tensorflow_quantum/core/ops/BUILD | 112 ++++- .../core/ops/tfq_adj_grad_op_cuquantum.py | 48 +++ .../ops/tfq_adj_grad_op_cuquantum_test.py | 400 ++++++++++++++++++ .../ops/tfq_simulate_ops_cuquantum_test.py | 210 ++++----- 4 files changed, 656 insertions(+), 114 deletions(-) create mode 100644 tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.py create mode 100644 tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index bbf17d2a4..3c9d61bb6 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -52,6 +52,7 @@ py_library( ] + if_cuda_is_configured([ ":tfq_simulate_ops_cuda_py", ":tfq_simulate_ops_cuquantum_py", + ":tfq_adj_grad_op_cuquantum_py", ]), ) @@ -721,11 +722,6 @@ cc_binary( ], "//conditions:default": [ "-Iexternal/local_cuda/cuda/include", - # "--cuda-gpu-arch=sm_86", - # "-L/usr/local/cuda/lib64", - # "-lcudart_static", - # "-ldl", - # "-lrt", "-pthread", "-std=c++17", "-D_GLIBCXX_USE_CXX11_ABI=1", @@ -820,11 +816,6 @@ cc_binary( ], "//conditions:default": [ "-Iexternal/local_cuda/cuda/include", - # "--cuda-gpu-arch=sm_86", - # "-L/usr/local/cuda/lib64", - # "-lcudart_static", - # "-ldl", - # "-lrt", "-pthread", "-std=c++17", "-D_GLIBCXX_USE_CXX11_ABI=1", @@ -864,6 +855,107 @@ cc_binary( # alwayslink=1, ) +cc_binary( + name = "_tfq_adj_grad_cuquantum.so", + srcs = [ + "tfq_adj_grad_op_cuquantum.cu.cc", + ], + linkshared = 1, + features = select({ + ":windows": ["windows_export_all_symbols"], + "//conditions:default": [], + }), + copts = select({ + ":windows": [ + "/D__CLANG_SUPPORT_DYN_ANNOTATION__", + "/D_USE_MATH_DEFINES", + "/DEIGEN_MPL2_ONLY", + "/DEIGEN_MAX_ALIGN_BYTES=64", + "/DEIGEN_HAS_TYPE_TRAITS=0", + "/DTF_USE_SNAPPY", + "/showIncludes", + "/MD", + "/O2", + "/DNDEBUG", + "/w", + "-DWIN32_LEAN_AND_MEAN", + "-DNOGDI", + "/d2ReducedOptimizeHugeFunctions", + "/arch:AVX", + "/std:c++17", + "-DTENSORFLOW_MONOLITHIC_BUILD", + "/DPLATFORM_WINDOWS", + "/DEIGEN_HAS_C99_MATH", + "/DTENSORFLOW_USE_EIGEN_THREADPOOL", + "/DEIGEN_AVOID_STL_ARRAY", + "/Iexternal/gemmlowp", + "/wd4018", + "/wd4577", + "/DNOGDI", + "/UTF_COMPILE_LIBRARY", + "/D__CUSTATEVEC__", + ], + "//conditions:default": [ + "-Iexternal/local_cuda/cuda/include", + "-pthread", + "-std=c++17", + "-D_GLIBCXX_USE_CXX11_ABI=1", + "-O3", + "-Iexternal/cuda_headers", + "-DNV_CUDNN_DISABLE_EXCEPTION", + # "-fpermissive", + ], + }) + if_cuda_is_configured([ + "-DTENSORFLOW_USE_NVCC=1", + "-DGOOGLE_CUDA=1", + "-x cuda", + "-nvcc_options=relaxed-constexpr", + "-nvcc_options=ftz=true", + "-D__CUSTATEVEC__", + ]), + deps = [ + "//tensorflow_quantum/core/ops:parse_context", + "//tensorflow_quantum/core/src:util_qsim", + "//tensorflow_quantum/core/src:adj_util", + # "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", + # "//tensorflow_quantum/core/proto:program_cc_proto", + # "//tensorflow_quantum/core/src:circuit_parser_qsim", + # "@eigen//:eigen3", + ] + if_cuda_is_configured([ + ":cuda", + "@local_config_cuda//cuda:cuda_headers", + "@local_config_cuquantum//:cuquantum_headers", + "@local_config_cuquantum//:libcuquantum", + "@qsim//lib:qsim_cuquantum_lib", + ]), + # alwayslink=1, +) + +py_library( + name = "tfq_adj_grad_op_cuquantum_py", + srcs = ["tfq_adj_grad_op_cuquantum.py"], + data = [":_tfq_adj_grad_cuquantum.so"], + srcs_version = "PY3", + deps = [ + ":load_module", + # pauli sum cc proto + # projector sum cc proto + # tensorflow framework for wrappers + ], +) + +py_test( + name = "tfq_adj_grad_op_cuquantum_test", + srcs = ["tfq_adj_grad_op_cuquantum.py"], + python_version = "PY3", + deps = [ + ":tfq_adj_grad_op_cuquantum_py", + "//tensorflow_quantum/python:util", + ], + srcs_version = "PY3", + tags = ["cuquantum"], +) + py_library( name = "load_module", srcs = ["load_module.py"], diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.py new file mode 100644 index 000000000..a96e13d23 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.py @@ -0,0 +1,48 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +"""Module to register python op gradient.""" +import tensorflow as tf +from tensorflow_quantum.core.ops.load_module import load_module + +SIM_OP_MODULE = load_module("_tfq_adj_grad_cuquantum.so") + + +def tfq_adj_grad(programs, symbol_names, symbol_values, pauli_sums, prev_grad): + """Calculate gradient of expectation value of circuits wrt some operator(s). + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] + containing the string representation of the operators that will + be used on all of the circuits in the expectation calculations. + prev_grad: `tf.Tensor` of real numbers with shape [batch_size, n_ops] + backprop of values from downstream in the compute graph. + Returns: + `tf.Tensor` with shape [batch_size, n_params] that holds the gradient of + expectation value for each circuit with each op applied to it + (after resolving the corresponding parameters in). + """ + return SIM_OP_MODULE.tfq_adjoint_gradient_cuquantum( + programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums, + tf.cast(prev_grad, tf.float32)) diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py new file mode 100644 index 000000000..a0c63841e --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py @@ -0,0 +1,400 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== +"""Tests that specifically target tfq_unitary_op.""" +# 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 + +import numpy as np +from absl.testing import parameterized +import tensorflow as tf +import cirq +import sympy + +from tensorflow_quantum.python import util +from tensorflow_quantum.core.ops import tfq_adj_grad_op_cuquantum + + +class ADJGradTest(tf.test.TestCase, parameterized.TestCase): + """Tests tfq_calculate_unitary.""" + + def test_adj_grad_inputs(self): + """Make sure that the expectation op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + upstream_grads = np.ones((batch_size, len(symbol_names))) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # Circuit tensor has too many dimensions. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor([circuit_batch]), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1.'): + # symbol_names tensor has too many dimensions. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too many dimensions. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(np.array([symbol_values_array])), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too few dimensions. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array[0]), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too few dimensions. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor(list(pauli_sums)), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too many dimensions. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[[x]] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # circuit tensor has the right type but invalid values. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + ['junk'] * batch_size, symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type but invalid values. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), ['junk'], + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'qubits not found in circuit'): + # pauli_sums tensor has the right type but invalid values. + new_qubits = [cirq.GridQubit(5, 5), cirq.GridQubit(9, 9)] + new_pauli_sums = util.random_pauli_sums(new_qubits, 2, batch_size) + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in new_pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # pauli_sums tensor has the right type but invalid values 2. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + [['junk']] * batch_size, tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # circuits tensor has the wrong type. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + [1.0] * batch_size, symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), [0.1234], + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size, + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # pauli_sums tensor has the wrong type. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), [[1.0]] * batch_size, + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(TypeError, 'missing'): + # we are missing an argument. + # pylint: disable=no-value-for-parameter + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + tf.convert_to_tensor(upstream_grads)) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(TypeError, 'positional arguments'): + # pylint: disable=too-many-function-args + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads), []) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong op size. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor([cirq.Circuit()]), symbol_names, + symbol_values_array.astype(np.float64), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='rank 2'): + # wrong grad shape. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor([upstream_grads])) + + with self.assertRaisesRegex( + tf.errors.InvalidArgumentError, + expected_regex='gradients and circuits do not match'): + # wrong grad batch size. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor([[0 for i in range(len(symbol_names))]])) + + with self.assertRaisesRegex( + tf.errors.InvalidArgumentError, + expected_regex='gradients and pauli sum dimension do not match' + ): + # wrong grad inner size. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor([[0, 0] for _ in range(len(circuit_batch)) + ])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor([noisy_circuit for _ in circuit_batch]), + symbol_names, tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + def test_calculate_adj_grad_empty(self): + """Verify that the empty case is handled gracefully.""" + out = tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor([cirq.Circuit()]), + tf.convert_to_tensor([], dtype=tf.dtypes.string), + tf.convert_to_tensor([[]]), + tf.convert_to_tensor([[]], dtype=tf.dtypes.string), + tf.convert_to_tensor([[]])) + self.assertShapeEqual(np.zeros((1, 0)), out) + + def test_calculate_adj_grad_no_circuit(self): + """Verify that the no circuit case is handled gracefully.""" + out = tfq_adj_grad_op_cuquantum.tfq_adj_grad( + tf.raw_ops.Empty(shape=(0,), dtype=tf.string), + tf.raw_ops.Empty(shape=(0,), dtype=tf.string), + tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32), + tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string), + tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32), + ) + self.assertShapeEqual(np.zeros((0, 0)), out) + + def test_calculate_adj_grad_simple_case(self): + """Make sure that adjoint gradient works on simple input case.""" + n_qubits = 2 + batch_size = 1 + symbol_names = ['alpha', 'beta'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + [cirq.Circuit(cirq.X(qubits[0]) ** sympy.Symbol('alpha'), + cirq.Y(qubits[1]) ** sympy.Symbol('beta'), + cirq.CNOT(qubits[0], qubits[1]))], [{'alpha': 0.123, 'beta': 0.456}] + + op_batch = [ + [cirq.Z(qubits[0]), cirq.X(qubits[1])] for _ in range(batch_size) + ] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + prev_grads = tf.ones([batch_size, len(symbol_names)]) + + out = tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), + tf.convert_to_tensor(symbol_names), + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor(op_batch), prev_grads) + + self.assertAllClose(out, np.array([[-1.18392, 0.43281]]), atol=1e-3) + + def test_calculate_adj_grad_simple_case2(self): + """Make sure the adjoint gradient works on another simple input case.""" + n_qubits = 2 + batch_size = 1 + symbol_names = ['alpha', 'beta', 'gamma'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + [cirq.Circuit(cirq.X(qubits[0]) ** sympy.Symbol('alpha'), + cirq.Y(qubits[1]) ** sympy.Symbol('beta'), + cirq.CNOT(qubits[0], qubits[1]), + cirq.FSimGate(sympy.Symbol('gamma'), 0.5)(qubits[0], qubits[1])) + ], [{'alpha': 0.123, 'beta': 0.456, 'gamma': 0.789}] + + op_batch = [ + [cirq.Z(qubits[0]), cirq.X(qubits[1])] for _ in range(batch_size) + ] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + prev_grads = tf.ones([batch_size, len(op_batch[0])]) + + out = tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), + tf.convert_to_tensor(symbol_names), + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor(op_batch), prev_grads) + + self.assertAllClose(out, + np.array([[-2.100, -1.7412, -1.5120]]), + atol=1e-3) + + def test_calculate_adj_grad_simple_case_shared(self): + """Make sure the adjoint gradient works on a shared symbol gate.""" + n_qubits = 2 + batch_size = 1 + symbol_names = ['alpha', 'beta', 'gamma'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + [cirq.Circuit(cirq.X(qubits[0]) ** sympy.Symbol('alpha'), + cirq.Y(qubits[1]) ** sympy.Symbol('beta'), + cirq.CNOT(qubits[0], qubits[1]), + cirq.FSimGate( + sympy.Symbol('gamma'), + sympy.Symbol('gamma'))(qubits[0], qubits[1])) + ], [{'alpha': 0.123, 'beta': 0.456, 'gamma': 0.789}] + + op_batch = [ + [cirq.Z(qubits[0]), cirq.X(qubits[1])] for _ in range(batch_size) + ] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + prev_grads = tf.ones([batch_size, len(op_batch[0])]) + + out = tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), + tf.convert_to_tensor(symbol_names), + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor(op_batch), prev_grads) + + self.assertAllClose(out, + np.array([[-2.3484, -1.7532, -1.64264]]), + atol=1e-3) + + def test_calculate_adj_grad_simple_case_single(self): + """Make sure the adjoint gradient works on a one symbol for all gate.""" + n_qubits = 2 + batch_size = 1 + symbol_names = ['alpha', 'beta', 'gamma'] + qubits = cirq.LineQubit.range(n_qubits) + circuit_batch, resolver_batch = \ + [cirq.Circuit(cirq.X(qubits[0]) ** sympy.Symbol('alpha'), + cirq.Y(qubits[1]) ** sympy.Symbol('alpha'), + cirq.CNOT(qubits[0], qubits[1]), + cirq.FSimGate( + -0.56, + sympy.Symbol('alpha'))(qubits[0], qubits[1])) + ], [{'alpha': 0.123, 'beta': 0.456, 'gamma': 0.789}] + + op_batch = [ + [cirq.Z(qubits[0]), cirq.X(qubits[1])] for _ in range(batch_size) + ] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + prev_grads = tf.ones([batch_size, len(op_batch[0])]) + + out = tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), + tf.convert_to_tensor(symbol_names), + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor(op_batch), prev_grads) + + self.assertAllClose(out, np.array([[1.2993, 0, 0]]), atol=1e-3) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index f9f7aa180..9d0f5237f 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -84,7 +84,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor), "CPU", - num_samples=10, + num_samples=100, ) cuquantum_avg_time, res_cuquantum = measure_average_runtime( @@ -92,7 +92,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor), "cuQuantum", - num_samples=10, + num_samples=100, ) # cuQuantum op should be faster than CPU op. @@ -139,7 +139,8 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): symbol_values_array.astype(np.float64), pauli_sums_tensor, n_samples), "CPU", - num_samples=10, + num_samples=100, + result_avg=True, ) cuquantum_avg_time, res_cuquantum = measure_average_runtime( @@ -148,59 +149,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): symbol_values_array.astype(np.float64), pauli_sums_tensor, n_samples), "cuQuantum", - num_samples=10, - ) - - # cuQuantum op should be faster than CPU op. - self.assertGreater(cpu_avg_time, cuquantum_avg_time) - - # The result should be the similar within a tolerance. - np.testing.assert_allclose(res_cpu, - res_cuquantum, - atol=1e-4, - err_msg=""" - # If failed, the GPU architecture in this system may be unsupported. - # Please refer to the supported architectures here. - # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec - """) - - -class SimulateSamplesCuquantumTest(tf.test.TestCase): - """Tests tfq_simulate_samples.""" - - def test_simulate_samples_cpu_vs_cuquantum(self): - """Make sure that cpu & gpu(cuquantum) ops have the same results.""" - n_qubits = 20 - batch_size = 5 - symbol_names = ['alpha'] - n_samples = [100] - qubits = cirq.GridQubit.rect(1, n_qubits) - circuit_batch, resolver_batch = \ - util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, batch_size) - - circuit_batch_tensor = util.convert_to_tensor(circuit_batch) - - symbol_values_array = np.array( - [[resolver[symbol] - for symbol in symbol_names] - for resolver in resolver_batch]) - - cpu_avg_time, res_cpu = measure_average_runtime( - lambda: tfq_simulate_ops.tfq_simulate_samples( - circuit_batch_tensor, symbol_names, - symbol_values_array.astype(np.float64), n_samples), - "CPU", - num_samples=10, - result_avg=True, - ) - - cuquantum_avg_time, res_cuquantum = measure_average_runtime( - lambda: tfq_simulate_ops_cuquantum.tfq_simulate_samples( - circuit_batch_tensor, symbol_names, - symbol_values_array.astype(np.float64), n_samples), - "cuQuantum", - num_samples=10, + num_samples=100, result_avg=True, ) @@ -218,54 +167,107 @@ def test_simulate_samples_cpu_vs_cuquantum(self): """) -class SimulateStateCuquantumTest(tf.test.TestCase): - """Tests tfq_simulate_samples.""" - - def test_simulate_state_cpu_vs_cuquantum(self): - """Make sure that cpu & gpu(cuquantum) ops have the same results.""" - n_qubits = 10 - batch_size = 5 - symbol_names = ['alpha'] - qubits = cirq.GridQubit.rect(1, n_qubits) - circuit_batch, resolver_batch = \ - util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, batch_size) - - circuit_batch_tensor = util.convert_to_tensor(circuit_batch) - - symbol_values_array = np.array( - [[resolver[symbol] - for symbol in symbol_names] - for resolver in resolver_batch]) - - cpu_avg_time, res_cpu = measure_average_runtime( - lambda: tfq_simulate_ops.tfq_simulate_state( - circuit_batch_tensor, symbol_names, - symbol_values_array.astype(np.float64)), - "CPU", - num_samples=10, - ) - - cuquantum_avg_time, res_cuquantum = measure_average_runtime( - lambda: tfq_simulate_ops_cuquantum.tfq_simulate_state( - circuit_batch_tensor, symbol_names, - symbol_values_array.astype(np.float64)), - "cuQuantum", - num_samples=10, - ) - - # cuQuantum op should be faster than CPU op. - self.assertGreater(cpu_avg_time, cuquantum_avg_time) - - # The result should be the similar within a tolerance. - np.testing.assert_allclose(res_cpu, - res_cuquantum, - atol=1e-4, - err_msg=""" - # If failed, the GPU architecture in this system may be unsupported. - # Please refer to the supported architectures here. - # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec - """) +# class SimulateSamplesCuquantumTest(tf.test.TestCase): +# """Tests tfq_simulate_samples.""" + +# def test_simulate_samples_cpu_vs_cuquantum(self): +# """Make sure that cpu & gpu(cuquantum) ops have the same results.""" +# n_qubits = 20 +# batch_size = 5 +# symbol_names = ['alpha'] +# n_samples = [100] +# qubits = cirq.GridQubit.rect(1, n_qubits) +# circuit_batch, resolver_batch = \ +# util.random_symbol_circuit_resolver_batch( +# qubits, symbol_names, batch_size) + +# circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + +# symbol_values_array = np.array( +# [[resolver[symbol] +# for symbol in symbol_names] +# for resolver in resolver_batch]) + +# cpu_avg_time, res_cpu = measure_average_runtime( +# lambda: tfq_simulate_ops.tfq_simulate_samples( +# circuit_batch_tensor, symbol_names, +# symbol_values_array.astype(np.float64), n_samples), +# "CPU", +# num_samples=10, +# result_avg=True, +# ) + +# cuquantum_avg_time, res_cuquantum = measure_average_runtime( +# lambda: tfq_simulate_ops_cuquantum.tfq_simulate_samples( +# circuit_batch_tensor, symbol_names, +# symbol_values_array.astype(np.float64), n_samples), +# "cuQuantum", +# num_samples=10, +# result_avg=True, +# ) + +# # cuQuantum op should be faster than CPU op. +# self.assertGreater(cpu_avg_time, cuquantum_avg_time) + +# # The result should be the similar within a tolerance. +# np.testing.assert_allclose(res_cpu, +# res_cuquantum, +# atol=1e-4, +# err_msg=""" +# # If failed, the GPU architecture in this system may be unsupported. +# # Please refer to the supported architectures here. +# # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec +# """) + + +# class SimulateStateCuquantumTest(tf.test.TestCase): +# """Tests tfq_simulate_samples.""" + +# def test_simulate_state_cpu_vs_cuquantum(self): +# """Make sure that cpu & gpu(cuquantum) ops have the same results.""" +# n_qubits = 10 +# batch_size = 5 +# symbol_names = ['alpha'] +# qubits = cirq.GridQubit.rect(1, n_qubits) +# circuit_batch, resolver_batch = \ +# util.random_symbol_circuit_resolver_batch( +# qubits, symbol_names, batch_size) + +# circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + +# symbol_values_array = np.array( +# [[resolver[symbol] +# for symbol in symbol_names] +# for resolver in resolver_batch]) + +# cpu_avg_time, res_cpu = measure_average_runtime( +# lambda: tfq_simulate_ops.tfq_simulate_state( +# circuit_batch_tensor, symbol_names, +# symbol_values_array.astype(np.float64)), +# "CPU", +# num_samples=10, +# ) + +# cuquantum_avg_time, res_cuquantum = measure_average_runtime( +# lambda: tfq_simulate_ops_cuquantum.tfq_simulate_state( +# circuit_batch_tensor, symbol_names, +# symbol_values_array.astype(np.float64)), +# "cuQuantum", +# num_samples=10, +# ) + +# # cuQuantum op should be faster than CPU op. +# self.assertGreater(cpu_avg_time, cuquantum_avg_time) + +# # The result should be the similar within a tolerance. +# np.testing.assert_allclose(res_cpu, +# res_cuquantum, +# atol=1e-4, +# err_msg=""" +# # If failed, the GPU architecture in this system may be unsupported. +# # Please refer to the supported architectures here. +# # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec +# """) if __name__ == "__main__": From 9b59824f0e755d693a27cf1480fb49445e540b8a Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Tue, 4 Apr 2023 04:54:33 +0000 Subject: [PATCH 019/106] add adj grad cuquantum op to release BUILD --- release/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/release/BUILD b/release/BUILD index b588a6c5a..7eb2a6b40 100644 --- a/release/BUILD +++ b/release/BUILD @@ -71,5 +71,6 @@ sh_binary( ] + if_cuda_is_configured([ "//tensorflow_quantum/core/ops:tfq_simulate_ops_cuda_py", "//tensorflow_quantum/core/ops:tfq_simulate_ops_cuquantum_py", + "//tensorflow_quantum/core/ops:tfq_adj_grad_op_cuquantum_py", ]), ) From bad38a0014c1c3a7c335bca3a12b0b21f4c74a3e Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Tue, 4 Apr 2023 05:04:40 +0000 Subject: [PATCH 020/106] uncomment accidentally commented out tests --- .../ops/tfq_simulate_ops_cuquantum_test.py | 202 +++++++++--------- 1 file changed, 101 insertions(+), 101 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 9d0f5237f..411078531 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -167,107 +167,107 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): """) -# class SimulateSamplesCuquantumTest(tf.test.TestCase): -# """Tests tfq_simulate_samples.""" - -# def test_simulate_samples_cpu_vs_cuquantum(self): -# """Make sure that cpu & gpu(cuquantum) ops have the same results.""" -# n_qubits = 20 -# batch_size = 5 -# symbol_names = ['alpha'] -# n_samples = [100] -# qubits = cirq.GridQubit.rect(1, n_qubits) -# circuit_batch, resolver_batch = \ -# util.random_symbol_circuit_resolver_batch( -# qubits, symbol_names, batch_size) - -# circuit_batch_tensor = util.convert_to_tensor(circuit_batch) - -# symbol_values_array = np.array( -# [[resolver[symbol] -# for symbol in symbol_names] -# for resolver in resolver_batch]) - -# cpu_avg_time, res_cpu = measure_average_runtime( -# lambda: tfq_simulate_ops.tfq_simulate_samples( -# circuit_batch_tensor, symbol_names, -# symbol_values_array.astype(np.float64), n_samples), -# "CPU", -# num_samples=10, -# result_avg=True, -# ) - -# cuquantum_avg_time, res_cuquantum = measure_average_runtime( -# lambda: tfq_simulate_ops_cuquantum.tfq_simulate_samples( -# circuit_batch_tensor, symbol_names, -# symbol_values_array.astype(np.float64), n_samples), -# "cuQuantum", -# num_samples=10, -# result_avg=True, -# ) - -# # cuQuantum op should be faster than CPU op. -# self.assertGreater(cpu_avg_time, cuquantum_avg_time) - -# # The result should be the similar within a tolerance. -# np.testing.assert_allclose(res_cpu, -# res_cuquantum, -# atol=1e-4, -# err_msg=""" -# # If failed, the GPU architecture in this system may be unsupported. -# # Please refer to the supported architectures here. -# # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec -# """) - - -# class SimulateStateCuquantumTest(tf.test.TestCase): -# """Tests tfq_simulate_samples.""" - -# def test_simulate_state_cpu_vs_cuquantum(self): -# """Make sure that cpu & gpu(cuquantum) ops have the same results.""" -# n_qubits = 10 -# batch_size = 5 -# symbol_names = ['alpha'] -# qubits = cirq.GridQubit.rect(1, n_qubits) -# circuit_batch, resolver_batch = \ -# util.random_symbol_circuit_resolver_batch( -# qubits, symbol_names, batch_size) - -# circuit_batch_tensor = util.convert_to_tensor(circuit_batch) - -# symbol_values_array = np.array( -# [[resolver[symbol] -# for symbol in symbol_names] -# for resolver in resolver_batch]) - -# cpu_avg_time, res_cpu = measure_average_runtime( -# lambda: tfq_simulate_ops.tfq_simulate_state( -# circuit_batch_tensor, symbol_names, -# symbol_values_array.astype(np.float64)), -# "CPU", -# num_samples=10, -# ) - -# cuquantum_avg_time, res_cuquantum = measure_average_runtime( -# lambda: tfq_simulate_ops_cuquantum.tfq_simulate_state( -# circuit_batch_tensor, symbol_names, -# symbol_values_array.astype(np.float64)), -# "cuQuantum", -# num_samples=10, -# ) - -# # cuQuantum op should be faster than CPU op. -# self.assertGreater(cpu_avg_time, cuquantum_avg_time) - -# # The result should be the similar within a tolerance. -# np.testing.assert_allclose(res_cpu, -# res_cuquantum, -# atol=1e-4, -# err_msg=""" -# # If failed, the GPU architecture in this system may be unsupported. -# # Please refer to the supported architectures here. -# # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec -# """) +class SimulateSamplesCuquantumTest(tf.test.TestCase): + """Tests tfq_simulate_samples.""" + + def test_simulate_samples_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + n_samples = [100] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cpu_avg_time, res_cpu = measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_samples( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), n_samples), + "CPU", + num_samples=10, + result_avg=True, + ) + + cuquantum_avg_time, res_cuquantum = measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_samples( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), n_samples), + "cuQuantum", + num_samples=10, + result_avg=True, + ) + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuquantum_avg_time) + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, + res_cuquantum, + atol=1e-4, + err_msg=""" + # If failed, the GPU architecture in this system may be unsupported. + # Please refer to the supported architectures here. + # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec + """) + + +class SimulateStateCuquantumTest(tf.test.TestCase): + """Tests tfq_simulate_samples.""" + + def test_simulate_state_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 10 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cpu_avg_time, res_cpu = measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_state( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64)), + "CPU", + num_samples=10, + ) + + cuquantum_avg_time, res_cuquantum = measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_state( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64)), + "cuQuantum", + num_samples=10, + ) + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuquantum_avg_time) + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, + res_cuquantum, + atol=1e-4, + err_msg=""" + # If failed, the GPU architecture in this system may be unsupported. + # Please refer to the supported architectures here. + # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec + """) if __name__ == "__main__": From 69a61a5df5a6ca106e9a41401dbf84067df8c003 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Tue, 4 Apr 2023 05:33:58 +0000 Subject: [PATCH 021/106] add passing sanity check tests for cuquantm simulate ops --- .../ops/tfq_simulate_ops_cuquantum_test.py | 655 +++++++++++++++++- 1 file changed, 651 insertions(+), 4 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index f9f7aa180..e2b502c91 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -15,6 +15,7 @@ """Tests that specifically target tfq_simulate_ops_cu*.""" import time import numpy as np +from absl.testing import parameterized import tensorflow as tf import cirq @@ -84,7 +85,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor), "CPU", - num_samples=10, + num_samples=100, ) cuquantum_avg_time, res_cuquantum = measure_average_runtime( @@ -92,7 +93,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor), "cuQuantum", - num_samples=10, + num_samples=100, ) # cuQuantum op should be faster than CPU op. @@ -108,6 +109,175 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec """) + def test_simulate_expectation_inputs(self): + """Make sure that the expectation op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # Circuit tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor([circuit_batch]), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1.'): + # symbol_names tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array]), + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too few dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[0], + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too few dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, util.convert_to_tensor(list(pauli_sums))) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[[x]] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # circuit tensor has the right type but invalid values. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + ['junk'] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type but invalid values. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), ['junk'], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'qubits not found in circuit'): + # pauli_sums tensor has the right type but invalid values. + new_qubits = [cirq.GridQubit(5, 5), cirq.GridQubit(9, 9)] + new_pauli_sums = util.random_pauli_sums(new_qubits, 2, batch_size) + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in new_pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # pauli_sums tensor has the right type but invalid values 2. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [['junk']] * batch_size) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # circuits tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + [1.0] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), [0.1234], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # pauli_sums tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [[1.0]] * batch_size) + + with self.assertRaisesRegex(TypeError, 'missing'): + # we are missing an argument. + # pylint: disable=no-value-for-parameter + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(TypeError, 'positional arguments'): + # pylint: disable=too-many-function-args + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), []) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong op size. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums + ][:int(batch_size * 0.5)])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)], + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor([noisy_circuit for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + res = tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor([cirq.Circuit() for _ in pauli_sums]), + symbol_names, symbol_values_array.astype(np.float64), + util.convert_to_tensor([[x] for x in pauli_sums])) + self.assertDTypeEqual(res, np.float32) + class SimulateSampledExpectationCuquantumTest(tf.test.TestCase): """Tests tfq_simulate_sampled_expectation.""" @@ -165,7 +335,201 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): """) -class SimulateSamplesCuquantumTest(tf.test.TestCase): + def test_simulate_sampled_expectation_inputs(self): + """Make sure sampled expectation op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + num_samples = [[10]] * batch_size + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # Circuit tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor([circuit_batch]), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1.'): + # symbol_names tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array]), + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too few dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[0], + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too few dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + util.convert_to_tensor(list(pauli_sums)), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + [util.convert_to_tensor([[x] for x in pauli_sums])], + num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'num_samples must be rank 2'): + # num_samples tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'num_samples must be rank 2'): + # num_samples tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + num_samples[0]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # circuit tensor has the right type but invalid values. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + ['junk'] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type but invalid values. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), ['junk'], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'qubits not found in circuit'): + # pauli_sums tensor has the right type but invalid values. + new_qubits = [cirq.GridQubit(5, 5), cirq.GridQubit(9, 9)] + new_pauli_sums = util.random_pauli_sums(new_qubits, 2, batch_size) + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in new_pauli_sums]), + num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # pauli_sums tensor has the right type but invalid values 2. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [['junk']] * batch_size, num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # circuits tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + [1.0] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), [0.1234], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # pauli_sums tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [[1.0]] * batch_size, num_samples) + + with self.assertRaisesRegex(TypeError, 'missing'): + # we are missing an argument. + # pylint: disable=no-value-for-parameter + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, num_samples) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(TypeError, 'positional arguments'): + # pylint: disable=too-many-function-args + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), [], + num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong op size. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor([cirq.Circuit()]), symbol_names, + symbol_values_array.astype(np.float64), + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'greater than 0'): + # pylint: disable=too-many-function-args + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + [[-1]] * batch_size) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)], + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor([noisy_circuit for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + +class SimulateSamplesCuquantumTest(tf.test.TestCase, parameterized.TestCase): """Tests tfq_simulate_samples.""" def test_simulate_samples_cpu_vs_cuquantum(self): @@ -218,7 +582,150 @@ def test_simulate_samples_cpu_vs_cuquantum(self): """) -class SimulateStateCuquantumTest(tf.test.TestCase): + def test_simulate_samples_inputs(self): + """Make sure the sample op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + num_samples = 10 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 1. Got rank 2'): + # programs tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor([circuit_batch]), symbol_names, + symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 1. Got rank 2'): + # symbol_names tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 2. Got rank 3'): + # symbol_values tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array]), [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 2. Got rank 1'): + # symbol_values tensor has the wrong shape 2. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[0], [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 1. Got rank 2'): + # num_samples tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [[num_samples]]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # programs tensor has the right type, but invalid value. + tfq_simulate_ops_cuquantum.tfq_simulate_samples(['junk'] * batch_size, + symbol_names, + symbol_values_array, + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type, but invalid value. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), ['junk'], + symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # programs tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_samples([1] * batch_size, + symbol_names, + symbol_values_array, + [num_samples]) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # programs tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), [1], symbol_values_array, + [num_samples]) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, + 'Cast string to float is not supported'): + # programs tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size, [num_samples]) + + with self.assertRaisesRegex(Exception, 'junk'): + # num_samples tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, ['junk']) + + with self.assertRaisesRegex(TypeError, 'missing'): + # too few tensors. + # pylint: disable=no-value-for-parameter + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)], num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor([noisy_circuit for _ in circuit_batch]), + symbol_names, symbol_values_array, [num_samples]) + + @parameterized.parameters([ + { + 'all_n_qubits': [2, 3], + 'n_samples': 10 + }, + { + 'all_n_qubits': [1, 5, 8], + 'n_samples': 10 + }, + ]) + def test_sampling_output_padding(self, all_n_qubits, n_samples): + """Check that the sampling ops pad outputs correctly""" + op = tfq_simulate_ops_cuquantum.tfq_simulate_samples + circuits = [] + expected_outputs = [] + for n_qubits in all_n_qubits: + this_expected_output = np.zeros((n_samples, max(all_n_qubits))) + this_expected_output[:, max(all_n_qubits) - n_qubits:] = 1 + this_expected_output[:, :max(all_n_qubits) - n_qubits] = -2 + expected_outputs.append(this_expected_output) + circuits.append( + cirq.Circuit(*cirq.X.on_each( + *cirq.GridQubit.rect(1, n_qubits)))) + results = op(util.convert_to_tensor(circuits), [], [[]] * len(circuits), + [n_samples]).numpy() + self.assertAllClose(expected_outputs, results) + + +class SimulateStateCuquantumTest(tf.test.TestCase, parameterized.TestCase): """Tests tfq_simulate_samples.""" def test_simulate_state_cpu_vs_cuquantum(self): @@ -268,5 +775,145 @@ def test_simulate_state_cpu_vs_cuquantum(self): """) + def test_simulate_state_inputs(self): + """Make sure the state op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # programs tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor([circuit_batch]), symbol_names, + symbol_values_array) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1'): + # symbol_names tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + symbol_values_array) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2'): + # symbol_values tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2'): + # symbol_values tensor has the wrong shape 2. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[0]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # programs tensor has the right type, but invalid value. + tfq_simulate_ops_cuquantum.tfq_simulate_state(['junk'] * batch_size, + symbol_names, + symbol_values_array) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type, but invalid value. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), ['junk'], + symbol_values_array) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # programs tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_state([1] * batch_size, symbol_names, + symbol_values_array) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), [1], symbol_values_array) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size) + + with self.assertRaisesRegex(TypeError, 'missing'): + # too few tensors. + # pylint: disable=no-value-for-parameter + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), symbol_names) + # pylint: enable=no-value-for-parameter + + # TODO (mbbrough): determine if we should allow extra arguments ? + with self.assertRaisesRegex(TypeError, 'positional arguments'): + # pylint: disable=too-many-function-args + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, []) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor([noisy_circuit for _ in circuit_batch]), + symbol_names, symbol_values_array) + + @parameterized.parameters([ + { + 'all_n_qubits': [2, 3] + }, + { + 'all_n_qubits': [1, 5, 8] + }, + ]) + def test_simulate_state_output_padding(self, all_n_qubits): + """If a tfq_simulate op is asked to simulate states given circuits + acting on different numbers of qubits, the op should return a tensor + padded with zeros up to the size of the largest circuit. The padding + should be physically correct, such that samples taken from the padded + states still match samples taken from the original circuit. """ + circuit_batch = [] + for n_qubits in all_n_qubits: + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch += util.random_circuit_resolver_batch(qubits, 1)[0] + + tfq_results = tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), [], + [[]] * len(circuit_batch)) + + # Don't use batch_util here to enforce consistent padding everywhere + # without extra tests. + sim = cirq.Simulator() + manual_padded_results = [] + for circuit in circuit_batch: + result = sim.simulate(circuit) + wf = result.final_state_vector + blank_state = np.ones( + (2**max(all_n_qubits)), dtype=np.complex64) * -2 + blank_state[:wf.shape[0]] = wf + manual_padded_results.append(blank_state) + + self.assertAllClose(tfq_results, manual_padded_results, atol=1e-5) + + if __name__ == "__main__": tf.test.main() From 39ba7c2e461884b193a2acc721a146048339ddac Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Tue, 4 Apr 2023 05:48:29 +0000 Subject: [PATCH 022/106] modify bazel test target --- tensorflow_quantum/core/ops/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index 3c9d61bb6..0e78e1f5a 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -946,7 +946,7 @@ py_library( py_test( name = "tfq_adj_grad_op_cuquantum_test", - srcs = ["tfq_adj_grad_op_cuquantum.py"], + srcs = ["tfq_adj_grad_op_cuquantum_test.py"], python_version = "PY3", deps = [ ":tfq_adj_grad_op_cuquantum_py", From d457e600f639800040250f484443b8abb6a5c13c Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Tue, 4 Apr 2023 08:18:14 +0000 Subject: [PATCH 023/106] add cpu vs gpu benchmark test --- tensorflow_quantum/core/ops/BUILD | 1 + .../ops/tfq_adj_grad_op_cuquantum_test.py | 88 +++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index 0e78e1f5a..75a34d2e4 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -950,6 +950,7 @@ py_test( python_version = "PY3", deps = [ ":tfq_adj_grad_op_cuquantum_py", + ":tfq_adj_grad_op_py", "//tensorflow_quantum/python:util", ], srcs_version = "PY3", diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py index a0c63841e..e1d8f332f 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py @@ -21,18 +21,106 @@ # pylint: enable=wrong-import-position import numpy as np +import time from absl.testing import parameterized import tensorflow as tf import cirq import sympy from tensorflow_quantum.python import util +from tensorflow_quantum.core.ops import tfq_adj_grad_op from tensorflow_quantum.core.ops import tfq_adj_grad_op_cuquantum +def measure_average_runtime( + fn, + tag, + num_samples=10, + result_avg=False, +): + """Measures average runtime for given function. + + Args: + fn: function. + tag: The message title. + num_samples: The number of measurements. + result_avg: True if the results are all averaged. + + Returns: + The average time and the (averaged) result. + """ + avg_time = [] + avg_res = [] + for _ in range(num_samples): + begin_time = time.time() + result = fn() + duration = time.time() - begin_time + avg_time.append(duration) + if result_avg: + avg_res.append(result) + avg_time = sum(avg_time) / float(num_samples) + print(f"\n\t{tag} time: {avg_time}\n") + if result_avg: + result = np.average(avg_res, axis=0) + return avg_time, result class ADJGradTest(tf.test.TestCase, parameterized.TestCase): """Tests tfq_calculate_unitary.""" + def test_calculate_adj_grad_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + prev_grads = tf.ones([batch_size, len(symbol_names)]) + + cpu_avg_time, res_cpu = measure_average_runtime( + lambda: tfq_adj_grad_op.tfq_adj_grad( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor, + prev_grads), + "CPU", + num_samples=100, + result_avg=True, + ) + + cuquantum_avg_time, res_cuquantum = measure_average_runtime( + lambda: tfq_adj_grad_op_cuquantum.tfq_adj_grad( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor, + prev_grads), + "cuQuantum", + num_samples=100, + result_avg=True, + ) + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuquantum_avg_time) + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, + res_cuquantum, + atol=1e-4, + err_msg=""" + # If failed, the GPU architecture in this system may be unsupported. + # Please refer to the supported architectures here. + # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec + """) + def test_adj_grad_inputs(self): """Make sure that the expectation op fails gracefully on bad inputs.""" n_qubits = 5 From 34ad903855eab047b8c0b7af297000fdde613b60 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Thu, 6 Apr 2023 23:10:51 +0000 Subject: [PATCH 024/106] lint all --- .../core/ops/tfq_adj_grad_op_cuquantum_test.py | 2 +- .../core/ops/tfq_simulate_ops_cuquantum_test.py | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py index e1d8f332f..10ace5bf3 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py @@ -20,8 +20,8 @@ sys.path = NEW_PATH # pylint: enable=wrong-import-position -import numpy as np import time +import numpy as np from absl.testing import parameterized import tensorflow as tf import cirq diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 0e37e6ba4..47f6004b9 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -638,7 +638,8 @@ def test_simulate_samples_inputs(self): with self.assertRaisesRegex(tf.errors.InvalidArgumentError, 'Unparseable proto'): # programs tensor has the right type, but invalid value. - tfq_simulate_ops_cuquantum.tfq_simulate_samples(['junk'] * batch_size, + tfq_simulate_ops_cuquantum.tfq_simulate_samples(\ + ['junk'] * batch_size, symbol_names, symbol_values_array, [num_samples]) @@ -836,8 +837,9 @@ def test_simulate_state_inputs(self): with self.assertRaisesRegex(TypeError, 'Cannot convert'): # programs tensor has the wrong type. - tfq_simulate_ops_cuquantum.tfq_simulate_state([1] * batch_size, symbol_names, - symbol_values_array) + tfq_simulate_ops_cuquantum.tfq_simulate_state([1] * batch_size, + symbol_names, + symbol_values_array) with self.assertRaisesRegex(TypeError, 'Cannot convert'): # symbol_names tensor has the wrong type. From 50814f6545a8e518b1ee5c3cec40cf1ddb87d568 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Tue, 11 Apr 2023 08:20:09 +0000 Subject: [PATCH 025/106] add adj grad keras layer use_gpu option [left debug statements] --- tensorflow_quantum/core/ops/BUILD | 1 + tensorflow_quantum/python/differentiators/BUILD | 1 + .../python/differentiators/adjoint.py | 10 ++++++++-- .../python/differentiators/differentiator.py | 16 ++++++++++++---- .../layers/circuit_executors/expectation.py | 3 ++- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index 75a34d2e4..d61fde618 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -538,6 +538,7 @@ py_library( deps = [ ":cirq_ops", ":tfq_simulate_ops_py", + ":tfq_simulate_ops_cuquantum_py", ":tfq_utility_ops_py", "//tensorflow_quantum/python:quantum_context", ], diff --git a/tensorflow_quantum/python/differentiators/BUILD b/tensorflow_quantum/python/differentiators/BUILD index 9e5f28aab..1f5ddb9bf 100644 --- a/tensorflow_quantum/python/differentiators/BUILD +++ b/tensorflow_quantum/python/differentiators/BUILD @@ -25,6 +25,7 @@ py_library( deps = [ ":differentiator", "//tensorflow_quantum/core/ops:tfq_adj_grad_op_py", + "//tensorflow_quantum/core/ops:tfq_adj_grad_op_cuquantum_py", ], ) diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index af78fe0b3..749f616df 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -62,7 +62,7 @@ class Adjoint(differentiator.Differentiator): """ - def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): + def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, use_gpu=False): """Generate a differentiable op by attaching self to an op. See `tfq.differentiators.Differentiator`. This has been partially @@ -75,18 +75,23 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): using this differentiator's `differentiate_sampled` method. analytic_op: A `callable` op that you want to make differentiable using this differentiators `differentiate_analytic` method. + use_gpu: A `bool` indicating whether to use the GPU version of the + adjoint gradient op. Returns: A `callable` op that who's gradients are now registered to be a call to this differentiators `differentiate_*` function. """ + self.use_gpu = use_gpu + if self.use_gpu: + print("[LOG] USING GPU version") if sampled_op is not None: raise ValueError("sample base backends are not supported by the " "Adjoint method, please use analytic expectation" " or choose another differentiator.") - return super().generate_differentiable_op(analytic_op=analytic_op) + return super().generate_differentiable_op(analytic_op=analytic_op, use_gpu=use_gpu) @tf.function def get_gradient_circuits(self, programs, symbol_names, symbol_values): @@ -100,6 +105,7 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values): def differentiate_analytic(self, programs, symbol_names, symbol_values, pauli_sums, forward_pass_vals, grad, use_gpu=False): if use_gpu: + print("[LOG] USING GPU version") return tfq_adj_grad_op_cuquantum.tfq_adj_grad(programs, symbol_names, symbol_values, pauli_sums, grad) else: diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index 4b1d597ed..f91a27d2f 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -55,7 +55,8 @@ class Differentiator(metaclass=abc.ABCMeta): to backpropagate through a quantum circuit. """ - def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): + def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, + use_gpu=False): """Generate a differentiable op by attaching self to an op. This function returns a `tf.function` that passes values through to @@ -80,6 +81,7 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): using this differentiator's `differentiate_sampled` method. analytic_op: A `callable` op that you want to make differentiable using this differentiators `differentiate_analytic` method. + use_gpu: A `bool` indicating whether to use GPU Returns: A `callable` op that who's gradients are now registered to be @@ -117,7 +119,9 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): # put inside of the analytical_op argument or vice versa. # right all that is checked is that the desire op signatures # are substrings of the given op signature. + print("analytic_op: ", analytic_op) if analytic_op is not None: + print("[LOG] analytic_op is not None") signature = inspect.signature(analytic_op).parameters expected_signature = [ 'programs', 'symbol_names', 'symbol_values', 'pauli_sums' @@ -138,6 +142,7 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): 'Note: noisy ops should use sampled_op') if sampled_op is not None: + print("[LOG] sampled_op is not None") signature = inspect.signature(sampled_op).parameters expected_signature = [ 'programs', 'symbol_names', 'symbol_values', 'pauli_sums', @@ -159,7 +164,8 @@ def op_wrapper_analytic(programs, symbol_names, symbol_values, def gradient(grad): return self._differentiate_ana(programs, symbol_names, symbol_values, pauli_sums, - forward_pass_vals, grad) + forward_pass_vals, grad, + use_gpu=use_gpu) return forward_pass_vals, gradient @@ -181,16 +187,18 @@ def gradient(grad): self.expectation_op = analytic_op return_func = op_wrapper_analytic if analytic_op is None: + print("[LOG] analytic_op is None") self.expectation_op = sampled_op return_func = op_wrapper_sampled + print("[LOG] return_func: ", return_func) return return_func def _differentiate_ana(self, programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad): + pauli_sums, forward_pass_vals, grad, use_gpu): return None, None, self.differentiate_analytic( programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad), \ + pauli_sums, forward_pass_vals, grad, use_gpu=use_gpu), \ None def _differentiate_sam(self, programs, symbol_names, symbol_values, diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation.py b/tensorflow_quantum/python/layers/circuit_executors/expectation.py index bce5c7d91..dcd39a73c 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation.py @@ -247,6 +247,7 @@ def __init__(self, backend='noiseless', differentiator=None, use_gpu=False, if differentiator is None: differentiator = parameter_shift.ParameterShift() if backend is None: + print("[LOG] Using Adjoint Differentiator for noiseless") differentiator = adjoint.Adjoint() if not isinstance(differentiator, diff.Differentiator): @@ -264,7 +265,7 @@ def __init__(self, backend='noiseless', differentiator=None, use_gpu=False, used_op = circuit_execution_ops.get_expectation_op(backend=backend, use_gpu=use_gpu) self._expectation_op = differentiator.generate_differentiable_op( - analytic_op=used_op) + analytic_op=used_op, use_gpu=use_gpu) self._w = None From 40f1ba2d04b93ede00f54e1d598fbb8809183d2e Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Tue, 11 Apr 2023 08:22:08 +0000 Subject: [PATCH 026/106] comment out all tests but trivial adj grad op learning with gpu test --- .../circuit_executors/expectation_test.py | 797 +++++++++--------- 1 file changed, 399 insertions(+), 398 deletions(-) diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py index e4489e763..28ffdbe3f 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py @@ -47,262 +47,262 @@ def _gen_single_bit_rotation_problem(bit, symbols, noisy): return circuit -class ExpectationTest(tf.test.TestCase): - """Basic tests for the expectation layer.""" - - def test_expectation_instantiate(self): - """Test that Expectation instantiates correctly.""" - expectation.Expectation() - expectation.Expectation(backend=None) - expectation.Expectation(backend='noisy') - expectation.Expectation(backend='noiseless') - expectation.Expectation(backend=cirq.Simulator()) - expectation.Expectation( - differentiator=linear_combination.ForwardDifference()) - - def test_expectation_instantiate_error(self): - """Test that Expectation errors with bad inputs.""" - - class MySampler(cirq.Sampler): - """Class to test sampler detection in Expectation.""" - - def run_sweep(self): - """do nothing.""" - return - - with self.assertRaisesRegex(TypeError, - expected_regex="SampledExpectation"): - expectation.Expectation(backend=MySampler()) - - with self.assertRaisesRegex( - TypeError, expected_regex="SimulatesExpectationValues or None"): - expectation.Expectation(backend='junk') - - with self.assertRaisesRegex( - TypeError, expected_regex="tfq.differentiators.Differentiator"): - expectation.Expectation(differentiator='junk') - - def test_expectation_type_inputs_error(self): - """Test that expectation errors within Keras call.""" - - bit = cirq.GridQubit(0, 0) - test_pstring = cirq.Z(bit) - test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) - reg_circuit = cirq.Circuit(cirq.H(bit)) - - with self.assertRaisesRegex(Exception, - expected_regex="Unknown initializer"): - expectation.Expectation()(reg_circuit, - operators=test_psum, - initializer='junk') - - with self.assertRaisesRegex(Exception, - expected_regex="repetitions not provided"): - expectation.Expectation(backend='noisy')(reg_circuit, - operators=test_psum) - - with self.assertRaisesRegex(Exception, - expected_regex="cannot be parsed"): - expectation.Expectation(backend='noisy')(reg_circuit, - operators=test_psum, - repetitions='junk') - - with self.assertRaisesRegex(Exception, expected_regex="noiseless"): - expectation.Expectation(backend='noiseless')(reg_circuit, - operators=test_psum, - repetitions=1) - - def test_expectation_op_error(self): - """Test that expectation errors within underlying ops correctly.""" - - bit = cirq.GridQubit(0, 0) - symbol = sympy.Symbol('alpha') - test_pstring = cirq.Z(bit) - test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) - symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) - reg_circuit = cirq.Circuit(cirq.H(bit)) - - with self.assertRaisesRegex(Exception, - expected_regex="Could not find symbol"): - # No symbol matchups. - expectation.Expectation()([symb_circuit], operators=test_psum) - - with self.assertRaisesRegex(Exception, - expected_regex="Unparseable proto"): - # Proto is unparseable. - expectation.Expectation()([reg_circuit], - operators=tf.convert_to_tensor( - [['bad_operator']])) - - with self.assertRaisesRegex(Exception, expected_regex="rank 2"): - # Operators has wrong rank. - expectation.Expectation()([reg_circuit], - operators=util.convert_to_tensor( - [test_psum])) - - with self.assertRaisesRegex(Exception, expected_regex="rank 2"): - # symbol_values has wrong rank. - expectation.Expectation()([symb_circuit], - symbol_names=[symbol], - symbol_values=[0.5], - operators=test_psum) - - with self.assertRaisesRegex(Exception, expected_regex="do not match."): - # Wrong batch size for pauli operators. - expectation.Expectation()(symb_circuit, - symbol_names=[symbol], - operators=[[test_psum], [test_psum]]) - - with self.assertRaisesRegex(Exception, expected_regex="do not match."): - # Wrong batch_size for symbol values. - expectation.Expectation()([symb_circuit], - symbol_names=[symbol], - symbol_values=np.zeros((3, 1)), - operators=test_psum) - - def test_static_cases(self): - """Run inputs through in complex cases.""" - - bit = cirq.GridQubit(0, 0) - symbol = sympy.Symbol('alpha') - test_pstring = cirq.Z(bit) - test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) - symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) - reg_circuit = cirq.Circuit(cirq.H(bit)) - - # Passing a 2d operators input requires a 1d circuit input. - expectation.Expectation()([reg_circuit, reg_circuit], - operators=[[test_psum, test_psum], - [test_psum, test_psum]]) - - # Passing 2d operators along with other inputs. - expectation.Expectation()([symb_circuit, symb_circuit], - symbol_names=[symbol], - operators=[[test_psum, test_psum], - [test_psum, test_psum]]) - expectation.Expectation()([symb_circuit, symb_circuit], - symbol_names=[symbol], - symbol_values=[[0.5], [0.8]], - operators=[[test_psum, test_psum], - [test_psum, test_psum]]) - - # Ensure tiling up of circuits works as expected. - expectation.Expectation()(reg_circuit, operators=test_psum) - expectation.Expectation()(reg_circuit, operators=[test_psum, test_psum]) - - # Ensure tiling up of symbol_values works as expected. - expectation.Expectation()(symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5], [0.8]], - operators=test_psum) - expectation.Expectation()(symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=test_psum) - - def test_static_cases_noisy(self): - """Test that the noisy trajectory backend works in complex cases.""" - bit = cirq.GridQubit(0, 0) - symbol = sympy.Symbol('alpha') - test_pstring = cirq.Z(bit) - test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) - symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) - reg_circuit = cirq.Circuit(cirq.H(bit)) - - # Passing a 2d operators input requires a 1d circuit input. - expectation.Expectation(backend='noisy')( - [reg_circuit, reg_circuit], - operators=[[test_psum, test_psum], [test_psum, test_psum]], - repetitions=1) - - # Passing 2d operators along with other inputs. - expectation.Expectation(backend='noisy')( - [symb_circuit, symb_circuit], - symbol_names=[symbol], - operators=[[test_psum, test_psum], [test_psum, test_psum]], - repetitions=1) - expectation.Expectation(backend='noisy')( - [symb_circuit, symb_circuit], - symbol_names=[symbol], - symbol_values=[[0.5], [0.8]], - operators=[[test_psum, test_psum], [test_psum, test_psum]], - repetitions=1) - - # Ensure tiling up of circuits works as expected. - expectation.Expectation(backend='noisy')(reg_circuit, - operators=test_psum, - repetitions=1) - expectation.Expectation(backend='noisy')( - reg_circuit, operators=[test_psum, test_psum], repetitions=1) - - # Ensure tiling up of symbol_values works as expected. - expectation.Expectation(backend='noisy')(symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5], [0.8]], - operators=test_psum, - repetitions=1) - expectation.Expectation(backend='noisy')(symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=test_psum, - repetitions=1) - - # Test multiple operators with integer valued repetition. - expectation.Expectation(backend='noisy')( - symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=[-1.0 * cirq.Z(bit), - cirq.X(bit) + 2.0 * cirq.Z(bit)], - repetitions=1) - expectation.Expectation(backend='noisy')( - symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=[-1.0 * cirq.Z(bit), - cirq.X(bit) + 2.0 * cirq.Z(bit)], - repetitions=[5, 1]) - - # Test 2d repetitions. - expectation.Expectation(backend='noisy')( - [symb_circuit, symb_circuit], - symbol_names=[symbol], - symbol_values=[[0.5], [0.4]], - operators=[[ - -1.0 * cirq.Z(bit), - cirq.X(bit) + 2.0 * cirq.Z(bit), - cirq.Z(bit) - ], [cirq.Z(bit), cirq.Z(bit), cirq.Z(bit)]], - repetitions=[[1, 2, 3], [4, 5, 6]]) - - def test_expectation_simple_tf_train(self): - """Train a layer using standard tf (not keras). - This is a subtle test that will work since we don't use keras compile. - """ - bit = cirq.GridQubit(0, 0) - circuit = \ - cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) - op = cirq.Z(bit) - layer = expectation.Expectation() - optimizer = tf.optimizers.Adam(learning_rate=0.05) - for _ in range(200): - with tf.GradientTape() as tape: - circuit_out = layer(circuit, - symbol_names=['theta'], - operators=op) - mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) - grads = tape.gradient(mse, layer.trainable_weights) - optimizer.apply_gradients(zip(grads, layer.trainable_weights)) - self.assertAllClose(mse.numpy(), 0, atol=1e-3) +# class ExpectationTest(tf.test.TestCase): +# """Basic tests for the expectation layer.""" + +# def test_expectation_instantiate(self): +# """Test that Expectation instantiates correctly.""" +# expectation.Expectation() +# expectation.Expectation(backend=None) +# expectation.Expectation(backend='noisy') +# expectation.Expectation(backend='noiseless') +# expectation.Expectation(backend=cirq.Simulator()) +# expectation.Expectation( +# differentiator=linear_combination.ForwardDifference()) + +# def test_expectation_instantiate_error(self): +# """Test that Expectation errors with bad inputs.""" + +# class MySampler(cirq.Sampler): +# """Class to test sampler detection in Expectation.""" + +# def run_sweep(self): +# """do nothing.""" +# return + +# with self.assertRaisesRegex(TypeError, +# expected_regex="SampledExpectation"): +# expectation.Expectation(backend=MySampler()) + +# with self.assertRaisesRegex( +# TypeError, expected_regex="SimulatesExpectationValues or None"): +# expectation.Expectation(backend='junk') + +# with self.assertRaisesRegex( +# TypeError, expected_regex="tfq.differentiators.Differentiator"): +# expectation.Expectation(differentiator='junk') + +# def test_expectation_type_inputs_error(self): +# """Test that expectation errors within Keras call.""" + +# bit = cirq.GridQubit(0, 0) +# test_pstring = cirq.Z(bit) +# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) +# reg_circuit = cirq.Circuit(cirq.H(bit)) + +# with self.assertRaisesRegex(Exception, +# expected_regex="Unknown initializer"): +# expectation.Expectation()(reg_circuit, +# operators=test_psum, +# initializer='junk') + +# with self.assertRaisesRegex(Exception, +# expected_regex="repetitions not provided"): +# expectation.Expectation(backend='noisy')(reg_circuit, +# operators=test_psum) + +# with self.assertRaisesRegex(Exception, +# expected_regex="cannot be parsed"): +# expectation.Expectation(backend='noisy')(reg_circuit, +# operators=test_psum, +# repetitions='junk') + +# with self.assertRaisesRegex(Exception, expected_regex="noiseless"): +# expectation.Expectation(backend='noiseless')(reg_circuit, +# operators=test_psum, +# repetitions=1) + +# def test_expectation_op_error(self): +# """Test that expectation errors within underlying ops correctly.""" + +# bit = cirq.GridQubit(0, 0) +# symbol = sympy.Symbol('alpha') +# test_pstring = cirq.Z(bit) +# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) +# symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) +# reg_circuit = cirq.Circuit(cirq.H(bit)) + +# with self.assertRaisesRegex(Exception, +# expected_regex="Could not find symbol"): +# # No symbol matchups. +# expectation.Expectation()([symb_circuit], operators=test_psum) + +# with self.assertRaisesRegex(Exception, +# expected_regex="Unparseable proto"): +# # Proto is unparseable. +# expectation.Expectation()([reg_circuit], +# operators=tf.convert_to_tensor( +# [['bad_operator']])) + +# with self.assertRaisesRegex(Exception, expected_regex="rank 2"): +# # Operators has wrong rank. +# expectation.Expectation()([reg_circuit], +# operators=util.convert_to_tensor( +# [test_psum])) + +# with self.assertRaisesRegex(Exception, expected_regex="rank 2"): +# # symbol_values has wrong rank. +# expectation.Expectation()([symb_circuit], +# symbol_names=[symbol], +# symbol_values=[0.5], +# operators=test_psum) + +# with self.assertRaisesRegex(Exception, expected_regex="do not match."): +# # Wrong batch size for pauli operators. +# expectation.Expectation()(symb_circuit, +# symbol_names=[symbol], +# operators=[[test_psum], [test_psum]]) + +# with self.assertRaisesRegex(Exception, expected_regex="do not match."): +# # Wrong batch_size for symbol values. +# expectation.Expectation()([symb_circuit], +# symbol_names=[symbol], +# symbol_values=np.zeros((3, 1)), +# operators=test_psum) + +# def test_static_cases(self): +# """Run inputs through in complex cases.""" + +# bit = cirq.GridQubit(0, 0) +# symbol = sympy.Symbol('alpha') +# test_pstring = cirq.Z(bit) +# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) +# symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) +# reg_circuit = cirq.Circuit(cirq.H(bit)) + +# # Passing a 2d operators input requires a 1d circuit input. +# expectation.Expectation()([reg_circuit, reg_circuit], +# operators=[[test_psum, test_psum], +# [test_psum, test_psum]]) + +# # Passing 2d operators along with other inputs. +# expectation.Expectation()([symb_circuit, symb_circuit], +# symbol_names=[symbol], +# operators=[[test_psum, test_psum], +# [test_psum, test_psum]]) +# expectation.Expectation()([symb_circuit, symb_circuit], +# symbol_names=[symbol], +# symbol_values=[[0.5], [0.8]], +# operators=[[test_psum, test_psum], +# [test_psum, test_psum]]) + +# # Ensure tiling up of circuits works as expected. +# expectation.Expectation()(reg_circuit, operators=test_psum) +# expectation.Expectation()(reg_circuit, operators=[test_psum, test_psum]) + +# # Ensure tiling up of symbol_values works as expected. +# expectation.Expectation()(symb_circuit, +# symbol_names=[symbol], +# symbol_values=[[0.5], [0.8]], +# operators=test_psum) +# expectation.Expectation()(symb_circuit, +# symbol_names=[symbol], +# symbol_values=[[0.5]], +# operators=test_psum) + +# def test_static_cases_noisy(self): +# """Test that the noisy trajectory backend works in complex cases.""" +# bit = cirq.GridQubit(0, 0) +# symbol = sympy.Symbol('alpha') +# test_pstring = cirq.Z(bit) +# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) +# symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) +# reg_circuit = cirq.Circuit(cirq.H(bit)) + +# # Passing a 2d operators input requires a 1d circuit input. +# expectation.Expectation(backend='noisy')( +# [reg_circuit, reg_circuit], +# operators=[[test_psum, test_psum], [test_psum, test_psum]], +# repetitions=1) + +# # Passing 2d operators along with other inputs. +# expectation.Expectation(backend='noisy')( +# [symb_circuit, symb_circuit], +# symbol_names=[symbol], +# operators=[[test_psum, test_psum], [test_psum, test_psum]], +# repetitions=1) +# expectation.Expectation(backend='noisy')( +# [symb_circuit, symb_circuit], +# symbol_names=[symbol], +# symbol_values=[[0.5], [0.8]], +# operators=[[test_psum, test_psum], [test_psum, test_psum]], +# repetitions=1) + +# # Ensure tiling up of circuits works as expected. +# expectation.Expectation(backend='noisy')(reg_circuit, +# operators=test_psum, +# repetitions=1) +# expectation.Expectation(backend='noisy')( +# reg_circuit, operators=[test_psum, test_psum], repetitions=1) + +# # Ensure tiling up of symbol_values works as expected. +# expectation.Expectation(backend='noisy')(symb_circuit, +# symbol_names=[symbol], +# symbol_values=[[0.5], [0.8]], +# operators=test_psum, +# repetitions=1) +# expectation.Expectation(backend='noisy')(symb_circuit, +# symbol_names=[symbol], +# symbol_values=[[0.5]], +# operators=test_psum, +# repetitions=1) + +# # Test multiple operators with integer valued repetition. +# expectation.Expectation(backend='noisy')( +# symb_circuit, +# symbol_names=[symbol], +# symbol_values=[[0.5]], +# operators=[-1.0 * cirq.Z(bit), +# cirq.X(bit) + 2.0 * cirq.Z(bit)], +# repetitions=1) +# expectation.Expectation(backend='noisy')( +# symb_circuit, +# symbol_names=[symbol], +# symbol_values=[[0.5]], +# operators=[-1.0 * cirq.Z(bit), +# cirq.X(bit) + 2.0 * cirq.Z(bit)], +# repetitions=[5, 1]) + +# # Test 2d repetitions. +# expectation.Expectation(backend='noisy')( +# [symb_circuit, symb_circuit], +# symbol_names=[symbol], +# symbol_values=[[0.5], [0.4]], +# operators=[[ +# -1.0 * cirq.Z(bit), +# cirq.X(bit) + 2.0 * cirq.Z(bit), +# cirq.Z(bit) +# ], [cirq.Z(bit), cirq.Z(bit), cirq.Z(bit)]], +# repetitions=[[1, 2, 3], [4, 5, 6]]) + +# def test_expectation_simple_tf_train(self): +# """Train a layer using standard tf (not keras). +# This is a subtle test that will work since we don't use keras compile. +# """ +# bit = cirq.GridQubit(0, 0) +# circuit = \ +# cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) +# op = cirq.Z(bit) +# layer = expectation.Expectation() +# optimizer = tf.optimizers.Adam(learning_rate=0.05) +# for _ in range(200): +# with tf.GradientTape() as tape: +# circuit_out = layer(circuit, +# symbol_names=['theta'], +# operators=op) +# mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) +# grads = tape.gradient(mse, layer.trainable_weights) +# optimizer.apply_gradients(zip(grads, layer.trainable_weights)) +# self.assertAllClose(mse.numpy(), 0, atol=1e-3) class ExpectationFunctionalTests(parameterized.TestCase, tf.test.TestCase): """Test hybrid/integrated models that include an expectation layer.""" @parameterized.parameters([ - { - 'backend': 'noisy' - }, + # { + # 'backend': 'noisy' + # }, { 'backend': None # old API usage } @@ -324,7 +324,8 @@ def test_simple_param_value_input(self, backend): l1 = tf.keras.layers.Dense(10)(inputs) l2 = tf.keras.layers.Dense(3)(l1) reps = 1000 if noisy else None - outputs = expectation.Expectation(backend=backend)( + print("Initializing expectation layer...") + outputs = expectation.Expectation(backend=backend, use_gpu=True)( datum, symbol_names=symbols, operators=cirq.Z(bit), @@ -344,153 +345,153 @@ def test_simple_param_value_input(self, backend): tol = 5e-2 if noisy else 1e-3 self.assertAllClose(history.history['loss'][-1], 0, atol=tol) - @parameterized.parameters([ - { - 'backend': 'noisy' - }, - { - 'backend': None # old API usage - } - ]) - def test_simple_op_input(self, backend): - """Test a simple operator input - - Learn qubit in the z+ state using two different measurement operators. - This tests input signature Expectation([operator_batch]) - """ - noisy = backend == 'noisy' - bit = cirq.GridQubit(0, 0) - symbols = sympy.symbols('x, y, z') - - circuits = util.convert_to_tensor( - [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) - - data_out = tf.convert_to_tensor(np.array([[1], [1]])) - ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) - - circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) - op_input = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) - - reps = 1000 if noisy else None - output = expectation.Expectation(backend=backend)( - circuit_input, - symbol_names=symbols, - operators=op_input, - initializer=tf.keras.initializers.RandomNormal(), - repetitions=reps) - - model = tf.keras.Model(inputs=[circuit_input, op_input], outputs=output) - - model.compile( - optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), - loss=tf.keras.losses.mean_squared_error, - ) - history = model.fit(x=[circuits, ops], - y=data_out, - batch_size=2, - epochs=200) - tol = 5e-2 if noisy else 1e-3 - self.assertAllClose(history.history['loss'][-1], 0, atol=tol) - - @parameterized.parameters([ - { - 'backend': 'noisy' - }, - { - 'backend': None # old api usage. - }, - { - 'backend': cirq.Simulator() - } - ]) - def test_simple_op_and_param_input(self, backend): - """Test a simple operator and parameter input. - - Train a NN to put a qubit in the z+ or x+ states based on a classical - binary input. This tests the input signature: - Expectation([value_batch, operator_batch]). - """ - noisy = backend == 'noisy' - bit = cirq.GridQubit(0, 0) - symbols = sympy.symbols('x, y, z') - ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.X(bit)]]) - circuits = util.convert_to_tensor( - [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) - data_in = np.array([[1], [0]]) - data_out = np.array([[1], [1]]) - - data_inp = tf.keras.Input(shape=(1), dtype=tf.dtypes.float32) - op_inp = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) - circuit_inp = tf.keras.Input(shape=(), dtype=tf.dtypes.string) - dense_1 = tf.keras.layers.Dense(10)(data_inp) - dense_2 = tf.keras.layers.Dense(3)(dense_1) - reps = 1000 if noisy else None - circuit_output = expectation.Expectation(backend=backend)( - circuit_inp, - symbol_names=symbols, - symbol_values=dense_2, - operators=op_inp, - repetitions=reps) - - functional_model = tf.keras.Model( - inputs=[data_inp, op_inp, circuit_inp], outputs=[circuit_output]) - - functional_model.compile( - optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), - loss=tf.keras.losses.mean_squared_error) - history = functional_model.fit(x=[data_in, ops, circuits], - y=data_out, - batch_size=2, - epochs=100) - tol = 5e-2 if noisy else 1e-3 - self.assertAllClose(history.history['loss'][-1], 0, atol=tol) - - @parameterized.parameters([ - { - 'backend': 'noisy' - }, - { - 'backend': None # old api usage. - } - ]) - def test_dnn_qnn_dnn(self, backend): - """Train a fully hybrid network using an Expectation layer. - - Train the network to output +-5 given an input of 1 or 0. This tests - that everything works when Expectation layer is a middle layers. - """ - noisy = backend == 'noisy' - bit = cirq.GridQubit(0, 0) - symbols = sympy.symbols('x, y, z') - circuits = util.convert_to_tensor( - [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) - data_in = np.array([[1], [0]], dtype=np.float32) - data_out = np.array([[5], [-5]], dtype=np.float32) - - classical_input = tf.keras.Input(shape=(1,)) - circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) - d1 = tf.keras.layers.Dense(10)(classical_input) - d2 = tf.keras.layers.Dense(3)(d1) - reps = 1000 if noisy else None - quantum = expectation.Expectation(backend=backend)( - circuit_input, - symbol_names=symbols, - symbol_values=d2, - operators=cirq.Z(bit), - repetitions=reps) - d3 = tf.keras.layers.Dense(1)(quantum) - - model = tf.keras.Model(inputs=[circuit_input, classical_input], - outputs=d3) - - model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), - loss=tf.keras.losses.mean_squared_error) - history = model.fit(x=[circuits, data_in], - y=data_out, - batch_size=2, - epochs=300) - tol = 5e-2 if noisy else 1e-3 - self.assertAllClose(history.history['loss'][-1], 0, atol=tol) +# @parameterized.parameters([ +# { +# 'backend': 'noisy' +# }, +# { +# 'backend': None # old API usage +# } +# ]) +# def test_simple_op_input(self, backend): +# """Test a simple operator input + +# Learn qubit in the z+ state using two different measurement operators. +# This tests input signature Expectation([operator_batch]) +# """ +# noisy = backend == 'noisy' +# bit = cirq.GridQubit(0, 0) +# symbols = sympy.symbols('x, y, z') + +# circuits = util.convert_to_tensor( +# [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) + +# data_out = tf.convert_to_tensor(np.array([[1], [1]])) +# ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) + +# circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) +# op_input = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) + +# reps = 1000 if noisy else None +# output = expectation.Expectation(backend=backend)( +# circuit_input, +# symbol_names=symbols, +# operators=op_input, +# initializer=tf.keras.initializers.RandomNormal(), +# repetitions=reps) + +# model = tf.keras.Model(inputs=[circuit_input, op_input], outputs=output) + +# model.compile( +# optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), +# loss=tf.keras.losses.mean_squared_error, +# ) +# history = model.fit(x=[circuits, ops], +# y=data_out, +# batch_size=2, +# epochs=200) +# tol = 5e-2 if noisy else 1e-3 +# self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + +# @parameterized.parameters([ +# { +# 'backend': 'noisy' +# }, +# { +# 'backend': None # old api usage. +# }, +# { +# 'backend': cirq.Simulator() +# } +# ]) +# def test_simple_op_and_param_input(self, backend): +# """Test a simple operator and parameter input. + +# Train a NN to put a qubit in the z+ or x+ states based on a classical +# binary input. This tests the input signature: +# Expectation([value_batch, operator_batch]). +# """ +# noisy = backend == 'noisy' +# bit = cirq.GridQubit(0, 0) +# symbols = sympy.symbols('x, y, z') +# ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.X(bit)]]) +# circuits = util.convert_to_tensor( +# [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) +# data_in = np.array([[1], [0]]) +# data_out = np.array([[1], [1]]) + +# data_inp = tf.keras.Input(shape=(1), dtype=tf.dtypes.float32) +# op_inp = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) +# circuit_inp = tf.keras.Input(shape=(), dtype=tf.dtypes.string) +# dense_1 = tf.keras.layers.Dense(10)(data_inp) +# dense_2 = tf.keras.layers.Dense(3)(dense_1) +# reps = 1000 if noisy else None +# circuit_output = expectation.Expectation(backend=backend)( +# circuit_inp, +# symbol_names=symbols, +# symbol_values=dense_2, +# operators=op_inp, +# repetitions=reps) + +# functional_model = tf.keras.Model( +# inputs=[data_inp, op_inp, circuit_inp], outputs=[circuit_output]) + +# functional_model.compile( +# optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), +# loss=tf.keras.losses.mean_squared_error) +# history = functional_model.fit(x=[data_in, ops, circuits], +# y=data_out, +# batch_size=2, +# epochs=100) +# tol = 5e-2 if noisy else 1e-3 +# self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + +# @parameterized.parameters([ +# { +# 'backend': 'noisy' +# }, +# { +# 'backend': None # old api usage. +# } +# ]) +# def test_dnn_qnn_dnn(self, backend): +# """Train a fully hybrid network using an Expectation layer. + +# Train the network to output +-5 given an input of 1 or 0. This tests +# that everything works when Expectation layer is a middle layers. +# """ +# noisy = backend == 'noisy' +# bit = cirq.GridQubit(0, 0) +# symbols = sympy.symbols('x, y, z') +# circuits = util.convert_to_tensor( +# [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) +# data_in = np.array([[1], [0]], dtype=np.float32) +# data_out = np.array([[5], [-5]], dtype=np.float32) + +# classical_input = tf.keras.Input(shape=(1,)) +# circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) +# d1 = tf.keras.layers.Dense(10)(classical_input) +# d2 = tf.keras.layers.Dense(3)(d1) +# reps = 1000 if noisy else None +# quantum = expectation.Expectation(backend=backend)( +# circuit_input, +# symbol_names=symbols, +# symbol_values=d2, +# operators=cirq.Z(bit), +# repetitions=reps) +# d3 = tf.keras.layers.Dense(1)(quantum) + +# model = tf.keras.Model(inputs=[circuit_input, classical_input], +# outputs=d3) + +# model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), +# loss=tf.keras.losses.mean_squared_error) +# history = model.fit(x=[circuits, data_in], +# y=data_out, +# batch_size=2, +# epochs=300) +# tol = 5e-2 if noisy else 1e-3 +# self.assertAllClose(history.history['loss'][-1], 0, atol=tol) if __name__ == '__main__': From f2fb9ca2285166b574dd8e2dae9ac20109b8737d Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Thu, 13 Apr 2023 21:33:05 +0000 Subject: [PATCH 027/106] remove the debug print statements --- tensorflow_quantum/python/differentiators/adjoint.py | 4 ---- tensorflow_quantum/python/differentiators/differentiator.py | 5 ----- .../python/layers/circuit_executors/expectation.py | 1 - 3 files changed, 10 deletions(-) diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index 749f616df..6ffa1f405 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -83,9 +83,6 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, use_g a call to this differentiators `differentiate_*` function. """ - self.use_gpu = use_gpu - if self.use_gpu: - print("[LOG] USING GPU version") if sampled_op is not None: raise ValueError("sample base backends are not supported by the " "Adjoint method, please use analytic expectation" @@ -105,7 +102,6 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values): def differentiate_analytic(self, programs, symbol_names, symbol_values, pauli_sums, forward_pass_vals, grad, use_gpu=False): if use_gpu: - print("[LOG] USING GPU version") return tfq_adj_grad_op_cuquantum.tfq_adj_grad(programs, symbol_names, symbol_values, pauli_sums, grad) else: diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index f91a27d2f..f57ce39da 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -119,9 +119,7 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, # put inside of the analytical_op argument or vice versa. # right all that is checked is that the desire op signatures # are substrings of the given op signature. - print("analytic_op: ", analytic_op) if analytic_op is not None: - print("[LOG] analytic_op is not None") signature = inspect.signature(analytic_op).parameters expected_signature = [ 'programs', 'symbol_names', 'symbol_values', 'pauli_sums' @@ -142,7 +140,6 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, 'Note: noisy ops should use sampled_op') if sampled_op is not None: - print("[LOG] sampled_op is not None") signature = inspect.signature(sampled_op).parameters expected_signature = [ 'programs', 'symbol_names', 'symbol_values', 'pauli_sums', @@ -187,11 +184,9 @@ def gradient(grad): self.expectation_op = analytic_op return_func = op_wrapper_analytic if analytic_op is None: - print("[LOG] analytic_op is None") self.expectation_op = sampled_op return_func = op_wrapper_sampled - print("[LOG] return_func: ", return_func) return return_func def _differentiate_ana(self, programs, symbol_names, symbol_values, diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation.py b/tensorflow_quantum/python/layers/circuit_executors/expectation.py index dcd39a73c..c8684d942 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation.py @@ -247,7 +247,6 @@ def __init__(self, backend='noiseless', differentiator=None, use_gpu=False, if differentiator is None: differentiator = parameter_shift.ParameterShift() if backend is None: - print("[LOG] Using Adjoint Differentiator for noiseless") differentiator = adjoint.Adjoint() if not isinstance(differentiator, diff.Differentiator): From 5158802178084977ee5a7f8ac6f7ded6431e5cf4 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Thu, 13 Apr 2023 21:44:03 +0000 Subject: [PATCH 028/106] modify the cuquantum dep in adjoint build target to be conditional on cuda config --- tensorflow_quantum/core/ops/BUILD | 2 +- tensorflow_quantum/python/differentiators/BUILD | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index d61fde618..6a0ea5225 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -951,7 +951,7 @@ py_test( python_version = "PY3", deps = [ ":tfq_adj_grad_op_cuquantum_py", - ":tfq_adj_grad_op_py", + ":tfq_adj_grad_op_py", # for testing cpu vs gpu diff "//tensorflow_quantum/python:util", ], srcs_version = "PY3", diff --git a/tensorflow_quantum/python/differentiators/BUILD b/tensorflow_quantum/python/differentiators/BUILD index 1f5ddb9bf..6c6d2c26f 100644 --- a/tensorflow_quantum/python/differentiators/BUILD +++ b/tensorflow_quantum/python/differentiators/BUILD @@ -25,8 +25,9 @@ py_library( deps = [ ":differentiator", "//tensorflow_quantum/core/ops:tfq_adj_grad_op_py", + ] + if_cuda_is_configured([ "//tensorflow_quantum/core/ops:tfq_adj_grad_op_cuquantum_py", - ], + ]), ) py_test( From ccd2138caaba1fdb9973822d9035f398e108f573 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Fri, 14 Apr 2023 04:37:17 +0000 Subject: [PATCH 029/106] uncomment out the tests --- .../circuit_executors/expectation_test.py | 797 +++++++++--------- 1 file changed, 398 insertions(+), 399 deletions(-) diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py index 28ffdbe3f..3057fdd9c 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py @@ -47,262 +47,262 @@ def _gen_single_bit_rotation_problem(bit, symbols, noisy): return circuit -# class ExpectationTest(tf.test.TestCase): -# """Basic tests for the expectation layer.""" - -# def test_expectation_instantiate(self): -# """Test that Expectation instantiates correctly.""" -# expectation.Expectation() -# expectation.Expectation(backend=None) -# expectation.Expectation(backend='noisy') -# expectation.Expectation(backend='noiseless') -# expectation.Expectation(backend=cirq.Simulator()) -# expectation.Expectation( -# differentiator=linear_combination.ForwardDifference()) - -# def test_expectation_instantiate_error(self): -# """Test that Expectation errors with bad inputs.""" - -# class MySampler(cirq.Sampler): -# """Class to test sampler detection in Expectation.""" - -# def run_sweep(self): -# """do nothing.""" -# return - -# with self.assertRaisesRegex(TypeError, -# expected_regex="SampledExpectation"): -# expectation.Expectation(backend=MySampler()) - -# with self.assertRaisesRegex( -# TypeError, expected_regex="SimulatesExpectationValues or None"): -# expectation.Expectation(backend='junk') - -# with self.assertRaisesRegex( -# TypeError, expected_regex="tfq.differentiators.Differentiator"): -# expectation.Expectation(differentiator='junk') - -# def test_expectation_type_inputs_error(self): -# """Test that expectation errors within Keras call.""" - -# bit = cirq.GridQubit(0, 0) -# test_pstring = cirq.Z(bit) -# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) -# reg_circuit = cirq.Circuit(cirq.H(bit)) - -# with self.assertRaisesRegex(Exception, -# expected_regex="Unknown initializer"): -# expectation.Expectation()(reg_circuit, -# operators=test_psum, -# initializer='junk') - -# with self.assertRaisesRegex(Exception, -# expected_regex="repetitions not provided"): -# expectation.Expectation(backend='noisy')(reg_circuit, -# operators=test_psum) - -# with self.assertRaisesRegex(Exception, -# expected_regex="cannot be parsed"): -# expectation.Expectation(backend='noisy')(reg_circuit, -# operators=test_psum, -# repetitions='junk') - -# with self.assertRaisesRegex(Exception, expected_regex="noiseless"): -# expectation.Expectation(backend='noiseless')(reg_circuit, -# operators=test_psum, -# repetitions=1) - -# def test_expectation_op_error(self): -# """Test that expectation errors within underlying ops correctly.""" - -# bit = cirq.GridQubit(0, 0) -# symbol = sympy.Symbol('alpha') -# test_pstring = cirq.Z(bit) -# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) -# symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) -# reg_circuit = cirq.Circuit(cirq.H(bit)) - -# with self.assertRaisesRegex(Exception, -# expected_regex="Could not find symbol"): -# # No symbol matchups. -# expectation.Expectation()([symb_circuit], operators=test_psum) - -# with self.assertRaisesRegex(Exception, -# expected_regex="Unparseable proto"): -# # Proto is unparseable. -# expectation.Expectation()([reg_circuit], -# operators=tf.convert_to_tensor( -# [['bad_operator']])) - -# with self.assertRaisesRegex(Exception, expected_regex="rank 2"): -# # Operators has wrong rank. -# expectation.Expectation()([reg_circuit], -# operators=util.convert_to_tensor( -# [test_psum])) - -# with self.assertRaisesRegex(Exception, expected_regex="rank 2"): -# # symbol_values has wrong rank. -# expectation.Expectation()([symb_circuit], -# symbol_names=[symbol], -# symbol_values=[0.5], -# operators=test_psum) - -# with self.assertRaisesRegex(Exception, expected_regex="do not match."): -# # Wrong batch size for pauli operators. -# expectation.Expectation()(symb_circuit, -# symbol_names=[symbol], -# operators=[[test_psum], [test_psum]]) - -# with self.assertRaisesRegex(Exception, expected_regex="do not match."): -# # Wrong batch_size for symbol values. -# expectation.Expectation()([symb_circuit], -# symbol_names=[symbol], -# symbol_values=np.zeros((3, 1)), -# operators=test_psum) - -# def test_static_cases(self): -# """Run inputs through in complex cases.""" - -# bit = cirq.GridQubit(0, 0) -# symbol = sympy.Symbol('alpha') -# test_pstring = cirq.Z(bit) -# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) -# symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) -# reg_circuit = cirq.Circuit(cirq.H(bit)) - -# # Passing a 2d operators input requires a 1d circuit input. -# expectation.Expectation()([reg_circuit, reg_circuit], -# operators=[[test_psum, test_psum], -# [test_psum, test_psum]]) - -# # Passing 2d operators along with other inputs. -# expectation.Expectation()([symb_circuit, symb_circuit], -# symbol_names=[symbol], -# operators=[[test_psum, test_psum], -# [test_psum, test_psum]]) -# expectation.Expectation()([symb_circuit, symb_circuit], -# symbol_names=[symbol], -# symbol_values=[[0.5], [0.8]], -# operators=[[test_psum, test_psum], -# [test_psum, test_psum]]) - -# # Ensure tiling up of circuits works as expected. -# expectation.Expectation()(reg_circuit, operators=test_psum) -# expectation.Expectation()(reg_circuit, operators=[test_psum, test_psum]) - -# # Ensure tiling up of symbol_values works as expected. -# expectation.Expectation()(symb_circuit, -# symbol_names=[symbol], -# symbol_values=[[0.5], [0.8]], -# operators=test_psum) -# expectation.Expectation()(symb_circuit, -# symbol_names=[symbol], -# symbol_values=[[0.5]], -# operators=test_psum) - -# def test_static_cases_noisy(self): -# """Test that the noisy trajectory backend works in complex cases.""" -# bit = cirq.GridQubit(0, 0) -# symbol = sympy.Symbol('alpha') -# test_pstring = cirq.Z(bit) -# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) -# symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) -# reg_circuit = cirq.Circuit(cirq.H(bit)) - -# # Passing a 2d operators input requires a 1d circuit input. -# expectation.Expectation(backend='noisy')( -# [reg_circuit, reg_circuit], -# operators=[[test_psum, test_psum], [test_psum, test_psum]], -# repetitions=1) - -# # Passing 2d operators along with other inputs. -# expectation.Expectation(backend='noisy')( -# [symb_circuit, symb_circuit], -# symbol_names=[symbol], -# operators=[[test_psum, test_psum], [test_psum, test_psum]], -# repetitions=1) -# expectation.Expectation(backend='noisy')( -# [symb_circuit, symb_circuit], -# symbol_names=[symbol], -# symbol_values=[[0.5], [0.8]], -# operators=[[test_psum, test_psum], [test_psum, test_psum]], -# repetitions=1) - -# # Ensure tiling up of circuits works as expected. -# expectation.Expectation(backend='noisy')(reg_circuit, -# operators=test_psum, -# repetitions=1) -# expectation.Expectation(backend='noisy')( -# reg_circuit, operators=[test_psum, test_psum], repetitions=1) - -# # Ensure tiling up of symbol_values works as expected. -# expectation.Expectation(backend='noisy')(symb_circuit, -# symbol_names=[symbol], -# symbol_values=[[0.5], [0.8]], -# operators=test_psum, -# repetitions=1) -# expectation.Expectation(backend='noisy')(symb_circuit, -# symbol_names=[symbol], -# symbol_values=[[0.5]], -# operators=test_psum, -# repetitions=1) - -# # Test multiple operators with integer valued repetition. -# expectation.Expectation(backend='noisy')( -# symb_circuit, -# symbol_names=[symbol], -# symbol_values=[[0.5]], -# operators=[-1.0 * cirq.Z(bit), -# cirq.X(bit) + 2.0 * cirq.Z(bit)], -# repetitions=1) -# expectation.Expectation(backend='noisy')( -# symb_circuit, -# symbol_names=[symbol], -# symbol_values=[[0.5]], -# operators=[-1.0 * cirq.Z(bit), -# cirq.X(bit) + 2.0 * cirq.Z(bit)], -# repetitions=[5, 1]) - -# # Test 2d repetitions. -# expectation.Expectation(backend='noisy')( -# [symb_circuit, symb_circuit], -# symbol_names=[symbol], -# symbol_values=[[0.5], [0.4]], -# operators=[[ -# -1.0 * cirq.Z(bit), -# cirq.X(bit) + 2.0 * cirq.Z(bit), -# cirq.Z(bit) -# ], [cirq.Z(bit), cirq.Z(bit), cirq.Z(bit)]], -# repetitions=[[1, 2, 3], [4, 5, 6]]) - -# def test_expectation_simple_tf_train(self): -# """Train a layer using standard tf (not keras). -# This is a subtle test that will work since we don't use keras compile. -# """ -# bit = cirq.GridQubit(0, 0) -# circuit = \ -# cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) -# op = cirq.Z(bit) -# layer = expectation.Expectation() -# optimizer = tf.optimizers.Adam(learning_rate=0.05) -# for _ in range(200): -# with tf.GradientTape() as tape: -# circuit_out = layer(circuit, -# symbol_names=['theta'], -# operators=op) -# mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) -# grads = tape.gradient(mse, layer.trainable_weights) -# optimizer.apply_gradients(zip(grads, layer.trainable_weights)) -# self.assertAllClose(mse.numpy(), 0, atol=1e-3) +class ExpectationTest(tf.test.TestCase): + """Basic tests for the expectation layer.""" + + def test_expectation_instantiate(self): + """Test that Expectation instantiates correctly.""" + expectation.Expectation() + expectation.Expectation(backend=None) + expectation.Expectation(backend='noisy') + expectation.Expectation(backend='noiseless') + expectation.Expectation(backend=cirq.Simulator()) + expectation.Expectation( + differentiator=linear_combination.ForwardDifference()) + + def test_expectation_instantiate_error(self): + """Test that Expectation errors with bad inputs.""" + + class MySampler(cirq.Sampler): + """Class to test sampler detection in Expectation.""" + + def run_sweep(self): + """do nothing.""" + return + + with self.assertRaisesRegex(TypeError, + expected_regex="SampledExpectation"): + expectation.Expectation(backend=MySampler()) + + with self.assertRaisesRegex( + TypeError, expected_regex="SimulatesExpectationValues or None"): + expectation.Expectation(backend='junk') + + with self.assertRaisesRegex( + TypeError, expected_regex="tfq.differentiators.Differentiator"): + expectation.Expectation(differentiator='junk') + + def test_expectation_type_inputs_error(self): + """Test that expectation errors within Keras call.""" + + bit = cirq.GridQubit(0, 0) + test_pstring = cirq.Z(bit) + test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) + reg_circuit = cirq.Circuit(cirq.H(bit)) + + with self.assertRaisesRegex(Exception, + expected_regex="Unknown initializer"): + expectation.Expectation()(reg_circuit, + operators=test_psum, + initializer='junk') + + with self.assertRaisesRegex(Exception, + expected_regex="repetitions not provided"): + expectation.Expectation(backend='noisy')(reg_circuit, + operators=test_psum) + + with self.assertRaisesRegex(Exception, + expected_regex="cannot be parsed"): + expectation.Expectation(backend='noisy')(reg_circuit, + operators=test_psum, + repetitions='junk') + + with self.assertRaisesRegex(Exception, expected_regex="noiseless"): + expectation.Expectation(backend='noiseless')(reg_circuit, + operators=test_psum, + repetitions=1) + + def test_expectation_op_error(self): + """Test that expectation errors within underlying ops correctly.""" + + bit = cirq.GridQubit(0, 0) + symbol = sympy.Symbol('alpha') + test_pstring = cirq.Z(bit) + test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) + symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) + reg_circuit = cirq.Circuit(cirq.H(bit)) + + with self.assertRaisesRegex(Exception, + expected_regex="Could not find symbol"): + # No symbol matchups. + expectation.Expectation()([symb_circuit], operators=test_psum) + + with self.assertRaisesRegex(Exception, + expected_regex="Unparseable proto"): + # Proto is unparseable. + expectation.Expectation()([reg_circuit], + operators=tf.convert_to_tensor( + [['bad_operator']])) + + with self.assertRaisesRegex(Exception, expected_regex="rank 2"): + # Operators has wrong rank. + expectation.Expectation()([reg_circuit], + operators=util.convert_to_tensor( + [test_psum])) + + with self.assertRaisesRegex(Exception, expected_regex="rank 2"): + # symbol_values has wrong rank. + expectation.Expectation()([symb_circuit], + symbol_names=[symbol], + symbol_values=[0.5], + operators=test_psum) + + with self.assertRaisesRegex(Exception, expected_regex="do not match."): + # Wrong batch size for pauli operators. + expectation.Expectation()(symb_circuit, + symbol_names=[symbol], + operators=[[test_psum], [test_psum]]) + + with self.assertRaisesRegex(Exception, expected_regex="do not match."): + # Wrong batch_size for symbol values. + expectation.Expectation()([symb_circuit], + symbol_names=[symbol], + symbol_values=np.zeros((3, 1)), + operators=test_psum) + + def test_static_cases(self): + """Run inputs through in complex cases.""" + + bit = cirq.GridQubit(0, 0) + symbol = sympy.Symbol('alpha') + test_pstring = cirq.Z(bit) + test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) + symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) + reg_circuit = cirq.Circuit(cirq.H(bit)) + + # Passing a 2d operators input requires a 1d circuit input. + expectation.Expectation()([reg_circuit, reg_circuit], + operators=[[test_psum, test_psum], + [test_psum, test_psum]]) + + # Passing 2d operators along with other inputs. + expectation.Expectation()([symb_circuit, symb_circuit], + symbol_names=[symbol], + operators=[[test_psum, test_psum], + [test_psum, test_psum]]) + expectation.Expectation()([symb_circuit, symb_circuit], + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=[[test_psum, test_psum], + [test_psum, test_psum]]) + + # Ensure tiling up of circuits works as expected. + expectation.Expectation()(reg_circuit, operators=test_psum) + expectation.Expectation()(reg_circuit, operators=[test_psum, test_psum]) + + # Ensure tiling up of symbol_values works as expected. + expectation.Expectation()(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=test_psum) + expectation.Expectation()(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=test_psum) + + def test_static_cases_noisy(self): + """Test that the noisy trajectory backend works in complex cases.""" + bit = cirq.GridQubit(0, 0) + symbol = sympy.Symbol('alpha') + test_pstring = cirq.Z(bit) + test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) + symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) + reg_circuit = cirq.Circuit(cirq.H(bit)) + + # Passing a 2d operators input requires a 1d circuit input. + expectation.Expectation(backend='noisy')( + [reg_circuit, reg_circuit], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) + + # Passing 2d operators along with other inputs. + expectation.Expectation(backend='noisy')( + [symb_circuit, symb_circuit], + symbol_names=[symbol], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) + expectation.Expectation(backend='noisy')( + [symb_circuit, symb_circuit], + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) + + # Ensure tiling up of circuits works as expected. + expectation.Expectation(backend='noisy')(reg_circuit, + operators=test_psum, + repetitions=1) + expectation.Expectation(backend='noisy')( + reg_circuit, operators=[test_psum, test_psum], repetitions=1) + + # Ensure tiling up of symbol_values works as expected. + expectation.Expectation(backend='noisy')(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=test_psum, + repetitions=1) + expectation.Expectation(backend='noisy')(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=test_psum, + repetitions=1) + + # Test multiple operators with integer valued repetition. + expectation.Expectation(backend='noisy')( + symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=[-1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit)], + repetitions=1) + expectation.Expectation(backend='noisy')( + symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=[-1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit)], + repetitions=[5, 1]) + + # Test 2d repetitions. + expectation.Expectation(backend='noisy')( + [symb_circuit, symb_circuit], + symbol_names=[symbol], + symbol_values=[[0.5], [0.4]], + operators=[[ + -1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit), + cirq.Z(bit) + ], [cirq.Z(bit), cirq.Z(bit), cirq.Z(bit)]], + repetitions=[[1, 2, 3], [4, 5, 6]]) + + def test_expectation_simple_tf_train(self): + """Train a layer using standard tf (not keras). + This is a subtle test that will work since we don't use keras compile. + """ + bit = cirq.GridQubit(0, 0) + circuit = \ + cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) + op = cirq.Z(bit) + layer = expectation.Expectation() + optimizer = tf.optimizers.Adam(learning_rate=0.05) + for _ in range(200): + with tf.GradientTape() as tape: + circuit_out = layer(circuit, + symbol_names=['theta'], + operators=op) + mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) + grads = tape.gradient(mse, layer.trainable_weights) + optimizer.apply_gradients(zip(grads, layer.trainable_weights)) + self.assertAllClose(mse.numpy(), 0, atol=1e-3) class ExpectationFunctionalTests(parameterized.TestCase, tf.test.TestCase): """Test hybrid/integrated models that include an expectation layer.""" @parameterized.parameters([ - # { - # 'backend': 'noisy' - # }, + { + 'backend': 'noisy' + }, { 'backend': None # old API usage } @@ -324,8 +324,7 @@ def test_simple_param_value_input(self, backend): l1 = tf.keras.layers.Dense(10)(inputs) l2 = tf.keras.layers.Dense(3)(l1) reps = 1000 if noisy else None - print("Initializing expectation layer...") - outputs = expectation.Expectation(backend=backend, use_gpu=True)( + outputs = expectation.Expectation(backend=backend, use_gpu=False)( datum, symbol_names=symbols, operators=cirq.Z(bit), @@ -345,153 +344,153 @@ def test_simple_param_value_input(self, backend): tol = 5e-2 if noisy else 1e-3 self.assertAllClose(history.history['loss'][-1], 0, atol=tol) -# @parameterized.parameters([ -# { -# 'backend': 'noisy' -# }, -# { -# 'backend': None # old API usage -# } -# ]) -# def test_simple_op_input(self, backend): -# """Test a simple operator input - -# Learn qubit in the z+ state using two different measurement operators. -# This tests input signature Expectation([operator_batch]) -# """ -# noisy = backend == 'noisy' -# bit = cirq.GridQubit(0, 0) -# symbols = sympy.symbols('x, y, z') - -# circuits = util.convert_to_tensor( -# [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) - -# data_out = tf.convert_to_tensor(np.array([[1], [1]])) -# ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) - -# circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) -# op_input = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) - -# reps = 1000 if noisy else None -# output = expectation.Expectation(backend=backend)( -# circuit_input, -# symbol_names=symbols, -# operators=op_input, -# initializer=tf.keras.initializers.RandomNormal(), -# repetitions=reps) - -# model = tf.keras.Model(inputs=[circuit_input, op_input], outputs=output) - -# model.compile( -# optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), -# loss=tf.keras.losses.mean_squared_error, -# ) -# history = model.fit(x=[circuits, ops], -# y=data_out, -# batch_size=2, -# epochs=200) -# tol = 5e-2 if noisy else 1e-3 -# self.assertAllClose(history.history['loss'][-1], 0, atol=tol) - -# @parameterized.parameters([ -# { -# 'backend': 'noisy' -# }, -# { -# 'backend': None # old api usage. -# }, -# { -# 'backend': cirq.Simulator() -# } -# ]) -# def test_simple_op_and_param_input(self, backend): -# """Test a simple operator and parameter input. - -# Train a NN to put a qubit in the z+ or x+ states based on a classical -# binary input. This tests the input signature: -# Expectation([value_batch, operator_batch]). -# """ -# noisy = backend == 'noisy' -# bit = cirq.GridQubit(0, 0) -# symbols = sympy.symbols('x, y, z') -# ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.X(bit)]]) -# circuits = util.convert_to_tensor( -# [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) -# data_in = np.array([[1], [0]]) -# data_out = np.array([[1], [1]]) - -# data_inp = tf.keras.Input(shape=(1), dtype=tf.dtypes.float32) -# op_inp = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) -# circuit_inp = tf.keras.Input(shape=(), dtype=tf.dtypes.string) -# dense_1 = tf.keras.layers.Dense(10)(data_inp) -# dense_2 = tf.keras.layers.Dense(3)(dense_1) -# reps = 1000 if noisy else None -# circuit_output = expectation.Expectation(backend=backend)( -# circuit_inp, -# symbol_names=symbols, -# symbol_values=dense_2, -# operators=op_inp, -# repetitions=reps) - -# functional_model = tf.keras.Model( -# inputs=[data_inp, op_inp, circuit_inp], outputs=[circuit_output]) - -# functional_model.compile( -# optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), -# loss=tf.keras.losses.mean_squared_error) -# history = functional_model.fit(x=[data_in, ops, circuits], -# y=data_out, -# batch_size=2, -# epochs=100) -# tol = 5e-2 if noisy else 1e-3 -# self.assertAllClose(history.history['loss'][-1], 0, atol=tol) - -# @parameterized.parameters([ -# { -# 'backend': 'noisy' -# }, -# { -# 'backend': None # old api usage. -# } -# ]) -# def test_dnn_qnn_dnn(self, backend): -# """Train a fully hybrid network using an Expectation layer. - -# Train the network to output +-5 given an input of 1 or 0. This tests -# that everything works when Expectation layer is a middle layers. -# """ -# noisy = backend == 'noisy' -# bit = cirq.GridQubit(0, 0) -# symbols = sympy.symbols('x, y, z') -# circuits = util.convert_to_tensor( -# [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) -# data_in = np.array([[1], [0]], dtype=np.float32) -# data_out = np.array([[5], [-5]], dtype=np.float32) - -# classical_input = tf.keras.Input(shape=(1,)) -# circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) -# d1 = tf.keras.layers.Dense(10)(classical_input) -# d2 = tf.keras.layers.Dense(3)(d1) -# reps = 1000 if noisy else None -# quantum = expectation.Expectation(backend=backend)( -# circuit_input, -# symbol_names=symbols, -# symbol_values=d2, -# operators=cirq.Z(bit), -# repetitions=reps) -# d3 = tf.keras.layers.Dense(1)(quantum) - -# model = tf.keras.Model(inputs=[circuit_input, classical_input], -# outputs=d3) - -# model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), -# loss=tf.keras.losses.mean_squared_error) -# history = model.fit(x=[circuits, data_in], -# y=data_out, -# batch_size=2, -# epochs=300) -# tol = 5e-2 if noisy else 1e-3 -# self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + @parameterized.parameters([ + { + 'backend': 'noisy' + }, + { + 'backend': None # old API usage + } + ]) + def test_simple_op_input(self, backend): + """Test a simple operator input + + Learn qubit in the z+ state using two different measurement operators. + This tests input signature Expectation([operator_batch]) + """ + noisy = backend == 'noisy' + bit = cirq.GridQubit(0, 0) + symbols = sympy.symbols('x, y, z') + + circuits = util.convert_to_tensor( + [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) + + data_out = tf.convert_to_tensor(np.array([[1], [1]])) + ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) + + circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) + op_input = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) + + reps = 1000 if noisy else None + output = expectation.Expectation(backend=backend)( + circuit_input, + symbol_names=symbols, + operators=op_input, + initializer=tf.keras.initializers.RandomNormal(), + repetitions=reps) + + model = tf.keras.Model(inputs=[circuit_input, op_input], outputs=output) + + model.compile( + optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), + loss=tf.keras.losses.mean_squared_error, + ) + history = model.fit(x=[circuits, ops], + y=data_out, + batch_size=2, + epochs=200) + tol = 5e-2 if noisy else 1e-3 + self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + + @parameterized.parameters([ + { + 'backend': 'noisy' + }, + { + 'backend': None # old api usage. + }, + { + 'backend': cirq.Simulator() + } + ]) + def test_simple_op_and_param_input(self, backend): + """Test a simple operator and parameter input. + + Train a NN to put a qubit in the z+ or x+ states based on a classical + binary input. This tests the input signature: + Expectation([value_batch, operator_batch]). + """ + noisy = backend == 'noisy' + bit = cirq.GridQubit(0, 0) + symbols = sympy.symbols('x, y, z') + ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.X(bit)]]) + circuits = util.convert_to_tensor( + [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) + data_in = np.array([[1], [0]]) + data_out = np.array([[1], [1]]) + + data_inp = tf.keras.Input(shape=(1), dtype=tf.dtypes.float32) + op_inp = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) + circuit_inp = tf.keras.Input(shape=(), dtype=tf.dtypes.string) + dense_1 = tf.keras.layers.Dense(10)(data_inp) + dense_2 = tf.keras.layers.Dense(3)(dense_1) + reps = 1000 if noisy else None + circuit_output = expectation.Expectation(backend=backend)( + circuit_inp, + symbol_names=symbols, + symbol_values=dense_2, + operators=op_inp, + repetitions=reps) + + functional_model = tf.keras.Model( + inputs=[data_inp, op_inp, circuit_inp], outputs=[circuit_output]) + + functional_model.compile( + optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), + loss=tf.keras.losses.mean_squared_error) + history = functional_model.fit(x=[data_in, ops, circuits], + y=data_out, + batch_size=2, + epochs=100) + tol = 5e-2 if noisy else 1e-3 + self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + + @parameterized.parameters([ + { + 'backend': 'noisy' + }, + { + 'backend': None # old api usage. + } + ]) + def test_dnn_qnn_dnn(self, backend): + """Train a fully hybrid network using an Expectation layer. + + Train the network to output +-5 given an input of 1 or 0. This tests + that everything works when Expectation layer is a middle layers. + """ + noisy = backend == 'noisy' + bit = cirq.GridQubit(0, 0) + symbols = sympy.symbols('x, y, z') + circuits = util.convert_to_tensor( + [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) + data_in = np.array([[1], [0]], dtype=np.float32) + data_out = np.array([[5], [-5]], dtype=np.float32) + + classical_input = tf.keras.Input(shape=(1,)) + circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) + d1 = tf.keras.layers.Dense(10)(classical_input) + d2 = tf.keras.layers.Dense(3)(d1) + reps = 1000 if noisy else None + quantum = expectation.Expectation(backend=backend)( + circuit_input, + symbol_names=symbols, + symbol_values=d2, + operators=cirq.Z(bit), + repetitions=reps) + d3 = tf.keras.layers.Dense(1)(quantum) + + model = tf.keras.Model(inputs=[circuit_input, classical_input], + outputs=d3) + + model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), + loss=tf.keras.losses.mean_squared_error) + history = model.fit(x=[circuits, data_in], + y=data_out, + batch_size=2, + epochs=300) + tol = 5e-2 if noisy else 1e-3 + self.assertAllClose(history.history['loss'][-1], 0, atol=tol) if __name__ == '__main__': From 44fae736c61aef020b4825ce5e9b91064daf5a06 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Fri, 14 Apr 2023 04:47:56 +0000 Subject: [PATCH 030/106] linting --- .../core/ops/circuit_execution_ops.py | 6 +- .../ops/tfq_adj_grad_op_cuquantum_test.py | 2 +- .../ops/tfq_simulate_ops_cuquantum_test.py | 6 +- .../python/differentiators/adjoint.py | 61 +++++++++++++------ .../python/differentiators/differentiator.py | 2 +- .../python/layers/circuit_executors/sample.py | 3 +- .../python/layers/circuit_executors/state.py | 3 +- .../python/layers/high_level/noisy_pqc.py | 3 +- 8 files changed, 60 insertions(+), 26 deletions(-) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index 36c2ad42d..bcc6b7e2e 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -34,8 +34,10 @@ class TFQStateVectorSimulator(enum.Enum): state = tfq_simulate_ops.tfq_simulate_state state_gpu_cpu = tfq_simulate_ops_cuquantum.tfq_simulate_state - sampled_expectation = tfq_simulate_ops.tfq_simulate_sampled_expectation - sampled_expectation_gpu_cpu = tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation + sampled_expectation = \ + tfq_simulate_ops.tfq_simulate_sampled_expectation + sampled_expectation_gpu_cpu = \ + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation def _check_quantum_concurrent(quantum_concurrent): diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py index e1d8f332f..10ace5bf3 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py @@ -20,8 +20,8 @@ sys.path = NEW_PATH # pylint: enable=wrong-import-position -import numpy as np import time +import numpy as np from absl.testing import parameterized import tensorflow as tf import cirq diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 0e37e6ba4..bb16d3625 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -638,7 +638,8 @@ def test_simulate_samples_inputs(self): with self.assertRaisesRegex(tf.errors.InvalidArgumentError, 'Unparseable proto'): # programs tensor has the right type, but invalid value. - tfq_simulate_ops_cuquantum.tfq_simulate_samples(['junk'] * batch_size, + tfq_simulate_ops_cuquantum.tfq_simulate_samples( \ + ['junk'] * batch_size, symbol_names, symbol_values_array, [num_samples]) @@ -836,7 +837,8 @@ def test_simulate_state_inputs(self): with self.assertRaisesRegex(TypeError, 'Cannot convert'): # programs tensor has the wrong type. - tfq_simulate_ops_cuquantum.tfq_simulate_state([1] * batch_size, symbol_names, + tfq_simulate_ops_cuquantum.tfq_simulate_state([1] * batch_size, + symbol_names, symbol_values_array) with self.assertRaisesRegex(TypeError, 'Cannot convert'): diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index 6ffa1f405..7e533b439 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -15,7 +15,8 @@ """Compute gradients by combining function values linearly.""" import tensorflow as tf -from tensorflow_quantum.core.ops import tfq_adj_grad_op, tfq_adj_grad_op_cuquantum +from tensorflow_quantum.core.ops import tfq_adj_grad_op, \ + tfq_adj_grad_op_cuquantum from tensorflow_quantum.python.differentiators import differentiator @@ -62,7 +63,9 @@ class Adjoint(differentiator.Differentiator): """ - def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, use_gpu=False): + def generate_differentiable_op( + self, *, sampled_op=None, analytic_op=None, use_gpu=False + ): """Generate a differentiable op by attaching self to an op. See `tfq.differentiators.Differentiator`. This has been partially @@ -84,33 +87,57 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, use_g """ if sampled_op is not None: - raise ValueError("sample base backends are not supported by the " - "Adjoint method, please use analytic expectation" - " or choose another differentiator.") + raise ValueError( + "sample base backends are not supported by the " + "Adjoint method, please use analytic expectation" + " or choose another differentiator." + ) - return super().generate_differentiable_op(analytic_op=analytic_op, use_gpu=use_gpu) + return super().generate_differentiable_op( + analytic_op=analytic_op, use_gpu=use_gpu + ) @tf.function def get_gradient_circuits(self, programs, symbol_names, symbol_values): """See base class description.""" raise NotImplementedError( "Adjoint differentiator cannot run on a real QPU, " - "therefore it has no accessible gradient circuits.") + "therefore it has no accessible gradient circuits." + ) @differentiator.catch_empty_inputs @tf.function - def differentiate_analytic(self, programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad, use_gpu=False): + def differentiate_analytic( + self, + programs, + symbol_names, + symbol_values, + pauli_sums, + forward_pass_vals, + grad, + use_gpu=False, + ): if use_gpu: - return tfq_adj_grad_op_cuquantum.tfq_adj_grad(programs, symbol_names, - symbol_values, pauli_sums, grad) + return tfq_adj_grad_op_cuquantum.tfq_adj_grad( + programs, symbol_names, symbol_values, pauli_sums, grad + ) else: - return tfq_adj_grad_op.tfq_adj_grad(programs, symbol_names, - symbol_values, pauli_sums, grad) - - def differentiate_sampled(self, programs, symbol_names, symbol_values, - pauli_sums, num_samples, forward_pass_vals, grad): + return tfq_adj_grad_op.tfq_adj_grad( + programs, symbol_names, symbol_values, pauli_sums, grad + ) + + def differentiate_sampled( + self, + programs, + symbol_names, + symbol_values, + pauli_sums, + num_samples, + forward_pass_vals, + grad, + ): raise NotImplementedError( "Adjoint state methods are not supported in sample based settings." " Please use analytic expectation calculation or a different " - "tfq.differentiator.") \ No newline at end of file + "tfq.differentiator." + ) diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index f57ce39da..c0208194d 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -161,7 +161,7 @@ def op_wrapper_analytic(programs, symbol_names, symbol_values, def gradient(grad): return self._differentiate_ana(programs, symbol_names, symbol_values, pauli_sums, - forward_pass_vals, grad, + forward_pass_vals, grad, use_gpu=use_gpu) return forward_pass_vals, gradient diff --git a/tensorflow_quantum/python/layers/circuit_executors/sample.py b/tensorflow_quantum/python/layers/circuit_executors/sample.py index 026fb74df..a96a4e28f 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample.py @@ -155,7 +155,8 @@ def __init__(self, backend='noiseless', use_gpu=False, **kwargs): super().__init__(**kwargs) used_op = None if backend == 'noiseless': - used_op = circuit_execution_ops.get_sampling_op(None, use_gpu=use_gpu) + used_op = circuit_execution_ops.get_sampling_op(None, \ + use_gpu=use_gpu) elif backend == 'noisy': if use_gpu: raise ValueError('noisy backend does not currently support GPU') diff --git a/tensorflow_quantum/python/layers/circuit_executors/state.py b/tensorflow_quantum/python/layers/circuit_executors/state.py index f59c67333..92e35e180 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/state.py +++ b/tensorflow_quantum/python/layers/circuit_executors/state.py @@ -129,7 +129,8 @@ def __init__(self, backend=None, use_gpu=False, **kwargs): use_gpu: Calls TFQ GPU version op. """ super().__init__(**kwargs) - self.state_op = circuit_execution_ops.get_state_op(backend, use_gpu=use_gpu) + self.state_op = circuit_execution_ops.get_state_op(backend, \ + use_gpu=use_gpu) def call(self, inputs, *, symbol_names=None, symbol_values=None): """Keras call function. diff --git a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py index bfc4a4463..597933058 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py @@ -225,7 +225,8 @@ def __init__( # Use gpu not supported yet. if use_gpu: - raise NotImplementedError("GPU support for noisy PQC is not yet implemented.") + raise NotImplementedError("GPU support for noisy PQC is not \ + yet implemented.") # Ingest differentiator. if differentiator is None: From 75f8cb3f741c18f69848b8386d78dce84f47be39 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 14 Apr 2023 15:42:07 -0700 Subject: [PATCH 031/106] Fix BUILD error with unloaded bzl rule. --- tensorflow_quantum/core/ops/BUILD | 4 +--- tensorflow_quantum/python/differentiators/BUILD | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index 6a0ea5225..2270cb82f 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -1,6 +1,4 @@ -# load op_wrapper -load("@org_tensorflow//tensorflow:tensorflow.bzl", "tf_gpu_kernel_library", "tf_gen_op_wrapper_py") -load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured", "if_cuda") +load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured") package(default_visibility = ["//visibility:public"]) diff --git a/tensorflow_quantum/python/differentiators/BUILD b/tensorflow_quantum/python/differentiators/BUILD index 6c6d2c26f..329e0b2d8 100644 --- a/tensorflow_quantum/python/differentiators/BUILD +++ b/tensorflow_quantum/python/differentiators/BUILD @@ -1,3 +1,5 @@ +load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured") + package(default_visibility = ["//visibility:public"]) licenses(["notice"]) From eb056924f2257806e46ba4e21b474930eda595a7 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sat, 15 Apr 2023 16:44:30 -0700 Subject: [PATCH 032/106] Rename old _gpu_cpu to _cuquantum --- .../core/ops/circuit_execution_ops.py | 16 ++++++++-------- third_party/cuquantum/cuquantum_configure.bzl | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index bcc6b7e2e..8b8ca5701 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -26,17 +26,17 @@ class TFQStateVectorSimulator(enum.Enum): """Enum to make specifying TFQ simulators user-friendly.""" expectation = tfq_simulate_ops.tfq_simulate_expectation - expectation_gpu_cpu = tfq_simulate_ops_cuquantum.tfq_simulate_expectation + expectation_cuquantum = tfq_simulate_ops_cuquantum.tfq_simulate_expectation samples = tfq_simulate_ops.tfq_simulate_samples - samples_gpu_cpu = tfq_simulate_ops_cuquantum.tfq_simulate_samples + samples_cuquantum = tfq_simulate_ops_cuquantum.tfq_simulate_samples state = tfq_simulate_ops.tfq_simulate_state - state_gpu_cpu = tfq_simulate_ops_cuquantum.tfq_simulate_state + state_cuquantum = tfq_simulate_ops_cuquantum.tfq_simulate_state sampled_expectation = \ tfq_simulate_ops.tfq_simulate_sampled_expectation - sampled_expectation_gpu_cpu = \ + sampled_expectation_cuquantum = \ tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation @@ -133,7 +133,7 @@ def get_expectation_op( op = None if backend is None: if use_gpu: - op = TFQStateVectorSimulator.expectation_gpu_cpu + op = TFQStateVectorSimulator.expectation_cuquantum else: op = TFQStateVectorSimulator.expectation @@ -236,7 +236,7 @@ def get_sampling_op( op = None if backend is None: if use_gpu: - op = TFQStateVectorSimulator.samples_gpu_cpu + op = TFQStateVectorSimulator.samples_cuquantum else: op = TFQStateVectorSimulator.samples @@ -329,7 +329,7 @@ def get_state_op( op = None if backend is None: if use_gpu: - op = TFQStateVectorSimulator.state_gpu_cpu + op = TFQStateVectorSimulator.state_cuquantum else: op = TFQStateVectorSimulator.state @@ -444,7 +444,7 @@ def get_sampled_expectation_op( op = None if backend is None: if use_gpu: - op = TFQStateVectorSimulator.sampled_expectation_gpu_cpu + op = TFQStateVectorSimulator.sampled_expectation_cuquantum else: op = TFQStateVectorSimulator.sampled_expectation diff --git a/third_party/cuquantum/cuquantum_configure.bzl b/third_party/cuquantum/cuquantum_configure.bzl index 2eb1fb11b..b8ff2f9b9 100644 --- a/third_party/cuquantum/cuquantum_configure.bzl +++ b/third_party/cuquantum/cuquantum_configure.bzl @@ -190,7 +190,7 @@ def _cuquantum_pip_imple(repository_ctx): "%{CUQUANTUM_HEADER_GENRULE}": cuquantum_header_rule, "%{CUSTATEVEC_SHARED_LIBRARY_GENRULE}": custatevec_shared_library_rule, }) - + cuquantum_configure = repository_rule( implementation = _cuquantum_pip_imple, From 2ba5a20dec867a1e0c60d4a14a6760045f2427e8 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sat, 15 Apr 2023 16:49:32 -0700 Subject: [PATCH 033/106] cuquantum op should not be called in paralell. --- tensorflow_quantum/core/ops/circuit_execution_ops.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index 8b8ca5701..97989216c 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -143,7 +143,7 @@ def get_expectation_op( op = cirq_ops._get_cirq_analytical_expectation(backend) if op is not None: - if quantum_concurrent is True: + if use_gpu is False and quantum_concurrent is True: # Return an op that does not block graph level parallelism. return lambda programs, symbol_names, symbol_values, pauli_sums: \ op(programs, symbol_names, symbol_values, pauli_sums) @@ -244,7 +244,7 @@ def get_sampling_op( op = cirq_ops._get_cirq_samples(backend) if op is not None: - if quantum_concurrent is True: + if use_gpu is False and quantum_concurrent is True: # Return an op that does not block graph level parallelism. return lambda programs, symbol_names, symbol_values, num_samples: \ tfq_utility_ops.padded_to_ragged( @@ -337,7 +337,7 @@ def get_state_op( op = cirq_ops._get_cirq_simulate_state(backend) if op is not None: - if quantum_concurrent is True: + if use_gpu is False and quantum_concurrent is True: # Return an op that does not block graph level parallelism. return lambda programs, symbol_names, symbol_values: \ tfq_utility_ops.padded_to_ragged( @@ -452,7 +452,7 @@ def get_sampled_expectation_op( op = cirq_ops._get_cirq_sampled_expectation(backend) if op is not None: - if quantum_concurrent is True: + if use_gpu is False and quantum_concurrent is True: # Return an op that does not block graph level parallelism. return lambda programs, symbol_names, symbol_values, pauli_sums, \ num_samples: op(programs, From de033ac4229370bf23e16fba942cf655b71d1c5e Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sat, 15 Apr 2023 16:52:17 -0700 Subject: [PATCH 034/106] Rename use_gpu to use_cuquantum not to mean cuda. --- .../core/ops/circuit_execution_ops.py | 24 +++++++++---------- .../python/differentiators/adjoint.py | 10 ++++---- .../python/differentiators/differentiator.py | 10 ++++---- .../layers/circuit_executors/expectation.py | 10 ++++---- .../circuit_executors/expectation_test.py | 2 +- .../python/layers/circuit_executors/sample.py | 8 +++---- .../circuit_executors/sampled_expectation.py | 10 ++++---- .../python/layers/circuit_executors/state.py | 6 ++--- .../layers/high_level/noisy_controlled_pqc.py | 6 ++--- .../python/layers/high_level/noisy_pqc.py | 6 ++--- .../python/layers/high_level/pqc.py | 8 +++---- 11 files changed, 50 insertions(+), 50 deletions(-) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index 97989216c..70b6deb99 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -48,7 +48,7 @@ def _check_quantum_concurrent(quantum_concurrent): def get_expectation_op( backend=None, - use_gpu=False, + use_cuquantum=False, *, quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): """Get a TensorFlow op that will calculate batches of expectation values. @@ -132,7 +132,7 @@ def get_expectation_op( op = None if backend is None: - if use_gpu: + if use_cuquantum: op = TFQStateVectorSimulator.expectation_cuquantum else: op = TFQStateVectorSimulator.expectation @@ -143,7 +143,7 @@ def get_expectation_op( op = cirq_ops._get_cirq_analytical_expectation(backend) if op is not None: - if use_gpu is False and quantum_concurrent is True: + if use_cuquantum is False and quantum_concurrent is True: # Return an op that does not block graph level parallelism. return lambda programs, symbol_names, symbol_values, pauli_sums: \ op(programs, symbol_names, symbol_values, pauli_sums) @@ -165,7 +165,7 @@ def get_expectation_op( def get_sampling_op( backend=None, - use_gpu=False, + use_cuquantum=False, *, quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): """Get a Tensorflow op that produces samples from given quantum circuits. @@ -235,7 +235,7 @@ def get_sampling_op( op = None if backend is None: - if use_gpu: + if use_cuquantum: op = TFQStateVectorSimulator.samples_cuquantum else: op = TFQStateVectorSimulator.samples @@ -244,7 +244,7 @@ def get_sampling_op( op = cirq_ops._get_cirq_samples(backend) if op is not None: - if use_gpu is False and quantum_concurrent is True: + if use_cuquantum is False and quantum_concurrent is True: # Return an op that does not block graph level parallelism. return lambda programs, symbol_names, symbol_values, num_samples: \ tfq_utility_ops.padded_to_ragged( @@ -261,7 +261,7 @@ def get_sampling_op( def get_state_op( backend=None, - use_gpu=False, + use_cuquantum=False, *, quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): """Get a TensorFlow op that produces states from given quantum circuits. @@ -328,7 +328,7 @@ def get_state_op( op = None if backend is None: - if use_gpu: + if use_cuquantum: op = TFQStateVectorSimulator.state_cuquantum else: op = TFQStateVectorSimulator.state @@ -337,7 +337,7 @@ def get_state_op( op = cirq_ops._get_cirq_simulate_state(backend) if op is not None: - if use_gpu is False and quantum_concurrent is True: + if use_cuquantum is False and quantum_concurrent is True: # Return an op that does not block graph level parallelism. return lambda programs, symbol_names, symbol_values: \ tfq_utility_ops.padded_to_ragged( @@ -355,7 +355,7 @@ def get_state_op( def get_sampled_expectation_op( backend=None, - use_gpu=False, + use_cuquantum=False, *, quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): """Get a TensorFlow op that will calculate sampled expectation values. @@ -443,7 +443,7 @@ def get_sampled_expectation_op( op = None if backend is None: - if use_gpu: + if use_cuquantum: op = TFQStateVectorSimulator.sampled_expectation_cuquantum else: op = TFQStateVectorSimulator.sampled_expectation @@ -452,7 +452,7 @@ def get_sampled_expectation_op( op = cirq_ops._get_cirq_sampled_expectation(backend) if op is not None: - if use_gpu is False and quantum_concurrent is True: + if use_cuquantum is False and quantum_concurrent is True: # Return an op that does not block graph level parallelism. return lambda programs, symbol_names, symbol_values, pauli_sums, \ num_samples: op(programs, diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index 7e533b439..30eafd157 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -64,7 +64,7 @@ class Adjoint(differentiator.Differentiator): """ def generate_differentiable_op( - self, *, sampled_op=None, analytic_op=None, use_gpu=False + self, *, sampled_op=None, analytic_op=None, use_cuquantum=False ): """Generate a differentiable op by attaching self to an op. @@ -78,7 +78,7 @@ def generate_differentiable_op( using this differentiator's `differentiate_sampled` method. analytic_op: A `callable` op that you want to make differentiable using this differentiators `differentiate_analytic` method. - use_gpu: A `bool` indicating whether to use the GPU version of the + use_cuquantum: A `bool` indicating whether to use the GPU version of the adjoint gradient op. Returns: @@ -94,7 +94,7 @@ def generate_differentiable_op( ) return super().generate_differentiable_op( - analytic_op=analytic_op, use_gpu=use_gpu + analytic_op=analytic_op, use_cuquantum=use_cuquantum ) @tf.function @@ -115,9 +115,9 @@ def differentiate_analytic( pauli_sums, forward_pass_vals, grad, - use_gpu=False, + use_cuquantum=False, ): - if use_gpu: + if use_cuquantum: return tfq_adj_grad_op_cuquantum.tfq_adj_grad( programs, symbol_names, symbol_values, pauli_sums, grad ) diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index c0208194d..31d0bd623 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -56,7 +56,7 @@ class Differentiator(metaclass=abc.ABCMeta): """ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, - use_gpu=False): + use_cuquantum=False): """Generate a differentiable op by attaching self to an op. This function returns a `tf.function` that passes values through to @@ -81,7 +81,7 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, using this differentiator's `differentiate_sampled` method. analytic_op: A `callable` op that you want to make differentiable using this differentiators `differentiate_analytic` method. - use_gpu: A `bool` indicating whether to use GPU + use_cuquantum: A `bool` indicating whether to use GPU Returns: A `callable` op that who's gradients are now registered to be @@ -162,7 +162,7 @@ def gradient(grad): return self._differentiate_ana(programs, symbol_names, symbol_values, pauli_sums, forward_pass_vals, grad, - use_gpu=use_gpu) + use_cuquantum=use_cuquantum) return forward_pass_vals, gradient @@ -190,10 +190,10 @@ def gradient(grad): return return_func def _differentiate_ana(self, programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad, use_gpu): + pauli_sums, forward_pass_vals, grad, use_cuquantum): return None, None, self.differentiate_analytic( programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad, use_gpu=use_gpu), \ + pauli_sums, forward_pass_vals, grad, use_cuquantum=use_cuquantum), \ None def _differentiate_sam(self, programs, symbol_names, symbol_values, diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation.py b/tensorflow_quantum/python/layers/circuit_executors/expectation.py index c8684d942..9a83add3b 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation.py @@ -205,7 +205,7 @@ class Expectation(tf.keras.layers.Layer): """ - def __init__(self, backend='noiseless', differentiator=None, use_gpu=False, + def __init__(self, backend='noiseless', differentiator=None, use_cuquantum=False, **kwargs): """Instantiate this Layer. @@ -226,7 +226,7 @@ def __init__(self, backend='noiseless', differentiator=None, use_gpu=False, which uses `tfq.differentiators.ParameterShift()`. If `backend` is also 'noiseless' then default is `tfq.differentiators.Adjoint`. - use_gpu: Calls TFQ GPU version op. + use_cuquantum: Calls TFQ GPU version op. """ super().__init__(**kwargs) @@ -254,7 +254,7 @@ def __init__(self, backend='noiseless', differentiator=None, use_gpu=False, "tfq.differentiators.Differentiator") if backend == 'noisy': - if use_gpu: + if use_cuquantum: raise ValueError('noisy backend does not currently support GPU') used_op = noisy_expectation_op.expectation self._expectation_op = differentiator.generate_differentiable_op( @@ -262,9 +262,9 @@ def __init__(self, backend='noiseless', differentiator=None, use_gpu=False, self.noisy = True else: used_op = circuit_execution_ops.get_expectation_op(backend=backend, - use_gpu=use_gpu) + use_cuquantum=use_cuquantum) self._expectation_op = differentiator.generate_differentiable_op( - analytic_op=used_op, use_gpu=use_gpu) + analytic_op=used_op, use_cuquantum=use_cuquantum) self._w = None diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py index 3057fdd9c..1bb08a0e4 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py @@ -324,7 +324,7 @@ def test_simple_param_value_input(self, backend): l1 = tf.keras.layers.Dense(10)(inputs) l2 = tf.keras.layers.Dense(3)(l1) reps = 1000 if noisy else None - outputs = expectation.Expectation(backend=backend, use_gpu=False)( + outputs = expectation.Expectation(backend=backend, use_cuquantum=False)( datum, symbol_names=symbols, operators=cirq.Z(bit), diff --git a/tensorflow_quantum/python/layers/circuit_executors/sample.py b/tensorflow_quantum/python/layers/circuit_executors/sample.py index a96a4e28f..4de2964ab 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample.py @@ -139,7 +139,7 @@ class Sample(tf.keras.layers.Layer): """ - def __init__(self, backend='noiseless', use_gpu=False, **kwargs): + def __init__(self, backend='noiseless', use_cuquantum=False, **kwargs): """Instantiate this Layer. Create a layer that will output bitstring samples taken from either a @@ -150,15 +150,15 @@ def __init__(self, backend='noiseless', use_gpu=False, **kwargs): to the noiseless simulator. Options are {'noisy', 'noiseless'}, however users may also specify a preconfigured cirq execution object to use instead, which must inherit `cirq.Sampler`. - use_gpu: Calls TFQ GPU version op. + use_cuquantum: Calls TFQ GPU version op. """ super().__init__(**kwargs) used_op = None if backend == 'noiseless': used_op = circuit_execution_ops.get_sampling_op(None, \ - use_gpu=use_gpu) + use_cuquantum=use_cuquantum) elif backend == 'noisy': - if use_gpu: + if use_cuquantum: raise ValueError('noisy backend does not currently support GPU') used_op = noisy_samples_op.samples else: diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py index 436180fee..4ad664ae9 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py @@ -213,7 +213,7 @@ class SampledExpectation(tf.keras.layers.Layer): """ - def __init__(self, backend='noiseless', differentiator=None, use_gpu=False, + def __init__(self, backend='noiseless', differentiator=None, use_cuquantum=False, **kwargs): """Instantiate this Layer. @@ -228,7 +228,7 @@ def __init__(self, backend='noiseless', differentiator=None, use_gpu=False, derivative values of given operators_to_measure and circuit, which must inherit `tfq.differentiators.Differentiator`. Defaults to `parameter_shift.ParameterShift()` (None argument). - use_gpu: Calls TFQ GPU version op. + use_cuquantum: Calls TFQ GPU version op. """ super().__init__(**kwargs) @@ -250,14 +250,14 @@ def __init__(self, backend='noiseless', differentiator=None, use_gpu=False, used_op = None if backend == 'noiseless': used_op = circuit_execution_ops.get_sampled_expectation_op( - use_gpu=use_gpu) + use_cuquantum=use_cuquantum) elif backend == 'noisy': - if use_gpu: + if use_cuquantum: raise ValueError('noisy backend does not currently support GPU') used_op = noisy_sampled_expectation_op.sampled_expectation else: used_op = circuit_execution_ops.get_sampled_expectation_op( - backend=backend, use_gpu=use_gpu) + backend=backend, use_cuquantum=use_cuquantum) self._expectation_op = differentiator.generate_differentiable_op( sampled_op=used_op) diff --git a/tensorflow_quantum/python/layers/circuit_executors/state.py b/tensorflow_quantum/python/layers/circuit_executors/state.py index 92e35e180..8cc8d95b6 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/state.py +++ b/tensorflow_quantum/python/layers/circuit_executors/state.py @@ -112,7 +112,7 @@ class State(tf.keras.layers.Layer): """ - def __init__(self, backend=None, use_gpu=False, **kwargs): + def __init__(self, backend=None, use_cuquantum=False, **kwargs): """Instantiate a State Layer. Create a layer that will simulate a quantum state and output it into @@ -126,11 +126,11 @@ def __init__(self, backend=None, use_gpu=False, **kwargs): `cirq.SimulatesFinalState`. Note that C++ Density Matrix simulation is not yet supported so to do Density Matrix simulation please use `cirq.DensityMatrixSimulator`. - use_gpu: Calls TFQ GPU version op. + use_cuquantum: Calls TFQ GPU version op. """ super().__init__(**kwargs) self.state_op = circuit_execution_ops.get_state_op(backend, \ - use_gpu=use_gpu) + use_cuquantum=use_cuquantum) def call(self, inputs, *, symbol_names=None, symbol_values=None): """Keras call function. diff --git a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py index 98b314990..593177fbf 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py @@ -142,7 +142,7 @@ def __init__(self, repetitions=None, sample_based=None, differentiator=None, - use_gpu=False, + use_cuquantum=False, **kwargs): """Instantiate this layer. @@ -164,7 +164,7 @@ def __init__(self, trajectory. differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. - use_gpu: Optional `bool` indicating whether to use GPU for simulation + use_cuquantum: Optional `bool` indicating whether to use GPU for simulation or not. Defaults to `False`. NOT IMPLEMENTED YET. """ super().__init__(**kwargs) @@ -222,7 +222,7 @@ def __init__(self, differentiator = parameter_shift.ParameterShift() # Use gpu not supported yet. - if use_gpu: + if use_cuquantum: raise NotImplementedError("GPU support for noisy controlled PQC \ is not yet implemented.") diff --git a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py index 597933058..7084432cc 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py @@ -139,7 +139,7 @@ def __init__( repetitions=None, sample_based=None, differentiator=None, - use_gpu=False, + use_cuquantum=False, initializer=tf.keras.initializers.RandomUniform(0, 2 * np.pi), regularizer=None, constraint=None, @@ -165,7 +165,7 @@ def __init__( trajectory. differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. - use_gpu: Python `bool` indicating whether to use GPU ops (currently + use_cuquantum: Python `bool` indicating whether to use GPU ops (currently not supported/implemented). initializer: Optional `tf.keras.initializer` object to specify how the symbols in `model_circuit` should be initialized when creating @@ -224,7 +224,7 @@ def __init__( dtype=tf.dtypes.int32) # Use gpu not supported yet. - if use_gpu: + if use_cuquantum: raise NotImplementedError("GPU support for noisy PQC is not \ yet implemented.") diff --git a/tensorflow_quantum/python/layers/high_level/pqc.py b/tensorflow_quantum/python/layers/high_level/pqc.py index c4e1a5676..c11f99004 100644 --- a/tensorflow_quantum/python/layers/high_level/pqc.py +++ b/tensorflow_quantum/python/layers/high_level/pqc.py @@ -137,7 +137,7 @@ def __init__( *, repetitions=None, backend='noiseless', - use_gpu=False, + use_cuquantum=False, differentiator=None, initializer=tf.keras.initializers.RandomUniform(0, 2 * np.pi), regularizer=None, @@ -167,7 +167,7 @@ def __init__( `cirq.sim.simulator.SimulatesExpectationValues` if analytic expectations are desired or `cirq.Sampler` if sampled expectations are desired. - use_gpu: Optional Python `bool` indicating whether or not to use GPU ops + use_cuquantum: Optional Python `bool` indicating whether or not to use GPU ops differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. initializer: Optional `tf.keras.initializer` object to specify how the @@ -250,10 +250,10 @@ def __init__( "cirq.sim.simulator.SimulatesExpectationValues.") if self._analytic: self._executor = expectation.Expectation( - backend=backend, differentiator=differentiator, use_gpu=use_gpu) + backend=backend, differentiator=differentiator, use_cuquantum=use_cuquantum) else: self._executor = sampled_expectation.SampledExpectation( - backend=backend, differentiator=differentiator, use_gpu=use_gpu) + backend=backend, differentiator=differentiator, use_cuquantum=use_cuquantum) self._append_layer = elementary.AddCircuit() From b729c60e0d6449cc849b0072d78a53bf96e1355d Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sat, 15 Apr 2023 17:07:53 -0700 Subject: [PATCH 035/106] Fix wrong tfq version (0.7.2 to 0.7.3) and lint use_cuquantum --- tensorflow_quantum/__init__.py | 2 +- .../core/ops/circuit_execution_ops.py | 20 +++++++++++-------- .../python/differentiators/adjoint.py | 4 ++-- .../python/differentiators/differentiator.py | 7 ++++--- .../layers/circuit_executors/expectation.py | 6 +++--- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/tensorflow_quantum/__init__.py b/tensorflow_quantum/__init__.py index 7c781f882..5df8ae1f8 100644 --- a/tensorflow_quantum/__init__.py +++ b/tensorflow_quantum/__init__.py @@ -64,4 +64,4 @@ del core # pylint: enable=undefined-variable -__version__ = '0.7.2' +__version__ = '0.7.3' diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index 70b6deb99..4054ba315 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -48,9 +48,9 @@ def _check_quantum_concurrent(quantum_concurrent): def get_expectation_op( backend=None, - use_cuquantum=False, *, - quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): + quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode(), + use_cuquantum=False): """Get a TensorFlow op that will calculate batches of expectation values. This function produces a non-differentiable TF op that will calculate @@ -101,6 +101,7 @@ def get_expectation_op( (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. + use_cuquantum: Set True to turn on TFQ cuQuantum version op. Returns: A `callable` with the following signature: @@ -165,9 +166,9 @@ def get_expectation_op( def get_sampling_op( backend=None, - use_cuquantum=False, *, - quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): + quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode(), + use_cuquantum=False): """Get a Tensorflow op that produces samples from given quantum circuits. This function produces a non-differentiable op that will calculate @@ -205,6 +206,7 @@ def get_sampling_op( (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. + use_cuquantum: Set True to turn on TFQ cuQuantum version op. Returns: A `callable` with the following signature: @@ -261,9 +263,9 @@ def get_sampling_op( def get_state_op( backend=None, - use_cuquantum=False, *, - quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): + quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode(), + use_cuquantum=False): """Get a TensorFlow op that produces states from given quantum circuits. This function produces a non-differentiable op that will calculate @@ -301,6 +303,7 @@ def get_state_op( (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. + use_cuquantum: Set True to turn on TFQ cuQuantum version op. Returns: A `callable` with the following signature: @@ -355,9 +358,9 @@ def get_state_op( def get_sampled_expectation_op( backend=None, - use_cuquantum=False, *, - quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): + quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode(), + use_cuquantum=False): """Get a TensorFlow op that will calculate sampled expectation values. This function produces a non-differentiable TF op that will calculate @@ -409,6 +412,7 @@ def get_sampled_expectation_op( (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. + use_cuquantum: Set True to turn on TFQ cuQuantum version op. Returns: A `callable` with the following signature: diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index 30eafd157..29ea9a10d 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -78,8 +78,8 @@ def generate_differentiable_op( using this differentiator's `differentiate_sampled` method. analytic_op: A `callable` op that you want to make differentiable using this differentiators `differentiate_analytic` method. - use_cuquantum: A `bool` indicating whether to use the GPU version of the - adjoint gradient op. + use_cuquantum: A `bool` indicating whether to use the cuQuantum + version of the adjoint gradient op. Returns: A `callable` op that who's gradients are now registered to be diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index 31d0bd623..54c597b68 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -60,8 +60,8 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, """Generate a differentiable op by attaching self to an op. This function returns a `tf.function` that passes values through to - `forward_op` during the forward pass and this differentiator (`self`) to - backpropagate through the op during the backward pass. If sampled_op + `forward_op` during the forward pass and this differentiator (`self`) + to backpropagate through the op during the backward pass. If sampled_op is provided the differentiators `differentiate_sampled` method will be invoked (which requires sampled_op to be a sample based expectation op with num_samples input tensor). If analytic_op is provided the @@ -81,7 +81,8 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, using this differentiator's `differentiate_sampled` method. analytic_op: A `callable` op that you want to make differentiable using this differentiators `differentiate_analytic` method. - use_cuquantum: A `bool` indicating whether to use GPU + use_cuquantum: A `bool` indicating whether to use cuQuantum version + op. Returns: A `callable` op that who's gradients are now registered to be diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation.py b/tensorflow_quantum/python/layers/circuit_executors/expectation.py index 9a83add3b..a02d82809 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation.py @@ -255,14 +255,14 @@ def __init__(self, backend='noiseless', differentiator=None, use_cuquantum=False if backend == 'noisy': if use_cuquantum: - raise ValueError('noisy backend does not currently support GPU') + raise ValueError("noisy backend does not currently support GPU") used_op = noisy_expectation_op.expectation self._expectation_op = differentiator.generate_differentiable_op( sampled_op=used_op) self.noisy = True else: - used_op = circuit_execution_ops.get_expectation_op(backend=backend, - use_cuquantum=use_cuquantum) + used_op = circuit_execution_ops.get_expectation_op( + backend=backend, use_cuquantum=use_cuquantum) self._expectation_op = differentiator.generate_differentiable_op( analytic_op=used_op, use_cuquantum=use_cuquantum) From f1a09abac7744a284406cdaa5202ab5ebf5de38b Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sat, 15 Apr 2023 18:27:39 -0700 Subject: [PATCH 036/106] Add circuit_execution_ops_test --- WORKSPACE | 12 +-- tensorflow_quantum/core/ops/BUILD | 5 +- .../core/ops/circuit_execution_ops.py | 34 ++++++--- .../core/ops/circuit_execution_ops_test.py | 75 +++++++++++++++++-- ...ate_sampled_expectation_op_cuquantum.cu.cc | 6 +- .../python/layers/circuit_executors/BUILD | 2 +- 6 files changed, 103 insertions(+), 31 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 7a6cdd229..ba3bfb7c4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -24,12 +24,12 @@ cc_library( ], ) -# http_archive( -# name = "qsim", -# sha256 = "b9c1eba09a885a938b5e73dfc2e02f5231cf3b01d899415caa24769346a731d5", -# strip_prefix = "qsim-0.13.3", -# urls = ["https://github.com/quantumlib/qsim/archive/refs/tags/v0.13.3.zip"], -# ) +#http_archive( +# name = "qsim", +# sha256 = "", +# strip_prefix = "qsim-0.16.0", +# urls = ["https://github.com/quantumlib/qsim/archive/refs/tags/v0.16.0.zip"], +#) # TODO: After merging this patch later into qsim mainstream, remove this and uncomment the above. http_archive( diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index 2270cb82f..73e8dc597 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -536,10 +536,11 @@ py_library( deps = [ ":cirq_ops", ":tfq_simulate_ops_py", - ":tfq_simulate_ops_cuquantum_py", ":tfq_utility_ops_py", "//tensorflow_quantum/python:quantum_context", - ], + ] + if_cuda_is_configured([ + ":tfq_simulate_ops_cuquantum_py", + ]), ) py_test( diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index 4054ba315..7c4c03b70 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -40,10 +40,17 @@ class TFQStateVectorSimulator(enum.Enum): tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation -def _check_quantum_concurrent(quantum_concurrent): +def _check_quantum_concurrent(quantum_concurrent, use_cuquantum): if not isinstance(quantum_concurrent, bool): raise TypeError("quantum_concurrent must be type bool." " Given: {}".format(str(type(quantum_concurrent)))) + if not isinstance(use_cuquantum, bool): + raise TypeError("use_cuquantum must be type bool." + " Given: {}".format(str(type(use_cuquantum)))) + if use_cuquantum is True and quantum_concurrent is True: + raise ValueError("use_cuquantum and quantum_concurrent should " + "not be True at the same time. Please set False to " + "quantum_concurrent.") def get_expectation_op( @@ -91,8 +98,8 @@ def get_expectation_op( backend: Optional Python `object` that specifies what backend this op should use when evaluating circuits. Can be `cirq.DensityMatrixSimulator` or any - `cirq.sim.simulator.SimulatesExpectationValues`. If not provided the - default C++ analytical expectation calculation op is returned. + `cirq.sim.simulator.SimulatesExpectationValues`. If not provided + the default C++ analytical expectation calculation op is returned. quantum_concurrent: Optional Python `bool`. True indicates that the returned op should not block graph level parallelism on itself when executing. False indicates that graph level parallelism on itself @@ -101,7 +108,8 @@ def get_expectation_op( (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. - use_cuquantum: Set True to turn on TFQ cuQuantum version op. + use_cuquantum: Set True to turn on TFQ cuQuantum version op, which + requires `quantum_concurrent` to be False. Returns: A `callable` with the following signature: @@ -129,7 +137,7 @@ def get_expectation_op( """ # TODO (mbbrough): investigate how the above docstring renders. - _check_quantum_concurrent(quantum_concurrent) + _check_quantum_concurrent(quantum_concurrent, use_cuquantum) op = None if backend is None: @@ -206,7 +214,8 @@ def get_sampling_op( (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. - use_cuquantum: Set True to turn on TFQ cuQuantum version op. + use_cuquantum: Set True to turn on TFQ cuQuantum version op, which + requires `quantum_concurrent` to be False. Returns: A `callable` with the following signature: @@ -233,7 +242,7 @@ def get_sampling_op( """ # TODO (mbbrough): investigate how the above docstring renders. - _check_quantum_concurrent(quantum_concurrent) + _check_quantum_concurrent(quantum_concurrent, use_cuquantum) op = None if backend is None: @@ -303,7 +312,8 @@ def get_state_op( (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. - use_cuquantum: Set True to turn on TFQ cuQuantum version op. + use_cuquantum: Set True to turn on TFQ cuQuantum version op, which + requires `quantum_concurrent` to be False. Returns: A `callable` with the following signature: @@ -327,7 +337,7 @@ def get_state_op( """ # TODO (mbbrough): investigate how the above docstring renders. - _check_quantum_concurrent(quantum_concurrent) + _check_quantum_concurrent(quantum_concurrent, use_cuquantum) op = None if backend is None: @@ -412,7 +422,8 @@ def get_sampled_expectation_op( (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. - use_cuquantum: Set True to turn on TFQ cuQuantum version op. + use_cuquantum: Set True to turn on TFQ cuQuantum version op, which + requires `quantum_concurrent` to be False. Returns: A `callable` with the following signature: @@ -443,12 +454,13 @@ def get_sampled_expectation_op( (after resolving the corresponding parameters in). """ # TODO (mbbrough): investigate how the above docstring renders. - _check_quantum_concurrent(quantum_concurrent) + _check_quantum_concurrent(quantum_concurrent, use_cuquantum) op = None if backend is None: if use_cuquantum: op = TFQStateVectorSimulator.sampled_expectation_cuquantum + quantum_concurrent = False else: op = TFQStateVectorSimulator.sampled_expectation diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops_test.py b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py index f94297cdc..76c307598 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops_test.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py @@ -47,7 +47,11 @@ quantum_concurrent=True), # For timing interests C++ backend is tested in quantum_concurrent mode. circuit_execution_ops.get_expectation_op(backend=None, - quantum_concurrent=False) + quantum_concurrent=False), + # For cuQuantum op. quantum_concurrent=True is not allowed. + circuit_execution_ops.get_expectation_op(backend=None, + quantum_concurrent=False, + use_cuquantum=True) ] SAMPLING_OPS = [ @@ -59,16 +63,26 @@ quantum_concurrent=True), # For timing interests C++ backend is tested in quantum_concurrent mode. circuit_execution_ops.get_sampling_op(backend=None, - quantum_concurrent=False) + quantum_concurrent=False), + # For cuQuantum op. quantum_concurrent=True is not allowed. + circuit_execution_ops.get_sampling_op(backend=None, + quantum_concurrent=False, + use_cuquantum=True) ] STATE_OPS = [ circuit_execution_ops.get_state_op(backend=None, quantum_concurrent=True), - circuit_execution_ops.get_state_op(backend=WF_SIM, quantum_concurrent=True), - circuit_execution_ops.get_state_op(backend=DM_SIM, quantum_concurrent=True), + circuit_execution_ops.get_state_op(backend=WF_SIM, + quantum_concurrent=True), + circuit_execution_ops.get_state_op(backend=DM_SIM, + quantum_concurrent=True), # For timing interests C++ backend is tested in quantum_concurrent mode. - circuit_execution_ops.get_state_op(backend=None, quantum_concurrent=False) + circuit_execution_ops.get_state_op(backend=None, quantum_concurrent=False), + # For cuQuantum op. quantum_concurrent=True is not allowed. + circuit_execution_ops.get_state_op(backend=None, quantum_concurrent=False, + use_cuquantum=True) ] +NO_DM_STATE_OPS = STATE_OPS[:2] + STATE_OPS[2:] SAMPLED_EXPECTATION_OPS = [ circuit_execution_ops.get_sampled_expectation_op(backend=None, @@ -80,9 +94,14 @@ # For timing interests C++ backend is tested in quantum_concurrent mode. circuit_execution_ops.get_sampled_expectation_op(backend=None, quantum_concurrent=False), + # For cuQuantum op. quantum_concurrent=True is not allowed. + circuit_execution_ops.get_sampled_expectation_op(backend=None, + quantum_concurrent=False, + use_cuquantum=True) ] -SIMS = [WF_SIM, WF_SIM, DM_SIM, WF_SIM] +SIMS = [WF_SIM, WF_SIM, DM_SIM, WF_SIM, WF_SIM] +NO_DM_SIMS = SIMS[:2] + SIMS[2:] class OpGetterInputChecks(tf.test.TestCase): @@ -111,6 +130,15 @@ def test_get_expectation_inputs(self): expected_regex="must be type bool."): circuit_execution_ops.get_expectation_op(quantum_concurrent='junk') + with self.assertRaisesRegex(TypeError, + expected_regex="must be type bool."): + circuit_execution_ops.get_expectation_op(use_cuquantum='junk') + + with self.assertRaisesRegex( + ValueError, expected_regex="not be True at the same time"): + circuit_execution_ops.get_expectation_op( + quantum_concurrent=True, use_cuquantum=True) + def test_get_sampled_expectation_inputs(self): """Test that get expectation only accepts inputs it should.""" circuit_execution_ops.get_sampled_expectation_op() @@ -131,6 +159,16 @@ def test_get_sampled_expectation_inputs(self): circuit_execution_ops.get_sampled_expectation_op( quantum_concurrent='junk') + with self.assertRaisesRegex(TypeError, + expected_regex="must be type bool."): + circuit_execution_ops.get_sampled_expectation_op( + use_cuquantum='junk') + + with self.assertRaisesRegex( + ValueError, expected_regex="not be True at the same time"): + circuit_execution_ops.get_sampled_expectation_op( + quantum_concurrent=True, use_cuquantum=True) + def test_get_samples_inputs(self): """Test that get_samples only accepts inputs it should.""" circuit_execution_ops.get_sampling_op() @@ -150,6 +188,15 @@ def test_get_samples_inputs(self): expected_regex="must be type bool."): circuit_execution_ops.get_sampling_op(quantum_concurrent='junk') + with self.assertRaisesRegex(TypeError, + expected_regex="must be type bool."): + circuit_execution_ops.get_sampling_op(use_cuquantum='junk') + + with self.assertRaisesRegex( + ValueError, expected_regex="not be True at the same time"): + circuit_execution_ops.get_sampling_op( + quantum_concurrent=True, use_cuquantum=True) + def test_get_state_inputs(self): """Test that get_states only accepts inputs it should.""" circuit_execution_ops.get_state_op() @@ -172,6 +219,15 @@ def test_get_state_inputs(self): expected_regex="must be type bool."): circuit_execution_ops.get_state_op(quantum_concurrent='junk') + with self.assertRaisesRegex(TypeError, + expected_regex="must be type bool."): + circuit_execution_ops.get_state_op(use_cuquantum='junk') + + with self.assertRaisesRegex( + ValueError, expected_regex="not be True at the same time"): + circuit_execution_ops.get_state_op( + quantum_concurrent=True, use_cuquantum=True) + class ExecutionOpsConsistentyTest(tf.test.TestCase, parameterized.TestCase): """Test all ops produce equivalent output to one another.""" @@ -277,8 +333,7 @@ def test_simulate_state_with_symbols(self, op_and_sim, n_qubits, **{ 'op_and_sim': [(op, sim) for ( op, - sim) in zip(STATE_OPS[:-2] + - [STATE_OPS[-1]], SIMS[:-2] + [SIMS[-1]])], + sim) in zip(NO_DM_STATE_OPS, NO_DM_SIMS)], }))) def test_simulate_state_large(self, op_and_sim): """Test a reasonably large and complex circuit.""" @@ -298,6 +353,10 @@ def test_simulate_state_large(self, op_and_sim): cirq_states = batch_util.batch_calculate_state(circuit_batch, resolver_batch, sim) + # Due to numpy memory allocation error with large circuits, + # we deallocate these variables. + del circuit_batch + del resolver_batch self.assertAllClose(cirq_states, op_states, atol=1e-5, rtol=1e-5) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index 1e31a62cc..b87eb6319 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -108,7 +108,7 @@ class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { std::vector>> fused_circuits( programs.size(), std::vector>({})); - Status parse_status = Status::OK(); + Status parse_status = ::tensorflow::Status(); auto p_lock = tensorflow::mutex(); auto construct_f = [&](int start, int end) { for (int i = start; i < end; i++) { @@ -239,7 +239,7 @@ REGISTER_OP("TfqSimulateSampledExpectationCuquantum") c->Dim(pauli_sums_shape, 1); c->set_output(0, c->Matrix(output_rows, output_cols)); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); -} // namespace tfq \ No newline at end of file +} // namespace tfq diff --git a/tensorflow_quantum/python/layers/circuit_executors/BUILD b/tensorflow_quantum/python/layers/circuit_executors/BUILD index ae8feff9c..1e4541c42 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/BUILD +++ b/tensorflow_quantum/python/layers/circuit_executors/BUILD @@ -40,7 +40,7 @@ py_library( "//tensorflow_quantum/python/differentiators:adjoint", "//tensorflow_quantum/python/differentiators:differentiator", "//tensorflow_quantum/python/differentiators:parameter_shift", - ], + ] ) py_library( From 72ca20d6e21d44f1fdc0dfd926c0f2d0a7415ff4 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sat, 15 Apr 2023 19:41:51 -0700 Subject: [PATCH 037/106] Fix wrong usage of GuardedPhiloxRandom, so fix expectation_test error --- .../tfq_simulate_expectation_op_cuda.cu.cc | 204 ------------------ ...fq_simulate_expectation_op_cuquantum.cu.cc | 4 +- ...ate_sampled_expectation_op_cuquantum.cu.cc | 9 +- .../tfq_simulate_samples_op_cuquantum.cu.cc | 13 +- .../ops/tfq_simulate_state_op_cuquantum.cu.cc | 2 +- .../python/differentiators/adjoint.py | 27 ++- .../python/differentiators/differentiator.py | 22 +- .../layers/circuit_executors/expectation.py | 6 +- .../circuit_executors/expectation_test.py | 2 +- 9 files changed, 54 insertions(+), 235 deletions(-) delete mode 100644 tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuda.cu.cc diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuda.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuda.cu.cc deleted file mode 100644 index 5fa048227..000000000 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuda.cu.cc +++ /dev/null @@ -1,204 +0,0 @@ -/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ - -#include -#include -#include - -#include "../qsim/lib/circuit.h" -#include "../qsim/lib/gate_appl.h" -#include "../qsim/lib/gates_cirq.h" -#include "../qsim/lib/gates_qsim.h" -#include "../qsim/lib/seqfor.h" -#include "../qsim/lib/simmux.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/error_codes.pb.h" -#include "tensorflow/core/lib/core/status.h" -#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/pauli_sum.pb.h" -#include "tensorflow_quantum/core/proto/program.pb.h" -#include "tensorflow_quantum/core/src/util_qsim.h" - -namespace tfq { - -using ::tensorflow::Status; -using ::tfq::proto::PauliSum; -using ::tfq::proto::Program; - -typedef qsim::Cirq::GateCirq QsimGate; -typedef qsim::Circuit QsimCircuit; - -class TfqSimulateExpectationOpCuda : public tensorflow::OpKernel { - public: - explicit TfqSimulateExpectationOpCuda( - tensorflow::OpKernelConstruction* context) - : OpKernel(context) {} - - void Compute(tensorflow::OpKernelContext* context) override { - // TODO (mbbrough): add more dimension checks for other inputs here. - const int num_inputs = context->num_inputs(); - OP_REQUIRES(context, num_inputs == 4, - tensorflow::errors::InvalidArgument(absl::StrCat( - "Expected 4 inputs, got ", num_inputs, " inputs."))); - - // Create the output Tensor. - const int output_dim_batch_size = context->input(0).dim_size(0); - const int output_dim_op_size = context->input(3).dim_size(1); - tensorflow::TensorShape output_shape; - output_shape.AddDim(output_dim_batch_size); - output_shape.AddDim(output_dim_op_size); - - tensorflow::Tensor* output = nullptr; - tensorflow::AllocatorAttributes alloc_attr; - alloc_attr.set_on_host(true); - alloc_attr.set_gpu_compatible(true); - OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output, - alloc_attr)); - auto output_tensor = output->matrix(); - // Parse program protos. - std::vector programs; - std::vector num_qubits; - std::vector> pauli_sums; - OP_REQUIRES_OK(context, GetProgramsAndNumQubits(context, &programs, - &num_qubits, &pauli_sums)); - - std::vector maps; - OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); - - OP_REQUIRES(context, programs.size() == maps.size(), - tensorflow::errors::InvalidArgument(absl::StrCat( - "Number of circuits and symbol_values do not match. Got ", - programs.size(), " circuits and ", maps.size(), - " symbol values."))); - - // Construct qsim circuits. - std::vector qsim_circuits(programs.size(), QsimCircuit()); - std::vector>> fused_circuits( - programs.size(), std::vector>({})); - - Status parse_status = Status(); - auto p_lock = tensorflow::mutex(); - auto construct_f = [&](int start, int end) { - for (int i = start; i < end; i++) { - Status local = - QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], - &qsim_circuits[i], &fused_circuits[i]); - NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); - } - }; - - const int num_cycles = 1000; - context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( - programs.size(), num_cycles, construct_f); - OP_REQUIRES_OK(context, parse_status); - - int max_num_qubits = 0; - for (const int num : num_qubits) { - max_num_qubits = std::max(max_num_qubits, num); - } - ComputeLarge(num_qubits, fused_circuits, pauli_sums, context, - &output_tensor); - } - - private: - int num_threads_in_sim_; - int block_count_; - - // Define the GPU implementation that launches the CUDA kernel. - void ComputeLarge( - const std::vector& num_qubits, - const std::vector>>& fused_circuits, - const std::vector>& pauli_sums, - tensorflow::OpKernelContext* context, - tensorflow::TTypes::Matrix* output_tensor) { - // Instantiate qsim objects. - using Simulator = qsim::SimulatorCUDA; - using StateSpace = Simulator::StateSpace; - // Begin simulation with default parameters. - int largest_nq = 1; - Simulator sim = Simulator(); - StateSpace ss = StateSpace(StateSpace::Parameter()); - auto sv = ss.Create(largest_nq); - auto scratch = ss.Create(largest_nq); - - // Simulate programs one by one. Parallelizing over state vectors - // we no longer parallelize over circuits. Each time we encounter a - // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < fused_circuits.size(); i++) { - int nq = num_qubits[i]; - - if (nq > largest_nq) { - // need to switch to larger statespace. - largest_nq = nq; - sv = ss.Create(largest_nq); - scratch = ss.Create(largest_nq); - } - // TODO: add heuristic here so that we do not always recompute - // the state if there is a possibility that circuit[i] and - // circuit[i + 1] produce the same state. - ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { - qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); - } - for (int j = 0; j < pauli_sums[i].size(); j++) { - // (#679) Just ignore empty program - if (fused_circuits[i].size() == 0) { - (*output_tensor)(i, j) = -2.0; - continue; - } - float exp_v = 0.0; - OP_REQUIRES_OK(context, - ComputeExpectationQsim(pauli_sums[i][j], sim, ss, sv, - scratch, &exp_v)); - (*output_tensor)(i, j) = exp_v; - } - } - } -}; - -REGISTER_KERNEL_BUILDER( - Name("TfqSimulateExpectationCuda").Device(tensorflow::DEVICE_CPU), - TfqSimulateExpectationOpCuda); - -REGISTER_OP("TfqSimulateExpectationCuda") - .Input("programs: string") - .Input("symbol_names: string") - .Input("symbol_values: float") - .Input("pauli_sums: string") - .Output("expectations: float") - .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { - tensorflow::shape_inference::ShapeHandle programs_shape; - TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); - - tensorflow::shape_inference::ShapeHandle symbol_names_shape; - TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); - - tensorflow::shape_inference::ShapeHandle symbol_values_shape; - TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); - - tensorflow::shape_inference::ShapeHandle pauli_sums_shape; - TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 2, &pauli_sums_shape)); - - tensorflow::shape_inference::DimensionHandle output_rows = - c->Dim(programs_shape, 0); - tensorflow::shape_inference::DimensionHandle output_cols = - c->Dim(pauli_sums_shape, 1); - c->set_output(0, c->Matrix(output_rows, output_cols)); - - return ::tensorflow::Status(); - }); - -} // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc index 1052dd0d1..86387be72 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc @@ -92,7 +92,7 @@ class TfqSimulateExpectationOpCuQuantum : public tensorflow::OpKernel { std::vector>> fused_circuits( programs.size(), std::vector>({})); - Status parse_status = Status::OK(); + Status parse_status = ::tensorflow::Status(); auto p_lock = tensorflow::mutex(); auto construct_f = [&](int start, int end) { for (int i = start; i < end; i++) { @@ -213,7 +213,7 @@ REGISTER_OP("TfqSimulateExpectationCuquantum") c->Dim(pauli_sums_shape, 1); c->set_output(0, c->Matrix(output_rows, output_cols)); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index b87eb6319..69c82d622 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -52,7 +52,9 @@ class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { public: explicit TfqSimulateSampledExpectationOpCuQuantum( tensorflow::OpKernelConstruction* context) - : OpKernel(context) {} + : OpKernel(context) { + OP_REQUIRES_OK(context, random_gen_.Init(context)); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. @@ -140,6 +142,7 @@ class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { private: cublasHandle_t cublas_handle_; custatevecHandle_t custatevec_handle_; + tensorflow::GuardedPhiloxRandom random_gen_; void ComputeLarge( const std::vector& num_qubits, @@ -159,15 +162,13 @@ class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { auto sv = ss.Create(largest_nq); auto scratch = ss.Create(largest_nq); - tensorflow::GuardedPhiloxRandom random_gen; - random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); int largest_sum = -1; for (const auto& sums : pauli_sums) { for (const auto& sum : sums) { largest_sum = std::max(largest_sum, sum.terms().size()); } } - auto local_gen = random_gen.ReserveSamples32( + auto local_gen = random_gen_.ReserveSamples32( largest_sum * pauli_sums[0].size() * fused_circuits.size() + 1); tensorflow::random::SimplePhilox rand_source(&local_gen); diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc index 0e487fefd..33059f116 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -51,7 +51,9 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { public: explicit TfqSimulateSamplesOpCuQuantum( tensorflow::OpKernelConstruction* context) - : OpKernel(context) {} + : OpKernel(context) { + OP_REQUIRES_OK(context, random_gen_.Init(context)); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. @@ -80,7 +82,7 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { std::vector>> fused_circuits( programs.size(), std::vector>({})); - Status parse_status = Status::OK(); + Status parse_status = ::tensorflow::Status(); auto p_lock = tensorflow::mutex(); auto construct_f = [&](int start, int end) { for (int i = start; i < end; i++) { @@ -129,6 +131,7 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { private: cublasHandle_t cublas_handle_; custatevecHandle_t custatevec_handle_; + tensorflow::GuardedPhiloxRandom random_gen_; void ComputeLarge( const std::vector& num_qubits, const int max_num_qubits, @@ -146,9 +149,7 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); auto sv = ss.Create(largest_nq); - tensorflow::GuardedPhiloxRandom random_gen; - random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); - auto local_gen = random_gen.ReserveSamples32(fused_circuits.size() + 1); + auto local_gen = random_gen_.ReserveSamples32(fused_circuits.size() + 1); tensorflow::random::SimplePhilox rand_source(&local_gen); // Simulate programs one by one. Parallelizing over state vectors @@ -219,7 +220,7 @@ REGISTER_OP("TfqSimulateSamplesCuquantum") tensorflow::shape_inference::InferenceContext::kUnknownDim, tensorflow::shape_inference::InferenceContext::kUnknownDim})); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq \ No newline at end of file diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc index da4957e60..f65ac36be 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc @@ -201,7 +201,7 @@ REGISTER_OP("TfqSimulateStateCuquantum") {c->Dim(programs_shape, 0), tensorflow::shape_inference::InferenceContext::kUnknownDim})); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq \ No newline at end of file diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index 29ea9a10d..a2c11c8b2 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -105,6 +105,21 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values): "therefore it has no accessible gradient circuits." ) + @differentiator.catch_empty_inputs + @tf.function + def differentiate_analytic_cuquantum( + self, + programs, + symbol_names, + symbol_values, + pauli_sums, + forward_pass_vals, + grad, + ): + return tfq_adj_grad_op_cuquantum.tfq_adj_grad( + programs, symbol_names, symbol_values, pauli_sums, grad + ) + @differentiator.catch_empty_inputs @tf.function def differentiate_analytic( @@ -115,16 +130,10 @@ def differentiate_analytic( pauli_sums, forward_pass_vals, grad, - use_cuquantum=False, ): - if use_cuquantum: - return tfq_adj_grad_op_cuquantum.tfq_adj_grad( - programs, symbol_names, symbol_values, pauli_sums, grad - ) - else: - return tfq_adj_grad_op.tfq_adj_grad( - programs, symbol_names, symbol_values, pauli_sums, grad - ) + return tfq_adj_grad_op.tfq_adj_grad( + programs, symbol_names, symbol_values, pauli_sums, grad + ) def differentiate_sampled( self, diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index 54c597b68..91656d4d1 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -152,6 +152,10 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, 'Given arg: {}.'.format(str(key)) + '' 'The signature should contain: {}.'.format( list(expected_signature))) + _differentiate_ana = ( + self._differentiate_ana_cq if use_cuquantum else + self._differentiate_ana + ) @tf.custom_gradient def op_wrapper_analytic(programs, symbol_names, symbol_values, @@ -160,10 +164,9 @@ def op_wrapper_analytic(programs, symbol_names, symbol_values, symbol_values, pauli_sums) def gradient(grad): - return self._differentiate_ana(programs, symbol_names, - symbol_values, pauli_sums, - forward_pass_vals, grad, - use_cuquantum=use_cuquantum) + return _differentiate_ana(programs, symbol_names, + symbol_values, pauli_sums, + forward_pass_vals, grad) return forward_pass_vals, gradient @@ -190,11 +193,18 @@ def gradient(grad): return return_func + def _differentiate_ana_cq(self, programs, symbol_names, symbol_values, + pauli_sums, forward_pass_vals, grad): + return None, None, self.differentiate_analytic_cuquantum( + programs, symbol_names, symbol_values, + pauli_sums, forward_pass_vals, grad), \ + None + def _differentiate_ana(self, programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad, use_cuquantum): + pauli_sums, forward_pass_vals, grad): return None, None, self.differentiate_analytic( programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad, use_cuquantum=use_cuquantum), \ + pauli_sums, forward_pass_vals, grad), \ None def _differentiate_sam(self, programs, symbol_names, symbol_values, diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation.py b/tensorflow_quantum/python/layers/circuit_executors/expectation.py index a02d82809..d4426340c 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation.py @@ -226,7 +226,7 @@ def __init__(self, backend='noiseless', differentiator=None, use_cuquantum=False which uses `tfq.differentiators.ParameterShift()`. If `backend` is also 'noiseless' then default is `tfq.differentiators.Adjoint`. - use_cuquantum: Calls TFQ GPU version op. + use_cuquantum: Calls TFQ cuQuantum version op. """ super().__init__(**kwargs) @@ -264,7 +264,9 @@ def __init__(self, backend='noiseless', differentiator=None, use_cuquantum=False used_op = circuit_execution_ops.get_expectation_op( backend=backend, use_cuquantum=use_cuquantum) self._expectation_op = differentiator.generate_differentiable_op( - analytic_op=used_op, use_cuquantum=use_cuquantum) + analytic_op=used_op) + # self._expectation_op = differentiator.generate_differentiable_op( + # analytic_op=used_op, use_cuquantum=use_cuquantum) self._w = None diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py index 1bb08a0e4..e4489e763 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py @@ -324,7 +324,7 @@ def test_simple_param_value_input(self, backend): l1 = tf.keras.layers.Dense(10)(inputs) l2 = tf.keras.layers.Dense(3)(l1) reps = 1000 if noisy else None - outputs = expectation.Expectation(backend=backend, use_cuquantum=False)( + outputs = expectation.Expectation(backend=backend)( datum, symbol_names=symbols, operators=cirq.Z(bit), From 1eff5e651f10f6931827c83a8ebbded0e65732b7 Mon Sep 17 00:00:00 2001 From: Pavan Jayasinha <70229100+Sinestro38@users.noreply.github.com> Date: Tue, 25 Apr 2023 21:21:54 -0700 Subject: [PATCH 038/106] Update expectation_test.py --- .../circuit_executors/expectation_test.py | 801 +++++++++--------- 1 file changed, 401 insertions(+), 400 deletions(-) diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py index e4489e763..c7723b70d 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py @@ -47,262 +47,262 @@ def _gen_single_bit_rotation_problem(bit, symbols, noisy): return circuit -class ExpectationTest(tf.test.TestCase): - """Basic tests for the expectation layer.""" - - def test_expectation_instantiate(self): - """Test that Expectation instantiates correctly.""" - expectation.Expectation() - expectation.Expectation(backend=None) - expectation.Expectation(backend='noisy') - expectation.Expectation(backend='noiseless') - expectation.Expectation(backend=cirq.Simulator()) - expectation.Expectation( - differentiator=linear_combination.ForwardDifference()) - - def test_expectation_instantiate_error(self): - """Test that Expectation errors with bad inputs.""" - - class MySampler(cirq.Sampler): - """Class to test sampler detection in Expectation.""" - - def run_sweep(self): - """do nothing.""" - return - - with self.assertRaisesRegex(TypeError, - expected_regex="SampledExpectation"): - expectation.Expectation(backend=MySampler()) - - with self.assertRaisesRegex( - TypeError, expected_regex="SimulatesExpectationValues or None"): - expectation.Expectation(backend='junk') - - with self.assertRaisesRegex( - TypeError, expected_regex="tfq.differentiators.Differentiator"): - expectation.Expectation(differentiator='junk') - - def test_expectation_type_inputs_error(self): - """Test that expectation errors within Keras call.""" - - bit = cirq.GridQubit(0, 0) - test_pstring = cirq.Z(bit) - test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) - reg_circuit = cirq.Circuit(cirq.H(bit)) - - with self.assertRaisesRegex(Exception, - expected_regex="Unknown initializer"): - expectation.Expectation()(reg_circuit, - operators=test_psum, - initializer='junk') - - with self.assertRaisesRegex(Exception, - expected_regex="repetitions not provided"): - expectation.Expectation(backend='noisy')(reg_circuit, - operators=test_psum) - - with self.assertRaisesRegex(Exception, - expected_regex="cannot be parsed"): - expectation.Expectation(backend='noisy')(reg_circuit, - operators=test_psum, - repetitions='junk') - - with self.assertRaisesRegex(Exception, expected_regex="noiseless"): - expectation.Expectation(backend='noiseless')(reg_circuit, - operators=test_psum, - repetitions=1) - - def test_expectation_op_error(self): - """Test that expectation errors within underlying ops correctly.""" - - bit = cirq.GridQubit(0, 0) - symbol = sympy.Symbol('alpha') - test_pstring = cirq.Z(bit) - test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) - symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) - reg_circuit = cirq.Circuit(cirq.H(bit)) - - with self.assertRaisesRegex(Exception, - expected_regex="Could not find symbol"): - # No symbol matchups. - expectation.Expectation()([symb_circuit], operators=test_psum) - - with self.assertRaisesRegex(Exception, - expected_regex="Unparseable proto"): - # Proto is unparseable. - expectation.Expectation()([reg_circuit], - operators=tf.convert_to_tensor( - [['bad_operator']])) - - with self.assertRaisesRegex(Exception, expected_regex="rank 2"): - # Operators has wrong rank. - expectation.Expectation()([reg_circuit], - operators=util.convert_to_tensor( - [test_psum])) - - with self.assertRaisesRegex(Exception, expected_regex="rank 2"): - # symbol_values has wrong rank. - expectation.Expectation()([symb_circuit], - symbol_names=[symbol], - symbol_values=[0.5], - operators=test_psum) - - with self.assertRaisesRegex(Exception, expected_regex="do not match."): - # Wrong batch size for pauli operators. - expectation.Expectation()(symb_circuit, - symbol_names=[symbol], - operators=[[test_psum], [test_psum]]) - - with self.assertRaisesRegex(Exception, expected_regex="do not match."): - # Wrong batch_size for symbol values. - expectation.Expectation()([symb_circuit], - symbol_names=[symbol], - symbol_values=np.zeros((3, 1)), - operators=test_psum) - - def test_static_cases(self): - """Run inputs through in complex cases.""" - - bit = cirq.GridQubit(0, 0) - symbol = sympy.Symbol('alpha') - test_pstring = cirq.Z(bit) - test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) - symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) - reg_circuit = cirq.Circuit(cirq.H(bit)) - - # Passing a 2d operators input requires a 1d circuit input. - expectation.Expectation()([reg_circuit, reg_circuit], - operators=[[test_psum, test_psum], - [test_psum, test_psum]]) - - # Passing 2d operators along with other inputs. - expectation.Expectation()([symb_circuit, symb_circuit], - symbol_names=[symbol], - operators=[[test_psum, test_psum], - [test_psum, test_psum]]) - expectation.Expectation()([symb_circuit, symb_circuit], - symbol_names=[symbol], - symbol_values=[[0.5], [0.8]], - operators=[[test_psum, test_psum], - [test_psum, test_psum]]) - - # Ensure tiling up of circuits works as expected. - expectation.Expectation()(reg_circuit, operators=test_psum) - expectation.Expectation()(reg_circuit, operators=[test_psum, test_psum]) - - # Ensure tiling up of symbol_values works as expected. - expectation.Expectation()(symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5], [0.8]], - operators=test_psum) - expectation.Expectation()(symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=test_psum) - - def test_static_cases_noisy(self): - """Test that the noisy trajectory backend works in complex cases.""" - bit = cirq.GridQubit(0, 0) - symbol = sympy.Symbol('alpha') - test_pstring = cirq.Z(bit) - test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) - symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) - reg_circuit = cirq.Circuit(cirq.H(bit)) - - # Passing a 2d operators input requires a 1d circuit input. - expectation.Expectation(backend='noisy')( - [reg_circuit, reg_circuit], - operators=[[test_psum, test_psum], [test_psum, test_psum]], - repetitions=1) - - # Passing 2d operators along with other inputs. - expectation.Expectation(backend='noisy')( - [symb_circuit, symb_circuit], - symbol_names=[symbol], - operators=[[test_psum, test_psum], [test_psum, test_psum]], - repetitions=1) - expectation.Expectation(backend='noisy')( - [symb_circuit, symb_circuit], - symbol_names=[symbol], - symbol_values=[[0.5], [0.8]], - operators=[[test_psum, test_psum], [test_psum, test_psum]], - repetitions=1) - - # Ensure tiling up of circuits works as expected. - expectation.Expectation(backend='noisy')(reg_circuit, - operators=test_psum, - repetitions=1) - expectation.Expectation(backend='noisy')( - reg_circuit, operators=[test_psum, test_psum], repetitions=1) - - # Ensure tiling up of symbol_values works as expected. - expectation.Expectation(backend='noisy')(symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5], [0.8]], - operators=test_psum, - repetitions=1) - expectation.Expectation(backend='noisy')(symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=test_psum, - repetitions=1) - - # Test multiple operators with integer valued repetition. - expectation.Expectation(backend='noisy')( - symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=[-1.0 * cirq.Z(bit), - cirq.X(bit) + 2.0 * cirq.Z(bit)], - repetitions=1) - expectation.Expectation(backend='noisy')( - symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=[-1.0 * cirq.Z(bit), - cirq.X(bit) + 2.0 * cirq.Z(bit)], - repetitions=[5, 1]) - - # Test 2d repetitions. - expectation.Expectation(backend='noisy')( - [symb_circuit, symb_circuit], - symbol_names=[symbol], - symbol_values=[[0.5], [0.4]], - operators=[[ - -1.0 * cirq.Z(bit), - cirq.X(bit) + 2.0 * cirq.Z(bit), - cirq.Z(bit) - ], [cirq.Z(bit), cirq.Z(bit), cirq.Z(bit)]], - repetitions=[[1, 2, 3], [4, 5, 6]]) - - def test_expectation_simple_tf_train(self): - """Train a layer using standard tf (not keras). - This is a subtle test that will work since we don't use keras compile. - """ - bit = cirq.GridQubit(0, 0) - circuit = \ - cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) - op = cirq.Z(bit) - layer = expectation.Expectation() - optimizer = tf.optimizers.Adam(learning_rate=0.05) - for _ in range(200): - with tf.GradientTape() as tape: - circuit_out = layer(circuit, - symbol_names=['theta'], - operators=op) - mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) - grads = tape.gradient(mse, layer.trainable_weights) - optimizer.apply_gradients(zip(grads, layer.trainable_weights)) - self.assertAllClose(mse.numpy(), 0, atol=1e-3) - - +# class ExpectationTest(tf.test.TestCase): +# """Basic tests for the expectation layer.""" + +# def test_expectation_instantiate(self): +# """Test that Expectation instantiates correctly.""" +# expectation.Expectation() +# expectation.Expectation(backend=None) +# expectation.Expectation(backend='noisy') +# expectation.Expectation(backend='noiseless') +# expectation.Expectation(backend=cirq.Simulator()) +# expectation.Expectation( +# differentiator=linear_combination.ForwardDifference()) + +# def test_expectation_instantiate_error(self): +# """Test that Expectation errors with bad inputs.""" + +# class MySampler(cirq.Sampler): +# """Class to test sampler detection in Expectation.""" + +# def run_sweep(self): +# """do nothing.""" +# return + +# with self.assertRaisesRegex(TypeError, +# expected_regex="SampledExpectation"): +# expectation.Expectation(backend=MySampler()) + +# with self.assertRaisesRegex( +# TypeError, expected_regex="SimulatesExpectationValues or None"): +# expectation.Expectation(backend='junk') + +# with self.assertRaisesRegex( +# TypeError, expected_regex="tfq.differentiators.Differentiator"): +# expectation.Expectation(differentiator='junk') + +# def test_expectation_type_inputs_error(self): +# """Test that expectation errors within Keras call.""" + +# bit = cirq.GridQubit(0, 0) +# test_pstring = cirq.Z(bit) +# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) +# reg_circuit = cirq.Circuit(cirq.H(bit)) + +# with self.assertRaisesRegex(Exception, +# expected_regex="Unknown initializer"): +# expectation.Expectation()(reg_circuit, +# operators=test_psum, +# initializer='junk') + +# with self.assertRaisesRegex(Exception, +# expected_regex="repetitions not provided"): +# expectation.Expectation(backend='noisy')(reg_circuit, +# operators=test_psum) + +# with self.assertRaisesRegex(Exception, +# expected_regex="cannot be parsed"): +# expectation.Expectation(backend='noisy')(reg_circuit, +# operators=test_psum, +# repetitions='junk') + +# with self.assertRaisesRegex(Exception, expected_regex="noiseless"): +# expectation.Expectation(backend='noiseless')(reg_circuit, +# operators=test_psum, +# repetitions=1) + +# def test_expectation_op_error(self): +# """Test that expectation errors within underlying ops correctly.""" + +# bit = cirq.GridQubit(0, 0) +# symbol = sympy.Symbol('alpha') +# test_pstring = cirq.Z(bit) +# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) +# symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) +# reg_circuit = cirq.Circuit(cirq.H(bit)) + +# with self.assertRaisesRegex(Exception, +# expected_regex="Could not find symbol"): +# # No symbol matchups. +# expectation.Expectation()([symb_circuit], operators=test_psum) + +# with self.assertRaisesRegex(Exception, +# expected_regex="Unparseable proto"): +# # Proto is unparseable. +# expectation.Expectation()([reg_circuit], +# operators=tf.convert_to_tensor( +# [['bad_operator']])) + +# with self.assertRaisesRegex(Exception, expected_regex="rank 2"): +# # Operators has wrong rank. +# expectation.Expectation()([reg_circuit], +# operators=util.convert_to_tensor( +# [test_psum])) + +# with self.assertRaisesRegex(Exception, expected_regex="rank 2"): +# # symbol_values has wrong rank. +# expectation.Expectation()([symb_circuit], +# symbol_names=[symbol], +# symbol_values=[0.5], +# operators=test_psum) + +# with self.assertRaisesRegex(Exception, expected_regex="do not match."): +# # Wrong batch size for pauli operators. +# expectation.Expectation()(symb_circuit, +# symbol_names=[symbol], +# operators=[[test_psum], [test_psum]]) + +# with self.assertRaisesRegex(Exception, expected_regex="do not match."): +# # Wrong batch_size for symbol values. +# expectation.Expectation()([symb_circuit], +# symbol_names=[symbol], +# symbol_values=np.zeros((3, 1)), +# operators=test_psum) + +# def test_static_cases(self): +# """Run inputs through in complex cases.""" + +# bit = cirq.GridQubit(0, 0) +# symbol = sympy.Symbol('alpha') +# test_pstring = cirq.Z(bit) +# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) +# symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) +# reg_circuit = cirq.Circuit(cirq.H(bit)) + +# # Passing a 2d operators input requires a 1d circuit input. +# expectation.Expectation()([reg_circuit, reg_circuit], +# operators=[[test_psum, test_psum], +# [test_psum, test_psum]]) + +# # Passing 2d operators along with other inputs. +# expectation.Expectation()([symb_circuit, symb_circuit], +# symbol_names=[symbol], +# operators=[[test_psum, test_psum], +# [test_psum, test_psum]]) +# expectation.Expectation()([symb_circuit, symb_circuit], +# symbol_names=[symbol], +# symbol_values=[[0.5], [0.8]], +# operators=[[test_psum, test_psum], +# [test_psum, test_psum]]) + +# # Ensure tiling up of circuits works as expected. +# expectation.Expectation()(reg_circuit, operators=test_psum) +# expectation.Expectation()(reg_circuit, operators=[test_psum, test_psum]) + +# # Ensure tiling up of symbol_values works as expected. +# expectation.Expectation()(symb_circuit, +# symbol_names=[symbol], +# symbol_values=[[0.5], [0.8]], +# operators=test_psum) +# expectation.Expectation()(symb_circuit, +# symbol_names=[symbol], +# symbol_values=[[0.5]], +# operators=test_psum) + +# def test_static_cases_noisy(self): +# """Test that the noisy trajectory backend works in complex cases.""" +# bit = cirq.GridQubit(0, 0) +# symbol = sympy.Symbol('alpha') +# test_pstring = cirq.Z(bit) +# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) +# symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) +# reg_circuit = cirq.Circuit(cirq.H(bit)) + +# # Passing a 2d operators input requires a 1d circuit input. +# expectation.Expectation(backend='noisy')( +# [reg_circuit, reg_circuit], +# operators=[[test_psum, test_psum], [test_psum, test_psum]], +# repetitions=1) + +# # Passing 2d operators along with other inputs. +# expectation.Expectation(backend='noisy')( +# [symb_circuit, symb_circuit], +# symbol_names=[symbol], +# operators=[[test_psum, test_psum], [test_psum, test_psum]], +# repetitions=1) +# expectation.Expectation(backend='noisy')( +# [symb_circuit, symb_circuit], +# symbol_names=[symbol], +# symbol_values=[[0.5], [0.8]], +# operators=[[test_psum, test_psum], [test_psum, test_psum]], +# repetitions=1) + +# # Ensure tiling up of circuits works as expected. +# expectation.Expectation(backend='noisy')(reg_circuit, +# operators=test_psum, +# repetitions=1) +# expectation.Expectation(backend='noisy')( +# reg_circuit, operators=[test_psum, test_psum], repetitions=1) + +# # Ensure tiling up of symbol_values works as expected. +# expectation.Expectation(backend='noisy')(symb_circuit, +# symbol_names=[symbol], +# symbol_values=[[0.5], [0.8]], +# operators=test_psum, +# repetitions=1) +# expectation.Expectation(backend='noisy')(symb_circuit, +# symbol_names=[symbol], +# symbol_values=[[0.5]], +# operators=test_psum, +# repetitions=1) + +# # Test multiple operators with integer valued repetition. +# expectation.Expectation(backend='noisy')( +# symb_circuit, +# symbol_names=[symbol], +# symbol_values=[[0.5]], +# operators=[-1.0 * cirq.Z(bit), +# cirq.X(bit) + 2.0 * cirq.Z(bit)], +# repetitions=1) +# expectation.Expectation(backend='noisy')( +# symb_circuit, +# symbol_names=[symbol], +# symbol_values=[[0.5]], +# operators=[-1.0 * cirq.Z(bit), +# cirq.X(bit) + 2.0 * cirq.Z(bit)], +# repetitions=[5, 1]) + +# # Test 2d repetitions. +# expectation.Expectation(backend='noisy')( +# [symb_circuit, symb_circuit], +# symbol_names=[symbol], +# symbol_values=[[0.5], [0.4]], +# operators=[[ +# -1.0 * cirq.Z(bit), +# cirq.X(bit) + 2.0 * cirq.Z(bit), +# cirq.Z(bit) +# ], [cirq.Z(bit), cirq.Z(bit), cirq.Z(bit)]], +# repetitions=[[1, 2, 3], [4, 5, 6]]) + +# def test_expectation_simple_tf_train(self): +# """Train a layer using standard tf (not keras). +# This is a subtle test that will work since we don't use keras compile. +# """ +# bit = cirq.GridQubit(0, 0) +# circuit = \ +# cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) +# op = cirq.Z(bit) +# layer = expectation.Expectation() +# optimizer = tf.optimizers.Adam(learning_rate=0.05) +# for _ in range(200): +# with tf.GradientTape() as tape: +# circuit_out = layer(circuit, +# symbol_names=['theta'], +# operators=op) +# mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) +# grads = tape.gradient(mse, layer.trainable_weights) +# optimizer.apply_gradients(zip(grads, layer.trainable_weights)) +# self.assertAllClose(mse.numpy(), 0, atol=1e-3) + +from tensorflow_quantum.python import quantum_context class ExpectationFunctionalTests(parameterized.TestCase, tf.test.TestCase): """Test hybrid/integrated models that include an expectation layer.""" @parameterized.parameters([ - { - 'backend': 'noisy' - }, + # { + # 'backend': 'noisy' + # }, { 'backend': None # old API usage } @@ -324,7 +324,8 @@ def test_simple_param_value_input(self, backend): l1 = tf.keras.layers.Dense(10)(inputs) l2 = tf.keras.layers.Dense(3)(l1) reps = 1000 if noisy else None - outputs = expectation.Expectation(backend=backend)( + # quantum_context.set_quantum_concurrent_op_mode(False) + outputs = expectation.Expectation(backend=backend, use_cuquantum=True)( datum, symbol_names=symbols, operators=cirq.Z(bit), @@ -344,153 +345,153 @@ def test_simple_param_value_input(self, backend): tol = 5e-2 if noisy else 1e-3 self.assertAllClose(history.history['loss'][-1], 0, atol=tol) - @parameterized.parameters([ - { - 'backend': 'noisy' - }, - { - 'backend': None # old API usage - } - ]) - def test_simple_op_input(self, backend): - """Test a simple operator input - - Learn qubit in the z+ state using two different measurement operators. - This tests input signature Expectation([operator_batch]) - """ - noisy = backend == 'noisy' - bit = cirq.GridQubit(0, 0) - symbols = sympy.symbols('x, y, z') - - circuits = util.convert_to_tensor( - [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) - - data_out = tf.convert_to_tensor(np.array([[1], [1]])) - ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) - - circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) - op_input = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) - - reps = 1000 if noisy else None - output = expectation.Expectation(backend=backend)( - circuit_input, - symbol_names=symbols, - operators=op_input, - initializer=tf.keras.initializers.RandomNormal(), - repetitions=reps) - - model = tf.keras.Model(inputs=[circuit_input, op_input], outputs=output) - - model.compile( - optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), - loss=tf.keras.losses.mean_squared_error, - ) - history = model.fit(x=[circuits, ops], - y=data_out, - batch_size=2, - epochs=200) - tol = 5e-2 if noisy else 1e-3 - self.assertAllClose(history.history['loss'][-1], 0, atol=tol) - - @parameterized.parameters([ - { - 'backend': 'noisy' - }, - { - 'backend': None # old api usage. - }, - { - 'backend': cirq.Simulator() - } - ]) - def test_simple_op_and_param_input(self, backend): - """Test a simple operator and parameter input. - - Train a NN to put a qubit in the z+ or x+ states based on a classical - binary input. This tests the input signature: - Expectation([value_batch, operator_batch]). - """ - noisy = backend == 'noisy' - bit = cirq.GridQubit(0, 0) - symbols = sympy.symbols('x, y, z') - ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.X(bit)]]) - circuits = util.convert_to_tensor( - [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) - data_in = np.array([[1], [0]]) - data_out = np.array([[1], [1]]) - - data_inp = tf.keras.Input(shape=(1), dtype=tf.dtypes.float32) - op_inp = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) - circuit_inp = tf.keras.Input(shape=(), dtype=tf.dtypes.string) - dense_1 = tf.keras.layers.Dense(10)(data_inp) - dense_2 = tf.keras.layers.Dense(3)(dense_1) - reps = 1000 if noisy else None - circuit_output = expectation.Expectation(backend=backend)( - circuit_inp, - symbol_names=symbols, - symbol_values=dense_2, - operators=op_inp, - repetitions=reps) - - functional_model = tf.keras.Model( - inputs=[data_inp, op_inp, circuit_inp], outputs=[circuit_output]) - - functional_model.compile( - optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), - loss=tf.keras.losses.mean_squared_error) - history = functional_model.fit(x=[data_in, ops, circuits], - y=data_out, - batch_size=2, - epochs=100) - tol = 5e-2 if noisy else 1e-3 - self.assertAllClose(history.history['loss'][-1], 0, atol=tol) - - @parameterized.parameters([ - { - 'backend': 'noisy' - }, - { - 'backend': None # old api usage. - } - ]) - def test_dnn_qnn_dnn(self, backend): - """Train a fully hybrid network using an Expectation layer. - - Train the network to output +-5 given an input of 1 or 0. This tests - that everything works when Expectation layer is a middle layers. - """ - noisy = backend == 'noisy' - bit = cirq.GridQubit(0, 0) - symbols = sympy.symbols('x, y, z') - circuits = util.convert_to_tensor( - [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) - data_in = np.array([[1], [0]], dtype=np.float32) - data_out = np.array([[5], [-5]], dtype=np.float32) - - classical_input = tf.keras.Input(shape=(1,)) - circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) - d1 = tf.keras.layers.Dense(10)(classical_input) - d2 = tf.keras.layers.Dense(3)(d1) - reps = 1000 if noisy else None - quantum = expectation.Expectation(backend=backend)( - circuit_input, - symbol_names=symbols, - symbol_values=d2, - operators=cirq.Z(bit), - repetitions=reps) - d3 = tf.keras.layers.Dense(1)(quantum) - - model = tf.keras.Model(inputs=[circuit_input, classical_input], - outputs=d3) - - model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), - loss=tf.keras.losses.mean_squared_error) - history = model.fit(x=[circuits, data_in], - y=data_out, - batch_size=2, - epochs=300) - tol = 5e-2 if noisy else 1e-3 - self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + # @parameterized.parameters([ + # { + # 'backend': 'noisy' + # }, + # { + # 'backend': None # old API usage + # } + # ]) + # def test_simple_op_input(self, backend): + # """Test a simple operator input + + # Learn qubit in the z+ state using two different measurement operators. + # This tests input signature Expectation([operator_batch]) + # """ + # noisy = backend == 'noisy' + # bit = cirq.GridQubit(0, 0) + # symbols = sympy.symbols('x, y, z') + + # circuits = util.convert_to_tensor( + # [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) + + # data_out = tf.convert_to_tensor(np.array([[1], [1]])) + # ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) + + # circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) + # op_input = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) + + # reps = 1000 if noisy else None + # output = expectation.Expectation(backend=backend)( + # circuit_input, + # symbol_names=symbols, + # operators=op_input, + # initializer=tf.keras.initializers.RandomNormal(), + # repetitions=reps) + + # model = tf.keras.Model(inputs=[circuit_input, op_input], outputs=output) + + # model.compile( + # optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), + # loss=tf.keras.losses.mean_squared_error, + # ) + # history = model.fit(x=[circuits, ops], + # y=data_out, + # batch_size=2, + # epochs=200) + # tol = 5e-2 if noisy else 1e-3 + # self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + + # @parameterized.parameters([ + # { + # 'backend': 'noisy' + # }, + # { + # 'backend': None # old api usage. + # }, + # { + # 'backend': cirq.Simulator() + # } + # ]) + # def test_simple_op_and_param_input(self, backend): + # """Test a simple operator and parameter input. + + # Train a NN to put a qubit in the z+ or x+ states based on a classical + # binary input. This tests the input signature: + # Expectation([value_batch, operator_batch]). + # """ + # noisy = backend == 'noisy' + # bit = cirq.GridQubit(0, 0) + # symbols = sympy.symbols('x, y, z') + # ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.X(bit)]]) + # circuits = util.convert_to_tensor( + # [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) + # data_in = np.array([[1], [0]]) + # data_out = np.array([[1], [1]]) + + # data_inp = tf.keras.Input(shape=(1), dtype=tf.dtypes.float32) + # op_inp = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) + # circuit_inp = tf.keras.Input(shape=(), dtype=tf.dtypes.string) + # dense_1 = tf.keras.layers.Dense(10)(data_inp) + # dense_2 = tf.keras.layers.Dense(3)(dense_1) + # reps = 1000 if noisy else None + # circuit_output = expectation.Expectation(backend=backend)( + # circuit_inp, + # symbol_names=symbols, + # symbol_values=dense_2, + # operators=op_inp, + # repetitions=reps) + + # functional_model = tf.keras.Model( + # inputs=[data_inp, op_inp, circuit_inp], outputs=[circuit_output]) + + # functional_model.compile( + # optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), + # loss=tf.keras.losses.mean_squared_error) + # history = functional_model.fit(x=[data_in, ops, circuits], + # y=data_out, + # batch_size=2, + # epochs=100) + # tol = 5e-2 if noisy else 1e-3 + # self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + + # @parameterized.parameters([ + # { + # 'backend': 'noisy' + # }, + # { + # 'backend': None # old api usage. + # } + # ]) + # def test_dnn_qnn_dnn(self, backend): + # """Train a fully hybrid network using an Expectation layer. + + # Train the network to output +-5 given an input of 1 or 0. This tests + # that everything works when Expectation layer is a middle layers. + # """ + # noisy = backend == 'noisy' + # bit = cirq.GridQubit(0, 0) + # symbols = sympy.symbols('x, y, z') + # circuits = util.convert_to_tensor( + # [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) + # data_in = np.array([[1], [0]], dtype=np.float32) + # data_out = np.array([[5], [-5]], dtype=np.float32) + + # classical_input = tf.keras.Input(shape=(1,)) + # circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) + # d1 = tf.keras.layers.Dense(10)(classical_input) + # d2 = tf.keras.layers.Dense(3)(d1) + # reps = 1000 if noisy else None + # quantum = expectation.Expectation(backend=backend)( + # circuit_input, + # symbol_names=symbols, + # symbol_values=d2, + # operators=cirq.Z(bit), + # repetitions=reps) + # d3 = tf.keras.layers.Dense(1)(quantum) + + # model = tf.keras.Model(inputs=[circuit_input, classical_input], + # outputs=d3) + + # model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), + # loss=tf.keras.losses.mean_squared_error) + # history = model.fit(x=[circuits, data_in], + # y=data_out, + # batch_size=2, + # epochs=300) + # tol = 5e-2 if noisy else 1e-3 + # self.assertAllClose(history.history['loss'][-1], 0, atol=tol) if __name__ == '__main__': From 2b6af67dd1025580cddf40f87f9d7ed58ba417a2 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sat, 29 Apr 2023 01:17:25 +0000 Subject: [PATCH 039/106] Fix the quantum_concurrent for expectation layer --- .../python/layers/circuit_executors/expectation.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation.py b/tensorflow_quantum/python/layers/circuit_executors/expectation.py index d4426340c..bb6c3e544 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation.py @@ -21,12 +21,14 @@ import cirq from tensorflow_quantum.core.ops import circuit_execution_ops from tensorflow_quantum.core.ops.noise import noisy_expectation_op +from tensorflow_quantum.python import quantum_context from tensorflow_quantum.python.differentiators import adjoint from tensorflow_quantum.python.differentiators import parameter_shift from tensorflow_quantum.python.differentiators import differentiator as diff from tensorflow_quantum.python.layers.circuit_executors import input_checks + class Expectation(tf.keras.layers.Layer): """A Layer that calculates an expectation value. @@ -261,12 +263,13 @@ def __init__(self, backend='noiseless', differentiator=None, use_cuquantum=False sampled_op=used_op) self.noisy = True else: + mode = quantum_context.get_quantum_concurrent_op_mode() + quantum_concurrent = False if use_cuquantum else mode used_op = circuit_execution_ops.get_expectation_op( - backend=backend, use_cuquantum=use_cuquantum) + backend=backend, use_cuquantum=use_cuquantum, + quantum_concurrent=quantum_concurrent) self._expectation_op = differentiator.generate_differentiable_op( - analytic_op=used_op) - # self._expectation_op = differentiator.generate_differentiable_op( - # analytic_op=used_op, use_cuquantum=use_cuquantum) + analytic_op=used_op, use_cuquantum=use_cuquantum) self._w = None @@ -362,4 +365,4 @@ def call(self, else: return self._expectation_op(inputs, symbol_names, symbol_values, operators) - # pylint: enable=no-else-return \ No newline at end of file + # pylint: enable=no-else-return From 4efdb66e2acbde04db4ca3bac06bd62f8c0a4582 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 18:33:21 -0700 Subject: [PATCH 040/106] Remove *_cuda ops. support it later. --- release/BUILD | 1 - tensorflow_quantum/core/ops/BUILD | 105 ----------------- .../core/ops/tfq_simulate_ops_cuda.py | 44 -------- .../core/ops/tfq_simulate_ops_cuda_test.py | 106 ------------------ 4 files changed, 256 deletions(-) delete mode 100644 tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py delete mode 100644 tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py diff --git a/release/BUILD b/release/BUILD index 7eb2a6b40..ff3db2ba0 100644 --- a/release/BUILD +++ b/release/BUILD @@ -69,7 +69,6 @@ sh_binary( "//tensorflow_quantum/python/optimizers:rotosolve_minimizer", "//tensorflow_quantum/python/optimizers:spsa_minimizer", ] + if_cuda_is_configured([ - "//tensorflow_quantum/core/ops:tfq_simulate_ops_cuda_py", "//tensorflow_quantum/core/ops:tfq_simulate_ops_cuquantum_py", "//tensorflow_quantum/core/ops:tfq_adj_grad_op_cuquantum_py", ]), diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index 73e8dc597..361e31a48 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -48,7 +48,6 @@ py_library( "//tensorflow_quantum/core/ops/math_ops:fidelity_op_py", "//tensorflow_quantum/core/ops/noise:noisy_expectation_op_py", ] + if_cuda_is_configured([ - ":tfq_simulate_ops_cuda_py", ":tfq_simulate_ops_cuquantum_py", ":tfq_adj_grad_op_cuquantum_py", ]), @@ -642,19 +641,6 @@ py_test( ], ) -py_library( - name = "tfq_simulate_ops_cuda_py", - srcs = ["tfq_simulate_ops_cuda.py"], - data = [ - ":_tfq_simulate_ops_cuda.so", - ], - srcs_version = "PY3", - deps = [ - # tensorflow framework for wrappers - ":load_module", - ], -) - py_library( name = "tfq_simulate_ops_cuquantum_py", srcs = ["tfq_simulate_ops_cuquantum.py"], @@ -668,97 +654,6 @@ py_library( ], ) -py_test( - name = "tfq_simulate_ops_cuda_test", - srcs = ["tfq_simulate_ops_cuda_test.py"], - deps = [ - ":tfq_simulate_ops_cuda_py", - ":tfq_simulate_ops_py", - "//tensorflow_quantum/python:util", - ], - srcs_version = "PY3", - tags = ["cuda"], -) - -cc_binary( - name = "_tfq_simulate_ops_cuda.so", - srcs = [ - "tfq_simulate_expectation_op_cuda.cu.cc", - ], - linkshared = 1, - features = select({ - ":windows": ["windows_export_all_symbols"], - "//conditions:default": [], - }), - copts = select({ - ":windows": [ - "/D__CLANG_SUPPORT_DYN_ANNOTATION__", - "/D_USE_MATH_DEFINES", - "/DEIGEN_MPL2_ONLY", - "/DEIGEN_MAX_ALIGN_BYTES=64", - "/DEIGEN_HAS_TYPE_TRAITS=0", - "/DTF_USE_SNAPPY", - "/showIncludes", - "/MD", - "/O2", - "/DNDEBUG", - "/w", - "-DWIN32_LEAN_AND_MEAN", - "-DNOGDI", - "/d2ReducedOptimizeHugeFunctions", - "/arch:AVX", - "/std:c++17", - "-DTENSORFLOW_MONOLITHIC_BUILD", - "/DPLATFORM_WINDOWS", - "/DEIGEN_HAS_C99_MATH", - "/DTENSORFLOW_USE_EIGEN_THREADPOOL", - "/DEIGEN_AVOID_STL_ARRAY", - "/Iexternal/gemmlowp", - "/wd4018", - "/wd4577", - "/DNOGDI", - "/UTF_COMPILE_LIBRARY", - "/D__CUDA__", - ], - "//conditions:default": [ - "-Iexternal/local_cuda/cuda/include", - "-pthread", - "-std=c++17", - "-D_GLIBCXX_USE_CXX11_ABI=1", - "-O3", - "-Iexternal/cuda_headers", - "-DNV_CUDNN_DISABLE_EXCEPTION", - # "-fpermissive", - ], - }) + if_cuda_is_configured([ - "-DTENSORFLOW_USE_NVCC=1", - "-DGOOGLE_CUDA=1", - "-x cuda", - "-nvcc_options=relaxed-constexpr", - "-nvcc_options=ftz=true", - "-D__CUDA__", - ]), - deps = [ - # cirq cc proto - "//tensorflow_quantum/core/ops:parse_context", - "//tensorflow_quantum/core/ops:tfq_simulate_utils", - "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", - "//tensorflow_quantum/core/proto:program_cc_proto", - "//tensorflow_quantum/core/src:circuit_parser_qsim", - "//tensorflow_quantum/core/src:util_qsim", - "@eigen//:eigen3", - # "@local_cuda//:cuda_headers" - # tensorflow core framework - # tensorflow core lib - # tensorflow core protos - ] + if_cuda_is_configured([ - ":cuda", - "@local_config_cuda//cuda:cuda_headers", - "@qsim//lib:qsim_cuda_lib", - ]), - # alwayslink=1, -) - py_test( name = "tfq_simulate_ops_cuquantum_test", srcs = ["tfq_simulate_ops_cuquantum_test.py"], diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py deleted file mode 100644 index 3c5e9057b..000000000 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda.py +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -"""Module to register cuda simulation python op.""" -import tensorflow as tf -from tensorflow_quantum.core.ops.load_module import load_module - -SIM_OP_MODULE = load_module("_tfq_simulate_ops_cuda.so") - - -def tfq_simulate_expectation(programs, symbol_names, symbol_values, pauli_sums): - """Calculates the expectation value of circuits wrt some operator(s). - Args: - programs: `tf.Tensor` of strings with shape [batch_size] containing - the string representations of the circuits to be executed. - symbol_names: `tf.Tensor` of strings with shape [n_params], which - is used to specify the order in which the values in - `symbol_values` should be placed inside of the circuits in - `programs`. - symbol_values: `tf.Tensor` of real numbers with shape - [batch_size, n_params] specifying parameter values to resolve - into the circuits specificed by programs, following the ordering - dictated by `symbol_names`. - pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] - containing the string representation of the operators that will - be used on all of the circuits in the expectation calculations. - Returns: - `tf.Tensor` with shape [batch_size, n_ops] that holds the - expectation value for each circuit with each op applied to it - (after resolving the corresponding parameters in). - """ - return SIM_OP_MODULE.tfq_simulate_expectation_cuda( - programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums) \ No newline at end of file diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py deleted file mode 100644 index b21141a75..000000000 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuda_test.py +++ /dev/null @@ -1,106 +0,0 @@ -# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -"""Tests that specifically target tfq_simulate_ops_cu*.""" -import time -import numpy as np -import tensorflow as tf -import cirq - -from tensorflow_quantum.core.ops import tfq_simulate_ops -from tensorflow_quantum.core.ops import tfq_simulate_ops_cuda -from tensorflow_quantum.python import util - - -def measure_average_runtime( - fn, - tag, - num_samples=10, - result_avg=False, -): - """Measures average runtime for given function. - - Args: - fn: function. - tag: The message title. - num_samples: The number of measurements. - result_avg: True if the results are all averaged. - - Returns: - The average time and the (averaged) result. - """ - avg_time = [] - avg_res = [] - for _ in range(num_samples): - begin_time = time.time() - result = fn() - duration = time.time() - begin_time - avg_time.append(duration) - if result_avg: - avg_res.append(result) - avg_time = sum(avg_time) / float(num_samples) - print(f"\n\t{tag} time: {avg_time}\n") - if result_avg: - result = np.average(avg_res, axis=0) - return avg_time, result - - -class SimulateExpectationGpuTest(tf.test.TestCase): - """Tests tfq_simulate_expectation.""" - - def test_simulate_expectation_cpu_vs_cuda(self): - """Make sure that cpu & gpu(cuda) ops have the same results.""" - n_qubits = 20 - batch_size = 5 - symbol_names = ['alpha'] - qubits = cirq.GridQubit.rect(1, n_qubits) - circuit_batch, resolver_batch = \ - util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, batch_size) - - circuit_batch_tensor = util.convert_to_tensor(circuit_batch) - - symbol_values_array = np.array( - [[resolver[symbol] - for symbol in symbol_names] - for resolver in resolver_batch]) - - pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) - pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) - - cpu_avg_time, res_cpu = measure_average_runtime( - lambda: tfq_simulate_ops.tfq_simulate_expectation( - circuit_batch_tensor, symbol_names, - symbol_values_array.astype(np.float64), pauli_sums_tensor), - "CPU", - num_samples=100, - ) - - cuda_avg_time, res_cuda = measure_average_runtime( - lambda: tfq_simulate_ops_cuda.tfq_simulate_expectation( - circuit_batch_tensor, symbol_names, - symbol_values_array.astype(np.float64), pauli_sums_tensor), - "CUDA", - num_samples=100, - ) - - # The result should be the similar within a tolerance. - np.testing.assert_allclose(res_cpu, res_cuda, atol=1e-4) - - # CUDA op should be faster than CPU op. - self.assertGreater(cpu_avg_time, cuda_avg_time) - - -if __name__ == "__main__": - tf.test.main() From 3adb3ea218b67cd2d5af03f7d59cf851586fd7c5 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 19:08:02 -0700 Subject: [PATCH 041/106] Move cublas/custatevec init/destory handlers to cstr/dstr --- ...fq_simulate_expectation_op_cuquantum.cu.cc | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc index 86387be72..6f2a4d9c2 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc @@ -47,8 +47,18 @@ class TfqSimulateExpectationOpCuQuantum : public tensorflow::OpKernel { public: explicit TfqSimulateExpectationOpCuQuantum( tensorflow::OpKernelConstruction* context) - : OpKernel(context) {} + : OpKernel(context) { + // Allocates handlers for initializaiton. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } + ~TfqSimulateExpectationOpCuQuantum() { + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } + void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. const int num_inputs = context->num_inputs(); @@ -113,16 +123,8 @@ class TfqSimulateExpectationOpCuQuantum : public tensorflow::OpKernel { max_num_qubits = std::max(max_num_qubits, num); } - // create handles for simulator - cublasCreate(&cublas_handle_); - custatevecCreate(&custatevec_handle_); - ComputeLarge(num_qubits, fused_circuits, pauli_sums, context, &output_tensor); - - // destroy handles in sync with simulator lifetime - cublasDestroy(cublas_handle_); - custatevecDestroy(custatevec_handle_); } private: From 317cd46ffd606b4fc6a5b8c7d27f0bf7c96f1b30 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 19:46:46 -0700 Subject: [PATCH 042/106] Update 4 cuquantum ops --- .../tfq_simulate_expectation_op_cuquantum.cu.cc | 2 +- ...mulate_sampled_expectation_op_cuquantum.cu.cc | 11 ++++++++++- .../ops/tfq_simulate_samples_op_cuquantum.cu.cc | 16 ++++++++++------ .../ops/tfq_simulate_state_op_cuquantum.cu.cc | 12 +++++++++++- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc index 6f2a4d9c2..10603ae24 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc @@ -48,7 +48,7 @@ class TfqSimulateExpectationOpCuQuantum : public tensorflow::OpKernel { explicit TfqSimulateExpectationOpCuQuantum( tensorflow::OpKernelConstruction* context) : OpKernel(context) { - // Allocates handlers for initializaiton. + // Allocates handlers for initialization. cublasCreate(&cublas_handle_); custatevecCreate(&custatevec_handle_); } diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index 69c82d622..ba682585b 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -54,7 +54,16 @@ class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { tensorflow::OpKernelConstruction* context) : OpKernel(context) { OP_REQUIRES_OK(context, random_gen_.Init(context)); - } + // Allocates handlers for initialization. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } + + ~TfqSimulateExpectationOpCuQuantum() { + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc index 33059f116..0d7534725 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -53,7 +53,16 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { tensorflow::OpKernelConstruction* context) : OpKernel(context) { OP_REQUIRES_OK(context, random_gen_.Init(context)); - } + // Allocates handlers for initialization. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } + + ~TfqSimulateExpectationOpCuQuantum() { + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. @@ -119,13 +128,8 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { return; // bug in qsim dependency we can't control. } - // create handles for simulator - cublasCreate(&cublas_handle_); - custatevecCreate(&custatevec_handle_); ComputeLarge(num_qubits, max_num_qubits, num_samples, fused_circuits, context, &output_tensor); - cublasDestroy(cublas_handle_); - custatevecDestroy(custatevec_handle_); } private: diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc index f65ac36be..da2505d41 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc @@ -48,7 +48,17 @@ class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { public: explicit TfqSimulateStateOpCuQuantum( tensorflow::OpKernelConstruction* context) - : OpKernel(context) {} + : OpKernel(context) { + // Allocates handlers for initialization. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } + + ~TfqSimulateExpectationOpCuQuantum() { + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. From 790fc06ad4d4d699e167f98d0d2c8fab84fe8656 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 19:48:22 -0700 Subject: [PATCH 043/106] Fix typos --- .../ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc | 2 +- .../core/ops/tfq_simulate_samples_op_cuquantum.cu.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index ba682585b..0a35479ac 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -59,7 +59,7 @@ class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { custatevecCreate(&custatevec_handle_); } - ~TfqSimulateExpectationOpCuQuantum() { + ~TfqSimulateSampledExpectationOpCuQuantum() { // Destroys handlers in sync with simulator lifetime. cublasDestroy(cublas_handle_); custatevecDestroy(custatevec_handle_); diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc index 0d7534725..2f4fbc9b8 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -58,7 +58,7 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { custatevecCreate(&custatevec_handle_); } - ~TfqSimulateExpectationOpCuQuantum() { + ~TfqSimulateSamplesOpCuQuantum() { // Destroys handlers in sync with simulator lifetime. cublasDestroy(cublas_handle_); custatevecDestroy(custatevec_handle_); From e135088a9803146d63bd4e955c61372bc14f4886 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 19:51:42 -0700 Subject: [PATCH 044/106] Fix typo --- .../core/ops/tfq_simulate_state_op_cuquantum.cu.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc index da2505d41..bd31086b3 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc @@ -54,7 +54,7 @@ class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { custatevecCreate(&custatevec_handle_); } - ~TfqSimulateExpectationOpCuQuantum() { + ~TfqSimulateStateOpCuQuantum() { // Destroys handlers in sync with simulator lifetime. cublasDestroy(cublas_handle_); custatevecDestroy(custatevec_handle_); From c2220b1d7dcf098cf745749c13a283476ceb5ebc Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 20:13:25 -0700 Subject: [PATCH 045/106] Remove wrongly alive codes --- ...mulate_sampled_expectation_op_cuquantum.cu.cc | 5 +---- .../ops/tfq_simulate_samples_op_cuquantum.cu.cc | 16 ++++++---------- .../ops/tfq_simulate_state_op_cuquantum.cu.cc | 9 --------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index 0a35479ac..e2b7e8a70 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -140,12 +140,8 @@ class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { max_num_qubits = std::max(max_num_qubits, num); } - cublasCreate(&cublas_handle_); - custatevecCreate(&custatevec_handle_); ComputeLarge(num_qubits, fused_circuits, pauli_sums, num_samples, context, &output_tensor); - cublasDestroy(cublas_handle_); - custatevecDestroy(custatevec_handle_); } private: @@ -226,6 +222,7 @@ REGISTER_OP("TfqSimulateSampledExpectationCuquantum") .Input("symbol_values: float") .Input("pauli_sums: string") .Input("num_samples: int32") + .Attr("seed: numbertype") .Output("expectations: float") .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { tensorflow::shape_inference::ShapeHandle programs_shape; diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc index 2f4fbc9b8..33059f116 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -53,16 +53,7 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { tensorflow::OpKernelConstruction* context) : OpKernel(context) { OP_REQUIRES_OK(context, random_gen_.Init(context)); - // Allocates handlers for initialization. - cublasCreate(&cublas_handle_); - custatevecCreate(&custatevec_handle_); - } - - ~TfqSimulateSamplesOpCuQuantum() { - // Destroys handlers in sync with simulator lifetime. - cublasDestroy(cublas_handle_); - custatevecDestroy(custatevec_handle_); - } + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. @@ -128,8 +119,13 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { return; // bug in qsim dependency we can't control. } + // create handles for simulator + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); ComputeLarge(num_qubits, max_num_qubits, num_samples, fused_circuits, context, &output_tensor); + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); } private: diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc index bd31086b3..3742580a2 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc @@ -117,17 +117,8 @@ class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { tensorflow::TTypes, 1>::Matrix output_tensor = output->matrix>(); - // Cross reference with standard google cloud compute instances - // Memory ~= 2 * num_threads * (2 * 64 * 2 ** num_qubits in circuits) - // e2s2 = 2 CPU, 8GB -> Can safely do 25 since Memory = 4GB - // e2s4 = 4 CPU, 16GB -> Can safely do 25 since Memory = 8GB - // ... - cublasCreate(&cublas_handle_); - custatevecCreate(&custatevec_handle_); ComputeLarge(num_qubits, max_num_qubits, fused_circuits, context, &output_tensor); - cublasDestroy(cublas_handle_); - custatevecDestroy(custatevec_handle_); } private: From 32e10f60832ae82d55971097bfb7f859e92ac107 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 20:17:01 -0700 Subject: [PATCH 046/106] Change seed type from numbertype to int --- .../ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index e2b7e8a70..a6a9085d3 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -222,7 +222,7 @@ REGISTER_OP("TfqSimulateSampledExpectationCuquantum") .Input("symbol_values: float") .Input("pauli_sums: string") .Input("num_samples: int32") - .Attr("seed: numbertype") + .Attr("seed: int") .Output("expectations: float") .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { tensorflow::shape_inference::ShapeHandle programs_shape; From 4e7c36f69d3d8a5251314930f9d1a7bbe6d6613a Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 20:28:54 -0700 Subject: [PATCH 047/106] Apply unsaved changes --- ...late_sampled_expectation_op_cuquantum.cu.cc | 3 ++- .../tfq_simulate_samples_op_cuquantum.cu.cc | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index a6a9085d3..0e35ce6a7 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -222,8 +222,9 @@ REGISTER_OP("TfqSimulateSampledExpectationCuquantum") .Input("symbol_values: float") .Input("pauli_sums: string") .Input("num_samples: int32") - .Attr("seed: int") + .SetIsStateful() .Output("expectations: float") + .Attr("seed: int = 0") .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { tensorflow::shape_inference::ShapeHandle programs_shape; TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc index 33059f116..4c0ff4078 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -53,7 +53,16 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { tensorflow::OpKernelConstruction* context) : OpKernel(context) { OP_REQUIRES_OK(context, random_gen_.Init(context)); - } + // Allocates handlers for initialization. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } + + ~TfqSimulateSamplesOpCuQuantum() { + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. @@ -119,13 +128,8 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { return; // bug in qsim dependency we can't control. } - // create handles for simulator - cublasCreate(&cublas_handle_); - custatevecCreate(&custatevec_handle_); ComputeLarge(num_qubits, max_num_qubits, num_samples, fused_circuits, context, &output_tensor); - cublasDestroy(cublas_handle_); - custatevecDestroy(custatevec_handle_); } private: @@ -199,7 +203,9 @@ REGISTER_OP("TfqSimulateSamplesCuquantum") .Input("symbol_names: string") .Input("symbol_values: float") .Input("num_samples: int32") + .SetIsStateful() .Output("samples: int8") + .Attr("seed: int = 0") .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { tensorflow::shape_inference::ShapeHandle programs_shape; TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); From 636d2fe3c2b9dc77444da5feecf2cfd71a2188a8 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 20:32:25 -0700 Subject: [PATCH 048/106] Add seed2 --- .../core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc | 1 + .../core/ops/tfq_simulate_samples_op_cuquantum.cu.cc | 1 + 2 files changed, 2 insertions(+) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index 0e35ce6a7..c02f218a2 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -225,6 +225,7 @@ REGISTER_OP("TfqSimulateSampledExpectationCuquantum") .SetIsStateful() .Output("expectations: float") .Attr("seed: int = 0") + .Attr("seed2: int = 0") .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { tensorflow::shape_inference::ShapeHandle programs_shape; TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc index 4c0ff4078..4317f07ee 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -206,6 +206,7 @@ REGISTER_OP("TfqSimulateSamplesCuquantum") .SetIsStateful() .Output("samples: int8") .Attr("seed: int = 0") + .Attr("seed2: int = 0") .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { tensorflow::shape_inference::ShapeHandle programs_shape; TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); From 3783a650b8fa6b8f2aec01a538077ef73b6ff164 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 20:51:15 -0700 Subject: [PATCH 049/106] Fix sampled_expectation and samples ops of CPU version. --- .../core/ops/tfq_simulate_ops_cuquantum_test.py | 15 +++++++++------ .../ops/tfq_simulate_sampled_expectation_op.cc | 11 +++++++++-- .../core/ops/tfq_simulate_samples_op.cc | 9 ++++++++- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 47f6004b9..7bd09abc2 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -287,7 +287,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): n_qubits = 20 batch_size = 5 symbol_names = ['alpha'] - n_samples = [[100]] * batch_size + n_samples = [[1000]] * batch_size qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( @@ -310,7 +310,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): n_samples), "CPU", num_samples=100, - result_avg=True, + result_avg=False, ) cuquantum_avg_time, res_cuquantum = measure_average_runtime( @@ -320,7 +320,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): n_samples), "cuQuantum", num_samples=100, - result_avg=True, + result_avg=False, ) # cuQuantum op should be faster than CPU op. @@ -329,7 +329,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, res_cuquantum, - atol=1e-4, + atol=3e-2, err_msg=""" # If failed, the GPU architecture in this system may be unsupported. # Please refer to the supported architectures here. @@ -558,7 +558,7 @@ def test_simulate_samples_cpu_vs_cuquantum(self): symbol_values_array.astype(np.float64), n_samples), "CPU", num_samples=10, - result_avg=True, + result_avg=False, ) cuquantum_avg_time, res_cuquantum = measure_average_runtime( @@ -567,12 +567,15 @@ def test_simulate_samples_cpu_vs_cuquantum(self): symbol_values_array.astype(np.float64), n_samples), "cuQuantum", num_samples=10, - result_avg=True, + result_avg=False, ) # cuQuantum op should be faster than CPU op. self.assertGreater(cpu_avg_time, cuquantum_avg_time) + res_cpu = np.average(res_cpu, axis=1) + res_cuquantum = np.average(res_cuquantum, axis=1) + # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, res_cuquantum, diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc index e0ed05a49..b7c9e1003 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc @@ -49,7 +49,9 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { public: explicit TfqSimulateSampledExpectationOp( tensorflow::OpKernelConstruction* context) - : OpKernel(context) {} + : OpKernel(context) { + OP_REQUIRES_OK(context, random_gen_.Init(context)); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. @@ -141,6 +143,8 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { } private: + tensorflow::GuardedPhiloxRandom random_gen_; + void ComputeLarge( const std::vector& num_qubits, const std::vector>>& fused_circuits, @@ -168,7 +172,7 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { largest_sum = std::max(largest_sum, sum.terms().size()); } } - auto local_gen = random_gen.ReserveSamples32( + auto local_gen = random_gen_.ReserveSamples32( largest_sum * pauli_sums[0].size() * fused_circuits.size() + 1); tensorflow::random::SimplePhilox rand_source(&local_gen); @@ -310,7 +314,10 @@ REGISTER_OP("TfqSimulateSampledExpectation") .Input("symbol_values: float") .Input("pauli_sums: string") .Input("num_samples: int32") + .SetIsStateful() .Output("expectations: float") + .Attr("seed: int = 0") + .Attr("seed2: int = 0") .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { tensorflow::shape_inference::ShapeHandle programs_shape; TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc index 0e68020e9..cc0f7b3d5 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc @@ -48,7 +48,9 @@ typedef qsim::Circuit QsimCircuit; class TfqSimulateSamplesOp : public tensorflow::OpKernel { public: explicit TfqSimulateSamplesOp(tensorflow::OpKernelConstruction* context) - : OpKernel(context) {} + : OpKernel(context) { + OP_REQUIRES_OK(context, random_gen_.Init(context)); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. @@ -129,6 +131,8 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { } private: + tensorflow::GuardedPhiloxRandom random_gen_; + void ComputeLarge( const std::vector& num_qubits, const int max_num_qubits, const int num_samples, @@ -260,7 +264,10 @@ REGISTER_OP("TfqSimulateSamples") .Input("symbol_names: string") .Input("symbol_values: float") .Input("num_samples: int32") + .SetIsStateful() .Output("samples: int8") + .Attr("seed: int = 0") + .Attr("seed2: int = 0") .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { tensorflow::shape_inference::ShapeHandle programs_shape; TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); From 3a3d30e37b14b88428630c010c2287b13e2f4e16 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 21:00:04 -0700 Subject: [PATCH 050/106] Remove legacy random code --- .../core/ops/tfq_simulate_ops_cuquantum_test.py | 2 +- .../core/ops/tfq_simulate_sampled_expectation_op.cc | 7 ++----- tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc | 10 +++------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 7bd09abc2..401260d85 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -579,7 +579,7 @@ def test_simulate_samples_cpu_vs_cuquantum(self): # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, res_cuquantum, - atol=1e-4, + atol=0.2, err_msg=""" # If failed, the GPU architecture in this system may be unsupported. # Please refer to the supported architectures here. diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc index b7c9e1003..808637805 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc @@ -164,8 +164,6 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { auto sv = ss.Create(largest_nq); auto scratch = ss.Create(largest_nq); - tensorflow::GuardedPhiloxRandom random_gen; - random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); int largest_sum = -1; for (const auto& sums : pauli_sums) { for (const auto& sum : sums) { @@ -223,8 +221,6 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { const int output_dim_op_size = output_tensor->dimension(1); - tensorflow::GuardedPhiloxRandom random_gen; - random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); int largest_sum = -1; for (const auto& sums : pauli_sums) { for (const auto& sum : sums) { @@ -251,7 +247,8 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { int n_random = largest_sum * output_dim_op_size * fused_circuits.size(); n_random /= num_threads; n_random += 1; - auto local_gen = random_gen.ReserveSamples32(n_random); + auto local_gen = random_gen_.ReserveSamples32( + largest_sum * pauli_sums[0].size() * fused_circuits.size() + 1); tensorflow::random::SimplePhilox rand_source(&local_gen); for (int i = start; i < end; i++) { diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc index cc0f7b3d5..940835a83 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc @@ -150,9 +150,8 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { StateSpace ss = StateSpace(tfq_for); auto sv = ss.Create(largest_nq); - tensorflow::GuardedPhiloxRandom random_gen; - random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); - auto local_gen = random_gen.ReserveSamples32(fused_circuits.size() + 1); + + auto local_gen = random_gen_.ReserveSamples32(fused_circuits.size() + 1); tensorflow::random::SimplePhilox rand_source(&local_gen); // Simulate programs one by one. Parallelizing over state vectors @@ -202,16 +201,13 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { using Simulator = qsim::Simulator; using StateSpace = Simulator::StateSpace; - tensorflow::GuardedPhiloxRandom random_gen; - random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); - auto DoWork = [&](int start, int end) { int largest_nq = 1; Simulator sim = Simulator(tfq_for); StateSpace ss = StateSpace(tfq_for); auto sv = ss.Create(largest_nq); - auto local_gen = random_gen.ReserveSamples32(fused_circuits.size() + 1); + auto local_gen = random_gen_.ReserveSamples32(fused_circuits.size() + 1); tensorflow::random::SimplePhilox rand_source(&local_gen); for (int i = start; i < end; i++) { From 66fb6f06119d614b1c038ef4325a413ca76c92a5 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 21:03:14 -0700 Subject: [PATCH 051/106] Tune the test parameters --- .../core/ops/tfq_simulate_ops_cuquantum_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 401260d85..8ef71180d 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -287,7 +287,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): n_qubits = 20 batch_size = 5 symbol_names = ['alpha'] - n_samples = [[1000]] * batch_size + n_samples = [[10000]] * batch_size qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( @@ -309,7 +309,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): symbol_values_array.astype(np.float64), pauli_sums_tensor, n_samples), "CPU", - num_samples=100, + num_samples=10, result_avg=False, ) @@ -319,7 +319,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): symbol_values_array.astype(np.float64), pauli_sums_tensor, n_samples), "cuQuantum", - num_samples=100, + num_samples=10, result_avg=False, ) @@ -579,7 +579,7 @@ def test_simulate_samples_cpu_vs_cuquantum(self): # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, res_cuquantum, - atol=0.2, + atol=0.3, err_msg=""" # If failed, the GPU architecture in this system may be unsupported. # Please refer to the supported architectures here. From 0036ad85c7250150393218db3219c80e7c56174c Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 21:05:09 -0700 Subject: [PATCH 052/106] Add more tolerance because it's large number of qubits... --- tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 8ef71180d..d2f07f1f1 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -329,7 +329,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, res_cuquantum, - atol=3e-2, + atol=5e-2, err_msg=""" # If failed, the GPU architecture in this system may be unsupported. # Please refer to the supported architectures here. From 6e0aeaf8d5f4477ef367411a65d42e7457355d86 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 21:08:42 -0700 Subject: [PATCH 053/106] Tune tolerance one more.. --- tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index d2f07f1f1..22d84e979 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -329,7 +329,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, res_cuquantum, - atol=5e-2, + atol=0.07, err_msg=""" # If failed, the GPU architecture in this system may be unsupported. # Please refer to the supported architectures here. From 685498077f671ee2c7fc47ce1a561b0004731b04 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 21:15:18 -0700 Subject: [PATCH 054/106] Fix format --- .../core/ops/circuit_execution_ops_test.py | 32 ++++---- .../core/ops/tfq_adj_grad_op_cuquantum.cu.cc | 9 +- .../ops/tfq_adj_grad_op_cuquantum_test.py | 2 + ...fq_simulate_expectation_op_cuquantum.cu.cc | 18 ++-- .../core/ops/tfq_simulate_ops_cuquantum.py | 1 + .../ops/tfq_simulate_ops_cuquantum_test.py | 14 ++-- .../tfq_simulate_sampled_expectation_op.cc | 4 +- ...ate_sampled_expectation_op_cuquantum.cu.cc | 18 ++-- .../core/ops/tfq_simulate_samples_op.cc | 5 +- .../tfq_simulate_samples_op_cuquantum.cu.cc | 18 ++-- .../ops/tfq_simulate_state_op_cuquantum.cu.cc | 16 ++-- .../python/differentiators/adjoint.py | 82 +++++++++---------- .../python/differentiators/differentiator.py | 16 ++-- .../layers/circuit_executors/expectation.py | 9 +- .../circuit_executors/expectation_test.py | 2 + .../circuit_executors/sampled_expectation.py | 7 +- .../python/layers/high_level/pqc.py | 10 ++- 17 files changed, 135 insertions(+), 128 deletions(-) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops_test.py b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py index 76c307598..2a9356bb8 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops_test.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py @@ -72,14 +72,13 @@ STATE_OPS = [ circuit_execution_ops.get_state_op(backend=None, quantum_concurrent=True), - circuit_execution_ops.get_state_op(backend=WF_SIM, - quantum_concurrent=True), - circuit_execution_ops.get_state_op(backend=DM_SIM, - quantum_concurrent=True), + circuit_execution_ops.get_state_op(backend=WF_SIM, quantum_concurrent=True), + circuit_execution_ops.get_state_op(backend=DM_SIM, quantum_concurrent=True), # For timing interests C++ backend is tested in quantum_concurrent mode. circuit_execution_ops.get_state_op(backend=None, quantum_concurrent=False), # For cuQuantum op. quantum_concurrent=True is not allowed. - circuit_execution_ops.get_state_op(backend=None, quantum_concurrent=False, + circuit_execution_ops.get_state_op(backend=None, + quantum_concurrent=False, use_cuquantum=True) ] NO_DM_STATE_OPS = STATE_OPS[:2] + STATE_OPS[2:] @@ -135,9 +134,9 @@ def test_get_expectation_inputs(self): circuit_execution_ops.get_expectation_op(use_cuquantum='junk') with self.assertRaisesRegex( - ValueError, expected_regex="not be True at the same time"): - circuit_execution_ops.get_expectation_op( - quantum_concurrent=True, use_cuquantum=True) + ValueError, expected_regex="not be True at the same time"): + circuit_execution_ops.get_expectation_op(quantum_concurrent=True, + use_cuquantum=True) def test_get_sampled_expectation_inputs(self): """Test that get expectation only accepts inputs it should.""" @@ -165,7 +164,7 @@ def test_get_sampled_expectation_inputs(self): use_cuquantum='junk') with self.assertRaisesRegex( - ValueError, expected_regex="not be True at the same time"): + ValueError, expected_regex="not be True at the same time"): circuit_execution_ops.get_sampled_expectation_op( quantum_concurrent=True, use_cuquantum=True) @@ -193,9 +192,9 @@ def test_get_samples_inputs(self): circuit_execution_ops.get_sampling_op(use_cuquantum='junk') with self.assertRaisesRegex( - ValueError, expected_regex="not be True at the same time"): - circuit_execution_ops.get_sampling_op( - quantum_concurrent=True, use_cuquantum=True) + ValueError, expected_regex="not be True at the same time"): + circuit_execution_ops.get_sampling_op(quantum_concurrent=True, + use_cuquantum=True) def test_get_state_inputs(self): """Test that get_states only accepts inputs it should.""" @@ -224,9 +223,9 @@ def test_get_state_inputs(self): circuit_execution_ops.get_state_op(use_cuquantum='junk') with self.assertRaisesRegex( - ValueError, expected_regex="not be True at the same time"): - circuit_execution_ops.get_state_op( - quantum_concurrent=True, use_cuquantum=True) + ValueError, expected_regex="not be True at the same time"): + circuit_execution_ops.get_state_op(quantum_concurrent=True, + use_cuquantum=True) class ExecutionOpsConsistentyTest(tf.test.TestCase, parameterized.TestCase): @@ -332,8 +331,7 @@ def test_simulate_state_with_symbols(self, op_and_sim, n_qubits, util.kwargs_cartesian_product( **{ 'op_and_sim': [(op, sim) for ( - op, - sim) in zip(NO_DM_STATE_OPS, NO_DM_SIMS)], + op, sim) in zip(NO_DM_STATE_OPS, NO_DM_SIMS)], }))) def test_simulate_state_large(self, op_and_sim): """Test a reasonably large and complex circuit.""" diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc index 6347d6f5c..ada6d67b0 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc @@ -47,7 +47,8 @@ typedef qsim::Circuit QsimCircuit; class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { public: - explicit TfqAdjointGradientCuquantumOp(tensorflow::OpKernelConstruction* context) + explicit TfqAdjointGradientCuquantumOp( + tensorflow::OpKernelConstruction* context) : OpKernel(context) {} void Compute(tensorflow::OpKernelContext* context) override { @@ -153,10 +154,10 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { // ... // This method creates 3 big state vectors per thread so reducing size // here slightly. - + ComputeLarge(num_qubits, qsim_circuits, maps, full_fuse, - partial_fused_circuits, pauli_sums, gradient_gates, - downstream_grads, context, &output_tensor); + partial_fused_circuits, pauli_sums, gradient_gates, + downstream_grads, context, &output_tensor); // destroy handles in sync with simulator lifetime cublasDestroy(cublas_handle_); diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py index 10ace5bf3..747480c58 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py @@ -31,6 +31,7 @@ from tensorflow_quantum.core.ops import tfq_adj_grad_op from tensorflow_quantum.core.ops import tfq_adj_grad_op_cuquantum + def measure_average_runtime( fn, tag, @@ -63,6 +64,7 @@ def measure_average_runtime( result = np.average(avg_res, axis=0) return avg_time, result + class ADJGradTest(tf.test.TestCase, parameterized.TestCase): """Tests tfq_calculate_unitary.""" diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc index 10603ae24..070667ccf 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc @@ -48,17 +48,17 @@ class TfqSimulateExpectationOpCuQuantum : public tensorflow::OpKernel { explicit TfqSimulateExpectationOpCuQuantum( tensorflow::OpKernelConstruction* context) : OpKernel(context) { - // Allocates handlers for initialization. - cublasCreate(&cublas_handle_); - custatevecCreate(&custatevec_handle_); - } + // Allocates handlers for initialization. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } ~TfqSimulateExpectationOpCuQuantum() { - // Destroys handlers in sync with simulator lifetime. - cublasDestroy(cublas_handle_); - custatevecDestroy(custatevec_handle_); - } - + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } + void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. const int num_inputs = context->num_inputs(); diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py index 7de3856b5..ba448d27e 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py @@ -43,6 +43,7 @@ def tfq_simulate_expectation(programs, symbol_names, symbol_values, pauli_sums): return SIM_OP_MODULE.tfq_simulate_expectation_cuquantum( programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums) + def tfq_simulate_state(programs, symbol_names, symbol_values): """Returns the state of the programs using the C++ state vector simulator. diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 22d84e979..1c11fb3b2 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -336,7 +336,6 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec """) - def test_simulate_sampled_expectation_inputs(self): """Make sure sampled expectation op fails gracefully on bad inputs.""" n_qubits = 5 @@ -531,6 +530,7 @@ def test_simulate_sampled_expectation_inputs(self): symbol_names, symbol_values_array, util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + class SimulateSamplesCuquantumTest(tf.test.TestCase, parameterized.TestCase): """Tests tfq_simulate_samples.""" @@ -586,7 +586,6 @@ def test_simulate_samples_cpu_vs_cuquantum(self): # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec """) - def test_simulate_samples_inputs(self): """Make sure the sample op fails gracefully on bad inputs.""" n_qubits = 5 @@ -657,9 +656,9 @@ def test_simulate_samples_inputs(self): with self.assertRaisesRegex(TypeError, 'Cannot convert'): # programs tensor has the wrong type. tfq_simulate_ops_cuquantum.tfq_simulate_samples([1] * batch_size, - symbol_names, - symbol_values_array, - [num_samples]) + symbol_names, + symbol_values_array, + [num_samples]) with self.assertRaisesRegex(TypeError, 'Cannot convert'): # programs tensor has the wrong type. @@ -780,7 +779,6 @@ def test_simulate_state_cpu_vs_cuquantum(self): # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec """) - def test_simulate_state_inputs(self): """Make sure the state op fails gracefully on bad inputs.""" n_qubits = 5 @@ -828,8 +826,8 @@ def test_simulate_state_inputs(self): 'Unparseable proto'): # programs tensor has the right type, but invalid value. tfq_simulate_ops_cuquantum.tfq_simulate_state(['junk'] * batch_size, - symbol_names, - symbol_values_array) + symbol_names, + symbol_values_array) with self.assertRaisesRegex(tf.errors.InvalidArgumentError, 'Could not find symbol in parameter map'): diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc index 808637805..d15fa0914 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc @@ -50,8 +50,8 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { explicit TfqSimulateSampledExpectationOp( tensorflow::OpKernelConstruction* context) : OpKernel(context) { - OP_REQUIRES_OK(context, random_gen_.Init(context)); - } + OP_REQUIRES_OK(context, random_gen_.Init(context)); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index c02f218a2..5295b0c55 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -53,17 +53,17 @@ class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { explicit TfqSimulateSampledExpectationOpCuQuantum( tensorflow::OpKernelConstruction* context) : OpKernel(context) { - OP_REQUIRES_OK(context, random_gen_.Init(context)); - // Allocates handlers for initialization. - cublasCreate(&cublas_handle_); - custatevecCreate(&custatevec_handle_); - } + OP_REQUIRES_OK(context, random_gen_.Init(context)); + // Allocates handlers for initialization. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } ~TfqSimulateSampledExpectationOpCuQuantum() { - // Destroys handlers in sync with simulator lifetime. - cublasDestroy(cublas_handle_); - custatevecDestroy(custatevec_handle_); - } + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc index 940835a83..0ff8e62b1 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc @@ -49,8 +49,8 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { public: explicit TfqSimulateSamplesOp(tensorflow::OpKernelConstruction* context) : OpKernel(context) { - OP_REQUIRES_OK(context, random_gen_.Init(context)); - } + OP_REQUIRES_OK(context, random_gen_.Init(context)); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. @@ -150,7 +150,6 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { StateSpace ss = StateSpace(tfq_for); auto sv = ss.Create(largest_nq); - auto local_gen = random_gen_.ReserveSamples32(fused_circuits.size() + 1); tensorflow::random::SimplePhilox rand_source(&local_gen); diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc index 4317f07ee..2e01e30c2 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -52,17 +52,17 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { explicit TfqSimulateSamplesOpCuQuantum( tensorflow::OpKernelConstruction* context) : OpKernel(context) { - OP_REQUIRES_OK(context, random_gen_.Init(context)); - // Allocates handlers for initialization. - cublasCreate(&cublas_handle_); - custatevecCreate(&custatevec_handle_); - } + OP_REQUIRES_OK(context, random_gen_.Init(context)); + // Allocates handlers for initialization. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } ~TfqSimulateSamplesOpCuQuantum() { - // Destroys handlers in sync with simulator lifetime. - cublasDestroy(cublas_handle_); - custatevecDestroy(custatevec_handle_); - } + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc index 3742580a2..e12052589 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc @@ -49,16 +49,16 @@ class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { explicit TfqSimulateStateOpCuQuantum( tensorflow::OpKernelConstruction* context) : OpKernel(context) { - // Allocates handlers for initialization. - cublasCreate(&cublas_handle_); - custatevecCreate(&custatevec_handle_); - } + // Allocates handlers for initialization. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } ~TfqSimulateStateOpCuQuantum() { - // Destroys handlers in sync with simulator lifetime. - cublasDestroy(cublas_handle_); - custatevecDestroy(custatevec_handle_); - } + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index a2c11c8b2..ba19efcfe 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -63,9 +63,11 @@ class Adjoint(differentiator.Differentiator): """ - def generate_differentiable_op( - self, *, sampled_op=None, analytic_op=None, use_cuquantum=False - ): + def generate_differentiable_op(self, + *, + sampled_op=None, + analytic_op=None, + use_cuquantum=False): """Generate a differentiable op by attaching self to an op. See `tfq.differentiators.Differentiator`. This has been partially @@ -87,66 +89,60 @@ def generate_differentiable_op( """ if sampled_op is not None: - raise ValueError( - "sample base backends are not supported by the " - "Adjoint method, please use analytic expectation" - " or choose another differentiator." - ) + raise ValueError("sample base backends are not supported by the " + "Adjoint method, please use analytic expectation" + " or choose another differentiator.") - return super().generate_differentiable_op( - analytic_op=analytic_op, use_cuquantum=use_cuquantum - ) + return super().generate_differentiable_op(analytic_op=analytic_op, + use_cuquantum=use_cuquantum) @tf.function def get_gradient_circuits(self, programs, symbol_names, symbol_values): """See base class description.""" raise NotImplementedError( "Adjoint differentiator cannot run on a real QPU, " - "therefore it has no accessible gradient circuits." - ) + "therefore it has no accessible gradient circuits.") @differentiator.catch_empty_inputs @tf.function def differentiate_analytic_cuquantum( - self, - programs, - symbol_names, - symbol_values, - pauli_sums, - forward_pass_vals, - grad, + self, + programs, + symbol_names, + symbol_values, + pauli_sums, + forward_pass_vals, + grad, ): - return tfq_adj_grad_op_cuquantum.tfq_adj_grad( - programs, symbol_names, symbol_values, pauli_sums, grad - ) + return tfq_adj_grad_op_cuquantum.tfq_adj_grad(programs, symbol_names, + symbol_values, pauli_sums, + grad) @differentiator.catch_empty_inputs @tf.function def differentiate_analytic( - self, - programs, - symbol_names, - symbol_values, - pauli_sums, - forward_pass_vals, - grad, + self, + programs, + symbol_names, + symbol_values, + pauli_sums, + forward_pass_vals, + grad, ): - return tfq_adj_grad_op.tfq_adj_grad( - programs, symbol_names, symbol_values, pauli_sums, grad - ) + return tfq_adj_grad_op.tfq_adj_grad(programs, symbol_names, + symbol_values, pauli_sums, grad) def differentiate_sampled( - self, - programs, - symbol_names, - symbol_values, - pauli_sums, - num_samples, - forward_pass_vals, - grad, + self, + programs, + symbol_names, + symbol_values, + pauli_sums, + num_samples, + forward_pass_vals, + grad, ): raise NotImplementedError( "Adjoint state methods are not supported in sample based settings." " Please use analytic expectation calculation or a different " - "tfq.differentiator." - ) + "tfq.differentiator.") diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index 91656d4d1..851454e48 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -55,7 +55,10 @@ class Differentiator(metaclass=abc.ABCMeta): to backpropagate through a quantum circuit. """ - def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, + def generate_differentiable_op(self, + *, + sampled_op=None, + analytic_op=None, use_cuquantum=False): """Generate a differentiable op by attaching self to an op. @@ -152,10 +155,8 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None, 'Given arg: {}.'.format(str(key)) + '' 'The signature should contain: {}.'.format( list(expected_signature))) - _differentiate_ana = ( - self._differentiate_ana_cq if use_cuquantum else - self._differentiate_ana - ) + _differentiate_ana = (self._differentiate_ana_cq + if use_cuquantum else self._differentiate_ana) @tf.custom_gradient def op_wrapper_analytic(programs, symbol_names, symbol_values, @@ -164,9 +165,8 @@ def op_wrapper_analytic(programs, symbol_names, symbol_values, symbol_values, pauli_sums) def gradient(grad): - return _differentiate_ana(programs, symbol_names, - symbol_values, pauli_sums, - forward_pass_vals, grad) + return _differentiate_ana(programs, symbol_names, symbol_values, + pauli_sums, forward_pass_vals, grad) return forward_pass_vals, gradient diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation.py b/tensorflow_quantum/python/layers/circuit_executors/expectation.py index bb6c3e544..bc5c846a0 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation.py @@ -28,7 +28,6 @@ from tensorflow_quantum.python.layers.circuit_executors import input_checks - class Expectation(tf.keras.layers.Layer): """A Layer that calculates an expectation value. @@ -207,7 +206,10 @@ class Expectation(tf.keras.layers.Layer): """ - def __init__(self, backend='noiseless', differentiator=None, use_cuquantum=False, + def __init__(self, + backend='noiseless', + differentiator=None, + use_cuquantum=False, **kwargs): """Instantiate this Layer. @@ -266,7 +268,8 @@ def __init__(self, backend='noiseless', differentiator=None, use_cuquantum=False mode = quantum_context.get_quantum_concurrent_op_mode() quantum_concurrent = False if use_cuquantum else mode used_op = circuit_execution_ops.get_expectation_op( - backend=backend, use_cuquantum=use_cuquantum, + backend=backend, + use_cuquantum=use_cuquantum, quantum_concurrent=quantum_concurrent) self._expectation_op = differentiator.generate_differentiable_op( analytic_op=used_op, use_cuquantum=use_cuquantum) diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py index c7723b70d..b6aed3081 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py @@ -296,6 +296,8 @@ def _gen_single_bit_rotation_problem(bit, symbols, noisy): # self.assertAllClose(mse.numpy(), 0, atol=1e-3) from tensorflow_quantum.python import quantum_context + + class ExpectationFunctionalTests(parameterized.TestCase, tf.test.TestCase): """Test hybrid/integrated models that include an expectation layer.""" diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py index 4ad664ae9..02abfd1b7 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py @@ -213,7 +213,10 @@ class SampledExpectation(tf.keras.layers.Layer): """ - def __init__(self, backend='noiseless', differentiator=None, use_cuquantum=False, + def __init__(self, + backend='noiseless', + differentiator=None, + use_cuquantum=False, **kwargs): """Instantiate this Layer. @@ -343,4 +346,4 @@ def call(self, num_samples = repetitions return self._expectation_op(inputs, symbol_names, symbol_values, - operators, num_samples) \ No newline at end of file + operators, num_samples) diff --git a/tensorflow_quantum/python/layers/high_level/pqc.py b/tensorflow_quantum/python/layers/high_level/pqc.py index c11f99004..a2d9a4138 100644 --- a/tensorflow_quantum/python/layers/high_level/pqc.py +++ b/tensorflow_quantum/python/layers/high_level/pqc.py @@ -250,10 +250,14 @@ def __init__( "cirq.sim.simulator.SimulatesExpectationValues.") if self._analytic: self._executor = expectation.Expectation( - backend=backend, differentiator=differentiator, use_cuquantum=use_cuquantum) + backend=backend, + differentiator=differentiator, + use_cuquantum=use_cuquantum) else: self._executor = sampled_expectation.SampledExpectation( - backend=backend, differentiator=differentiator, use_cuquantum=use_cuquantum) + backend=backend, + differentiator=differentiator, + use_cuquantum=use_cuquantum) self._append_layer = elementary.AddCircuit() @@ -317,4 +321,4 @@ def call(self, inputs): symbol_values=tiled_up_parameters, operators=tiled_up_operators, repetitions=tiled_up_repetitions) - # pylint: enable=no-else-return \ No newline at end of file + # pylint: enable=no-else-return From a7c905f5e5ef6daf0eea8b041a8098db2dd2986d Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 28 Apr 2023 21:19:29 -0700 Subject: [PATCH 055/106] Fix --- .../python/layers/circuit_executors/expectation_test.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py index b6aed3081..808e82101 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py @@ -295,8 +295,6 @@ def _gen_single_bit_rotation_problem(bit, symbols, noisy): # optimizer.apply_gradients(zip(grads, layer.trainable_weights)) # self.assertAllClose(mse.numpy(), 0, atol=1e-3) -from tensorflow_quantum.python import quantum_context - class ExpectationFunctionalTests(parameterized.TestCase, tf.test.TestCase): """Test hybrid/integrated models that include an expectation layer.""" @@ -326,7 +324,6 @@ def test_simple_param_value_input(self, backend): l1 = tf.keras.layers.Dense(10)(inputs) l2 = tf.keras.layers.Dense(3)(l1) reps = 1000 if noisy else None - # quantum_context.set_quantum_concurrent_op_mode(False) outputs = expectation.Expectation(backend=backend, use_cuquantum=True)( datum, symbol_names=symbols, From feddbfad357cad85c361cfb6c899d511a13aa937 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sun, 30 Apr 2023 07:40:41 +0000 Subject: [PATCH 056/106] Upgrade qsim from jaeyoo's to official 0.16.0 --- WORKSPACE | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index ba3bfb7c4..44bce67ce 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -24,19 +24,11 @@ cc_library( ], ) -#http_archive( -# name = "qsim", -# sha256 = "", -# strip_prefix = "qsim-0.16.0", -# urls = ["https://github.com/quantumlib/qsim/archive/refs/tags/v0.16.0.zip"], -#) - -# TODO: After merging this patch later into qsim mainstream, remove this and uncomment the above. http_archive( name = "qsim", - sha256 = "75d62843020f8a70cf2aac85aca5e25fa6c1cea0945323afd06c3b7fcf3ee2b7", - strip_prefix = "qsim-0.15.0-dev-20230330_v2", - urls = ["https://github.com/jaeyoo/qsim/archive/refs/tags/v0.15.0-dev+20230330_v2.tar.gz"], + sha256 = "e4d716b945d44c6901ccc4ee4c2344e2af127b28713a0faebf0687745e0bf5e7", + strip_prefix = "qsim-0.16.0", + urls = ["https://github.com/quantumlib/qsim/archive/refs/tags/v0.16.0.zip"], ) http_archive( From 3fb6fe9b4d8959de826896c693b5b2208e033169 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sun, 30 Apr 2023 07:41:21 +0000 Subject: [PATCH 057/106] Add automatic linkopt for cuquantum without LD_LIBRARY_PATH --- third_party/cuquantum/BUILD.tpl | 3 + third_party/cuquantum/cuquantum_configure.bzl | 64 ++++++++++++++++--- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/third_party/cuquantum/BUILD.tpl b/third_party/cuquantum/BUILD.tpl index 1081bba8f..0ec87701f 100644 --- a/third_party/cuquantum/BUILD.tpl +++ b/third_party/cuquantum/BUILD.tpl @@ -13,6 +13,9 @@ cc_library( srcs = [ ":libcustatevec.so", ], + linkopts = [ + "-Wl,-rpath,%{CUQUANTUM_LIBRARY_PATH}", + ], visibility = ["//visibility:public"], ) diff --git a/third_party/cuquantum/cuquantum_configure.bzl b/third_party/cuquantum/cuquantum_configure.bzl index b8ff2f9b9..b79a7496e 100644 --- a/third_party/cuquantum/cuquantum_configure.bzl +++ b/third_party/cuquantum/cuquantum_configure.bzl @@ -1,4 +1,4 @@ -"""Setup cuQuantum as external dependency""" +"""Setup cuQuantum as external dependency.""" _CUQUANTUM_ROOT = "CUQUANTUM_ROOT" @@ -26,6 +26,7 @@ def _execute( error_details = None, empty_stdout_fine = False): """Executes an arbitrary shell command. + Args: repository_ctx: the repository_ctx object cmdline: list of strings, the command to execute @@ -33,6 +34,7 @@ def _execute( error_details: string, details about the error or steps to fix it empty_stdout_fine: bool, if True, an empty stdout result is fine, otherwise it's an error + Return: the result of repository_ctx.execute(cmdline) """ @@ -48,6 +50,7 @@ def _execute( def _read_dir(repository_ctx, src_dir): """Returns a string with all files in a directory. + Finds all files inside a directory, traversing subfolders and following symlinks. The returned string contains the full path of all files separated by line breaks. @@ -60,6 +63,18 @@ def _read_dir(repository_ctx, src_dir): result = find_result.stdout return result + +def _find_file(repository_ctx, filename): + """Returns a string with a directory path including the filename. + + The returned string contains the parent path of the filename. + """ + result = repository_ctx.execute( + ["timeout", "5", "find", "/", "-name", filename, "-print", "-quit", "-not", "-path", "'*/.*'", "-quit"]).stdout + result = result[:result.find(filename)+len(filename)] + return result + + def _genrule(genrule_name, command, outs): """Returns a string with a genrule. @@ -105,7 +120,27 @@ def _symlink_genrule_for_dir( """Returns a genrule to symlink(or copy if on Windows) a set of files. If src_dir is passed, files will be read from the given directory; otherwise - we assume files are in src_files and dest_files. + we assume files are in src_files and dest_files. Here are the examples: + + ``` + genrule( + name = "cuquantum_header_include", + outs = [ + "include/custatevec.h", + "include/cutensornet.h", + "include/cutensornet/types.h", + "include/cutensornet/typesDistributed.h", + ], + cmd = [some copy command lines based on users' local environment], + ) + genrule( + name = "libcustatevec.so", + outs = [ + "libcustatevec.so", + ], + cmd = [some copy command lines based on users' local environment], + ) + ``` Args: repository_ctx: the repository_ctx object. @@ -160,12 +195,21 @@ def _symlink_genrule_for_dir( return genrule -def _cuquantum_pip_imple(repository_ctx): - cuquantum_root = repository_ctx.os.environ[_CUQUANTUM_ROOT] +def _cuquantum_pip_impl(repository_ctx): + if _CUQUANTUM_ROOT in repository_ctx.os.environ: + cuquantum_root = repository_ctx.os.environ[_CUQUANTUM_ROOT] + else: + repository_ctx.os.environ[_CUQUANTUM_ROOT] = "" + cuquantum_root = "" + if cuquantum_root == "": + cuquantum_header_path = _find_file(repository_ctx, "custatevec.h") + cuquantum_header_path = cuquantum_header_path[:cuquantum_header_path.find("/custatevec.h")] + custatevec_shared_library_path = _find_file(repository_ctx, "libcustatevec.so") + else: + cuquantum_header_path = "%s/include" % cuquantum_root + custatevec_shared_library_path = "%s/lib/libcustatevec.so" % (cuquantum_root) - is_empty_genrule = cuquantum_root == "" - - cuquantum_header_path = "%s/include" % cuquantum_root + is_empty_genrule = cuquantum_header_path == "" or custatevec_shared_library_path == "" cuquantum_header_rule = _symlink_genrule_for_dir( repository_ctx, @@ -174,7 +218,6 @@ def _cuquantum_pip_imple(repository_ctx): "cuquantum_header_include", is_empty_genrule=is_empty_genrule, ) - custatevec_shared_library_path = "%s/lib/libcustatevec.so" % (cuquantum_root) custatevec_shared_library_rule = _symlink_genrule_for_dir( repository_ctx, @@ -185,15 +228,16 @@ def _cuquantum_pip_imple(repository_ctx): ["libcustatevec.so"], is_empty_genrule=is_empty_genrule, ) - + _tpl(repository_ctx, "BUILD", { + "%{CUQUANTUM_LIBRARY_PATH}": "%s/lib" % (cuquantum_root), "%{CUQUANTUM_HEADER_GENRULE}": cuquantum_header_rule, "%{CUSTATEVEC_SHARED_LIBRARY_GENRULE}": custatevec_shared_library_rule, }) cuquantum_configure = repository_rule( - implementation = _cuquantum_pip_imple, + implementation = _cuquantum_pip_impl, environ = [ _CUQUANTUM_ROOT, ], From 3e5b565e89d859b586da6f7336f03938b7f38b0f Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sun, 30 Apr 2023 07:43:01 +0000 Subject: [PATCH 058/106] Fix tensorflow/absl status & error --- tensorflow_quantum/core/ops/parse_context.cc | 31 ++++++++++--------- .../core/src/circuit_parser_qsim.cc | 13 ++++---- .../core/src/circuit_parser_qsim_test.cc | 1 + .../core/src/program_resolution.cc | 21 +++++++------ .../core/src/program_resolution_test.cc | 27 ++++++++-------- 5 files changed, 49 insertions(+), 44 deletions(-) diff --git a/tensorflow_quantum/core/ops/parse_context.cc b/tensorflow_quantum/core/ops/parse_context.cc index f926d15bb..be6e98b98 100644 --- a/tensorflow_quantum/core/ops/parse_context.cc +++ b/tensorflow_quantum/core/ops/parse_context.cc @@ -20,6 +20,7 @@ limitations under the License. #include #include +#include "absl/status/status.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/lib/core/error_codes.pb.h" #include "tensorflow/core/lib/core/status.h" @@ -51,7 +52,7 @@ Status ParseProto(const std::string& text, T* proto) { } return Status( - static_cast(absl::StatusCode::kInvalidArgument), + static_cast(absl::StatusCode::kInvalidArgument), "Unparseable proto: " + text); } @@ -68,7 +69,7 @@ Status ParsePrograms(OpKernelContext* context, const std::string& input_name, if (input->dims() != 1) { // Never parse anything other than a 1d list of circuits. return Status( - static_cast( + static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("programs must be rank 1. Got rank ", input->dims(), ".")); } @@ -101,7 +102,7 @@ Status ParsePrograms2D(OpKernelContext* context, const std::string& input_name, if (input->dims() != 2) { // Never parse anything other than a 1d list of circuits. - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("other_programs must be rank 2. Got rank ", input->dims(), ".")); @@ -143,7 +144,7 @@ Status GetProgramsAndProgramsToAppend( } if (programs->size() != programs_to_append->size()) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), "programs and programs_to_append must have matching sizes."); } @@ -171,7 +172,7 @@ Status GetProgramsAndNumQubits( } if (programs->size() != p_sums->size()) { return Status( - static_cast( + static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("Number of circuits and PauliSums do not match. Got ", programs->size(), " circuits and ", p_sums->size(), @@ -223,7 +224,7 @@ tensorflow::Status GetProgramsAndNumQubits( } if (programs->size() != other_programs->size()) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("programs and other_programs batch dimension", " do not match. Foud: ", programs->size(), @@ -260,7 +261,7 @@ Status GetPauliSums(OpKernelContext* context, } if (input->dims() != 2) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("pauli_sums must be rank 2. Got rank ", input->dims(), ".")); @@ -297,7 +298,7 @@ Status GetSymbolMaps(OpKernelContext* context, std::vector* maps) { } if (input_names->dims() != 1) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("symbol_names must be rank 1. Got rank ", input_names->dims(), ".")); @@ -310,7 +311,7 @@ Status GetSymbolMaps(OpKernelContext* context, std::vector* maps) { } if (input_values->dims() != 2) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("symbol_values must be rank 2. Got rank ", input_values->dims(), ".")); @@ -320,7 +321,7 @@ Status GetSymbolMaps(OpKernelContext* context, std::vector* maps) { const auto symbol_values = input_values->matrix(); if (symbol_names.dimension(0) != symbol_values.dimension(1)) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), "Input symbol names and value sizes do not match."); } @@ -356,7 +357,7 @@ tensorflow::Status GetNumSamples( } if (input_num_samples->dims() != 2) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("num_samples must be rank 2. Got rank ", input_num_samples->dims(), ".")); @@ -370,7 +371,7 @@ tensorflow::Status GetNumSamples( for (unsigned int j = 0; j < matrix_num_samples.dimension(1); j++) { const int num_samples = matrix_num_samples(i, j); if (num_samples < 1) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), "Each element of num_samples must be greater than 0."); } @@ -392,7 +393,7 @@ Status GetIndividualSample(tensorflow::OpKernelContext* context, } if (input_num_samples->dims() != 1) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("num_samples must be rank 1. Got rank ", input_num_samples->dims(), ".")); @@ -401,7 +402,7 @@ Status GetIndividualSample(tensorflow::OpKernelContext* context, const auto vector_num_samples = input_num_samples->vec(); if (vector_num_samples.dimension(0) != 1) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("num_samples must contain 1 element. Got ", vector_num_samples.dimension(0), ".")); @@ -422,7 +423,7 @@ tensorflow::Status GetPrevGrads( } if (input_grads->dims() != 2) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("downstream_grads must be rank 2. Got rank ", input_grads->dims(), ".")); diff --git a/tensorflow_quantum/core/src/circuit_parser_qsim.cc b/tensorflow_quantum/core/src/circuit_parser_qsim.cc index 1024d28c7..80f98a40f 100644 --- a/tensorflow_quantum/core/src/circuit_parser_qsim.cc +++ b/tensorflow_quantum/core/src/circuit_parser_qsim.cc @@ -27,6 +27,7 @@ limitations under the License. #include "../qsim/lib/gates_cirq.h" #include "../qsim/lib/io.h" #include "absl/container/flat_hash_map.h" +#include "absl/status/status.h" #include "absl/strings/numbers.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" @@ -58,7 +59,7 @@ inline Status ParseProtoArg( // iterator> const auto arg_v = op.args().find(arg_name); if (arg_v == op.args().end()) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), "Could not find arg: " + arg_name + " in op."); } @@ -71,7 +72,7 @@ inline Status ParseProtoArg( const auto iter = param_map.find(proto_arg.symbol()); if (iter == param_map.end()) { return Status( - static_cast( + static_cast( absl::StatusCode::kInvalidArgument), "Could not find symbol in parameter map: " + proto_arg.symbol()); } @@ -103,7 +104,7 @@ inline Status ParseProtoControls(const Operation& op, absl::StrSplit(control_v_str, ','); if (control_toks.size() != control_v_toks.size()) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), "Mistmatched number of control qubits and control values."); } @@ -123,7 +124,7 @@ inline Status ParseProtoControls(const Operation& op, for (auto tok : control_v_toks) { valid = absl::SimpleAtoi(tok, &tmp); if (!valid) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), "Unparseable control value: " + std::string(tok)); } @@ -595,7 +596,7 @@ tensorflow::Status ParseAppendGate(const Operation& op, auto build_f = func_map.find(op.gate().id()); if (build_f == func_map.end()) { *lookup_succeeded = false; - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("Could not parse gate id: ", op.gate().id(), ". This is likely because a cirq.Channel was " @@ -780,7 +781,7 @@ tensorflow::Status ParseAppendChannel(const Operation& op, auto build_f = chan_func_map.find(op.gate().id()); if (build_f == chan_func_map.end()) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("Could not parse channel id: ", op.gate().id())); } diff --git a/tensorflow_quantum/core/src/circuit_parser_qsim_test.cc b/tensorflow_quantum/core/src/circuit_parser_qsim_test.cc index e6ea68e80..0ce30e5da 100644 --- a/tensorflow_quantum/core/src/circuit_parser_qsim_test.cc +++ b/tensorflow_quantum/core/src/circuit_parser_qsim_test.cc @@ -23,6 +23,7 @@ limitations under the License. #include "../qsim/lib/circuit_noisy.h" #include "../qsim/lib/gates_cirq.h" #include "absl/container/flat_hash_map.h" +#include "absl/status/status.h" #include "absl/strings/numbers.h" #include "gtest/gtest.h" #include "tensorflow/core/lib/core/status.h" diff --git a/tensorflow_quantum/core/src/program_resolution.cc b/tensorflow_quantum/core/src/program_resolution.cc index 0fbda9368..8a543b3f2 100644 --- a/tensorflow_quantum/core/src/program_resolution.cc +++ b/tensorflow_quantum/core/src/program_resolution.cc @@ -20,6 +20,7 @@ limitations under the License. #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" +#include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/str_join.h" #include "absl/strings/str_split.h" @@ -66,17 +67,17 @@ Status RegisterQubits( } if (splits.size() != 2) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("Unable to parse qubit: ", qb)); } if (!absl::SimpleAtoi(splits[0], &r)) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("Unable to parse qubit: ", qb)); } if (!absl::SimpleAtoi(splits[1], &c)) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("Unable to parse qubit: ", qb)); } @@ -172,7 +173,7 @@ Status ResolveQubitIds(Program* program, unsigned int* num_qubits, const auto result = id_to_index.find(pair.qubit_id()); if (result == id_to_index.end()) { return Status( - static_cast( + static_cast( absl::StatusCode::kInvalidArgument), "Found a Pauli sum operating on qubits not found in circuit."); } @@ -264,7 +265,7 @@ Status ResolveQubitIds(Program* program, unsigned int* num_qubits, visited_qubits.erase(qubit.id()); const auto result = id_to_index.find(qubit.id()); if (result == id_to_index.end()) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), "A paired circuit contains qubits not found in " "reference circuit."); @@ -287,7 +288,7 @@ Status ResolveQubitIds(Program* program, unsigned int* num_qubits, visited_qubits.erase(id); const auto result = id_to_index.find(id); if (result == id_to_index.end()) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), "A paired circuit contains qubits not found in " "reference circuit."); @@ -302,7 +303,7 @@ Status ResolveQubitIds(Program* program, unsigned int* num_qubits, } if (!visited_qubits.empty()) { return Status( - static_cast( + static_cast( absl::StatusCode::kInvalidArgument), "A reference circuit contains qubits not found in paired circuit."); } @@ -323,7 +324,7 @@ Status ResolveSymbols( if (iter == param_map.end()) { if (resolve_all) { return Status( - static_cast( + static_cast( absl::StatusCode::kInvalidArgument), "Could not find symbol in parameter map: " + arg.symbol()); } @@ -364,7 +365,7 @@ Status CheckMPSSupported(const Program& program) { const int total_num_qubits = qubits.size() + control_ids.size(); if (total_num_qubits > 2) { return Status( - static_cast( + static_cast( absl::StatusCode::kInvalidArgument), absl::StrCat("1D operations only support 1 and 2 qubit gates. " "Found: ", @@ -383,7 +384,7 @@ Status CheckMPSSupported(const Program& program) { // Are the two qubits not neighbors? if (std::abs((int)qids[0] - (int)qids[1]) > 1) { - return Status(static_cast( + return Status(static_cast( absl::StatusCode::kInvalidArgument), "A program is not in 1D topology. It contains an" " operation with qubits not neighbors each other."); diff --git a/tensorflow_quantum/core/src/program_resolution_test.cc b/tensorflow_quantum/core/src/program_resolution_test.cc index 2a4e61151..450d5d1cf 100644 --- a/tensorflow_quantum/core/src/program_resolution_test.cc +++ b/tensorflow_quantum/core/src/program_resolution_test.cc @@ -20,6 +20,7 @@ limitations under the License. #include #include "absl/container/flat_hash_map.h" +#include "absl/status/status.h" #include "gtest/gtest.h" #include "tensorflow/core/lib/core/status.h" #include "tensorflow_quantum/core/proto/program.pb.h" @@ -235,7 +236,7 @@ TEST(ProgramResolutionTest, ResolveQubitIdsInvalidControlQubit) { .mutable_arg_value() ->set_string_value("junk"); EXPECT_EQ(ResolveQubitIds(&program, &qubit_count), - tensorflow::Status(static_cast( + tensorflow::Status(static_cast( absl::StatusCode::kInvalidArgument), "Unable to parse qubit: junk")); } @@ -252,7 +253,7 @@ TEST(ProgramResolutionTest, ResolveQubitIdsInvalidQubit) { ->mutable_qubits(0) ->set_id("junk"); EXPECT_EQ(ResolveQubitIds(&program, &qubit_count), - tensorflow::Status(static_cast( + tensorflow::Status(static_cast( absl::StatusCode::kInvalidArgument), "Unable to parse qubit: junk")); } @@ -302,7 +303,7 @@ TEST(ProgramResolutionTest, ResolveQubitIdsWithInvalidPauliSum) { EXPECT_EQ(ResolveQubitIds(&program, &qubit_count, &p_sums), tensorflow::Status( - static_cast( + static_cast( absl::StatusCode::kInvalidArgument), "Found a Pauli sum operating on qubits not found in circuit.")); } @@ -376,7 +377,7 @@ TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgramInvalid) { ->set_id("junk"); std::vector others = {other, other}; EXPECT_EQ(ResolveQubitIds(&program, &qubit_count, &others), - tensorflow::Status(static_cast( + tensorflow::Status(static_cast( absl::StatusCode::kInvalidArgument), "Unable to parse qubit: junk")); } @@ -397,7 +398,7 @@ TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgramInvalidControl) { ->set_string_value("junk"); std::vector others = {other, other}; EXPECT_EQ(ResolveQubitIds(&program, &qubit_count, &others), - tensorflow::Status(static_cast( + tensorflow::Status(static_cast( absl::StatusCode::kInvalidArgument), "Unable to parse qubit: junk")); } @@ -418,7 +419,7 @@ TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgramMismatch) { EXPECT_EQ( ResolveQubitIds(&program, &qubit_count, &others), tensorflow::Status( - static_cast( + static_cast( absl::StatusCode::kInvalidArgument), "A paired circuit contains qubits not found in reference circuit.")); } @@ -441,7 +442,7 @@ TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgramMismatchControl) { EXPECT_EQ( ResolveQubitIds(&program, &qubit_count, &others), tensorflow::Status( - static_cast( + static_cast( absl::StatusCode::kInvalidArgument), "A paired circuit contains qubits not found in reference circuit.")); } @@ -462,7 +463,7 @@ TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgramSmaller) { EXPECT_EQ( ResolveQubitIds(&program, &qubit_count, &others), tensorflow::Status( - static_cast( + static_cast( absl::StatusCode::kInvalidArgument), "A reference circuit contains qubits not found in paired circuit.")); } @@ -485,7 +486,7 @@ TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgramSmallerControl) { EXPECT_EQ( ResolveQubitIds(&program, &qubit_count, &others), tensorflow::Status( - static_cast( + static_cast( absl::StatusCode::kInvalidArgument), "A reference circuit contains qubits not found in paired circuit.")); } @@ -546,7 +547,7 @@ TEST(ProgramResolutionTest, ResolveSymbolsStrictPartial) { const absl::flat_hash_map> param_map = { {"v1", {0, 1.0}}}; EXPECT_EQ(ResolveSymbols(param_map, &symbol_program, true), - Status(static_cast( + Status(static_cast( absl::StatusCode::kInvalidArgument), "Could not find symbol in parameter map: v2")); } @@ -586,7 +587,7 @@ TEST(ProgramResolutionTest, CheckQubitsIn1DFailedByOpWithMoreThan2Qubits) { ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( three_qubit_op_program, &program_with_3qubit_op)); EXPECT_EQ(CheckMPSSupported(program_with_3qubit_op), - Status(static_cast( + Status(static_cast( absl::StatusCode::kInvalidArgument), "1D operations only support 1 and 2 qubit gates. " "Found: 3 qubit gate.")); @@ -598,7 +599,7 @@ TEST(ProgramResolutionTest, ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( valid_program, &program_with_3qubit_op)); EXPECT_EQ(CheckMPSSupported(program_with_3qubit_op), - Status(static_cast( + Status(static_cast( absl::StatusCode::kInvalidArgument), "1D operations only support 1 and 2 qubit gates. " "Found: 3 qubit gate.")); @@ -609,7 +610,7 @@ TEST(ProgramResolutionTest, CheckQubitsIn1DFailedByNot1DTopology) { ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( resolved_qubit_program_not_1d, &program_not_1d)); EXPECT_EQ(CheckMPSSupported(program_not_1d), - Status(static_cast( + Status(static_cast( absl::StatusCode::kInvalidArgument), "A program is not in 1D topology. It contains an" " operation with qubits not neighbors each other.")); From ea3ff944884d62ba2069a8d71a09c4132cfa85ac Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sun, 30 Apr 2023 07:43:29 +0000 Subject: [PATCH 059/106] Fix configure.sh for users not to type bazel options manually --- configure.sh | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/configure.sh b/configure.sh index 481bb7d6d..decaaa2c6 100755 --- a/configure.sh +++ b/configure.sh @@ -20,11 +20,11 @@ function write_to_bazelrc() { } function write_action_env_to_bazelrc() { - write_to_bazelrc "build --action_env $1=\"$2\"" + write_to_bazelrc "$1 --action_env $2=\"$3\"" } function write_linkopt_dir_to_bazelrc() { - write_to_bazelrc "build --linkopt -Wl,-rpath,$1" >> .bazelrc + write_to_bazelrc "$1 --linkopt -Wl,-rpath,$2" >> .bazelrc } @@ -77,9 +77,10 @@ if [[ "$TF_NEED_CUDA" == "1" ]]; then echo "Searching cuQuantum library from environment variable CUQUANTUM_ROOT..." if [[ "$CUQUANTUM_ROOT" != "" ]]; then echo " [*] cuQuantum library is detected here: CUQUANTUM_ROOT=$CUQUANTUM_ROOT." - write_action_env_to_bazelrc "CUQUANTUM_ROOT" ${CUQUANTUM_ROOT} + write_action_env_to_bazelrc "build:cuda" "CUQUANTUM_ROOT" ${CUQUANTUM_ROOT} + write_linkopt_dir_to_bazelrc "build:cuda" "${CUQUANTUM_ROOT}/lib" else - echo " [*] cuQuantum library is NOT detected. Using general CUDA ops..." + echo " [*] cuQuantum library is NOT detected. Lazily detect it later, OR please set CUQUANTUM_ROOT environment variable." fi fi @@ -138,29 +139,34 @@ if is_windows; then SHARED_LIBRARY_NAME=${SHARED_LIBRARY_NAME//\\//} HEADER_DIR=${HEADER_DIR//\\//} fi -write_action_env_to_bazelrc "TF_HEADER_DIR" ${HEADER_DIR} -write_action_env_to_bazelrc "TF_SHARED_LIBRARY_DIR" ${SHARED_LIBRARY_DIR} -write_action_env_to_bazelrc "TF_SHARED_LIBRARY_NAME" ${SHARED_LIBRARY_NAME} -write_action_env_to_bazelrc "TF_NEED_CUDA" ${TF_NEED_CUDA} +write_action_env_to_bazelrc "build" "TF_HEADER_DIR" ${HEADER_DIR} "" +write_action_env_to_bazelrc "build" "TF_SHARED_LIBRARY_DIR" ${SHARED_LIBRARY_DIR} "" +write_action_env_to_bazelrc "build" "TF_SHARED_LIBRARY_NAME" ${SHARED_LIBRARY_NAME} "" +write_action_env_to_bazelrc "build" "TF_NEED_CUDA" ${TF_NEED_CUDA} "" if ! is_windows; then - write_linkopt_dir_to_bazelrc ${SHARED_LIBRARY_DIR} + write_linkopt_dir_to_bazelrc "build" ${SHARED_LIBRARY_DIR} "" fi # TODO(yifeif): do not hardcode path if [[ "$TF_NEED_CUDA" == "1" ]]; then - write_to_bazelrc "build:cuda --define=using_cuda=true --define=using_cuda_nvcc=true" + write_to_bazelrc "build:cuda --experimental_repo_remote_exec" + write_to_bazelrc "build:cuda --spawn_strategy=standalone" + write_to_bazelrc "build:cuda --strategy=Genrule=standalone" + write_to_bazelrc "build:cuda -c opt" + write_to_bazelrc "build:cuda --cxxopt=\"-D_GLIBCXX_USE_CXX11_ABI=1\"" + write_to_bazelrc "build:cuda --cxxopt=\"-std=c++17\"" write_to_bazelrc "build:cuda --@local_config_cuda//:enable_cuda" write_to_bazelrc "build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain" - write_action_env_to_bazelrc "TF_CUDA_VERSION" ${TF_CUDA_VERSION} - write_action_env_to_bazelrc "TF_CUDNN_VERSION" "8" + write_action_env_to_bazelrc "build:cuda" "TF_CUDA_VERSION" ${TF_CUDA_VERSION} + write_action_env_to_bazelrc "build:cuda" "TF_CUDNN_VERSION" "8" if is_windows; then - write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${TF_CUDA_VERSION}" - write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${TF_CUDA_VERSION}" + write_action_env_to_bazelrc "build:cuda" "CUDNN_INSTALL_PATH" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${TF_CUDA_VERSION}" + write_action_env_to_bazelrc "build:cuda" "CUDA_TOOLKIT_PATH" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${TF_CUDA_VERSION}" else - write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "/usr/lib/x86_64-linux-gnu" - write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "/usr/local/cuda" + write_action_env_to_bazelrc "build:cuda" "CUDNN_INSTALL_PATH" "/usr/lib/x86_64-linux-gnu" + write_action_env_to_bazelrc "build:cuda" "CUDA_TOOLKIT_PATH" "/usr/local/cuda" fi write_to_bazelrc "build --config=cuda" write_to_bazelrc "test --config=cuda" From 9f03bb1a4a940ecb9cad3016eee64258be8acd16 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sun, 30 Apr 2023 07:47:22 +0000 Subject: [PATCH 060/106] Fix typo nescessary to necessary --- tensorflow_quantum/core/ops/tfq_simulate_state_op.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc index e659800ce..8ff2126be 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc @@ -135,7 +135,7 @@ class TfqSimulateStateOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a - // a larger circuit we will grow the Statevector as nescessary. + // a larger circuit we will grow the Statevector as necessary. for (int i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; From 0d17c1feb3be451876d1194b402838f066556a0c Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sun, 30 Apr 2023 07:47:56 +0000 Subject: [PATCH 061/106] Fix the copy&paste error. --- .../core/ops/tfq_simulate_sampled_expectation_op.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc index d15fa0914..6cfd459dd 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc @@ -247,8 +247,7 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { int n_random = largest_sum * output_dim_op_size * fused_circuits.size(); n_random /= num_threads; n_random += 1; - auto local_gen = random_gen_.ReserveSamples32( - largest_sum * pauli_sums[0].size() * fused_circuits.size() + 1); + auto local_gen = random_gen_.ReserveSamples32(n_random); tensorflow::random::SimplePhilox rand_source(&local_gen); for (int i = start; i < end; i++) { From 7323c7311b608637921feaae9d7abbc9eeaa5796 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sun, 30 Apr 2023 07:48:35 +0000 Subject: [PATCH 062/106] Increase the test time for 4 cuquantum ops --- tensorflow_quantum/core/ops/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index 361e31a48..65f3d1bf2 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -656,6 +656,7 @@ py_library( py_test( name = "tfq_simulate_ops_cuquantum_test", + timeout = "long", srcs = ["tfq_simulate_ops_cuquantum_test.py"], deps = [ ":tfq_simulate_ops_cuquantum_py", From d9243e5d709587caf3911efc9b1df69de195801f Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sun, 30 Apr 2023 07:49:10 +0000 Subject: [PATCH 063/106] Increase state cpu vs gpu test qubit size to 20 & add logs --- .../ops/tfq_simulate_ops_cuquantum_test.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 1c11fb3b2..7922504b3 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -84,7 +84,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): lambda: tfq_simulate_ops.tfq_simulate_expectation( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor), - "CPU", + "Expectation CPU", num_samples=100, ) @@ -92,7 +92,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor), - "cuQuantum", + "Expectation cuQuantum", num_samples=100, ) @@ -308,7 +308,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor, n_samples), - "CPU", + "SampledExpectation CPU", num_samples=10, result_avg=False, ) @@ -318,7 +318,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor, n_samples), - "cuQuantum", + "SampledExpectation cuQuantum", num_samples=10, result_avg=False, ) @@ -556,7 +556,7 @@ def test_simulate_samples_cpu_vs_cuquantum(self): lambda: tfq_simulate_ops.tfq_simulate_samples( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), n_samples), - "CPU", + "Samples CPU", num_samples=10, result_avg=False, ) @@ -565,7 +565,7 @@ def test_simulate_samples_cpu_vs_cuquantum(self): lambda: tfq_simulate_ops_cuquantum.tfq_simulate_samples( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), n_samples), - "cuQuantum", + "Samples cuQuantum", num_samples=10, result_avg=False, ) @@ -735,7 +735,7 @@ class SimulateStateCuquantumTest(tf.test.TestCase, parameterized.TestCase): def test_simulate_state_cpu_vs_cuquantum(self): """Make sure that cpu & gpu(cuquantum) ops have the same results.""" - n_qubits = 10 + n_qubits = 20 batch_size = 5 symbol_names = ['alpha'] qubits = cirq.GridQubit.rect(1, n_qubits) @@ -754,7 +754,7 @@ def test_simulate_state_cpu_vs_cuquantum(self): lambda: tfq_simulate_ops.tfq_simulate_state( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64)), - "CPU", + "State CPU", num_samples=10, ) @@ -762,7 +762,7 @@ def test_simulate_state_cpu_vs_cuquantum(self): lambda: tfq_simulate_ops_cuquantum.tfq_simulate_state( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64)), - "cuQuantum", + "State cuQuantum", num_samples=10, ) From 7ce9608fad0c44c55991331857f636a7e6ca8dad Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sun, 30 Apr 2023 07:50:40 +0000 Subject: [PATCH 064/106] Change simmux.h to simmux_gpu.h for qsim 0.16.0 --- .../core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc | 3 +-- .../ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc | 3 +-- .../core/ops/tfq_simulate_samples_op_cuquantum.cu.cc | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc index 070667ccf..8b92e513b 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc @@ -20,8 +20,7 @@ limitations under the License. #include "../qsim/lib/gate_appl.h" #include "../qsim/lib/gates_cirq.h" #include "../qsim/lib/gates_qsim.h" -#include "../qsim/lib/seqfor.h" -#include "../qsim/lib/simmux.h" +#include "../qsim/lib/simmux_gpu.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/shape_inference.h" #include "tensorflow/core/framework/tensor_shape.h" diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index 5295b0c55..151eb2c30 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -22,8 +22,7 @@ limitations under the License. #include "../qsim/lib/circuit.h" #include "../qsim/lib/gate_appl.h" #include "../qsim/lib/gates_cirq.h" -#include "../qsim/lib/seqfor.h" -#include "../qsim/lib/simmux.h" +#include "../qsim/lib/simmux_gpu.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/shape_inference.h" #include "tensorflow/core/framework/tensor_shape.h" diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc index 2e01e30c2..a48c80e3d 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -22,8 +22,7 @@ limitations under the License. #include "../qsim/lib/circuit.h" #include "../qsim/lib/gate_appl.h" #include "../qsim/lib/gates_cirq.h" -#include "../qsim/lib/seqfor.h" -#include "../qsim/lib/simmux.h" +#include "../qsim/lib/simmux_gpu.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/shape_inference.h" #include "tensorflow/core/framework/tensor_shape.h" From 912737980fdc5174003a0cd5de90aae8e6ee9bae Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Sun, 30 Apr 2023 07:51:02 +0000 Subject: [PATCH 065/106] Use cudaMemcpy for fast copy in state op. --- .../ops/tfq_simulate_state_op_cuquantum.cu.cc | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc index e12052589..9a9325e29 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc @@ -22,8 +22,7 @@ limitations under the License. #include "../qsim/lib/circuit.h" #include "../qsim/lib/gate_appl.h" #include "../qsim/lib/gates_cirq.h" -#include "../qsim/lib/seqfor.h" -#include "../qsim/lib/simmux.h" +#include "../qsim/lib/simmux_gpu.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/shape_inference.h" #include "tensorflow/core/framework/tensor_shape.h" @@ -124,6 +123,7 @@ class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { private: cublasHandle_t cublas_handle_; custatevecHandle_t custatevec_handle_; + void ComputeLarge( const std::vector& num_qubits, const int max_num_qubits, const std::vector>>& fused_circuits, @@ -134,14 +134,17 @@ class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { using StateSpace = Simulator::StateSpace; // Begin simulation. - int largest_nq = 1; Simulator sim = Simulator(cublas_handle_, custatevec_handle_); StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + // Begin simulation. + int largest_nq = 1; auto sv = ss.Create(largest_nq); + std::vector sv_host; + sv_host.resize(2 * (uint64_t(1) << largest_nq)); // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a - // a larger circuit we will grow the Statevector as nescessary. + // a larger circuit we will grow the Statevector as necessary. for (int i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; @@ -149,22 +152,28 @@ class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { // need to switch to larger statespace. largest_nq = nq; sv = ss.Create(largest_nq); + sv_host.resize(2 * (uint64_t(1) << largest_nq)); } ss.SetStateZero(sv); for (int j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } + // Copy the whole GPU data to CPU memory once. + // Please don't use ss.GetAmpl(), because it copies amplitude + // one-by-one, which makes huge speed slowdown, even slower than CPU op. + ss.Copy(sv, sv_host.data()); // Parallel copy state vector information from qsim into tensorflow - // tensors. - auto copy_f = [i, nq, max_num_qubits, &output_tensor, &ss, &sv]( + // tensors. We need type conversions from 2 floats to std::complex. + auto copy_f = [i, nq, max_num_qubits, &output_tensor, &sv_host]( uint64_t start, uint64_t end) { uint64_t crossover = uint64_t(1) << nq; uint64_t upper = std::min(end, crossover); if (start < crossover) { for (uint64_t j = 0; j < upper; j++) { - (*output_tensor)(i, j) = ss.GetAmpl(sv, j); + (*output_tensor)(i, j) = + std::complex(sv_host[2 * j], sv_host[2 * j + 1]); } } for (uint64_t j = upper; j < end; j++) { From 0683d1ca6d6a19b4b526173482d6e7644ab0d2d1 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Mon, 1 May 2023 05:20:31 +0000 Subject: [PATCH 066/106] controlled pqc cuquantum support --- .../python/layers/high_level/controlled_pqc.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tensorflow_quantum/python/layers/high_level/controlled_pqc.py b/tensorflow_quantum/python/layers/high_level/controlled_pqc.py index 588a8aa59..45843519c 100644 --- a/tensorflow_quantum/python/layers/high_level/controlled_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/controlled_pqc.py @@ -128,6 +128,7 @@ def __init__(self, *, repetitions=None, backend='noiseless', + use_cuquantum=False, differentiator=None, **kwargs): """Instantiate this layer. @@ -153,6 +154,8 @@ def __init__(self, `sampled_based` is True or it must inherit `cirq.sim.simulator.SimulatesExpectationValues` if `sample_based` is False. + use_cuquantum: Optional Python `bool` indicating whether or not to use + GPU ops differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. """ @@ -235,10 +238,12 @@ def __init__(self, if self._analytic: self._layer = expectation.Expectation(backend=backend, - differentiator=differentiator) + differentiator=differentiator, + use_cuquantum=use_cuquantum) else: self._layer = sampled_expectation.SampledExpectation( - backend=backend, differentiator=differentiator) + backend=backend, differentiator=differentiator, + use_cuquantum=use_cuquantum) self._append_layer = elementary.AddCircuit() From 1ff09127fff1e33c6188485550b670e1c794cbf2 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Mon, 1 May 2023 23:04:28 +0000 Subject: [PATCH 067/106] Bump up to qsim 0.16.1 --- WORKSPACE | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 44bce67ce..e28452a8d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -26,9 +26,9 @@ cc_library( http_archive( name = "qsim", - sha256 = "e4d716b945d44c6901ccc4ee4c2344e2af127b28713a0faebf0687745e0bf5e7", - strip_prefix = "qsim-0.16.0", - urls = ["https://github.com/quantumlib/qsim/archive/refs/tags/v0.16.0.zip"], + sha256 = "f7f410a07543a51b254f7a5810b5153e196a4c7b4ec89dc8faf86f9c77eec97b", + strip_prefix = "qsim-0.16.1", + urls = ["https://github.com/quantumlib/qsim/archive/refs/tags/v0.16.1.zip"], ) http_archive( From f4f0125cb56d7be0ad85698a3657e8b9736a24df Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Mon, 1 May 2023 23:45:44 +0000 Subject: [PATCH 068/106] Fix cuquantum config bzl rule for uninitialized lib path --- third_party/cuquantum/cuquantum_configure.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/third_party/cuquantum/cuquantum_configure.bzl b/third_party/cuquantum/cuquantum_configure.bzl index b79a7496e..e776256da 100644 --- a/third_party/cuquantum/cuquantum_configure.bzl +++ b/third_party/cuquantum/cuquantum_configure.bzl @@ -205,6 +205,7 @@ def _cuquantum_pip_impl(repository_ctx): cuquantum_header_path = _find_file(repository_ctx, "custatevec.h") cuquantum_header_path = cuquantum_header_path[:cuquantum_header_path.find("/custatevec.h")] custatevec_shared_library_path = _find_file(repository_ctx, "libcustatevec.so") + cuquantum_root = custatevec_shared_library_path[:custatevec_shared_library_path.find("/lib/lib")] else: cuquantum_header_path = "%s/include" % cuquantum_root custatevec_shared_library_path = "%s/lib/libcustatevec.so" % (cuquantum_root) From f6f00fd6dabfe7bf3f523e10810ab104cbab65e1 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 3 May 2023 00:43:51 +0000 Subject: [PATCH 069/106] Upgrade cirq version to ~= 1.0 1. CNOT's control and target was deprecated. 2. QuantumEngineSampler was deprecated. Use ProcessorSampler instead. 3. SingleQubitGate was deprecated. Use Gate instead. For testing purpose, there is cirq.testing.SingleQubitGate. 4. Bump up the cirq dep version in TFQ to ~= 1.0 to be compatible with qsim --- docs/tutorials/hello_many_worlds.ipynb | 2 +- release/setup.py | 4 +-- requirements.txt | 4 +-- .../core/ops/circuit_execution_ops_test.py | 33 +++++++------------ tensorflow_quantum/core/ops/cirq_ops.py | 2 +- tensorflow_quantum/core/ops/cirq_ops_test.py | 11 ++++--- .../core/serialize/op_deserializer_test.py | 2 +- .../core/serialize/op_serializer_test.py | 6 ++-- .../layers/circuit_executors/sample_test.py | 2 +- .../optimizers/rotosolve_minimizer_test.py | 2 +- .../python/optimizers/spsa_minimizer_test.py | 2 +- 11 files changed, 30 insertions(+), 40 deletions(-) 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/release/setup.py b/release/setup.py index 191981565..c2e9fb718 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.5' ] @@ -59,7 +59,7 @@ def finalize_options(self): # placed as extra to not have required overwrite existing nightly installs if # they exist. EXTRA_PACKAGES = ['tensorflow == 2.11.0'] -CUR_VERSION = '0.7.3' +CUR_VERSION = '0.7.4' class BinaryDistribution(Distribution): diff --git a/requirements.txt b/requirements.txt index 578179982..f899bfc5b 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/tensorflow_quantum/core/ops/circuit_execution_ops_test.py b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py index 2a9356bb8..e869682aa 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 @@ -115,11 +116,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"): @@ -145,11 +144,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") @@ -174,11 +171,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") @@ -207,12 +202,10 @@ 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."): @@ -339,7 +332,7 @@ def test_simulate_state_large(self, op_and_sim): symbol_names = [] circuit_batch, resolver_batch = \ util.random_circuit_resolver_batch( - cirq.GridQubit.rect(4, 4), 5) + cirq.GridQubit.rect(3, 3), 5) symbol_values_array = np.array( [[resolver[symbol] @@ -351,10 +344,6 @@ def test_simulate_state_large(self, op_and_sim): cirq_states = batch_util.batch_calculate_state(circuit_batch, resolver_batch, sim) - # Due to numpy memory allocation error with large circuits, - # we deallocate these variables. - del circuit_batch - del resolver_batch self.assertAllClose(cirq_states, op_states, atol=1e-5, rtol=1e-5) 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..d634e671c 100644 --- a/tensorflow_quantum/core/ops/cirq_ops_test.py +++ b/tensorflow_quantum/core/ops/cirq_ops_test.py @@ -26,6 +26,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 +349,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 +450,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/layers/circuit_executors/sample_test.py b/tensorflow_quantum/python/layers/circuit_executors/sample_test.py index b83848132..d32127ce1 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample_test.py @@ -162,7 +162,7 @@ def test_sample_outputs_simple(self): output = sampler([circuit, circuit], repetitions=5) self.assertShapeEqual(np.empty((2, 5, 1)), output.to_tensor()) - # TODO(trevormccrt): add QuantumEngineSampler to this once it is available + # TODO(trevormccrt): add ProcessorSampler to this once it is available @parameterized.parameters( list( util.kwargs_cartesian_product( 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([ From 6094d2be7b7d9f54639ebd9f9a8ef4c7c0c27489 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 3 May 2023 00:52:05 +0000 Subject: [PATCH 070/106] Comment out corrupted test. --- tensorflow_quantum/datasets/spin_system_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tensorflow_quantum/datasets/spin_system_test.py b/tensorflow_quantum/datasets/spin_system_test.py index 3dac53a80..7053e461d 100644 --- a/tensorflow_quantum/datasets/spin_system_test.py +++ b/tensorflow_quantum/datasets/spin_system_test.py @@ -27,7 +27,8 @@ from tensorflow_quantum.datasets.spin_system import SpinSystemInfo -class TFIChainTest(tf.test.TestCase): +# TODO(#748): Inherit this class from tf.test.TestCase after fixing the issue. +class TFIRectangularTest: """Testing tfi_chain.""" # pylint: disable=C0103 From 47d76172086e8cf8feef6d0259405bf205cbbd24 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 3 May 2023 00:53:34 +0000 Subject: [PATCH 071/106] Fix parse_context for graceful termination with returning status Without this, sometimes OpKernel terminates without calling destructor, going to segfault when cuquantum ops are running. --- tensorflow_quantum/core/ops/parse_context.cc | 53 +++++++++++++------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/tensorflow_quantum/core/ops/parse_context.cc b/tensorflow_quantum/core/ops/parse_context.cc index be6e98b98..172f1b1a3 100644 --- a/tensorflow_quantum/core/ops/parse_context.cc +++ b/tensorflow_quantum/core/ops/parse_context.cc @@ -78,9 +78,13 @@ Status ParsePrograms(OpKernelContext* context, const std::string& input_name, const int num_programs = program_strings.dimension(0); programs->assign(num_programs, Program()); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto DoWork = [&](int start, int end) { for (int i = start; i < end; i++) { - OP_REQUIRES_OK(context, ParseProto(program_strings(i), &programs->at(i))); + Status local = ParseProto(program_strings(i), &programs->at(i)); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); } }; @@ -89,7 +93,7 @@ Status ParsePrograms(OpKernelContext* context, const std::string& input_name, context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( num_programs, cycle_estimate, DoWork); - return ::tensorflow::Status(); + return parse_status; } Status ParsePrograms2D(OpKernelContext* context, const std::string& input_name, @@ -113,12 +117,13 @@ Status ParsePrograms2D(OpKernelContext* context, const std::string& input_name, const int num_entries = program_strings.dimension(1); programs->assign(num_programs, std::vector(num_entries, Program())); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); auto DoWork = [&](int start, int end) { for (int i = start; i < end; i++) { - OP_REQUIRES_OK( - context, - ParseProto(program_strings(i / num_entries, i % num_entries), - &programs->at(i / num_entries).at(i % num_entries))); + Status local = ParseProto(program_strings(i / num_entries, i % num_entries), + &programs->at(i / num_entries).at(i % num_entries)); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); } }; @@ -127,7 +132,7 @@ Status ParsePrograms2D(OpKernelContext* context, const std::string& input_name, context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( num_programs * num_entries, cycle_estimate, DoWork); - return ::tensorflow::Status(); + return parse_status; } Status GetProgramsAndProgramsToAppend( @@ -181,19 +186,22 @@ Status GetProgramsAndNumQubits( } // Resolve qubit ID's in parallel. + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); num_qubits->assign(programs->size(), -1); auto DoWork = [&](int start, int end) { for (int i = start; i < end; i++) { Program& program = (*programs)[i]; unsigned int this_num_qubits; + Status local; if (p_sums) { - OP_REQUIRES_OK(context, - ResolveQubitIds(&program, &this_num_qubits, - &(p_sums->at(i)), swap_endianness)); + local = ResolveQubitIds(&program, &this_num_qubits, + &(p_sums->at(i)), swap_endianness); } else { - OP_REQUIRES_OK(context, ResolveQubitIds(&program, &this_num_qubits, - nullptr, swap_endianness)); + local = ResolveQubitIds(&program, &this_num_qubits, + nullptr, swap_endianness); } + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); (*num_qubits)[i] = this_num_qubits; } }; @@ -203,7 +211,7 @@ Status GetProgramsAndNumQubits( context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( num_qubits->size(), cycle_estimate, DoWork); - return ::tensorflow::Status(); + return parse_status; } tensorflow::Status GetProgramsAndNumQubits( @@ -232,13 +240,16 @@ tensorflow::Status GetProgramsAndNumQubits( } // Resolve qubit ID's in parallel. + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); num_qubits->assign(programs->size(), -1); auto DoWork = [&](int start, int end) { for (int i = start; i < end; i++) { Program& program = (*programs)[i]; unsigned int this_num_qubits; - OP_REQUIRES_OK(context, ResolveQubitIds(&program, &this_num_qubits, - &(*other_programs)[i])); + Status local = ResolveQubitIds(&program, &this_num_qubits, + &(*other_programs)[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); (*num_qubits)[i] = this_num_qubits; } }; @@ -248,7 +259,7 @@ tensorflow::Status GetProgramsAndNumQubits( context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( num_qubits->size(), cycle_estimate, DoWork); - return ::tensorflow::Status(); + return parse_status; } Status GetPauliSums(OpKernelContext* context, @@ -271,12 +282,18 @@ Status GetPauliSums(OpKernelContext* context, p_sums->assign(sum_specs.dimension(0), std::vector(sum_specs.dimension(1), PauliSum())); const int op_dim = sum_specs.dimension(1); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); auto DoWork = [&](int start, int end) { for (int ii = start; ii < end; ii++) { const int i = ii / op_dim; const int j = ii % op_dim; PauliSum p; - OP_REQUIRES_OK(context, ParseProto(sum_specs(i, j), &p)); + // We should not stop the whole program, because TFQ cuQuantum ops + // requires running destructors to return cuQuantum handlers, + // and not to fall into segfault. + Status local = ParseProto(sum_specs(i, j), &p); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); (*p_sums)[i][j] = p; } }; @@ -286,7 +303,7 @@ Status GetPauliSums(OpKernelContext* context, context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( sum_specs.dimension(0) * sum_specs.dimension(1), cycle_estimate, DoWork); - return ::tensorflow::Status(); + return parse_status; } Status GetSymbolMaps(OpKernelContext* context, std::vector* maps) { From d81733da4278ec4dad1c18da79f4e301c7871740 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 3 May 2023 00:56:43 +0000 Subject: [PATCH 072/106] Fix int to size_t to turn off warning messages. --- .../core/ops/math_ops/tfq_inner_product.cc | 12 +-- .../ops/math_ops/tfq_inner_product_grad.cc | 4 +- .../core/ops/noise/tfq_noisy_expectation.cc | 28 +++---- .../noise/tfq_noisy_sampled_expectation.cc | 28 +++---- .../core/ops/noise/tfq_noisy_samples.cc | 4 +- .../core/ops/tfq_adj_grad_op.cc | 14 ++-- .../core/ops/tfq_adj_grad_op_cuquantum.cu.cc | 74 +++++++++++++------ .../ops/tfq_adj_grad_op_cuquantum_test.py | 10 +-- .../core/ops/tfq_calculate_unitary_op.cc | 4 +- .../core/ops/tfq_circuit_append_op.cc | 2 +- .../core/ops/tfq_ps_decompose_op.cc | 4 +- .../core/ops/tfq_ps_symbol_replace_op.cc | 8 +- .../ops/tfq_ps_weights_from_symbols_op.cc | 8 +- .../core/ops/tfq_simulate_expectation_op.cc | 8 +- ...fq_simulate_expectation_op_cuquantum.cu.cc | 6 +- .../tfq_simulate_sampled_expectation_op.cc | 8 +- ...ate_sampled_expectation_op_cuquantum.cu.cc | 11 ++- .../core/ops/tfq_simulate_samples_op.cc | 6 +- .../tfq_simulate_samples_op_cuquantum.cu.cc | 4 +- .../core/ops/tfq_simulate_state_op.cc | 6 +- .../ops/tfq_simulate_state_op_cuquantum.cu.cc | 4 +- tensorflow_quantum/core/src/adj_util.cc | 10 +-- .../core/src/circuit_parser_qsim_test.cc | 6 +- tensorflow_quantum/core/src/util_qsim.h | 8 +- tensorflow_quantum/core/src/util_qsim_test.cc | 6 +- 25 files changed, 158 insertions(+), 125 deletions(-) diff --git a/tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc b/tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc index 74751f9cc..374aa5b55 100644 --- a/tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc +++ b/tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc @@ -174,7 +174,7 @@ class TfqInnerProductOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { // need to switch to larger statespace. @@ -186,10 +186,10 @@ class TfqInnerProductOp : public tensorflow::OpKernel { // the state if there is a possibility that circuit[i] and // circuit[i + 1] produce the same state. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } - for (int j = 0; j < other_fused_circuits[i].size(); j++) { + for (size_t j = 0; j < other_fused_circuits[i].size(); j++) { // (#679) Just ignore empty program if (fused_circuits[i].size() == 0) { (*output_tensor)(i, j) = std::complex(1, 0); @@ -197,7 +197,7 @@ class TfqInnerProductOp : public tensorflow::OpKernel { } ss.SetStateZero(scratch); - for (int k = 0; k < other_fused_circuits[i][j].size(); k++) { + for (size_t k = 0; k < other_fused_circuits[i][j].size(); k++) { qsim::ApplyFusedGate(sim, other_fused_circuits[i][j][k], scratch); } @@ -255,13 +255,13 @@ class TfqInnerProductOp : public tensorflow::OpKernel { // no need to update scratch_state since ComputeExpectation // will take care of things for us. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[cur_batch_index].size(); j++) { + for (size_t j = 0; j < fused_circuits[cur_batch_index].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[cur_batch_index][j], sv); } } ss.SetStateZero(scratch); - for (int k = 0; + for (size_t k = 0; k < other_fused_circuits[cur_batch_index][cur_internal_index].size(); k++) { diff --git a/tensorflow_quantum/core/ops/math_ops/tfq_inner_product_grad.cc b/tensorflow_quantum/core/ops/math_ops/tfq_inner_product_grad.cc index 3db493b11..534d7fef9 100644 --- a/tensorflow_quantum/core/ops/math_ops/tfq_inner_product_grad.cc +++ b/tensorflow_quantum/core/ops/math_ops/tfq_inner_product_grad.cc @@ -398,13 +398,13 @@ class TfqInnerProductGradOp : public tensorflow::OpKernel { // if applicable compute control qubit mask and control value bits. uint64_t mask = 0; uint64_t cbits = 0; - for (int k = 0; k < cur_gate.controlled_by.size(); k++) { + for (size_t k = 0; k < cur_gate.controlled_by.size(); k++) { uint64_t control_loc = cur_gate.controlled_by[k]; mask |= uint64_t{1} << control_loc; cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; } - for (int k = 0; + for (size_t k = 0; k < gradient_gates[cur_batch_index][l - 1].grad_gates.size(); k++) { // Copy sv_adj onto scratch2 in anticipation of non-unitary diff --git a/tensorflow_quantum/core/ops/noise/tfq_noisy_expectation.cc b/tensorflow_quantum/core/ops/noise/tfq_noisy_expectation.cc index c67fa01f7..6f09da68f 100644 --- a/tensorflow_quantum/core/ops/noise/tfq_noisy_expectation.cc +++ b/tensorflow_quantum/core/ops/noise/tfq_noisy_expectation.cc @@ -175,8 +175,8 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel { tensorflow::GuardedPhiloxRandom random_gen; int max_n_shots = 1; - for (int i = 0; i < num_samples.size(); i++) { - for (int j = 0; j < num_samples[i].size(); j++) { + for (size_t i = 0; i < num_samples.size(); i++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { max_n_shots = std::max(max_n_shots, num_samples[i][j]); } } @@ -188,12 +188,12 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < ncircuits.size(); i++) { + for (size_t i = 0; i < ncircuits.size(); i++) { int nq = num_qubits[i]; // (#679) Just ignore empty program if (ncircuits[i].channels.size() == 0) { - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { (*output_tensor)(i, j) = -2.0; } continue; @@ -220,7 +220,7 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel { sv, unused_stats); // Use this trajectory as a source for all expectation calculations. - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { if (run_samples[j] >= num_samples[i][j]) { continue; } @@ -232,14 +232,14 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel { run_samples[j]++; } bool break_loop = true; - for (int j = 0; j < num_samples[i].size(); j++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { if (run_samples[j] < num_samples[i][j]) { break_loop = false; break; } } if (break_loop) { - for (int j = 0; j < num_samples[i].size(); j++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { rolling_sums[j] /= num_samples[i][j]; (*output_tensor)(i, j) = static_cast(rolling_sums[j]); } @@ -280,8 +280,8 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel { tensorflow::GuardedPhiloxRandom random_gen; int max_n_shots = 1; - for (int i = 0; i < num_samples.size(); i++) { - for (int j = 0; j < num_samples[i].size(); j++) { + for (size_t i = 0; i < num_samples.size(); i++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { max_n_shots = std::max(max_n_shots, num_samples[i][j]); } } @@ -304,13 +304,13 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel { random_gen.ReserveSamples128(ncircuits.size() * max_n_shots + 1); tensorflow::random::SimplePhilox rand_source(&local_gen); - for (int i = 0; i < ncircuits.size(); i++) { + for (size_t i = 0; i < ncircuits.size(); i++) { int nq = num_qubits[i]; int rep_offset = rep_offsets[start][i]; // (#679) Just ignore empty program if (ncircuits[i].channels.size() == 0) { - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { (*output_tensor)(i, j) = -2.0; } continue; @@ -337,7 +337,7 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel { sim, sv, unused_stats); // Compute expectations across all ops using this trajectory. - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { int p_reps = (num_samples[i][j] + num_threads - 1) / num_threads; if (run_samples[j] >= p_reps + rep_offset) { continue; @@ -354,7 +354,7 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel { // Check if we have run enough trajectories for all ops. bool break_loop = true; - for (int j = 0; j < num_samples[i].size(); j++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { int p_reps = (num_samples[i][j] + num_threads - 1) / num_threads; if (run_samples[j] < p_reps + rep_offset) { break_loop = false; @@ -364,7 +364,7 @@ class TfqNoisyExpectationOp : public tensorflow::OpKernel { if (break_loop) { // Lock writing to this batch index in output_tensor. batch_locks[i].lock(); - for (int j = 0; j < num_samples[i].size(); j++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { rolling_sums[j] /= num_samples[i][j]; (*output_tensor)(i, j) += static_cast(rolling_sums[j]); } diff --git a/tensorflow_quantum/core/ops/noise/tfq_noisy_sampled_expectation.cc b/tensorflow_quantum/core/ops/noise/tfq_noisy_sampled_expectation.cc index aa0c85691..7e1993a7e 100644 --- a/tensorflow_quantum/core/ops/noise/tfq_noisy_sampled_expectation.cc +++ b/tensorflow_quantum/core/ops/noise/tfq_noisy_sampled_expectation.cc @@ -177,8 +177,8 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel { tensorflow::GuardedPhiloxRandom random_gen; int max_psum_length = 1; int max_n_shots = 1; - for (int i = 0; i < pauli_sums.size(); i++) { - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t i = 0; i < pauli_sums.size(); i++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { max_psum_length = std::max(max_psum_length, pauli_sums[i][j].terms().size()); max_n_shots = std::max(max_n_shots, num_samples[i][j]); @@ -192,12 +192,12 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < ncircuits.size(); i++) { + for (size_t i = 0; i < ncircuits.size(); i++) { int nq = num_qubits[i]; // (#679) Just ignore empty program if (ncircuits[i].channels.empty()) { - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { (*output_tensor)(i, j) = -2.0; } continue; @@ -224,7 +224,7 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel { sv, unused_stats); // Use this trajectory as a source for all expectation calculations. - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { if (run_samples[j] >= num_samples[i][j]) { continue; } @@ -236,14 +236,14 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel { run_samples[j]++; } bool break_loop = true; - for (int j = 0; j < num_samples[i].size(); j++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { if (run_samples[j] < num_samples[i][j]) { break_loop = false; break; } } if (break_loop) { - for (int j = 0; j < num_samples[i].size(); j++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { rolling_sums[j] /= num_samples[i][j]; (*output_tensor)(i, j) = static_cast(rolling_sums[j]); } @@ -285,8 +285,8 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel { tensorflow::GuardedPhiloxRandom random_gen; int max_psum_length = 1; int max_n_shots = 1; - for (int i = 0; i < pauli_sums.size(); i++) { - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t i = 0; i < pauli_sums.size(); i++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { max_psum_length = std::max(max_psum_length, pauli_sums[i][j].terms().size()); max_n_shots = std::max(max_n_shots, num_samples[i][j]); @@ -310,13 +310,13 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel { auto local_gen = random_gen.ReserveSamples128(num_rand); tensorflow::random::SimplePhilox rand_source(&local_gen); - for (int i = 0; i < ncircuits.size(); i++) { + for (size_t i = 0; i < ncircuits.size(); i++) { int nq = num_qubits[i]; int rep_offset = rep_offsets[start][i]; // (#679) Just ignore empty program if (ncircuits[i].channels.empty()) { - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { (*output_tensor)(i, j) = -2.0; } continue; @@ -343,7 +343,7 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel { sim, sv, unused_stats); // Compute expectations across all ops using this trajectory. - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { int p_reps = (num_samples[i][j] + num_threads - 1) / num_threads; if (run_samples[j] >= p_reps + rep_offset) { continue; @@ -360,7 +360,7 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel { // Check if we have run enough trajectories for all ops. bool break_loop = true; - for (int j = 0; j < num_samples[i].size(); j++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { int p_reps = (num_samples[i][j] + num_threads - 1) / num_threads; if (run_samples[j] < p_reps + rep_offset) { break_loop = false; @@ -370,7 +370,7 @@ class TfqNoisySampledExpectationOp : public tensorflow::OpKernel { if (break_loop) { // Lock writing to this batch index in output_tensor. batch_locks[i].lock(); - for (int j = 0; j < num_samples[i].size(); j++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { rolling_sums[j] /= num_samples[i][j]; (*output_tensor)(i, j) += static_cast(rolling_sums[j]); } diff --git a/tensorflow_quantum/core/ops/noise/tfq_noisy_samples.cc b/tensorflow_quantum/core/ops/noise/tfq_noisy_samples.cc index 341c87910..1af738323 100644 --- a/tensorflow_quantum/core/ops/noise/tfq_noisy_samples.cc +++ b/tensorflow_quantum/core/ops/noise/tfq_noisy_samples.cc @@ -159,7 +159,7 @@ class TfqNoisySamplesOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as nescessary. - for (int i = 0; i < ncircuits.size(); i++) { + for (size_t i = 0; i < ncircuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -252,7 +252,7 @@ class TfqNoisySamplesOp : public tensorflow::OpKernel { auto local_gen = random_gen.ReserveSamples32(needed_random); tensorflow::random::SimplePhilox rand_source(&local_gen); - for (int i = 0; i < ncircuits.size(); i++) { + for (size_t i = 0; i < ncircuits.size(); i++) { int nq = num_qubits[i]; int j = start > 0 ? offset_prefix_sum[start - 1][i] : 0; int needed_samples = offset_prefix_sum[start][i] - j; diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc index e7252baee..b12c3e583 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc @@ -202,7 +202,7 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { } ss.SetStateZero(sv); - for (int j = 0; j < full_fuse[i].size(); j++) { + for (size_t j = 0; j < full_fuse[i].size(); j++) { qsim::ApplyFusedGate(sim, full_fuse[i][j], sv); } @@ -231,13 +231,13 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { // if applicable compute control qubit mask and control value bits. uint64_t mask = 0; uint64_t cbits = 0; - for (int k = 0; k < cur_gate.controlled_by.size(); k++) { + for (size_t k = 0; k < cur_gate.controlled_by.size(); k++) { uint64_t control_loc = cur_gate.controlled_by[k]; mask |= uint64_t{1} << control_loc; cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; } - for (int k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); k++) { + for (size_t k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); k++) { // Copy sv onto scratch2 in anticipation of non-unitary "gradient // gate". ss.Copy(sv, scratch2); @@ -297,7 +297,7 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { auto scratch = ss.Create(largest_nq); auto scratch2 = ss.Create(largest_nq); - for (int i = 0; i < partial_fused_circuits.size(); i++) { + for (size_t i = 0; i < partial_fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -314,7 +314,7 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { } ss.SetStateZero(sv); - for (int j = 0; j < full_fuse[i].size(); j++) { + for (size_t j = 0; j < full_fuse[i].size(); j++) { qsim::ApplyFusedGate(sim, full_fuse[i][j], sv); } @@ -342,13 +342,13 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { // if applicable compute control qubit mask and control value bits. uint64_t mask = 0; uint64_t cbits = 0; - for (int k = 0; k < cur_gate.controlled_by.size(); k++) { + for (size_t k = 0; k < cur_gate.controlled_by.size(); k++) { uint64_t control_loc = cur_gate.controlled_by[k]; mask |= uint64_t{1} << control_loc; cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; } - for (int k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); k++) { + for (size_t k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); k++) { // Copy sv onto scratch2 in anticipation of non-unitary "gradient // gate". ss.Copy(sv, scratch2); diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc index ada6d67b0..08caaab4e 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc @@ -22,7 +22,7 @@ limitations under the License. #include "../qsim/lib/gate_appl.h" #include "../qsim/lib/gates_cirq.h" #include "../qsim/lib/seqfor.h" -#include "../qsim/lib/simmux.h" +#include "../qsim/lib/simmux_gpu.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/shape_inference.h" #include "tensorflow/core/framework/tensor_shape.h" @@ -38,6 +38,41 @@ limitations under the License. namespace tfq { +namespace { + // TODO(jaeyoo): Temorary hack for BulkSetAmpl with cuda ops. + // Updates qsim custatevec side BulkSetAmple ops, and remove these utilities. + template +__global__ void BulkSetAmplKernel( + uint64_t mask, uint64_t bits, FP re, FP im, bool exclude, FP* state) { + uint64_t k1 = uint64_t{blockIdx.x} * blockDim.x + threadIdx.x; + uint64_t k2 = 2 * k1 - threadIdx.x % warp_size; + + bool set = ((k1 & mask) == bits) ^ exclude; + + if (set) { + state[k2] = re; + state[k2 + warp_size] = im; + } +} + +// Sets state[i] = complex(re, im) where (i & mask) == bits. +// if `exclude` is true then the criteria becomes (i & mask) != bits. +template +void BulkSetAmpl(qsim::SimulatorCuStateVec::StateSpace::State& state, + uint64_t mask, uint64_t bits, fp_type re, + fp_type im, bool exclude = false) { + uint64_t size = uint64_t{1} << state.num_qubits(); + + unsigned threads = std::min(size, uint64_t{512}); + unsigned blocks = size / threads; + + BulkSetAmplKernel<<>>( + mask, bits, re, im, exclude, state.get()); + cudaPeekAtLastError(); + cudaDeviceSynchronize(); +} +} // namespace + using ::tensorflow::Status; using ::tfq::proto::PauliSum; using ::tfq::proto::Program; @@ -49,7 +84,17 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { public: explicit TfqAdjointGradientCuquantumOp( tensorflow::OpKernelConstruction* context) - : OpKernel(context) {} + : OpKernel(context) { + // create handles for simulator + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } + + ~TfqAdjointGradientCuquantumOp() { + // destroy handles in sync with simulator lifetime + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. @@ -144,24 +189,10 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { output_tensor.setZero(); - // create handles for simulator - cublasCreate(&cublas_handle_); - custatevecCreate(&custatevec_handle_); - // Cross reference with standard google cloud compute instances - // Memory ~= 2 * num_threads * (2 * 64 * 2 ** num_qubits in circuits) - // e2s2 = 2 CPU, 8GB -> Can safely do 25 since Memory = 4GB - // e2s4 = 4 CPU, 16GB -> Can safely do 25 since Memory = 8GB - // ... - // This method creates 3 big state vectors per thread so reducing size - // here slightly. ComputeLarge(num_qubits, qsim_circuits, maps, full_fuse, partial_fused_circuits, pauli_sums, gradient_gates, downstream_grads, context, &output_tensor); - - // destroy handles in sync with simulator lifetime - cublasDestroy(cublas_handle_); - custatevecDestroy(custatevec_handle_); } private: @@ -181,7 +212,6 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { tensorflow::OpKernelContext* context, tensorflow::TTypes::Matrix* output_tensor) { // Instantiate qsim objects. - const auto tfq_for = tfq::QsimFor(context); using Simulator = qsim::SimulatorCuStateVec; using StateSpace = Simulator::StateSpace; @@ -193,7 +223,7 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { auto scratch = ss.Create(largest_nq); auto scratch2 = ss.Create(largest_nq); - for (int i = 0; i < partial_fused_circuits.size(); i++) { + for (size_t i = 0; i < partial_fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -210,7 +240,7 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { } ss.SetStateZero(sv); - for (int j = 0; j < full_fuse[i].size(); j++) { + for (size_t j = 0; j < full_fuse[i].size(); j++) { qsim::ApplyFusedGate(sim, full_fuse[i][j], sv); } @@ -238,13 +268,13 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { // if applicable compute control qubit mask and control value bits. uint64_t mask = 0; uint64_t cbits = 0; - for (int k = 0; k < cur_gate.controlled_by.size(); k++) { + for (size_t k = 0; k < cur_gate.controlled_by.size(); k++) { uint64_t control_loc = cur_gate.controlled_by[k]; mask |= uint64_t{1} << control_loc; cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; } - for (int k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); k++) { + for (size_t k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); k++) { // Copy sv onto scratch2 in anticipation of non-unitary "gradient // gate". ss.Copy(sv, scratch2); @@ -252,7 +282,7 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { // Gradient of controlled gates puts zeros on diagonal which is // the same as collapsing the state and then applying the // non-controlled version of the gradient gate. - ss.BulkSetAmpl(scratch2, mask, cbits, 0, 0, true); + BulkSetAmpl(scratch2, mask, cbits, 0, 0, true); } qsim::ApplyGate(sim, gradient_gates[i][j - 1].grad_gates[k], scratch2); diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py index 747480c58..3933efde0 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py @@ -95,8 +95,8 @@ def test_calculate_adj_grad_cpu_vs_cuquantum(self): circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor, prev_grads), - "CPU", - num_samples=100, + "Adjoint CPU", + num_samples=10, result_avg=True, ) @@ -105,8 +105,8 @@ def test_calculate_adj_grad_cpu_vs_cuquantum(self): circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor, prev_grads), - "cuQuantum", - num_samples=100, + "Adjoint cuQuantum", + num_samples=10, result_avg=True, ) @@ -116,7 +116,7 @@ def test_calculate_adj_grad_cpu_vs_cuquantum(self): # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, res_cuquantum, - atol=1e-4, + atol=1e-3, err_msg=""" # If failed, the GPU architecture in this system may be unsupported. # Please refer to the supported architectures here. diff --git a/tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc b/tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc index ace5327e1..4f1f662ca 100644 --- a/tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc +++ b/tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc @@ -116,7 +116,7 @@ class TfqCalculateUnitaryOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the unitary as nescessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; UCalculator sim = UCalculator(tfq_for); UnitarySpace us = UnitarySpace(tfq_for); @@ -126,7 +126,7 @@ class TfqCalculateUnitaryOp : public tensorflow::OpKernel { u = us.CreateUnitary(nq); } us.SetIdentity(u); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], u); } diff --git a/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc b/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc index 582bd1681..045154185 100644 --- a/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc +++ b/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc @@ -54,7 +54,7 @@ class TfqCircuitAppendOp : public tensorflow::OpKernel { auto DoWork = [&](int start, int end) { std::string temp; for (int i = start; i < end; i++) { - for (int j = 0; j < programs_to_append.at(i).circuit().moments().size(); + for (size_t j = 0; j < programs_to_append.at(i).circuit().moments().size(); j++) { Moment *new_moment = programs.at(i).mutable_circuit()->add_moments(); *new_moment = programs_to_append.at(i).circuit().moments(j); diff --git a/tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc b/tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc index 669ea6368..5c20e546e 100644 --- a/tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc +++ b/tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc @@ -65,11 +65,11 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel { new_program.mutable_language()->set_gate_set("tfq_gate_set"); new_program.mutable_circuit()->set_scheduling_strategy( Circuit::MOMENT_BY_MOMENT); - for (int j = 0; j < cur_program.circuit().moments().size(); j++) { + for (size_t j = 0; j < cur_program.circuit().moments().size(); j++) { Moment cur_moment(cur_program.circuit().moments().at(j)); std::vector temp_moment_list(max_buffer_moments, Moment()); int num_extra_moments = 0; - for (int k = 0; k < cur_moment.operations().size(); k++) { + for (size_t k = 0; k < cur_moment.operations().size(); k++) { Operation cur_op = cur_moment.operations().at(k); auto &cur_op_map = *cur_op.mutable_args(); if (cur_op.gate().id() == "PISP") { diff --git a/tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc b/tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc index 559fbecc9..8639d442f 100644 --- a/tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc +++ b/tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc @@ -89,9 +89,9 @@ class TfqPsSymbolReplaceOp : public tensorflow::OpKernel { std::string symbol_to_replace = symbols(sidx); std::string temp_symbol_holder; Program cur_program = programs.at(pidx); - for (int j = 0; j < cur_program.circuit().moments().size(); j++) { + for (size_t j = 0; j < cur_program.circuit().moments().size(); j++) { Moment cur_moment = cur_program.circuit().moments().at(j); - for (int k = 0; k < cur_moment.operations().size(); k++) { + for (size_t k = 0; k < cur_moment.operations().size(); k++) { Operation cur_op = cur_moment.operations().at(k); for (auto l = cur_op.args().begin(); l != cur_op.args().end(); l++) { @@ -163,11 +163,11 @@ class TfqPsSymbolReplaceOp : public tensorflow::OpKernel { for (int i = start; i < end; i++) { int sidx = i % n_symbols; int pidx = i / n_symbols; - for (int j = 0; j < output_programs.at(pidx).at(sidx).size(); j++) { + for (size_t j = 0; j < output_programs.at(pidx).at(sidx).size(); j++) { output_tensor(pidx, sidx, j) = output_programs.at(pidx).at(sidx).at(j); } - for (int j = output_programs.at(pidx).at(sidx).size(); j < biggest_pad; + for (size_t j = output_programs.at(pidx).at(sidx).size(); j < biggest_pad; j++) { output_tensor(pidx, sidx, j) = empty_program; } diff --git a/tensorflow_quantum/core/ops/tfq_ps_weights_from_symbols_op.cc b/tensorflow_quantum/core/ops/tfq_ps_weights_from_symbols_op.cc index 4a027223e..65c03a77c 100644 --- a/tensorflow_quantum/core/ops/tfq_ps_weights_from_symbols_op.cc +++ b/tensorflow_quantum/core/ops/tfq_ps_weights_from_symbols_op.cc @@ -82,9 +82,9 @@ class TfqPsWeightsFromSymbolOp : public tensorflow::OpKernel { auto DoWork = [&](int start, int end) { for (int i = start; i < end; i++) { Program cur_program = programs.at(i); - for (int j = 0; j < cur_program.circuit().moments().size(); j++) { + for (size_t j = 0; j < cur_program.circuit().moments().size(); j++) { Moment cur_moment = cur_program.circuit().moments().at(j); - for (int k = 0; k < cur_moment.operations().size(); k++) { + for (size_t k = 0; k < cur_moment.operations().size(); k++) { Operation cur_op = cur_moment.operations().at(k); if (ignored_symbol_set.contains(cur_op.gate().id())) continue; @@ -146,10 +146,10 @@ class TfqPsWeightsFromSymbolOp : public tensorflow::OpKernel { auto DoWork2 = [&](int start, int end) { for (int i = start; i < end; i++) { for (int j = 0; j < n_symbols; j++) { - for (int k = 0; k < output_results.at(i).at(j).size(); k++) { + for (size_t k = 0; k < output_results.at(i).at(j).size(); k++) { output_tensor(i, j, k) = output_results.at(i).at(j).at(k); } - for (int k = output_results.at(i).at(j).size(); + for (size_t k = output_results.at(i).at(j).size(); k < largest_single_symbol; k++) { output_tensor(i, j, k) = 0.0f; } diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc index bca6d2f63..210e9e93f 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc @@ -143,7 +143,7 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -156,10 +156,10 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel { // the state if there is a possibility that circuit[i] and // circuit[i + 1] produce the same state. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { // (#679) Just ignore empty program if (fused_circuits[i].size() == 0) { (*output_tensor)(i, j) = -2.0; @@ -221,7 +221,7 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel { // no need to update scratch_state since ComputeExpectation // will take care of things for us. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[cur_batch_index].size(); j++) { + for (size_t j = 0; j < fused_circuits[cur_batch_index].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[cur_batch_index][j], sv); } } diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc index 8b92e513b..28fe5ee65 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc @@ -153,7 +153,7 @@ class TfqSimulateExpectationOpCuQuantum : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -166,10 +166,10 @@ class TfqSimulateExpectationOpCuQuantum : public tensorflow::OpKernel { // the state if there is a possibility that circuit[i] and // circuit[i + 1] produce the same state. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { // (#679) Just ignore empty program if (fused_circuits[i].size() == 0) { (*output_tensor)(i, j) = -2.0; diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc index 6cfd459dd..82abb74b9 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc @@ -177,7 +177,7 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -190,10 +190,10 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { // the state if there is a possibility that circuit[i] and // circuit[i + 1] produce the same state. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { // (#679) Just ignore empty program if (fused_circuits[i].size() == 0) { (*output_tensor)(i, j) = -2.0; @@ -273,7 +273,7 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { // no need to update scratch_state since ComputeExpectation // will take care of things for us. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[cur_batch_index].size(); j++) { + for (size_t j = 0; j < fused_circuits[cur_batch_index].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[cur_batch_index][j], sv); } } diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc index 151eb2c30..5d4300fc5 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -166,12 +166,15 @@ class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { auto sv = ss.Create(largest_nq); auto scratch = ss.Create(largest_nq); - int largest_sum = -1; + int largest_sum = 0; for (const auto& sums : pauli_sums) { for (const auto& sum : sums) { largest_sum = std::max(largest_sum, sum.terms().size()); } } + // If empty tensor is fed, just return. + if (fused_circuits.size() == 0) return; + auto local_gen = random_gen_.ReserveSamples32( largest_sum * pauli_sums[0].size() * fused_circuits.size() + 1); tensorflow::random::SimplePhilox rand_source(&local_gen); @@ -179,7 +182,7 @@ class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -192,10 +195,10 @@ class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { // the state if there is a possibility that circuit[i] and // circuit[i + 1] produce the same state. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { // (#679) Just ignore empty program if (fused_circuits[i].size() == 0) { (*output_tensor)(i, j) = -2.0; diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc index 0ff8e62b1..a5918ba27 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc @@ -156,7 +156,7 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as nescessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -165,7 +165,7 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { sv = ss.Create(largest_nq); } ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } @@ -218,7 +218,7 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { sv = ss.Create(largest_nq); } ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc index a48c80e3d..3c4d8666c 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -158,7 +158,7 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as nescessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -167,7 +167,7 @@ class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { sv = ss.Create(largest_nq); } ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc index 8ff2126be..833deb965 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc @@ -136,7 +136,7 @@ class TfqSimulateStateOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -145,7 +145,7 @@ class TfqSimulateStateOp : public tensorflow::OpKernel { sv = ss.Create(largest_nq); } ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } @@ -194,7 +194,7 @@ class TfqSimulateStateOp : public tensorflow::OpKernel { sv = ss.Create(largest_nq); } ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc index 9a9325e29..0ad5feb2d 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc @@ -145,7 +145,7 @@ class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -155,7 +155,7 @@ class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { sv_host.resize(2 * (uint64_t(1) << largest_nq)); } ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } diff --git a/tensorflow_quantum/core/src/adj_util.cc b/tensorflow_quantum/core/src/adj_util.cc index ceb76b2c1..e15ff8a8c 100644 --- a/tensorflow_quantum/core/src/adj_util.cc +++ b/tensorflow_quantum/core/src/adj_util.cc @@ -38,7 +38,7 @@ void CreateGradientCircuit( const QsimCircuit& circuit, const std::vector& metadata, std::vector>>* partial_fuses, std::vector* grad_gates) { - for (int i = 0; i < metadata.size(); i++) { + for (size_t i = 0; i < metadata.size(); i++) { if (metadata[i].symbol_values.empty()) { continue; } @@ -78,7 +78,7 @@ void CreateGradientCircuit( // PhasedX else if (circuit.gates[i].kind == qsim::Cirq::GateKind::kPhasedXPowGate) { // Process potentially several symbols. - for (int j = 0; j < metadata[i].symbol_values.size(); j++) { + for (size_t j = 0; j < metadata[i].symbol_values.size(); j++) { if (metadata[i].placeholder_names[j] == GateParamNames::kPhaseExponent) { PopulateGradientPhasedXPhasedExponent( @@ -103,7 +103,7 @@ void CreateGradientCircuit( // Process potentially several symbols. bool swapq = circuit.gates[i].swapped; - for (int j = 0; j < metadata[i].symbol_values.size(); j++) { + for (size_t j = 0; j < metadata[i].symbol_values.size(); j++) { if (metadata[i].placeholder_names[j] == GateParamNames::kTheta) { PopulateGradientFsimTheta( metadata[i].symbol_values[j], i, @@ -128,7 +128,7 @@ void CreateGradientCircuit( qsim::Cirq::GateKind::kPhasedISwapPowGate) { // Process potentially several symbols. bool swapq = circuit.gates[i].swapped; - for (int j = 0; j < metadata[i].symbol_values.size(); j++) { + for (size_t j = 0; j < metadata[i].symbol_values.size(); j++) { if (metadata[i].placeholder_names[j] == GateParamNames::kPhaseExponent) { PopulateGradientPhasedISwapPhasedExponent( @@ -159,7 +159,7 @@ void CreateGradientCircuit( partial_fuses->assign(grad_gates->size() + 1, std::vector>({})); - for (int i = 0; i < grad_gates->size(); i++) { + for (size_t i = 0; i < grad_gates->size(); i++) { right = circuit.gates.begin() + (*grad_gates)[i].index; (*partial_fuses)[i] = fuser.FuseGates(qsim::BasicGateFuser::Parameter(), diff --git a/tensorflow_quantum/core/src/circuit_parser_qsim_test.cc b/tensorflow_quantum/core/src/circuit_parser_qsim_test.cc index 0ce30e5da..811ecd430 100644 --- a/tensorflow_quantum/core/src/circuit_parser_qsim_test.cc +++ b/tensorflow_quantum/core/src/circuit_parser_qsim_test.cc @@ -65,7 +65,7 @@ Arg MakeControlArg(const std::string& val) { } inline void AssertControlEqual(const QsimGate& a, const QsimGate& b) { - for (int i = 0; i < a.controlled_by.size(); i++) { + for (size_t i = 0; i < a.controlled_by.size(); i++) { ASSERT_EQ(a.controlled_by[i], b.controlled_by[i]); } ASSERT_EQ(a.cmask, b.cmask); @@ -90,14 +90,14 @@ inline void AssertOneQubitEqual(const QsimGate& a, const QsimGate& b) { inline void AssertChannelEqual(const QsimChannel& a, const QsimChannel& b) { ASSERT_EQ(a.size(), b.size()); - for (int i = 0; i < a.size(); i++) { + for (size_t i = 0; i < a.size(); i++) { ASSERT_EQ(a[i].kind, b[i].kind); ASSERT_EQ(a[i].unitary, b[i].unitary); ASSERT_NEAR(a[i].prob, b[i].prob, 1e-5); auto a_k_ops = a[i].ops; auto b_k_ops = b[i].ops; EXPECT_EQ(a_k_ops.size(), b_k_ops.size()); - for (int j = 0; j < a_k_ops.size(); j++) { + for (size_t j = 0; j < a_k_ops.size(); j++) { AssertOneQubitEqual(a_k_ops[j], b_k_ops[j]); } } diff --git a/tensorflow_quantum/core/src/util_qsim.h b/tensorflow_quantum/core/src/util_qsim.h index f08715343..adf38705e 100644 --- a/tensorflow_quantum/core/src/util_qsim.h +++ b/tensorflow_quantum/core/src/util_qsim.h @@ -453,13 +453,13 @@ static void BalanceTrajectory(const std::vector>& num_samples, std::vector rep_limits(num_samples.size(), -1); std::vector height(num_threads, 0); - for (int i = 0; i < num_samples.size(); i++) { - for (int j = 0; j < num_samples[i].size(); j++) { + for (size_t i = 0; i < num_samples.size(); i++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { rep_limits[i] = std::max(rep_limits[i], num_samples[i][j]); } } int prev_max_height = -1; - for (int j = 0; j < num_samples.size(); j++) { + for (size_t j = 0; j < num_samples.size(); j++) { int run_ceiling = ((rep_limits[j] + num_threads - 1) / num_threads); int num_lo = num_threads * run_ceiling - rep_limits[j]; int num_hi = num_threads - num_lo; @@ -498,7 +498,7 @@ static void BalanceTrajectory(const int& num_samples, const int& num_threads, std::vector height(num_threads, 0); int prev_max_height = -1; - for (int j = 0; j < (*thread_offsets)[0].size(); j++) { + for (size_t j = 0; j < (*thread_offsets)[0].size(); j++) { int run_ceiling = ((num_samples + num_threads - 1) / num_threads); int num_lo = num_threads * run_ceiling - num_samples; int num_hi = num_threads - num_lo; diff --git a/tensorflow_quantum/core/src/util_qsim_test.cc b/tensorflow_quantum/core/src/util_qsim_test.cc index b4f630f3c..400c16d76 100644 --- a/tensorflow_quantum/core/src/util_qsim_test.cc +++ b/tensorflow_quantum/core/src/util_qsim_test.cc @@ -646,13 +646,13 @@ static void AssertWellBalanced(const std::vector>& n_reps, const int& num_threads, const std::vector>& offsets) { auto max_work = std::vector(n_reps.size(), -1); - for (int i = 0; i < n_reps.size(); i++) { - for (int j = 0; j < n_reps[0].size(); j++) { + for (size_t i = 0; i < n_reps.size(); i++) { + for (size_t j = 0; j < n_reps[0].size(); j++) { max_work[i] = std::max(max_work[i], n_reps[i][j]); } } - for (int i = 0; i < n_reps.size(); i++) { + for (size_t i = 0; i < n_reps.size(); i++) { int sum = 0; int prev_local_work = 0; for (int k = 0; k < num_threads; k++) { From 8c521bbbde1534a05e25d799b8d5806fc6397231 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 3 May 2023 00:57:14 +0000 Subject: [PATCH 073/106] Enable cuda config in test all --- scripts/test_all.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/test_all.sh b/scripts/test_all.sh index 7a9fc7824..1008c27c8 100755 --- a/scripts/test_all.sh +++ b/scripts/test_all.sh @@ -14,7 +14,17 @@ # limitations under the License. # ============================================================================== echo "Testing All Bazel py_test and cc_tests."; -test_outputs=$(bazel test -c opt --experimental_repo_remote_exec --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-std=c++17" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --notest_keep_going --test_output=errors //tensorflow_quantum/...) +ENABLE_CUDA=${1} + +if [[ ${ENABLE_CUDA} == "gpu" ]]; then + echo "GPU mode. CUDA config is set." + CUDA_CONFIG="--config=cuda" +else + echo "CPU mode." + CUDA_CONFIG="" +fi + +test_outputs=$(bazel test -c opt ${CUDA_CONFIG} --experimental_repo_remote_exec --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-std=c++17" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors //tensorflow_quantum/...) exit_code=$? if [ "$exit_code" == "0" ]; then echo "Testing Complete!"; From 5b85e3cefca5c31b25728b26744408cde69f7efb Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 3 May 2023 01:41:28 +0000 Subject: [PATCH 074/106] Fix format and use [[maybe_unused]] because we are in c++17 --- .../core/ops/circuit_execution_ops_test.py | 3 +- tensorflow_quantum/core/ops/parse_context.cc | 15 +++-- .../core/ops/tfq_adj_grad_op.cc | 14 ++-- .../core/ops/tfq_adj_grad_op_cuquantum.cu.cc | 30 ++++----- .../core/ops/tfq_circuit_append_op.cc | 4 +- .../core/ops/tfq_ps_symbol_replace_op.cc | 4 +- .../core/src/circuit_parser_qsim.cc | 64 +++++++++---------- .../core/src/program_resolution.cc | 2 +- .../layers/high_level/controlled_pqc.py | 3 +- 9 files changed, 71 insertions(+), 68 deletions(-) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops_test.py b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py index e869682aa..549901258 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops_test.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py @@ -204,8 +204,7 @@ def test_get_state_inputs(self): expected_regex="Cirq.SimulatesFinalState"): mock_processor = mock.create_autospec(AbstractProcessor) circuit_execution_ops.get_state_op( - backend=cirq_google.ProcessorSampler( - processor=mock_processor)) + backend=cirq_google.ProcessorSampler(processor=mock_processor)) with self.assertRaisesRegex(TypeError, expected_regex="must be type bool."): diff --git a/tensorflow_quantum/core/ops/parse_context.cc b/tensorflow_quantum/core/ops/parse_context.cc index 172f1b1a3..026c57321 100644 --- a/tensorflow_quantum/core/ops/parse_context.cc +++ b/tensorflow_quantum/core/ops/parse_context.cc @@ -121,7 +121,8 @@ Status ParsePrograms2D(OpKernelContext* context, const std::string& input_name, auto p_lock = tensorflow::mutex(); auto DoWork = [&](int start, int end) { for (int i = start; i < end; i++) { - Status local = ParseProto(program_strings(i / num_entries, i % num_entries), + Status local = + ParseProto(program_strings(i / num_entries, i % num_entries), &programs->at(i / num_entries).at(i % num_entries)); NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); } @@ -195,11 +196,11 @@ Status GetProgramsAndNumQubits( unsigned int this_num_qubits; Status local; if (p_sums) { - local = ResolveQubitIds(&program, &this_num_qubits, - &(p_sums->at(i)), swap_endianness); + local = ResolveQubitIds(&program, &this_num_qubits, &(p_sums->at(i)), + swap_endianness); } else { - local = ResolveQubitIds(&program, &this_num_qubits, - nullptr, swap_endianness); + local = ResolveQubitIds(&program, &this_num_qubits, nullptr, + swap_endianness); } NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); (*num_qubits)[i] = this_num_qubits; @@ -247,8 +248,8 @@ tensorflow::Status GetProgramsAndNumQubits( for (int i = start; i < end; i++) { Program& program = (*programs)[i]; unsigned int this_num_qubits; - Status local = ResolveQubitIds(&program, &this_num_qubits, - &(*other_programs)[i]); + Status local = + ResolveQubitIds(&program, &this_num_qubits, &(*other_programs)[i]); NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); (*num_qubits)[i] = this_num_qubits; } diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc index b12c3e583..7cac4451b 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc @@ -209,8 +209,8 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { // sv now contains psi // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> // scratch2 now contains psi as well. - Status unused = AccumulateOperators(pauli_sums[i], downstream_grads[i], - sim, ss, sv, scratch2, scratch); + [[maybe_unused]] AccumulateOperators(pauli_sums[i], downstream_grads[i], + sim, ss, sv, scratch2, scratch); for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { for (int k = partial_fused_circuits[i][j].size() - 1; k >= 0; k--) { @@ -237,7 +237,8 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; } - for (size_t k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); k++) { + for (size_t k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); + k++) { // Copy sv onto scratch2 in anticipation of non-unitary "gradient // gate". ss.Copy(sv, scratch2); @@ -321,8 +322,8 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { // sv now contains psi // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> // scratch2 now contains psi as well. - Status unused = AccumulateOperators(pauli_sums[i], downstream_grads[i], - sim, ss, sv, scratch2, scratch); + [[maybe_unused]] AccumulateOperators(pauli_sums[i], downstream_grads[i], + sim, ss, sv, scratch2, scratch); for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { for (int k = partial_fused_circuits[i][j].size() - 1; k >= 0; k--) { @@ -348,7 +349,8 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; } - for (size_t k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); k++) { + for (size_t k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); + k++) { // Copy sv onto scratch2 in anticipation of non-unitary "gradient // gate". ss.Copy(sv, scratch2); diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc index 08caaab4e..e0485841b 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc @@ -39,11 +39,11 @@ limitations under the License. namespace tfq { namespace { - // TODO(jaeyoo): Temorary hack for BulkSetAmpl with cuda ops. - // Updates qsim custatevec side BulkSetAmple ops, and remove these utilities. - template -__global__ void BulkSetAmplKernel( - uint64_t mask, uint64_t bits, FP re, FP im, bool exclude, FP* state) { +// TODO(jaeyoo): Temorary hack for BulkSetAmpl with cuda ops. +// Updates qsim custatevec side BulkSetAmple ops, and remove these utilities. +template +__global__ void BulkSetAmplKernel(uint64_t mask, uint64_t bits, FP re, FP im, + bool exclude, FP* state) { uint64_t k1 = uint64_t{blockIdx.x} * blockDim.x + threadIdx.x; uint64_t k2 = 2 * k1 - threadIdx.x % warp_size; @@ -57,21 +57,21 @@ __global__ void BulkSetAmplKernel( // Sets state[i] = complex(re, im) where (i & mask) == bits. // if `exclude` is true then the criteria becomes (i & mask) != bits. -template +template void BulkSetAmpl(qsim::SimulatorCuStateVec::StateSpace::State& state, - uint64_t mask, uint64_t bits, fp_type re, - fp_type im, bool exclude = false) { + uint64_t mask, uint64_t bits, fp_type re, fp_type im, + bool exclude = false) { uint64_t size = uint64_t{1} << state.num_qubits(); unsigned threads = std::min(size, uint64_t{512}); unsigned blocks = size / threads; - BulkSetAmplKernel<<>>( - mask, bits, re, im, exclude, state.get()); + BulkSetAmplKernel<<>>(mask, bits, re, im, exclude, + state.get()); cudaPeekAtLastError(); cudaDeviceSynchronize(); } -} // namespace +} // namespace using ::tensorflow::Status; using ::tfq::proto::PauliSum; @@ -189,7 +189,6 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { output_tensor.setZero(); - ComputeLarge(num_qubits, qsim_circuits, maps, full_fuse, partial_fused_circuits, pauli_sums, gradient_gates, downstream_grads, context, &output_tensor); @@ -247,8 +246,8 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { // sv now contains psi // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> // scratch2 now contains psi as well. - Status unused = AccumulateOperators(pauli_sums[i], downstream_grads[i], - sim, ss, sv, scratch2, scratch); + [[maybe_unused]] AccumulateOperators(pauli_sums[i], downstream_grads[i], + sim, ss, sv, scratch2, scratch); for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { for (int k = partial_fused_circuits[i][j].size() - 1; k >= 0; k--) { @@ -274,7 +273,8 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; } - for (size_t k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); k++) { + for (size_t k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); + k++) { // Copy sv onto scratch2 in anticipation of non-unitary "gradient // gate". ss.Copy(sv, scratch2); diff --git a/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc b/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc index 045154185..9f2e8bdde 100644 --- a/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc +++ b/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc @@ -54,8 +54,8 @@ class TfqCircuitAppendOp : public tensorflow::OpKernel { auto DoWork = [&](int start, int end) { std::string temp; for (int i = start; i < end; i++) { - for (size_t j = 0; j < programs_to_append.at(i).circuit().moments().size(); - j++) { + for (size_t j = 0; + j < programs_to_append.at(i).circuit().moments().size(); j++) { Moment *new_moment = programs.at(i).mutable_circuit()->add_moments(); *new_moment = programs_to_append.at(i).circuit().moments(j); } diff --git a/tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc b/tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc index 8639d442f..6a38be061 100644 --- a/tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc +++ b/tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc @@ -167,8 +167,8 @@ class TfqPsSymbolReplaceOp : public tensorflow::OpKernel { output_tensor(pidx, sidx, j) = output_programs.at(pidx).at(sidx).at(j); } - for (size_t j = output_programs.at(pidx).at(sidx).size(); j < biggest_pad; - j++) { + for (size_t j = output_programs.at(pidx).at(sidx).size(); + j < biggest_pad; j++) { output_tensor(pidx, sidx, j) = empty_program; } } diff --git a/tensorflow_quantum/core/src/circuit_parser_qsim.cc b/tensorflow_quantum/core/src/circuit_parser_qsim.cc index 80f98a40f..2ab8277dd 100644 --- a/tensorflow_quantum/core/src/circuit_parser_qsim.cc +++ b/tensorflow_quantum/core/src/circuit_parser_qsim.cc @@ -187,8 +187,8 @@ inline Status TwoConstantGate( const unsigned int num_qubits, const unsigned int time, QsimCircuit* circuit, std::vector* metadata) { unsigned int q0, q1; - bool unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); - unused = absl::SimpleAtoi(op.qubits(1).id(), &q1); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q0); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(1).id(), &q1); auto gate = create_f(time, num_qubits - q0 - 1, num_qubits - q1 - 1); Status s = OptionalInsertControls(op, num_qubits, &gate); if (!s.ok()) { @@ -213,10 +213,10 @@ inline Status SingleEigenGate( const unsigned int num_qubits, const unsigned int time, QsimCircuit* circuit, std::vector* metadata) { unsigned int q0; - bool unused; + float exp, exp_s, gs; Status u; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q0); absl::optional exponent_symbol; u = ParseProtoArg(op, "exponent", param_map, &exp, &exponent_symbol); @@ -263,10 +263,10 @@ inline Status TwoEigenGate( QsimCircuit* circuit, std::vector* metadata) { unsigned int q0, q1; float exp, exp_s, gs; - bool unused; + Status u; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); - unused = absl::SimpleAtoi(op.qubits(1).id(), &q1); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q0); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(1).id(), &q1); absl::optional exponent_symbol; u = ParseProtoArg(op, "exponent", param_map, &exp, &exponent_symbol); @@ -402,10 +402,10 @@ inline Status PhasedXGate(const Operation& op, const SymbolMap& param_map, const unsigned int time, QsimCircuit* circuit, std::vector* metadata) { int q0; - bool unused; + float pexp, pexp_s, exp, exp_s, gs; Status u; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q0); absl::optional exponent_symbol; u = ParseProtoArg(op, "exponent", param_map, &exp, &exponent_symbol); @@ -462,11 +462,11 @@ inline Status FsimGate(const Operation& op, const SymbolMap& param_map, QsimCircuit* circuit, std::vector* metadata) { int q0, q1; - bool unused; + float theta, theta_s, phi, phi_s; Status u; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); - unused = absl::SimpleAtoi(op.qubits(1).id(), &q1); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q0); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(1).id(), &q1); absl::optional theta_symbol; u = ParseProtoArg(op, "theta", param_map, &theta, &theta_symbol); @@ -519,11 +519,11 @@ inline Status PhasedISwapGate(const Operation& op, const SymbolMap& param_map, const unsigned int time, QsimCircuit* circuit, std::vector* metadata) { int q0, q1; - bool unused; + float pexp, pexp_s, exp, exp_s; Status u; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); - unused = absl::SimpleAtoi(op.qubits(1).id(), &q1); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q0); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(1).id(), &q1); absl::optional exponent_symbol; u = ParseProtoArg(op, "exponent", param_map, &exp, &exponent_symbol); @@ -611,10 +611,10 @@ inline Status AsymmetricDepolarizingChannel(const Operation& op, const unsigned int time, NoisyQsimCircuit* ncircuit) { int q; - bool unused; + float p_x, p_y, p_z; Status u; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "p_x", {}, &p_x); u = ParseProtoArg(op, "p_y", {}, &p_y); @@ -633,10 +633,10 @@ inline Status DepolarizingChannel(const Operation& op, const unsigned int time, NoisyQsimCircuit* ncircuit) { int q; - bool unused; + float p; Status u; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "p", {}, &p); if (!u.ok()) { @@ -651,10 +651,10 @@ inline Status DepolarizingChannel(const Operation& op, inline Status GADChannel(const Operation& op, const unsigned int num_qubits, const unsigned int time, NoisyQsimCircuit* ncircuit) { int q; - bool unused; + float p, gamma; Status u; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "p", {}, &p); if (!u.ok()) { @@ -675,8 +675,8 @@ inline Status ResetChannel(const Operation& op, const unsigned int num_qubits, const unsigned int time, NoisyQsimCircuit* ncircuit) { int q; - bool unused; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); auto chan = qsim::Cirq::ResetChannel::Create(time, num_qubits - q - 1); ncircuit->channels.push_back(chan); @@ -688,10 +688,10 @@ inline Status AmplitudeDampingChannel(const Operation& op, const unsigned int time, NoisyQsimCircuit* ncircuit) { int q; - bool unused; + float gamma; Status u; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "gamma", {}, &gamma); if (!u.ok()) { @@ -708,10 +708,10 @@ inline Status PhaseDampingChannel(const Operation& op, const unsigned int time, NoisyQsimCircuit* ncircuit) { int q; - bool unused; + float gamma; Status u; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "gamma", {}, &gamma); if (!u.ok()) { @@ -729,10 +729,10 @@ inline Status PhaseFlipChannel(const Operation& op, const unsigned int time, NoisyQsimCircuit* ncircuit) { int q; - bool unused; + float p; Status u; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "p", {}, &p); if (!u.ok()) { @@ -749,10 +749,10 @@ inline Status BitFlipChannel(const Operation& op, const unsigned int num_qubits, const unsigned int time, NoisyQsimCircuit* ncircuit) { int q; - bool unused; + float p; Status u; - unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "p", {}, &p); if (!u.ok()) { @@ -852,7 +852,7 @@ tensorflow::Status QsimCircuitFromProgram( // Convert proto to qsim internal representation. circuit->num_qubits = num_qubits; int time = 0; - bool unused; + // Special case empty. if (num_qubits <= 0) { return ::tensorflow::Status(); diff --git a/tensorflow_quantum/core/src/program_resolution.cc b/tensorflow_quantum/core/src/program_resolution.cc index 8a543b3f2..86e3ab897 100644 --- a/tensorflow_quantum/core/src/program_resolution.cc +++ b/tensorflow_quantum/core/src/program_resolution.cc @@ -373,7 +373,7 @@ Status CheckMPSSupported(const Program& program) { } if (total_num_qubits == 2) { - int j = 0; + size_t j = 0; std::vector qids(2, -1234); for (; j < qubits.size(); j++) { (void)absl::SimpleAtoi(qubits[j].id(), &qids[j]); diff --git a/tensorflow_quantum/python/layers/high_level/controlled_pqc.py b/tensorflow_quantum/python/layers/high_level/controlled_pqc.py index 45843519c..0f932d5df 100644 --- a/tensorflow_quantum/python/layers/high_level/controlled_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/controlled_pqc.py @@ -242,7 +242,8 @@ def __init__(self, use_cuquantum=use_cuquantum) else: self._layer = sampled_expectation.SampledExpectation( - backend=backend, differentiator=differentiator, + backend=backend, + differentiator=differentiator, use_cuquantum=use_cuquantum) self._append_layer = elementary.AddCircuit() From 35c27158154c4c7650872dbfb15a5d1afe340668 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 3 May 2023 02:55:57 +0000 Subject: [PATCH 075/106] Fix format lint and enable expecation test for cpu&gpu --- .../datasets/spin_system_test.py | 2 +- .../python/differentiators/adjoint.py | 9 +- .../circuit_executors/expectation_test.py | 857 +++++++++--------- .../python/layers/circuit_executors/sample.py | 6 +- .../python/layers/circuit_executors/state.py | 4 +- .../layers/high_level/controlled_pqc.py | 2 +- .../layers/high_level/noisy_controlled_pqc.py | 4 +- .../python/layers/high_level/noisy_pqc.py | 4 +- .../python/layers/high_level/pqc.py | 3 +- 9 files changed, 469 insertions(+), 422 deletions(-) diff --git a/tensorflow_quantum/datasets/spin_system_test.py b/tensorflow_quantum/datasets/spin_system_test.py index 7053e461d..654b60e2a 100644 --- a/tensorflow_quantum/datasets/spin_system_test.py +++ b/tensorflow_quantum/datasets/spin_system_test.py @@ -28,7 +28,7 @@ # TODO(#748): Inherit this class from tf.test.TestCase after fixing the issue. -class TFIRectangularTest: +class TFIChainTest: """Testing tfi_chain.""" # pylint: disable=C0103 diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index ba19efcfe..0d8886d59 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -33,9 +33,10 @@ class Adjoint(differentiator.Differentiator): https://academic.oup.com/gji/article-pdf/167/2/495/1492368/167-2-495.pdf). The Adjoint method differentiates the input circuits in roughly one forward and backward pass over the circuits, to calculate the gradient of - a symbol only a constant number of gate operations need to be applied to the - circuits state. When the number of parameters in a circuit is very large, - this differentiator performs much better than all the others found in TFQ. + a symbol only a constant number of gate operations need to be applied to + the circuits state. When the number of parameters in a circuit is very + large, this differentiator performs much better than all the others found + in TFQ. >>> my_op = tfq.get_expectation_op() @@ -114,6 +115,7 @@ def differentiate_analytic_cuquantum( forward_pass_vals, grad, ): + """Returns cuquantum adjoint gradient op result.""" return tfq_adj_grad_op_cuquantum.tfq_adj_grad(programs, symbol_names, symbol_values, pauli_sums, grad) @@ -129,6 +131,7 @@ def differentiate_analytic( forward_pass_vals, grad, ): + """Returns cpu adjoint gradient op result.""" return tfq_adj_grad_op.tfq_adj_grad(programs, symbol_names, symbol_values, pauli_sums, grad) diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py index 808e82101..1b6a6a98d 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py @@ -47,271 +47,284 @@ def _gen_single_bit_rotation_problem(bit, symbols, noisy): return circuit -# class ExpectationTest(tf.test.TestCase): -# """Basic tests for the expectation layer.""" - -# def test_expectation_instantiate(self): -# """Test that Expectation instantiates correctly.""" -# expectation.Expectation() -# expectation.Expectation(backend=None) -# expectation.Expectation(backend='noisy') -# expectation.Expectation(backend='noiseless') -# expectation.Expectation(backend=cirq.Simulator()) -# expectation.Expectation( -# differentiator=linear_combination.ForwardDifference()) - -# def test_expectation_instantiate_error(self): -# """Test that Expectation errors with bad inputs.""" - -# class MySampler(cirq.Sampler): -# """Class to test sampler detection in Expectation.""" - -# def run_sweep(self): -# """do nothing.""" -# return - -# with self.assertRaisesRegex(TypeError, -# expected_regex="SampledExpectation"): -# expectation.Expectation(backend=MySampler()) - -# with self.assertRaisesRegex( -# TypeError, expected_regex="SimulatesExpectationValues or None"): -# expectation.Expectation(backend='junk') - -# with self.assertRaisesRegex( -# TypeError, expected_regex="tfq.differentiators.Differentiator"): -# expectation.Expectation(differentiator='junk') - -# def test_expectation_type_inputs_error(self): -# """Test that expectation errors within Keras call.""" - -# bit = cirq.GridQubit(0, 0) -# test_pstring = cirq.Z(bit) -# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) -# reg_circuit = cirq.Circuit(cirq.H(bit)) - -# with self.assertRaisesRegex(Exception, -# expected_regex="Unknown initializer"): -# expectation.Expectation()(reg_circuit, -# operators=test_psum, -# initializer='junk') - -# with self.assertRaisesRegex(Exception, -# expected_regex="repetitions not provided"): -# expectation.Expectation(backend='noisy')(reg_circuit, -# operators=test_psum) - -# with self.assertRaisesRegex(Exception, -# expected_regex="cannot be parsed"): -# expectation.Expectation(backend='noisy')(reg_circuit, -# operators=test_psum, -# repetitions='junk') - -# with self.assertRaisesRegex(Exception, expected_regex="noiseless"): -# expectation.Expectation(backend='noiseless')(reg_circuit, -# operators=test_psum, -# repetitions=1) - -# def test_expectation_op_error(self): -# """Test that expectation errors within underlying ops correctly.""" - -# bit = cirq.GridQubit(0, 0) -# symbol = sympy.Symbol('alpha') -# test_pstring = cirq.Z(bit) -# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) -# symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) -# reg_circuit = cirq.Circuit(cirq.H(bit)) - -# with self.assertRaisesRegex(Exception, -# expected_regex="Could not find symbol"): -# # No symbol matchups. -# expectation.Expectation()([symb_circuit], operators=test_psum) - -# with self.assertRaisesRegex(Exception, -# expected_regex="Unparseable proto"): -# # Proto is unparseable. -# expectation.Expectation()([reg_circuit], -# operators=tf.convert_to_tensor( -# [['bad_operator']])) - -# with self.assertRaisesRegex(Exception, expected_regex="rank 2"): -# # Operators has wrong rank. -# expectation.Expectation()([reg_circuit], -# operators=util.convert_to_tensor( -# [test_psum])) - -# with self.assertRaisesRegex(Exception, expected_regex="rank 2"): -# # symbol_values has wrong rank. -# expectation.Expectation()([symb_circuit], -# symbol_names=[symbol], -# symbol_values=[0.5], -# operators=test_psum) - -# with self.assertRaisesRegex(Exception, expected_regex="do not match."): -# # Wrong batch size for pauli operators. -# expectation.Expectation()(symb_circuit, -# symbol_names=[symbol], -# operators=[[test_psum], [test_psum]]) - -# with self.assertRaisesRegex(Exception, expected_regex="do not match."): -# # Wrong batch_size for symbol values. -# expectation.Expectation()([symb_circuit], -# symbol_names=[symbol], -# symbol_values=np.zeros((3, 1)), -# operators=test_psum) - -# def test_static_cases(self): -# """Run inputs through in complex cases.""" - -# bit = cirq.GridQubit(0, 0) -# symbol = sympy.Symbol('alpha') -# test_pstring = cirq.Z(bit) -# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) -# symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) -# reg_circuit = cirq.Circuit(cirq.H(bit)) - -# # Passing a 2d operators input requires a 1d circuit input. -# expectation.Expectation()([reg_circuit, reg_circuit], -# operators=[[test_psum, test_psum], -# [test_psum, test_psum]]) - -# # Passing 2d operators along with other inputs. -# expectation.Expectation()([symb_circuit, symb_circuit], -# symbol_names=[symbol], -# operators=[[test_psum, test_psum], -# [test_psum, test_psum]]) -# expectation.Expectation()([symb_circuit, symb_circuit], -# symbol_names=[symbol], -# symbol_values=[[0.5], [0.8]], -# operators=[[test_psum, test_psum], -# [test_psum, test_psum]]) - -# # Ensure tiling up of circuits works as expected. -# expectation.Expectation()(reg_circuit, operators=test_psum) -# expectation.Expectation()(reg_circuit, operators=[test_psum, test_psum]) - -# # Ensure tiling up of symbol_values works as expected. -# expectation.Expectation()(symb_circuit, -# symbol_names=[symbol], -# symbol_values=[[0.5], [0.8]], -# operators=test_psum) -# expectation.Expectation()(symb_circuit, -# symbol_names=[symbol], -# symbol_values=[[0.5]], -# operators=test_psum) - -# def test_static_cases_noisy(self): -# """Test that the noisy trajectory backend works in complex cases.""" -# bit = cirq.GridQubit(0, 0) -# symbol = sympy.Symbol('alpha') -# test_pstring = cirq.Z(bit) -# test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) -# symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) -# reg_circuit = cirq.Circuit(cirq.H(bit)) - -# # Passing a 2d operators input requires a 1d circuit input. -# expectation.Expectation(backend='noisy')( -# [reg_circuit, reg_circuit], -# operators=[[test_psum, test_psum], [test_psum, test_psum]], -# repetitions=1) - -# # Passing 2d operators along with other inputs. -# expectation.Expectation(backend='noisy')( -# [symb_circuit, symb_circuit], -# symbol_names=[symbol], -# operators=[[test_psum, test_psum], [test_psum, test_psum]], -# repetitions=1) -# expectation.Expectation(backend='noisy')( -# [symb_circuit, symb_circuit], -# symbol_names=[symbol], -# symbol_values=[[0.5], [0.8]], -# operators=[[test_psum, test_psum], [test_psum, test_psum]], -# repetitions=1) - -# # Ensure tiling up of circuits works as expected. -# expectation.Expectation(backend='noisy')(reg_circuit, -# operators=test_psum, -# repetitions=1) -# expectation.Expectation(backend='noisy')( -# reg_circuit, operators=[test_psum, test_psum], repetitions=1) - -# # Ensure tiling up of symbol_values works as expected. -# expectation.Expectation(backend='noisy')(symb_circuit, -# symbol_names=[symbol], -# symbol_values=[[0.5], [0.8]], -# operators=test_psum, -# repetitions=1) -# expectation.Expectation(backend='noisy')(symb_circuit, -# symbol_names=[symbol], -# symbol_values=[[0.5]], -# operators=test_psum, -# repetitions=1) - -# # Test multiple operators with integer valued repetition. -# expectation.Expectation(backend='noisy')( -# symb_circuit, -# symbol_names=[symbol], -# symbol_values=[[0.5]], -# operators=[-1.0 * cirq.Z(bit), -# cirq.X(bit) + 2.0 * cirq.Z(bit)], -# repetitions=1) -# expectation.Expectation(backend='noisy')( -# symb_circuit, -# symbol_names=[symbol], -# symbol_values=[[0.5]], -# operators=[-1.0 * cirq.Z(bit), -# cirq.X(bit) + 2.0 * cirq.Z(bit)], -# repetitions=[5, 1]) - -# # Test 2d repetitions. -# expectation.Expectation(backend='noisy')( -# [symb_circuit, symb_circuit], -# symbol_names=[symbol], -# symbol_values=[[0.5], [0.4]], -# operators=[[ -# -1.0 * cirq.Z(bit), -# cirq.X(bit) + 2.0 * cirq.Z(bit), -# cirq.Z(bit) -# ], [cirq.Z(bit), cirq.Z(bit), cirq.Z(bit)]], -# repetitions=[[1, 2, 3], [4, 5, 6]]) - -# def test_expectation_simple_tf_train(self): -# """Train a layer using standard tf (not keras). -# This is a subtle test that will work since we don't use keras compile. -# """ -# bit = cirq.GridQubit(0, 0) -# circuit = \ -# cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) -# op = cirq.Z(bit) -# layer = expectation.Expectation() -# optimizer = tf.optimizers.Adam(learning_rate=0.05) -# for _ in range(200): -# with tf.GradientTape() as tape: -# circuit_out = layer(circuit, -# symbol_names=['theta'], -# operators=op) -# mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) -# grads = tape.gradient(mse, layer.trainable_weights) -# optimizer.apply_gradients(zip(grads, layer.trainable_weights)) -# self.assertAllClose(mse.numpy(), 0, atol=1e-3) +class ExpectationTest(tf.test.TestCase): + """Basic tests for the expectation layer.""" + + def test_expectation_instantiate(self): + """Test that Expectation instantiates correctly.""" + expectation.Expectation() + expectation.Expectation(backend=None) + expectation.Expectation(backend='noisy') + expectation.Expectation(backend='noiseless') + expectation.Expectation(backend=cirq.Simulator()) + expectation.Expectation( + differentiator=linear_combination.ForwardDifference()) + + def test_expectation_instantiate_error(self): + """Test that Expectation errors with bad inputs.""" + + class MySampler(cirq.Sampler): + """Class to test sampler detection in Expectation.""" + + def run_sweep(self): + """do nothing.""" + return + + with self.assertRaisesRegex(TypeError, + expected_regex="SampledExpectation"): + expectation.Expectation(backend=MySampler()) + + with self.assertRaisesRegex( + TypeError, + expected_regex="SimulatesExpectationValues or None", + ): + expectation.Expectation(backend='junk') + + with self.assertRaisesRegex( + TypeError, + expected_regex="tfq.differentiators.Differentiator", + ): + expectation.Expectation(differentiator='junk') + + def test_expectation_type_inputs_error(self): + """Test that expectation errors within Keras call.""" + + bit = cirq.GridQubit(0, 0) + test_pstring = cirq.Z(bit) + test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) + reg_circuit = cirq.Circuit(cirq.H(bit)) + + with self.assertRaisesRegex(Exception, + expected_regex="Unknown initializer"): + expectation.Expectation()(reg_circuit, + operators=test_psum, + initializer='junk') + + with self.assertRaisesRegex(Exception, + expected_regex="repetitions not provided"): + expectation.Expectation(backend='noisy')(reg_circuit, + operators=test_psum) + + with self.assertRaisesRegex(Exception, + expected_regex="cannot be parsed"): + expectation.Expectation(backend='noisy')(reg_circuit, + operators=test_psum, + repetitions='junk') + + with self.assertRaisesRegex(Exception, expected_regex="noiseless"): + expectation.Expectation(backend='noiseless')(reg_circuit, + operators=test_psum, + repetitions=1) + + def test_expectation_op_error(self): + """Test that expectation errors within underlying ops correctly.""" + + bit = cirq.GridQubit(0, 0) + symbol = sympy.Symbol('alpha') + test_pstring = cirq.Z(bit) + test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) + symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) + reg_circuit = cirq.Circuit(cirq.H(bit)) + + with self.assertRaisesRegex(Exception, + expected_regex="Could not find symbol"): + # No symbol matchups. + expectation.Expectation()([symb_circuit], operators=test_psum) + + with self.assertRaisesRegex(Exception, + expected_regex="Unparseable proto"): + # Proto is unparseable. + expectation.Expectation()([reg_circuit], + operators=tf.convert_to_tensor( + [['bad_operator']])) + + with self.assertRaisesRegex(Exception, expected_regex="rank 2"): + # Operators has wrong rank. + expectation.Expectation()([reg_circuit], + operators=util.convert_to_tensor( + [test_psum])) + + with self.assertRaisesRegex(Exception, expected_regex="rank 2"): + # symbol_values has wrong rank. + expectation.Expectation()([symb_circuit], + symbol_names=[symbol], + symbol_values=[0.5], + operators=test_psum) + + with self.assertRaisesRegex(Exception, expected_regex="do not match."): + # Wrong batch size for pauli operators. + expectation.Expectation()(symb_circuit, + symbol_names=[symbol], + operators=[[test_psum], [test_psum]]) + + with self.assertRaisesRegex(Exception, expected_regex="do not match."): + # Wrong batch_size for symbol values. + expectation.Expectation()([symb_circuit], + symbol_names=[symbol], + symbol_values=np.zeros((3, 1)), + operators=test_psum) + + def test_static_cases(self): + """Run inputs through in complex cases.""" + + bit = cirq.GridQubit(0, 0) + symbol = sympy.Symbol('alpha') + test_pstring = cirq.Z(bit) + test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) + symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) + reg_circuit = cirq.Circuit(cirq.H(bit)) + + # Passing a 2d operators input requires a 1d circuit input. + expectation.Expectation()([reg_circuit, reg_circuit], + operators=[[test_psum, test_psum], + [test_psum, test_psum]]) + + # Passing 2d operators along with other inputs. + expectation.Expectation()([symb_circuit, symb_circuit], + symbol_names=[symbol], + operators=[[test_psum, test_psum], + [test_psum, test_psum]]) + expectation.Expectation()([symb_circuit, symb_circuit], + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=[[test_psum, test_psum], + [test_psum, test_psum]]) + + # Ensure tiling up of circuits works as expected. + expectation.Expectation()(reg_circuit, operators=test_psum) + expectation.Expectation()( + reg_circuit, + operators=[test_psum, test_psum], + ) + + # Ensure tiling up of symbol_values works as expected. + expectation.Expectation()(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=test_psum) + expectation.Expectation()(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=test_psum) + + def test_static_cases_noisy(self): + """Test that the noisy trajectory backend works in complex cases.""" + bit = cirq.GridQubit(0, 0) + symbol = sympy.Symbol('alpha') + test_pstring = cirq.Z(bit) + test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) + symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) + reg_circuit = cirq.Circuit(cirq.H(bit)) + + # Passing a 2d operators input requires a 1d circuit input. + expectation.Expectation(backend='noisy')( + [reg_circuit, reg_circuit], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) + + # Passing 2d operators along with other inputs. + expectation.Expectation(backend='noisy')( + [symb_circuit, symb_circuit], + symbol_names=[symbol], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) + expectation.Expectation(backend='noisy')( + [symb_circuit, symb_circuit], + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) + + # Ensure tiling up of circuits works as expected. + expectation.Expectation(backend='noisy')(reg_circuit, + operators=test_psum, + repetitions=1) + expectation.Expectation(backend='noisy')( + reg_circuit, operators=[test_psum, test_psum], repetitions=1) + + # Ensure tiling up of symbol_values works as expected. + expectation.Expectation(backend='noisy')(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=test_psum, + repetitions=1) + expectation.Expectation(backend='noisy')(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=test_psum, + repetitions=1) + + # Test multiple operators with integer valued repetition. + expectation.Expectation(backend='noisy')( + symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=[-1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit)], + repetitions=1) + expectation.Expectation(backend='noisy')( + symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=[-1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit)], + repetitions=[5, 1]) + + # Test 2d repetitions. + expectation.Expectation(backend='noisy')( + [symb_circuit, symb_circuit], + symbol_names=[symbol], + symbol_values=[[0.5], [0.4]], + operators=[[ + -1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit), + cirq.Z(bit) + ], [cirq.Z(bit), cirq.Z(bit), cirq.Z(bit)]], + repetitions=[[1, 2, 3], [4, 5, 6]]) + + def test_expectation_simple_tf_train(self): + """Train a layer using standard tf (not keras). + This is a subtle test that will work since we don't use keras compile. + """ + bit = cirq.GridQubit(0, 0) + circuit = \ + cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) + op = cirq.Z(bit) + layer = expectation.Expectation() + optimizer = tf.optimizers.Adam(learning_rate=0.05) + for _ in range(200): + with tf.GradientTape() as tape: + circuit_out = layer(circuit, + symbol_names=['theta'], + operators=op) + mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) + grads = tape.gradient(mse, layer.trainable_weights) + optimizer.apply_gradients(zip(grads, layer.trainable_weights)) + self.assertAllClose(mse.numpy(), 0, atol=1e-3) class ExpectationFunctionalTests(parameterized.TestCase, tf.test.TestCase): """Test hybrid/integrated models that include an expectation layer.""" @parameterized.parameters([ - # { - # 'backend': 'noisy' - # }, { - 'backend': None # old API usage + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': None, # old API usage + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, } ]) - def test_simple_param_value_input(self, backend): + def test_simple_param_value_input(self, backend, use_cuquantum): """Train a densely connected hybrid model. - This model will put a qubit in the zero or one state from a random state - given the input zero or one. This tests the input signature: + This model will put a qubit in the zero or one state from a random + state given the input zero or one. This tests the input signature: Expectation([input_value_batch]). """ noisy = backend == 'noisy' @@ -324,12 +337,14 @@ def test_simple_param_value_input(self, backend): l1 = tf.keras.layers.Dense(10)(inputs) l2 = tf.keras.layers.Dense(3)(l1) reps = 1000 if noisy else None - outputs = expectation.Expectation(backend=backend, use_cuquantum=True)( - datum, - symbol_names=symbols, - operators=cirq.Z(bit), - symbol_values=l2, - repetitions=reps) + outputs = expectation.Expectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(datum, + symbol_names=symbols, + operators=cirq.Z(bit), + symbol_values=l2, + repetitions=reps) model = tf.keras.Model(inputs=[datum, inputs], outputs=outputs) data_in = np.array([[1], [0]], dtype=np.float32) @@ -344,153 +359,181 @@ def test_simple_param_value_input(self, backend): tol = 5e-2 if noisy else 1e-3 self.assertAllClose(history.history['loss'][-1], 0, atol=tol) - # @parameterized.parameters([ - # { - # 'backend': 'noisy' - # }, - # { - # 'backend': None # old API usage - # } - # ]) - # def test_simple_op_input(self, backend): - # """Test a simple operator input - - # Learn qubit in the z+ state using two different measurement operators. - # This tests input signature Expectation([operator_batch]) - # """ - # noisy = backend == 'noisy' - # bit = cirq.GridQubit(0, 0) - # symbols = sympy.symbols('x, y, z') - - # circuits = util.convert_to_tensor( - # [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) - - # data_out = tf.convert_to_tensor(np.array([[1], [1]])) - # ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) - - # circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) - # op_input = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) - - # reps = 1000 if noisy else None - # output = expectation.Expectation(backend=backend)( - # circuit_input, - # symbol_names=symbols, - # operators=op_input, - # initializer=tf.keras.initializers.RandomNormal(), - # repetitions=reps) - - # model = tf.keras.Model(inputs=[circuit_input, op_input], outputs=output) - - # model.compile( - # optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), - # loss=tf.keras.losses.mean_squared_error, - # ) - # history = model.fit(x=[circuits, ops], - # y=data_out, - # batch_size=2, - # epochs=200) - # tol = 5e-2 if noisy else 1e-3 - # self.assertAllClose(history.history['loss'][-1], 0, atol=tol) - - # @parameterized.parameters([ - # { - # 'backend': 'noisy' - # }, - # { - # 'backend': None # old api usage. - # }, - # { - # 'backend': cirq.Simulator() - # } - # ]) - # def test_simple_op_and_param_input(self, backend): - # """Test a simple operator and parameter input. - - # Train a NN to put a qubit in the z+ or x+ states based on a classical - # binary input. This tests the input signature: - # Expectation([value_batch, operator_batch]). - # """ - # noisy = backend == 'noisy' - # bit = cirq.GridQubit(0, 0) - # symbols = sympy.symbols('x, y, z') - # ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.X(bit)]]) - # circuits = util.convert_to_tensor( - # [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) - # data_in = np.array([[1], [0]]) - # data_out = np.array([[1], [1]]) - - # data_inp = tf.keras.Input(shape=(1), dtype=tf.dtypes.float32) - # op_inp = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) - # circuit_inp = tf.keras.Input(shape=(), dtype=tf.dtypes.string) - # dense_1 = tf.keras.layers.Dense(10)(data_inp) - # dense_2 = tf.keras.layers.Dense(3)(dense_1) - # reps = 1000 if noisy else None - # circuit_output = expectation.Expectation(backend=backend)( - # circuit_inp, - # symbol_names=symbols, - # symbol_values=dense_2, - # operators=op_inp, - # repetitions=reps) - - # functional_model = tf.keras.Model( - # inputs=[data_inp, op_inp, circuit_inp], outputs=[circuit_output]) - - # functional_model.compile( - # optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), - # loss=tf.keras.losses.mean_squared_error) - # history = functional_model.fit(x=[data_in, ops, circuits], - # y=data_out, - # batch_size=2, - # epochs=100) - # tol = 5e-2 if noisy else 1e-3 - # self.assertAllClose(history.history['loss'][-1], 0, atol=tol) - - # @parameterized.parameters([ - # { - # 'backend': 'noisy' - # }, - # { - # 'backend': None # old api usage. - # } - # ]) - # def test_dnn_qnn_dnn(self, backend): - # """Train a fully hybrid network using an Expectation layer. - - # Train the network to output +-5 given an input of 1 or 0. This tests - # that everything works when Expectation layer is a middle layers. - # """ - # noisy = backend == 'noisy' - # bit = cirq.GridQubit(0, 0) - # symbols = sympy.symbols('x, y, z') - # circuits = util.convert_to_tensor( - # [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) - # data_in = np.array([[1], [0]], dtype=np.float32) - # data_out = np.array([[5], [-5]], dtype=np.float32) - - # classical_input = tf.keras.Input(shape=(1,)) - # circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) - # d1 = tf.keras.layers.Dense(10)(classical_input) - # d2 = tf.keras.layers.Dense(3)(d1) - # reps = 1000 if noisy else None - # quantum = expectation.Expectation(backend=backend)( - # circuit_input, - # symbol_names=symbols, - # symbol_values=d2, - # operators=cirq.Z(bit), - # repetitions=reps) - # d3 = tf.keras.layers.Dense(1)(quantum) - - # model = tf.keras.Model(inputs=[circuit_input, classical_input], - # outputs=d3) - - # model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), - # loss=tf.keras.losses.mean_squared_error) - # history = model.fit(x=[circuits, data_in], - # y=data_out, - # batch_size=2, - # epochs=300) - # tol = 5e-2 if noisy else 1e-3 - # self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + @parameterized.parameters([ + { + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': None, # old API usage + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, + } + ]) + def test_simple_op_input(self, backend, use_cuquantum): + """Test a simple operator input + + Learn qubit in the z+ state using two different measurement operators. + This tests input signature Expectation([operator_batch]) + """ + noisy = backend == 'noisy' + bit = cirq.GridQubit(0, 0) + symbols = sympy.symbols('x, y, z') + + circuits = util.convert_to_tensor( + [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) + + data_out = tf.convert_to_tensor(np.array([[1], [1]])) + ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) + + circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) + op_input = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) + + reps = 1000 if noisy else None + output = expectation.Expectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(circuit_input, + symbol_names=symbols, + operators=op_input, + initializer=tf.keras.initializers.RandomNormal(), + repetitions=reps) + + model = tf.keras.Model( + inputs=[circuit_input, op_input], + outputs=output, + ) + + model.compile( + optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), + loss=tf.keras.losses.mean_squared_error, + ) + history = model.fit(x=[circuits, ops], + y=data_out, + batch_size=2, + epochs=200) + tol = 5e-2 if noisy else 1e-3 + self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + + @parameterized.parameters([ + { + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': None, # old api usage. + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, + }, + { + 'backend': cirq.Simulator(), + 'use_cuquantum': False, + } + ]) + def test_simple_op_and_param_input(self, backend, use_cuquantum): + """Test a simple operator and parameter input. + + Train a NN to put a qubit in the z+ or x+ states based on a classical + binary input. This tests the input signature: + Expectation([value_batch, operator_batch]). + """ + noisy = backend == 'noisy' + bit = cirq.GridQubit(0, 0) + symbols = sympy.symbols('x, y, z') + ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.X(bit)]]) + circuits = util.convert_to_tensor( + [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) + data_in = np.array([[1], [0]]) + data_out = np.array([[1], [1]]) + + data_inp = tf.keras.Input(shape=(1), dtype=tf.dtypes.float32) + op_inp = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) + circuit_inp = tf.keras.Input(shape=(), dtype=tf.dtypes.string) + dense_1 = tf.keras.layers.Dense(10)(data_inp) + dense_2 = tf.keras.layers.Dense(3)(dense_1) + reps = 1000 if noisy else None + circuit_output = expectation.Expectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(circuit_inp, + symbol_names=symbols, + symbol_values=dense_2, + operators=op_inp, + repetitions=reps) + + functional_model = tf.keras.Model( + inputs=[data_inp, op_inp, circuit_inp], outputs=[circuit_output]) + + functional_model.compile( + optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), + loss=tf.keras.losses.mean_squared_error) + history = functional_model.fit(x=[data_in, ops, circuits], + y=data_out, + batch_size=2, + epochs=100) + tol = 5e-2 if noisy else 1e-3 + self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + + @parameterized.parameters([ + { + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': None, # old API usage + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, + } + ]) + def test_dnn_qnn_dnn(self, backend, use_cuquantum): + """Train a fully hybrid network using an Expectation layer. + + Train the network to output +-5 given an input of 1 or 0. This tests + that everything works when Expectation layer is a middle layers. + """ + noisy = backend == 'noisy' + bit = cirq.GridQubit(0, 0) + symbols = sympy.symbols('x, y, z') + circuits = util.convert_to_tensor( + [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) + data_in = np.array([[1], [0]], dtype=np.float32) + data_out = np.array([[5], [-5]], dtype=np.float32) + + classical_input = tf.keras.Input(shape=(1,)) + circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) + d1 = tf.keras.layers.Dense(10)(classical_input) + d2 = tf.keras.layers.Dense(3)(d1) + reps = 1000 if noisy else None + quantum = expectation.Expectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(circuit_input, + symbol_names=symbols, + symbol_values=d2, + operators=cirq.Z(bit), + repetitions=reps) + d3 = tf.keras.layers.Dense(1)(quantum) + + model = tf.keras.Model(inputs=[circuit_input, classical_input], + outputs=d3) + + model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), + loss=tf.keras.losses.mean_squared_error) + history = model.fit(x=[circuits, data_in], + y=data_out, + batch_size=2, + epochs=300) + tol = 5e-2 if noisy else 1e-3 + self.assertAllClose(history.history['loss'][-1], 0, atol=tol) if __name__ == '__main__': diff --git a/tensorflow_quantum/python/layers/circuit_executors/sample.py b/tensorflow_quantum/python/layers/circuit_executors/sample.py index 4de2964ab..e840172e7 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample.py @@ -155,11 +155,11 @@ def __init__(self, backend='noiseless', use_cuquantum=False, **kwargs): super().__init__(**kwargs) used_op = None if backend == 'noiseless': - used_op = circuit_execution_ops.get_sampling_op(None, \ - use_cuquantum=use_cuquantum) + used_op = circuit_execution_ops.get_sampling_op( + None, use_cuquantum=use_cuquantum) elif backend == 'noisy': if use_cuquantum: - raise ValueError('noisy backend does not currently support GPU') + raise ValueError('noisy backend has no GPU support.') used_op = noisy_samples_op.samples else: used_op = circuit_execution_ops.get_sampling_op(backend) diff --git a/tensorflow_quantum/python/layers/circuit_executors/state.py b/tensorflow_quantum/python/layers/circuit_executors/state.py index 8cc8d95b6..bf96848bf 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/state.py +++ b/tensorflow_quantum/python/layers/circuit_executors/state.py @@ -129,8 +129,8 @@ def __init__(self, backend=None, use_cuquantum=False, **kwargs): use_cuquantum: Calls TFQ GPU version op. """ super().__init__(**kwargs) - self.state_op = circuit_execution_ops.get_state_op(backend, \ - use_cuquantum=use_cuquantum) + self.state_op = circuit_execution_ops.get_state_op( + backend, use_cuquantum=use_cuquantum) def call(self, inputs, *, symbol_names=None, symbol_values=None): """Keras call function. diff --git a/tensorflow_quantum/python/layers/high_level/controlled_pqc.py b/tensorflow_quantum/python/layers/high_level/controlled_pqc.py index 0f932d5df..b35e4f69b 100644 --- a/tensorflow_quantum/python/layers/high_level/controlled_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/controlled_pqc.py @@ -154,7 +154,7 @@ def __init__(self, `sampled_based` is True or it must inherit `cirq.sim.simulator.SimulatesExpectationValues` if `sample_based` is False. - use_cuquantum: Optional Python `bool` indicating whether or not to use + use_cuquantum: Optional Python `bool` indicating whether or not to use GPU ops differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. diff --git a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py index 593177fbf..203a9cc10 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py @@ -164,8 +164,8 @@ def __init__(self, trajectory. differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. - use_cuquantum: Optional `bool` indicating whether to use GPU for simulation - or not. Defaults to `False`. NOT IMPLEMENTED YET. + use_cuquantum: Optional `bool` indicating whether to use GPU for + simulation or not. Defaults to `False`. NOT IMPLEMENTED YET. """ super().__init__(**kwargs) # Ingest model_circuit. diff --git a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py index 7084432cc..3cfdb6082 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py @@ -165,8 +165,8 @@ def __init__( trajectory. differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. - use_cuquantum: Python `bool` indicating whether to use GPU ops (currently - not supported/implemented). + use_cuquantum: Python `bool` indicating whether to use GPU ops + (currently not supported/implemented). initializer: Optional `tf.keras.initializer` object to specify how the symbols in `model_circuit` should be initialized when creating the managed variables. diff --git a/tensorflow_quantum/python/layers/high_level/pqc.py b/tensorflow_quantum/python/layers/high_level/pqc.py index a2d9a4138..7d05cc922 100644 --- a/tensorflow_quantum/python/layers/high_level/pqc.py +++ b/tensorflow_quantum/python/layers/high_level/pqc.py @@ -167,7 +167,8 @@ def __init__( `cirq.sim.simulator.SimulatesExpectationValues` if analytic expectations are desired or `cirq.Sampler` if sampled expectations are desired. - use_cuquantum: Optional Python `bool` indicating whether or not to use GPU ops + use_cuquantum: Optional Python `bool` indicating whether or not to use + GPU ops. differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. initializer: Optional `tf.keras.initializer` object to specify how the From 214709916b80d08d334d4b5a383e996aaaa202d8 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 3 May 2023 04:07:13 +0000 Subject: [PATCH 076/106] Fix [[maybe_unused]] decorator usage. --- .../core/src/circuit_parser_qsim.cc | 51 ++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/tensorflow_quantum/core/src/circuit_parser_qsim.cc b/tensorflow_quantum/core/src/circuit_parser_qsim.cc index 2ab8277dd..8b70ab041 100644 --- a/tensorflow_quantum/core/src/circuit_parser_qsim.cc +++ b/tensorflow_quantum/core/src/circuit_parser_qsim.cc @@ -187,8 +187,9 @@ inline Status TwoConstantGate( const unsigned int num_qubits, const unsigned int time, QsimCircuit* circuit, std::vector* metadata) { unsigned int q0, q1; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q0); - [[maybe_unused]] absl::SimpleAtoi(op.qubits(1).id(), &q1); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); + unused = absl::SimpleAtoi(op.qubits(1).id(), &q1); auto gate = create_f(time, num_qubits - q0 - 1, num_qubits - q1 - 1); Status s = OptionalInsertControls(op, num_qubits, &gate); if (!s.ok()) { @@ -216,7 +217,8 @@ inline Status SingleEigenGate( float exp, exp_s, gs; Status u; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q0); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); absl::optional exponent_symbol; u = ParseProtoArg(op, "exponent", param_map, &exp, &exponent_symbol); @@ -265,8 +267,9 @@ inline Status TwoEigenGate( float exp, exp_s, gs; Status u; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q0); - [[maybe_unused]] absl::SimpleAtoi(op.qubits(1).id(), &q1); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); + unused = absl::SimpleAtoi(op.qubits(1).id(), &q1); absl::optional exponent_symbol; u = ParseProtoArg(op, "exponent", param_map, &exp, &exponent_symbol); @@ -405,7 +408,8 @@ inline Status PhasedXGate(const Operation& op, const SymbolMap& param_map, float pexp, pexp_s, exp, exp_s, gs; Status u; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q0); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); absl::optional exponent_symbol; u = ParseProtoArg(op, "exponent", param_map, &exp, &exponent_symbol); @@ -465,8 +469,9 @@ inline Status FsimGate(const Operation& op, const SymbolMap& param_map, float theta, theta_s, phi, phi_s; Status u; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q0); - [[maybe_unused]] absl::SimpleAtoi(op.qubits(1).id(), &q1); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); + unused = absl::SimpleAtoi(op.qubits(1).id(), &q1); absl::optional theta_symbol; u = ParseProtoArg(op, "theta", param_map, &theta, &theta_symbol); @@ -522,8 +527,9 @@ inline Status PhasedISwapGate(const Operation& op, const SymbolMap& param_map, float pexp, pexp_s, exp, exp_s; Status u; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q0); - [[maybe_unused]] absl::SimpleAtoi(op.qubits(1).id(), &q1); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); + unused = absl::SimpleAtoi(op.qubits(1).id(), &q1); absl::optional exponent_symbol; u = ParseProtoArg(op, "exponent", param_map, &exp, &exponent_symbol); @@ -614,7 +620,8 @@ inline Status AsymmetricDepolarizingChannel(const Operation& op, float p_x, p_y, p_z; Status u; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "p_x", {}, &p_x); u = ParseProtoArg(op, "p_y", {}, &p_y); @@ -636,7 +643,8 @@ inline Status DepolarizingChannel(const Operation& op, float p; Status u; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "p", {}, &p); if (!u.ok()) { @@ -654,7 +662,8 @@ inline Status GADChannel(const Operation& op, const unsigned int num_qubits, float p, gamma; Status u; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "p", {}, &p); if (!u.ok()) { @@ -676,7 +685,8 @@ inline Status ResetChannel(const Operation& op, const unsigned int num_qubits, NoisyQsimCircuit* ncircuit) { int q; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); auto chan = qsim::Cirq::ResetChannel::Create(time, num_qubits - q - 1); ncircuit->channels.push_back(chan); @@ -691,7 +701,8 @@ inline Status AmplitudeDampingChannel(const Operation& op, float gamma; Status u; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "gamma", {}, &gamma); if (!u.ok()) { @@ -711,7 +722,8 @@ inline Status PhaseDampingChannel(const Operation& op, float gamma; Status u; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "gamma", {}, &gamma); if (!u.ok()) { @@ -732,7 +744,8 @@ inline Status PhaseFlipChannel(const Operation& op, float p; Status u; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "p", {}, &p); if (!u.ok()) { @@ -752,7 +765,8 @@ inline Status BitFlipChannel(const Operation& op, const unsigned int num_qubits, float p; Status u; - [[maybe_unused]] absl::SimpleAtoi(op.qubits(0).id(), &q); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); u = ParseProtoArg(op, "p", {}, &p); if (!u.ok()) { @@ -852,6 +866,7 @@ tensorflow::Status QsimCircuitFromProgram( // Convert proto to qsim internal representation. circuit->num_qubits = num_qubits; int time = 0; + [[maybe_unused]] bool unused; // Special case empty. if (num_qubits <= 0) { From 1e3a13e1a577a559ecbf7ef473914aa91a87e747 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 3 May 2023 04:07:31 +0000 Subject: [PATCH 077/106] Fix if-statements for backend & use_cuquantum for 4 major Keras layers. --- .../layers/circuit_executors/expectation.py | 24 +- .../python/layers/circuit_executors/sample.py | 11 +- .../layers/circuit_executors/sample_test.py | 32 +- .../circuit_executors/sampled_expectation.py | 12 +- .../sampled_expectation_test.py | 386 ++++++++++++------ .../python/layers/circuit_executors/state.py | 21 +- .../layers/circuit_executors/state_test.py | 37 +- 7 files changed, 351 insertions(+), 172 deletions(-) diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation.py b/tensorflow_quantum/python/layers/circuit_executors/expectation.py index bc5c846a0..22e91204d 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation.py @@ -244,20 +244,27 @@ def __init__(self, "Please use SampledExpectation instead.") used_op = None self.noisy = False - if backend == 'noiseless': - backend = None # Ingest differentiator. if differentiator is None: differentiator = parameter_shift.ParameterShift() - if backend is None: + if backend == 'noiseless' or backend is None: differentiator = adjoint.Adjoint() if not isinstance(differentiator, diff.Differentiator): raise TypeError("Differentiator must inherit from " "tfq.differentiators.Differentiator") - if backend == 'noisy': + if backend == 'noiseless' or backend is None: + mode = quantum_context.get_quantum_concurrent_op_mode() + quantum_concurrent = False if use_cuquantum else mode + used_op = circuit_execution_ops.get_expectation_op( + backend=None, + use_cuquantum=use_cuquantum, + quantum_concurrent=quantum_concurrent) + self._expectation_op = differentiator.generate_differentiable_op( + analytic_op=used_op, use_cuquantum=use_cuquantum) + elif backend == 'noisy': if use_cuquantum: raise ValueError("noisy backend does not currently support GPU") used_op = noisy_expectation_op.expectation @@ -265,14 +272,9 @@ def __init__(self, sampled_op=used_op) self.noisy = True else: - mode = quantum_context.get_quantum_concurrent_op_mode() - quantum_concurrent = False if use_cuquantum else mode - used_op = circuit_execution_ops.get_expectation_op( - backend=backend, - use_cuquantum=use_cuquantum, - quantum_concurrent=quantum_concurrent) + used_op = circuit_execution_ops.get_expectation_op(backend=backend) self._expectation_op = differentiator.generate_differentiable_op( - analytic_op=used_op, use_cuquantum=use_cuquantum) + analytic_op=used_op) self._w = None diff --git a/tensorflow_quantum/python/layers/circuit_executors/sample.py b/tensorflow_quantum/python/layers/circuit_executors/sample.py index e840172e7..80f27bafe 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample.py @@ -19,6 +19,7 @@ from tensorflow_quantum.core.ops import circuit_execution_ops from tensorflow_quantum.core.ops.noise import noisy_samples_op +from tensorflow_quantum.python import quantum_context from tensorflow_quantum.python.layers.circuit_executors import input_checks @@ -154,9 +155,13 @@ def __init__(self, backend='noiseless', use_cuquantum=False, **kwargs): """ super().__init__(**kwargs) used_op = None - if backend == 'noiseless': + if backend == 'noiseless' or backend is None: + mode = quantum_context.get_quantum_concurrent_op_mode() + quantum_concurrent = False if use_cuquantum else mode used_op = circuit_execution_ops.get_sampling_op( - None, use_cuquantum=use_cuquantum) + None, + use_cuquantum=use_cuquantum, + quantum_concurrent=quantum_concurrent) elif backend == 'noisy': if use_cuquantum: raise ValueError('noisy backend has no GPU support.') @@ -202,4 +207,4 @@ def call(self, inputs, symbol_names, symbol_values = input_checks.expand_circuits( inputs, symbol_names, symbol_values) - return self.sample_op(inputs, symbol_names, symbol_values, repetitions) \ No newline at end of file + return self.sample_op(inputs, symbol_names, symbol_values, repetitions) diff --git a/tensorflow_quantum/python/layers/circuit_executors/sample_test.py b/tensorflow_quantum/python/layers/circuit_executors/sample_test.py index d32127ce1..cb05d5242 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample_test.py @@ -85,21 +85,29 @@ def test_sample_invalid_shape_inputs(self): @parameterized.parameters([ { - 'backend': 'noiseless' + 'backend': 'noiseless', + 'use_cuquantum': False, }, { - 'backend': 'noisy' + 'backend': 'noisy', + 'use_cuquantum': False, }, { - 'backend': cirq.Simulator() + 'backend': cirq.Simulator(), + 'use_cuquantum': False, }, { - 'backend': None # old API usage. + 'backend': None, # old API usage. + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, } ]) - def test_sample_invalid_combinations(self, backend): + def test_sample_invalid_combinations(self, backend, use_cuquantum): """Test with valid type inputs and valid value, but incorrect combo.""" - sampler = sample.Sample(backend) + sampler = sample.Sample(backend, use_cuquantum=use_cuquantum) symbol = sympy.Symbol('alpha') circuit = cirq.Circuit(cirq.H(cirq.GridQubit(0, 0))**symbol) with self.assertRaisesRegex(Exception, expected_regex=""): @@ -168,18 +176,24 @@ def test_sample_outputs_simple(self): util.kwargs_cartesian_product( backend=['noiseless', 'noisy', cirq.Simulator(), None], + use_cuquantum=[False, True], all_n_qubits=[[3, 4, 10]], n_samples=[1], symbol_names=[[], ['a', 'b']]))) - def test_sample_output(self, backend, all_n_qubits, n_samples, - symbol_names): + def test_sample_output(self, backend, use_cuquantum, all_n_qubits, + n_samples, symbol_names): """Test that expected output format is preserved. Check that any pre or post processing done inside the layers does not cause what is output from the layer to structurally deviate from what is expected. """ - sampler = sample.Sample(backend=backend) + if use_cuquantum: + # If use_cuquantum is True, + if backend is not None and backend != 'noiseless': + return + # Passes backend=None or backend == 'noiseless' only. + sampler = sample.Sample(backend=backend, use_cuquantum=use_cuquantum) bits = cirq.GridQubit.rect(1, max(all_n_qubits)) programs = [] expected_outputs = [] diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py index 02abfd1b7..454fb61f1 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py @@ -22,6 +22,7 @@ import cirq from tensorflow_quantum.core.ops import circuit_execution_ops from tensorflow_quantum.core.ops.noise import noisy_sampled_expectation_op +from tensorflow_quantum.python import quantum_context from tensorflow_quantum.python.differentiators import differentiator as diff from tensorflow_quantum.python.differentiators import parameter_shift from tensorflow_quantum.python.layers.circuit_executors import input_checks @@ -251,16 +252,21 @@ def __init__(self, "not cirq.Sampler. Please use Expectation instead.") used_op = None - if backend == 'noiseless': + if backend == 'noiseless' or backend is None: + mode = quantum_context.get_quantum_concurrent_op_mode() + quantum_concurrent = False if use_cuquantum else mode used_op = circuit_execution_ops.get_sampled_expectation_op( - use_cuquantum=use_cuquantum) + backend=None, + use_cuquantum=use_cuquantum, + quantum_concurrent=quantum_concurrent, + ) elif backend == 'noisy': if use_cuquantum: raise ValueError('noisy backend does not currently support GPU') used_op = noisy_sampled_expectation_op.sampled_expectation else: used_op = circuit_execution_ops.get_sampled_expectation_op( - backend=backend, use_cuquantum=use_cuquantum) + backend=backend) self._expectation_op = differentiator.generate_differentiable_op( sampled_op=used_op) diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py index 4e96a5c49..e693068fc 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py @@ -97,22 +97,36 @@ def simulate_sweep(self): @parameterized.parameters([ { - 'backend': 'noisy' + 'backend': 'noisy', + 'use_cuquantum': False, }, { - 'backend': 'noiseless' + 'backend': 'noiseless', + 'use_cuquantum': False, }, { - 'backend': cirq.Simulator() + 'backend': 'noiseless', + 'use_cuquantum': True, }, { - 'backend': CustomSampler() + 'backend': cirq.Simulator(), + 'use_cuquantum': False, }, { - 'backend': None # older API usage. + 'backend': CustomSampler(), + 'use_cuquantum': False, + }, + { + 'backend': None, # older API usage. + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, } ]) - def test_sampled_expectation_type_inputs_error(self, backend): + def test_sampled_expectation_type_inputs_error(self, backend, + use_cuquantum): """Test that SampledExpectation errors within Keras call.""" bit = cirq.GridQubit(0, 0) @@ -124,43 +138,62 @@ def test_sampled_expectation_type_inputs_error(self, backend): with self.assertRaisesRegex(RuntimeError, expected_regex="repetitions not provided"): - sampled_expectation.SampledExpectation(backend=backend)( - symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=test_psum) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=test_psum) with self.assertRaisesRegex(Exception, expected_regex="Unknown initializer"): - sampled_expectation.SampledExpectation(backend=backend)( - reg_circuit, - operators=test_psum, - initializer='junk', - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, + operators=test_psum, + initializer='junk', + repetitions=1) with self.assertRaisesRegex(Exception, expected_regex="cannot be parsed"): - sampled_expectation.SampledExpectation(backend=backend)( - reg_circuit, operators=test_psum, repetitions='junk') + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, operators=test_psum, repetitions='junk') @parameterized.parameters([ { - 'backend': 'noisy' + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': 'noiseless', + 'use_cuquantum': False, }, { - 'backend': 'noiseless' + 'backend': 'noiseless', + 'use_cuquantum': True, }, { - 'backend': cirq.Simulator() + 'backend': cirq.Simulator(), + 'use_cuquantum': False, }, { - 'backend': CustomSampler() + 'backend': CustomSampler(), + 'use_cuquantum': False, }, { - 'backend': None # older API usage. + 'backend': None, # older API usage. + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, } ]) - def test_sampled_expectation_op_error(self, backend): + def test_sampled_expectation_op_error(self, backend, use_cuquantum): """Test that expectation errors within underlying ops correctly.""" # Note the expected_regex is left blank here since there is a # discrepancy between the error strings provided between backends. @@ -173,72 +206,97 @@ def test_sampled_expectation_op_error(self, backend): with self.assertRaisesRegex(Exception, expected_regex="pauli"): # Operators has wrong rank. Parse error. - sampled_expectation.SampledExpectation(backend=backend)( - [reg_circuit], - operators=util.convert_to_tensor([test_psum]), - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )([reg_circuit], + operators=util.convert_to_tensor([test_psum]), + repetitions=1) with self.assertRaisesRegex(Exception, expected_regex="symbol_values"): # symbol_values has wrong rank. - sampled_expectation.SampledExpectation(backend=backend)( - [symb_circuit], - symbol_names=[symbol], - symbol_values=[0.5], - operators=test_psum, - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )([symb_circuit], + symbol_names=[symbol], + symbol_values=[0.5], + operators=test_psum, + repetitions=1) with self.assertRaisesRegex(Exception, expected_regex="pauli"): # Wrong batch size for pauli operators. - sampled_expectation.SampledExpectation(backend=backend)( - symb_circuit, - symbol_names=[symbol], - operators=[[test_psum], [test_psum]], - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(symb_circuit, + symbol_names=[symbol], + operators=[[test_psum], [test_psum]], + repetitions=1) with self.assertRaisesRegex(Exception, expected_regex="pauli"): # Wrong batch size for pauli operators. - sampled_expectation.SampledExpectation(backend=backend)( - reg_circuit, - operators=[[test_psum], [test_psum]], - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, operators=[[test_psum], [test_psum]], repetitions=1) with self.assertRaisesRegex(Exception, expected_regex="0"): # Wrong repetitions. - sampled_expectation.SampledExpectation(backend=backend)( - reg_circuit, operators=test_psum, repetitions=-1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, operators=test_psum, repetitions=-1) with self.assertRaisesRegex(Exception, expected_regex=""): # Wrong second dimension size for repetitions & pauli operators. - sampled_expectation.SampledExpectation(backend=backend)( - reg_circuit, operators=test_psum, repetitions=[5, 4, 3]) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, operators=test_psum, repetitions=[5, 4, 3]) with self.assertRaisesRegex(Exception, expected_regex=""): # Wrong batch_size for symbol values. - sampled_expectation.SampledExpectation(backend=backend)( - [reg_circuit], - symbol_names=[symbol], - symbol_values=np.zeros((3, 1)), - operators=test_psum, - repetitions=5) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )([reg_circuit], + symbol_names=[symbol], + symbol_values=np.zeros((3, 1)), + operators=test_psum, + repetitions=5) @parameterized.parameters([ { - 'backend': 'noisy' + 'backend': 'noisy', + 'use_cuquantum': False, }, { - 'backend': 'noiseless' + 'backend': 'noiseless', + 'use_cuquantum': False, }, { - 'backend': cirq.Simulator() + 'backend': 'noiseless', + 'use_cuquantum': True, }, { - 'backend': CustomSampler() + 'backend': cirq.Simulator(), + 'use_cuquantum': False, }, { - 'backend': None # older API usage. + 'backend': CustomSampler(), + 'use_cuquantum': False, + }, + { + 'backend': None, # older API usage. + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, } ]) - def test_static_cases(self, backend): + def test_static_cases(self, backend, use_cuquantum): """Run inputs through in complex cases.""" bit = cirq.GridQubit(0, 0) @@ -249,59 +307,77 @@ def test_static_cases(self, backend): reg_circuit = cirq.Circuit(cirq.H(bit)) # Passing a 2d operators input requires a 1d circuit input. - sampled_expectation.SampledExpectation(backend=backend)( - [reg_circuit, reg_circuit], - operators=[[test_psum, test_psum], [test_psum, test_psum]], - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )([reg_circuit, reg_circuit], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) # Passing 2d operators along with other inputs. - sampled_expectation.SampledExpectation(backend=backend)( - [symb_circuit, symb_circuit], - symbol_names=[symbol], - operators=[[test_psum, test_psum], [test_psum, test_psum]], - repetitions=1) - sampled_expectation.SampledExpectation(backend=backend)( - [symb_circuit, symb_circuit], - symbol_names=[symbol], - symbol_values=[[0.5], [0.8]], - operators=[[test_psum, test_psum], [test_psum, test_psum]], - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )([symb_circuit, symb_circuit], + symbol_names=[symbol], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )([symb_circuit, symb_circuit], + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) # Ensure tiling up of circuits works as expected. - sampled_expectation.SampledExpectation(backend=backend)( - reg_circuit, operators=test_psum, repetitions=1) - sampled_expectation.SampledExpectation(backend=backend)( - reg_circuit, operators=[test_psum, test_psum], repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, operators=test_psum, repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, operators=[test_psum, test_psum], repetitions=1) # Ensure tiling up of symbol_values works as expected. - sampled_expectation.SampledExpectation(backend=backend)( - symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5], [0.8]], - operators=test_psum, - repetitions=1) - sampled_expectation.SampledExpectation(backend=backend)( - symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=test_psum, - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=test_psum, + repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=test_psum, + repetitions=1) # Test multiple operators with integer valued repetition. - sampled_expectation.SampledExpectation(backend=backend)( - symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=[-1.0 * cirq.Z(bit), - cirq.X(bit) + 2.0 * cirq.Z(bit)], - repetitions=1) - sampled_expectation.SampledExpectation(backend=backend)( - symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=[-1.0 * cirq.Z(bit), - cirq.X(bit) + 2.0 * cirq.Z(bit)], - repetitions=[5, 1]) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=[-1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit)], + repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=[-1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit)], + repetitions=[5, 1]) def test_sampled_expectation_simple_tf_train(self): """Train a layer using standard tf (not keras).""" @@ -325,8 +401,17 @@ class SampledExpectationFunctionalTests(parameterized.TestCase, tf.test.TestCase): """Test hybrid/integrated models that include a SampledExpectation layer.""" - @parameterized.parameters([{'backend': 'noisy'}, {'backend': 'noiseless'}]) - def test_simple_param_value_input(self, backend): + @parameterized.parameters([{ + 'backend': 'noisy', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': True, + }]) + def test_simple_param_value_input(self, backend, use_cuquantum): """Train a densely connected hybrid model. This model will put a qubit in the zero or one state from a random state @@ -341,12 +426,14 @@ def test_simple_param_value_input(self, backend): datum = tf.keras.Input(shape=(), dtype=tf.dtypes.string) l1 = tf.keras.layers.Dense(10)(inputs) l2 = tf.keras.layers.Dense(3)(l1) - outputs = sampled_expectation.SampledExpectation(backend=backend)( - datum, - symbol_names=symbols, - operators=cirq.Z(bit), - symbol_values=l2, - repetitions=5000) + outputs = sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(datum, + symbol_names=symbols, + operators=cirq.Z(bit), + symbol_values=l2, + repetitions=5000) model = tf.keras.Model(inputs=[datum, inputs], outputs=outputs) data_in = np.array([[1], [0]], dtype=np.float32) @@ -360,8 +447,17 @@ def test_simple_param_value_input(self, backend): history = model.fit(x=[circuits, data_in], y=data_out, epochs=30) self.assertAllClose(history.history['loss'][-1], 0, atol=0.3) - @parameterized.parameters([{'backend': 'noisy'}, {'backend': 'noiseless'}]) - def test_simple_op_input(self, backend): + @parameterized.parameters([{ + 'backend': 'noisy', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': True, + }]) + def test_simple_op_input(self, backend, use_cuquantum): """Test a simple operator input Learn qubit in the z+ state using two different measurement operators. @@ -381,10 +477,12 @@ def test_simple_op_input(self, backend): n_inp = tf.keras.Input(shape=(1,), dtype=tf.dtypes.int32) circuit_inp = tf.keras.Input(shape=(), dtype=tf.dtypes.string) circuit_output = sampled_expectation.SampledExpectation( - backend=backend)(circuit_inp, - symbol_names=symbols, - operators=op_inp, - repetitions=n_inp) + backend=backend, + use_cuquantum=use_cuquantum, + )(circuit_inp, + symbol_names=symbols, + operators=op_inp, + repetitions=n_inp) model = tf.keras.Model(inputs=[circuit_inp, op_inp, n_inp], outputs=[circuit_output]) @@ -399,8 +497,17 @@ def test_simple_op_input(self, backend): self.assertAllClose(history.history['loss'][-1], 0, atol=1e-2) - @parameterized.parameters([{'backend': 'noisy'}, {'backend': 'noiseless'}]) - def test_simple_op_and_param_input(self, backend): + @parameterized.parameters([{ + 'backend': 'noisy', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': True, + }]) + def test_simple_op_and_param_input(self, backend, use_cuquantum): """Test a simple operator and parameter input. Train a NN to put a qubit in the z+ or x+ states based on a classical @@ -424,11 +531,13 @@ def test_simple_op_and_param_input(self, backend): dense_1 = tf.keras.layers.Dense(10)(data_inp) dense_2 = tf.keras.layers.Dense(3)(dense_1) circuit_output = sampled_expectation.SampledExpectation( - backend=backend)(circuit_inp, - symbol_names=symbols, - symbol_values=dense_2, - operators=op_inp, - repetitions=n_inp) + backend=backend, + use_cuquantum=use_cuquantum, + )(circuit_inp, + symbol_names=symbols, + symbol_values=dense_2, + operators=op_inp, + repetitions=n_inp) functional_model = tf.keras.Model( inputs=[circuit_inp, data_inp, op_inp, n_inp], @@ -443,8 +552,17 @@ def test_simple_op_and_param_input(self, backend): epochs=20) self.assertAllClose(history.history['loss'][-1], 0, atol=3) - @parameterized.parameters([{'backend': 'noisy'}, {'backend': 'noiseless'}]) - def test_dnn_qnn_dnn(self, backend): + @parameterized.parameters([{ + 'backend': 'noisy', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': True, + }]) + def test_dnn_qnn_dnn(self, backend, use_cuquantum): """Train a fully hybrid network using an SampledExpectation layer. Train the network to output +-5 given an input of 1 or 0. This tests @@ -463,12 +581,14 @@ def test_dnn_qnn_dnn(self, backend): circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) d1 = tf.keras.layers.Dense(10)(classical_input) d2 = tf.keras.layers.Dense(3)(d1) - quantum = sampled_expectation.SampledExpectation(backend=backend)( - circuit_input, - symbol_names=symbols, - symbol_values=d2, - operators=cirq.Z(bit), - repetitions=5000) + quantum = sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(circuit_input, + symbol_names=symbols, + symbol_values=d2, + operators=cirq.Z(bit), + repetitions=5000) d3 = tf.keras.layers.Dense(1)(quantum) model = tf.keras.Model(inputs=[circuit_input, classical_input], diff --git a/tensorflow_quantum/python/layers/circuit_executors/state.py b/tensorflow_quantum/python/layers/circuit_executors/state.py index bf96848bf..d9219fbab 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/state.py +++ b/tensorflow_quantum/python/layers/circuit_executors/state.py @@ -16,6 +16,7 @@ import tensorflow as tf from tensorflow_quantum.core.ops import circuit_execution_ops +from tensorflow_quantum.python import quantum_context from tensorflow_quantum.python.layers.circuit_executors import input_checks @@ -129,8 +130,22 @@ def __init__(self, backend=None, use_cuquantum=False, **kwargs): use_cuquantum: Calls TFQ GPU version op. """ super().__init__(**kwargs) - self.state_op = circuit_execution_ops.get_state_op( - backend, use_cuquantum=use_cuquantum) + + used_op = None + if backend == 'noiseless' or backend is None: + mode = quantum_context.get_quantum_concurrent_op_mode() + quantum_concurrent = False if use_cuquantum else mode + used_op = circuit_execution_ops.get_state_op( + backend=None, + use_cuquantum=use_cuquantum, + quantum_concurrent=quantum_concurrent, + ) + elif backend == 'noisy': + raise ValueError('noisy backend is not supported in State layer.') + else: + used_op = circuit_execution_ops.get_state_op(backend=backend) + + self.state_op = used_op def call(self, inputs, *, symbol_names=None, symbol_values=None): """Keras call function. @@ -147,4 +162,4 @@ def call(self, inputs, *, symbol_names=None, symbol_values=None): """ inputs, symbol_names, symbol_values = input_checks.expand_circuits( inputs, symbol_names, symbol_values) - return self.state_op(inputs, symbol_names, symbol_values) \ No newline at end of file + return self.state_op(inputs, symbol_names, symbol_values) diff --git a/tensorflow_quantum/python/layers/circuit_executors/state_test.py b/tensorflow_quantum/python/layers/circuit_executors/state_test.py index 8addb0d8f..08980c937 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/state_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/state_test.py @@ -45,15 +45,21 @@ def test_state_create(self): state.State('junk') @parameterized.parameters([{ - 'backend': None + 'backend': None, + 'use_cuquantum': False, }, { - 'backend': cirq.Simulator() + 'backend': None, + 'use_cuquantum': True, }, { - 'backend': cirq.DensityMatrixSimulator() + 'backend': cirq.Simulator(), + 'use_cuquantum': False, + }, { + 'backend': cirq.DensityMatrixSimulator(), + 'use_cuquantum': False, }]) - def test_state_invalid_combinations(self, backend): + def test_state_invalid_combinations(self, backend, use_cuquantum): """Test with valid type inputs and valid value, but incorrect combo.""" - state_calc = state.State(backend) + state_calc = state.State(backend, use_cuquantum) symbol = sympy.Symbol('alpha') circuit = cirq.Circuit(cirq.H(cirq.GridQubit(0, 0))**symbol) with self.assertRaisesRegex(Exception, expected_regex=""): @@ -109,18 +115,26 @@ def test_sample_outputs_simple(self): @parameterized.parameters([ { - 'backend_output': (None, WF_OUTPUT) + 'backend_output': (None, WF_OUTPUT), + 'use_cuquantum': False, + }, + { + 'backend_output': (None, WF_OUTPUT), + 'use_cuquantum': True, }, { - 'backend_output': (cirq.sim.sparse_simulator.Simulator(), WF_OUTPUT) + 'backend_output': + (cirq.sim.sparse_simulator.Simulator(), WF_OUTPUT), + 'use_cuquantum': False, }, { 'backend_output': (cirq.sim.density_matrix_simulator.DensityMatrixSimulator(), - DM_OUTPUT) + DM_OUTPUT), + 'use_cuquantum': False, }, ]) - def test_state_output(self, backend_output): + def test_state_output(self, backend_output, use_cuquantum): """Check that any output type is as expected. This layer only allows for 2 different outputs, depending on whether a @@ -130,7 +144,10 @@ def test_state_output(self, backend_output): """ backend = backend_output[0] output = backend_output[1] - state_executor = state.State(backend=backend) + state_executor = state.State( + backend=backend, + use_cuquantum=use_cuquantum, + ) bits = cirq.GridQubit.rect(1, 2) circuit = cirq.Circuit() circuit.append(cirq.H.on(bits[0])) From f2934782a0d8e1ede94582e978d61fbca76952d7 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 3 May 2023 21:12:45 +0000 Subject: [PATCH 078/106] Fix ./scripts/test_all.sh for CPU mode to be testable and passed --- scripts/test_all.sh | 6 ++++- tensorflow_quantum/core/ops/BUILD | 4 +++ .../core/ops/circuit_execution_ops.py | 27 ++++++++++++++----- .../core/ops/tfq_adj_grad_op.cc | 4 +-- .../core/ops/tfq_adj_grad_op_cuquantum.cu.cc | 2 +- .../core/ops/tfq_circuit_append_op.cc | 2 +- .../python/differentiators/adjoint.py | 11 ++++++-- .../python/differentiators/differentiator.py | 8 ++++++ 8 files changed, 51 insertions(+), 13 deletions(-) diff --git a/scripts/test_all.sh b/scripts/test_all.sh index 1008c27c8..de82f406d 100755 --- a/scripts/test_all.sh +++ b/scripts/test_all.sh @@ -19,12 +19,16 @@ ENABLE_CUDA=${1} if [[ ${ENABLE_CUDA} == "gpu" ]]; then echo "GPU mode. CUDA config is set." CUDA_CONFIG="--config=cuda" + # Tests all including cuquantum ops. + TAG_FILTER="" else echo "CPU mode." CUDA_CONFIG="" + # Tests cpu only excluding cuquantum ops. + TAG_FILTER="--test_tag_filters=-cuquantum --build_tag_filters=-cuquantum" fi -test_outputs=$(bazel test -c opt ${CUDA_CONFIG} --experimental_repo_remote_exec --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-std=c++17" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors //tensorflow_quantum/...) +test_outputs=$(bazel test -c opt ${CUDA_CONFIG} ${TAG_FILTER} --experimental_repo_remote_exec --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-std=c++17" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors //tensorflow_quantum/...) exit_code=$? if [ "$exit_code" == "0" ]; then echo "Testing Complete!"; diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index 65f3d1bf2..cb764f25c 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -652,6 +652,7 @@ py_library( # tensorflow framework for wrappers ":load_module", ], + tags = ["cuquantum"], ) py_test( @@ -748,6 +749,7 @@ cc_binary( "@local_config_cuquantum//:libcuquantum", "@qsim//lib:qsim_cuquantum_lib", ]), + tags = ["cuquantum"], # alwayslink=1, ) @@ -824,6 +826,7 @@ cc_binary( "@local_config_cuquantum//:libcuquantum", "@qsim//lib:qsim_cuquantum_lib", ]), + tags = ["cuquantum"], # alwayslink=1, ) @@ -838,6 +841,7 @@ py_library( # projector sum cc proto # tensorflow framework for wrappers ], + tags = ["cuquantum"], ) py_test( diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index 7c4c03b70..d39edad48 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -18,10 +18,21 @@ import cirq from tensorflow_quantum.core.ops import (cirq_ops, tfq_simulate_ops, - tfq_utility_ops, - tfq_simulate_ops_cuquantum) + tfq_utility_ops) from tensorflow_quantum.python import quantum_context +try: + from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum + _enable_use_cuquantum = True +except: + # `_enable_use_cuquantum = False` makes `use_cuquantum` silent. + _enable_use_cuquantum = False + tfq_simulate_ops_cuquantum = tfq_simulate_ops + + +def is_cuda_configured() -> bool: + return _enable_use_cuquantum + class TFQStateVectorSimulator(enum.Enum): """Enum to make specifying TFQ simulators user-friendly.""" @@ -34,10 +45,12 @@ class TFQStateVectorSimulator(enum.Enum): state = tfq_simulate_ops.tfq_simulate_state state_cuquantum = tfq_simulate_ops_cuquantum.tfq_simulate_state - sampled_expectation = \ + sampled_expectation = ( tfq_simulate_ops.tfq_simulate_sampled_expectation - sampled_expectation_cuquantum = \ + ) + sampled_expectation_cuquantum = ( tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation + ) def _check_quantum_concurrent(quantum_concurrent, use_cuquantum): @@ -135,9 +148,9 @@ def get_expectation_op( expectation value for each circuit with each op applied to it (after resolving the corresponding parameters in). """ - # TODO (mbbrough): investigate how the above docstring renders. _check_quantum_concurrent(quantum_concurrent, use_cuquantum) + use_cuquantum = _enable_use_cuquantum and use_cuquantum op = None if backend is None: @@ -243,6 +256,7 @@ def get_sampling_op( # TODO (mbbrough): investigate how the above docstring renders. _check_quantum_concurrent(quantum_concurrent, use_cuquantum) + use_cuquantum = _enable_use_cuquantum and use_cuquantum op = None if backend is None: @@ -338,6 +352,7 @@ def get_state_op( # TODO (mbbrough): investigate how the above docstring renders. _check_quantum_concurrent(quantum_concurrent, use_cuquantum) + use_cuquantum = _enable_use_cuquantum and use_cuquantum op = None if backend is None: @@ -455,12 +470,12 @@ def get_sampled_expectation_op( """ # TODO (mbbrough): investigate how the above docstring renders. _check_quantum_concurrent(quantum_concurrent, use_cuquantum) + use_cuquantum = _enable_use_cuquantum and use_cuquantum op = None if backend is None: if use_cuquantum: op = TFQStateVectorSimulator.sampled_expectation_cuquantum - quantum_concurrent = False else: op = TFQStateVectorSimulator.sampled_expectation diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc index 7cac4451b..fa71bdad7 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc @@ -209,7 +209,7 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { // sv now contains psi // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> // scratch2 now contains psi as well. - [[maybe_unused]] AccumulateOperators(pauli_sums[i], downstream_grads[i], + [[maybe_unused]] Status unused = AccumulateOperators(pauli_sums[i], downstream_grads[i], sim, ss, sv, scratch2, scratch); for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { @@ -322,7 +322,7 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { // sv now contains psi // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> // scratch2 now contains psi as well. - [[maybe_unused]] AccumulateOperators(pauli_sums[i], downstream_grads[i], + [[maybe_unused]] Status unused = AccumulateOperators(pauli_sums[i], downstream_grads[i], sim, ss, sv, scratch2, scratch); for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc index e0485841b..93294c0fc 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc @@ -246,7 +246,7 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { // sv now contains psi // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> // scratch2 now contains psi as well. - [[maybe_unused]] AccumulateOperators(pauli_sums[i], downstream_grads[i], + [[maybe_unused]] Status unused = AccumulateOperators(pauli_sums[i], downstream_grads[i], sim, ss, sv, scratch2, scratch); for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { diff --git a/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc b/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc index 9f2e8bdde..188df8ab5 100644 --- a/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc +++ b/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc @@ -54,7 +54,7 @@ class TfqCircuitAppendOp : public tensorflow::OpKernel { auto DoWork = [&](int start, int end) { std::string temp; for (int i = start; i < end; i++) { - for (size_t j = 0; + for (int j = 0; j < programs_to_append.at(i).circuit().moments().size(); j++) { Moment *new_moment = programs.at(i).mutable_circuit()->add_moments(); *new_moment = programs_to_append.at(i).circuit().moments(j); diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index 0d8886d59..122d9fa0c 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -15,8 +15,15 @@ """Compute gradients by combining function values linearly.""" import tensorflow as tf -from tensorflow_quantum.core.ops import tfq_adj_grad_op, \ - tfq_adj_grad_op_cuquantum +from tensorflow_quantum.core.ops import tfq_adj_grad_op +try: + from tensorflow_quantum.core.ops import tfq_adj_grad_op_cuquantum + _enable_use_cuquantum = True +except: + _enable_use_cuquantum = False + tfq_adj_grad_op_cuquantum = tfq_adj_grad_op + + from tensorflow_quantum.python.differentiators import differentiator diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index 851454e48..40fc15ee9 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -338,6 +338,14 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values): the output `batch_weights`. """ + @catch_empty_inputs + @tf.function + def differentiate_analytic_cuquantum(self, programs, symbol_names, symbol_values, + pauli_sums, forward_pass_vals, grad): + # `self.expectation_op` is already set to cuquantum op. + return self.differentiate_analytic(programs, symbol_names, symbol_values, + pauli_sums, forward_pass_vals, grad) + @catch_empty_inputs @tf.function def differentiate_analytic(self, programs, symbol_names, symbol_values, From 41bde6d7a0e258141dd7a3898e00dc5d93335150 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 3 May 2023 21:19:34 +0000 Subject: [PATCH 079/106] Fix format --- tensorflow_quantum/core/ops/circuit_execution_ops.py | 9 +++------ tensorflow_quantum/core/ops/tfq_adj_grad_op.cc | 8 ++++---- .../core/ops/tfq_adj_grad_op_cuquantum.cu.cc | 4 ++-- tensorflow_quantum/core/ops/tfq_circuit_append_op.cc | 4 ++-- tensorflow_quantum/python/differentiators/adjoint.py | 1 - .../python/differentiators/differentiator.py | 10 ++++++---- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index d39edad48..2326cf454 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -45,12 +45,9 @@ class TFQStateVectorSimulator(enum.Enum): state = tfq_simulate_ops.tfq_simulate_state state_cuquantum = tfq_simulate_ops_cuquantum.tfq_simulate_state - sampled_expectation = ( - tfq_simulate_ops.tfq_simulate_sampled_expectation - ) + sampled_expectation = (tfq_simulate_ops.tfq_simulate_sampled_expectation) sampled_expectation_cuquantum = ( - tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation - ) + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation) def _check_quantum_concurrent(quantum_concurrent, use_cuquantum): @@ -503,4 +500,4 @@ def get_sampled_expectation_op( raise TypeError( "Backend {} is invalid. Expected a Cirq.Sampler or None.".format( - backend)) \ No newline at end of file + backend)) diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc index fa71bdad7..fe88a5817 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc @@ -209,8 +209,8 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { // sv now contains psi // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> // scratch2 now contains psi as well. - [[maybe_unused]] Status unused = AccumulateOperators(pauli_sums[i], downstream_grads[i], - sim, ss, sv, scratch2, scratch); + [[maybe_unused]] Status unused = AccumulateOperators( + pauli_sums[i], downstream_grads[i], sim, ss, sv, scratch2, scratch); for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { for (int k = partial_fused_circuits[i][j].size() - 1; k >= 0; k--) { @@ -322,8 +322,8 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { // sv now contains psi // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> // scratch2 now contains psi as well. - [[maybe_unused]] Status unused = AccumulateOperators(pauli_sums[i], downstream_grads[i], - sim, ss, sv, scratch2, scratch); + [[maybe_unused]] Status unused = AccumulateOperators( + pauli_sums[i], downstream_grads[i], sim, ss, sv, scratch2, scratch); for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { for (int k = partial_fused_circuits[i][j].size() - 1; k >= 0; k--) { diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc index 93294c0fc..a218363ad 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc @@ -246,8 +246,8 @@ class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { // sv now contains psi // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> // scratch2 now contains psi as well. - [[maybe_unused]] Status unused = AccumulateOperators(pauli_sums[i], downstream_grads[i], - sim, ss, sv, scratch2, scratch); + [[maybe_unused]] Status unused = AccumulateOperators( + pauli_sums[i], downstream_grads[i], sim, ss, sv, scratch2, scratch); for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { for (int k = partial_fused_circuits[i][j].size() - 1; k >= 0; k--) { diff --git a/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc b/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc index 188df8ab5..582bd1681 100644 --- a/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc +++ b/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc @@ -54,8 +54,8 @@ class TfqCircuitAppendOp : public tensorflow::OpKernel { auto DoWork = [&](int start, int end) { std::string temp; for (int i = start; i < end; i++) { - for (int j = 0; - j < programs_to_append.at(i).circuit().moments().size(); j++) { + for (int j = 0; j < programs_to_append.at(i).circuit().moments().size(); + j++) { Moment *new_moment = programs.at(i).mutable_circuit()->add_moments(); *new_moment = programs_to_append.at(i).circuit().moments(j); } diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index 122d9fa0c..ab95e44ec 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -23,7 +23,6 @@ _enable_use_cuquantum = False tfq_adj_grad_op_cuquantum = tfq_adj_grad_op - from tensorflow_quantum.python.differentiators import differentiator diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index 40fc15ee9..2a3f6a0e1 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -340,11 +340,13 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values): @catch_empty_inputs @tf.function - def differentiate_analytic_cuquantum(self, programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad): + def differentiate_analytic_cuquantum(self, programs, symbol_names, + symbol_values, pauli_sums, + forward_pass_vals, grad): # `self.expectation_op` is already set to cuquantum op. - return self.differentiate_analytic(programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad) + return self.differentiate_analytic(programs, symbol_names, + symbol_values, pauli_sums, + forward_pass_vals, grad) @catch_empty_inputs @tf.function From 53222dfce78549742db7d0dbdf02601662435649 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Wed, 3 May 2023 21:30:39 +0000 Subject: [PATCH 080/106] Fix lint --- .../core/ops/circuit_execution_ops.py | 19 ++++++++++--------- .../python/differentiators/adjoint.py | 5 +++-- .../python/differentiators/differentiator.py | 4 +++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index 2326cf454..64dd1dc71 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -23,15 +23,16 @@ try: from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum - _enable_use_cuquantum = True + _ENABLE_USE_CUQUANTUM = True except: - # `_enable_use_cuquantum = False` makes `use_cuquantum` silent. - _enable_use_cuquantum = False + # `_ENABLE_USE_CUQUANTUM = False` makes `use_cuquantum` silent. + _ENABLE_USE_CUQUANTUM = False tfq_simulate_ops_cuquantum = tfq_simulate_ops -def is_cuda_configured() -> bool: - return _enable_use_cuquantum +def is_gpu_configured() -> bool: + """Returns True if gpu ops are available or not.""" + return _ENABLE_USE_CUQUANTUM class TFQStateVectorSimulator(enum.Enum): @@ -147,7 +148,7 @@ def get_expectation_op( """ # TODO (mbbrough): investigate how the above docstring renders. _check_quantum_concurrent(quantum_concurrent, use_cuquantum) - use_cuquantum = _enable_use_cuquantum and use_cuquantum + use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum op = None if backend is None: @@ -253,7 +254,7 @@ def get_sampling_op( # TODO (mbbrough): investigate how the above docstring renders. _check_quantum_concurrent(quantum_concurrent, use_cuquantum) - use_cuquantum = _enable_use_cuquantum and use_cuquantum + use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum op = None if backend is None: @@ -349,7 +350,7 @@ def get_state_op( # TODO (mbbrough): investigate how the above docstring renders. _check_quantum_concurrent(quantum_concurrent, use_cuquantum) - use_cuquantum = _enable_use_cuquantum and use_cuquantum + use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum op = None if backend is None: @@ -467,7 +468,7 @@ def get_sampled_expectation_op( """ # TODO (mbbrough): investigate how the above docstring renders. _check_quantum_concurrent(quantum_concurrent, use_cuquantum) - use_cuquantum = _enable_use_cuquantum and use_cuquantum + use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum op = None if backend is None: diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index ab95e44ec..a5a6c8252 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -18,9 +18,9 @@ from tensorflow_quantum.core.ops import tfq_adj_grad_op try: from tensorflow_quantum.core.ops import tfq_adj_grad_op_cuquantum - _enable_use_cuquantum = True + _ENABLE_USE_CUQUANTUM = True except: - _enable_use_cuquantum = False + _ENABLE_USE_CUQUANTUM = False tfq_adj_grad_op_cuquantum = tfq_adj_grad_op from tensorflow_quantum.python.differentiators import differentiator @@ -99,6 +99,7 @@ def generate_differentiable_op(self, raise ValueError("sample base backends are not supported by the " "Adjoint method, please use analytic expectation" " or choose another differentiator.") + use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum return super().generate_differentiable_op(analytic_op=analytic_op, use_cuquantum=use_cuquantum) diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index 2a3f6a0e1..ed195d29d 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -343,7 +343,9 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values): def differentiate_analytic_cuquantum(self, programs, symbol_names, symbol_values, pauli_sums, forward_pass_vals, grad): - # `self.expectation_op` is already set to cuquantum op. + """Differentiate a circuit with analytical expectation with GPU ops.""" + # `self.expectation_op` is already set to cuquantum op at + # generate_differentiable_op._differentiate_ana. return self.differentiate_analytic(programs, symbol_names, symbol_values, pauli_sums, forward_pass_vals, grad) From 9e30f8d9c651aadb9ae92c6f3c147eea97cf3adf Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Thu, 4 May 2023 01:19:10 +0000 Subject: [PATCH 081/106] Fix BulkSetAmpl bug, Add more diff cuquantum unit tests --- .../core/ops/circuit_execution_ops.py | 2 +- .../core/ops/tfq_adj_grad_op_cuquantum.cu.cc | 7 +- .../ops/tfq_adj_grad_op_cuquantum_test.py | 2 +- .../python/differentiators/BUILD | 2 + .../python/differentiators/adjoint.py | 15 ++ .../python/differentiators/adjoint_test.py | 51 ++++- .../python/differentiators/differentiator.py | 37 +++- .../differentiators/differentiator_test.py | 20 ++ .../python/differentiators/gradient_test.py | 199 ++++++++++++++---- 9 files changed, 279 insertions(+), 56 deletions(-) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index 64dd1dc71..e75a4bfd5 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -46,7 +46,7 @@ class TFQStateVectorSimulator(enum.Enum): state = tfq_simulate_ops.tfq_simulate_state state_cuquantum = tfq_simulate_ops_cuquantum.tfq_simulate_state - sampled_expectation = (tfq_simulate_ops.tfq_simulate_sampled_expectation) + sampled_expectation = tfq_simulate_ops.tfq_simulate_sampled_expectation sampled_expectation_cuquantum = ( tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation) diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc index a218363ad..55213c78b 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc @@ -41,17 +41,16 @@ namespace tfq { namespace { // TODO(jaeyoo): Temorary hack for BulkSetAmpl with cuda ops. // Updates qsim custatevec side BulkSetAmple ops, and remove these utilities. -template +template __global__ void BulkSetAmplKernel(uint64_t mask, uint64_t bits, FP re, FP im, bool exclude, FP* state) { uint64_t k1 = uint64_t{blockIdx.x} * blockDim.x + threadIdx.x; - uint64_t k2 = 2 * k1 - threadIdx.x % warp_size; bool set = ((k1 & mask) == bits) ^ exclude; if (set) { - state[k2] = re; - state[k2 + warp_size] = im; + state[2 * k1] = re; + state[2 * k1 + 1] = im; } } diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py index 3933efde0..0e9848ab3 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py @@ -116,7 +116,7 @@ def test_calculate_adj_grad_cpu_vs_cuquantum(self): # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, res_cuquantum, - atol=1e-3, + atol=1e-4, err_msg=""" # If failed, the GPU architecture in this system may be unsupported. # Please refer to the supported architectures here. diff --git a/tensorflow_quantum/python/differentiators/BUILD b/tensorflow_quantum/python/differentiators/BUILD index 329e0b2d8..33103e4e7 100644 --- a/tensorflow_quantum/python/differentiators/BUILD +++ b/tensorflow_quantum/python/differentiators/BUILD @@ -39,6 +39,7 @@ py_test( deps = [ ":adjoint", "//tensorflow_quantum/core/ops:circuit_execution_ops", + "//tensorflow_quantum/python:util", ], ) @@ -122,6 +123,7 @@ py_test( py_test( name = "gradient_test", timeout = "eternal", + shard_count = 5, srcs = ["gradient_test.py"], python_version = "PY3", deps = [ diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index a5a6c8252..68a06cf89 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -142,6 +142,21 @@ def differentiate_analytic( return tfq_adj_grad_op.tfq_adj_grad(programs, symbol_names, symbol_values, pauli_sums, grad) + def differentiate_sampled_cuquantum( + self, + programs, + symbol_names, + symbol_values, + pauli_sums, + num_samples, + forward_pass_vals, + grad, + ): + raise NotImplementedError( + "Adjoint state methods are not supported in sample based settings." + " Please use analytic expectation calculation or a different " + "tfq.differentiator.") + def differentiate_sampled( self, programs, diff --git a/tensorflow_quantum/python/differentiators/adjoint_test.py b/tensorflow_quantum/python/differentiators/adjoint_test.py index ffbf9173e..7bdeeb547 100644 --- a/tensorflow_quantum/python/differentiators/adjoint_test.py +++ b/tensorflow_quantum/python/differentiators/adjoint_test.py @@ -19,20 +19,65 @@ NEW_PATH = [x for x in sys.path if 'com_google_protobuf' not in x] sys.path = NEW_PATH # pylint: enable=wrong-import-position +from unittest import mock +from absl.testing import parameterized +import cirq +import numpy as np +import sympy import tensorflow as tf -from tensorflow_quantum.python.differentiators import adjoint from tensorflow_quantum.core.ops import circuit_execution_ops +from tensorflow_quantum.python import util +from tensorflow_quantum.python.differentiators import adjoint -class AdjointTest(tf.test.TestCase): +class AdjointTest(tf.test.TestCase, parameterized.TestCase): """Test that we can properly subclass differentiator.""" def test_instantiation(self): """Test that adjoint can be created.""" adjoint.Adjoint() + @parameterized.parameters( + list(util.kwargs_cartesian_product(**{ + 'use_cuquantum': [False, True], + }))) + def test_use_cuquantum(self, use_cuquantum): + """Ensure that use_cuquantum switches to cuquantum ops well.""" + if not circuit_execution_ops.is_gpu_configured(): + # Ignores this test if gpu is not configured. + self.skipTest() + # Prepares a simple circuit. + qubit = cirq.GridQubit(0, 0) + circuit = util.convert_to_tensor( + [cirq.Circuit(cirq.X(qubit)**sympy.Symbol('alpha'))]) + psums = util.convert_to_tensor([[cirq.Z(qubit)]]) + symbol_values_array = np.array([[0.123]], dtype=np.float32) + symbol_values_tensor = tf.convert_to_tensor(symbol_values_array) + + # Mocks `Adjoint.differentiate_analytic*()` to check if + # it's called once correctly. + method_name = ("differentiate_analytic_cuquantum" + if use_cuquantum else "differentiate_analytic") + with mock.patch.object(adjoint.Adjoint, + method_name, + return_value=None, + autospec=True) as mock_adj: + dif = adjoint.Adjoint() + op = circuit_execution_ops.get_expectation_op( + use_cuquantum=use_cuquantum, quantum_concurrent=False) + diff_op = dif.generate_differentiable_op( + analytic_op=op, use_cuquantum=use_cuquantum) + + # Calculate tfq gradient. + with tf.GradientTape() as g: + g.watch(symbol_values_tensor) + expectations = diff_op(circuit, tf.convert_to_tensor(['alpha']), + symbol_values_tensor, psums) + grads = g.gradient(expectations, symbol_values_tensor) + mock_adj.assert_called_once() + def test_sample_errors(self): """Ensure that the adjoint method won't attach to sample ops.""" @@ -40,6 +85,8 @@ def test_sample_errors(self): op = circuit_execution_ops.get_sampled_expectation_op() with self.assertRaisesRegex(ValueError, expected_regex='not supported'): dif.generate_differentiable_op(sampled_op=op) + with self.assertRaisesRegex(ValueError, expected_regex='not supported'): + dif.generate_differentiable_op(sampled_op=op, use_cuquantum=True) def test_no_gradient_circuits(self): """Confirm the adjoint differentiator has no gradient circuits.""" diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index ed195d29d..cfa83d50f 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -118,6 +118,9 @@ def generate_differentiable_op(self, raise TypeError('Provided arguments must be callable tensorflow ' 'ops.') + if not isinstance(use_cuquantum, bool): + raise TypeError('use_cuquantum should be boolean.') + # TODO (mbbrough): find a better workaround than this to ensure # that the correct sample based expectation wasn't accidentally # put inside of the analytical_op argument or vice versa. @@ -155,8 +158,12 @@ def generate_differentiable_op(self, 'Given arg: {}.'.format(str(key)) + '' 'The signature should contain: {}.'.format( list(expected_signature))) - _differentiate_ana = (self._differentiate_ana_cq - if use_cuquantum else self._differentiate_ana) + if use_cuquantum: + _differentiate_ana, _differentiate_sam = ( + self._differentiate_ana_cq, self._differentiate_sam_cq) + else: + _differentiate_ana, _differentiate_sam = (self._differentiate_ana, + self._differentiate_sam) @tf.custom_gradient def op_wrapper_analytic(programs, symbol_names, symbol_values, @@ -178,10 +185,9 @@ def op_wrapper_sampled(programs, symbol_names, symbol_values, num_samples) def gradient(grad): - return self._differentiate_sam(programs, symbol_names, - symbol_values, pauli_sums, - num_samples, forward_pass_vals, - grad) + return _differentiate_sam(programs, symbol_names, symbol_values, + pauli_sums, num_samples, + forward_pass_vals, grad) return forward_pass_vals, gradient @@ -207,6 +213,13 @@ def _differentiate_ana(self, programs, symbol_names, symbol_values, pauli_sums, forward_pass_vals, grad), \ None + def _differentiate_sam_cq(self, programs, symbol_names, symbol_values, + pauli_sums, num_samples, forward_pass_vals, grad): + return None, None, self.differentiate_sampled_cuquantum( + programs, symbol_names, symbol_values, + pauli_sums, num_samples, forward_pass_vals, grad), \ + None, None + def _differentiate_sam(self, programs, symbol_names, symbol_values, pauli_sums, num_samples, forward_pass_vals, grad): return None, None, self.differentiate_sampled( @@ -350,6 +363,18 @@ def differentiate_analytic_cuquantum(self, programs, symbol_names, symbol_values, pauli_sums, forward_pass_vals, grad) + @catch_empty_inputs + @tf.function + def differentiate_sampled_cuquantum(self, programs, symbol_names, + symbol_values, pauli_sums, num_samples, + forward_pass_vals, grad): + """Differentiate a circuit with sampled expectation with GPU ops.""" + # `self.expectation_op` is already set to cuquantum op at + # generate_differentiable_op._differentiate_sam. + return self.differentiate_sampled(programs, symbol_names, symbol_values, + pauli_sums, num_samples, + forward_pass_vals, grad) + @catch_empty_inputs @tf.function def differentiate_analytic(self, programs, symbol_names, symbol_values, diff --git a/tensorflow_quantum/python/differentiators/differentiator_test.py b/tensorflow_quantum/python/differentiators/differentiator_test.py index 6f21f2e18..5cefce512 100644 --- a/tensorflow_quantum/python/differentiators/differentiator_test.py +++ b/tensorflow_quantum/python/differentiators/differentiator_test.py @@ -72,6 +72,26 @@ def test_generate_differentiable_op(self): WorkingDifferentiator().generate_differentiable_op( sampled_op=lambda programs, symbol_names, pauli_sums: 1) + def test_generate_differentiable_op_cuquantum(self): + """test the type checking on this method with `use_cuquantum`.""" + WorkingDifferentiator().generate_differentiable_op( + analytic_op=lambda programs, symbol_names, symbol_values, + pauli_sums: 1, + use_cuquantum=True) + WorkingDifferentiator().generate_differentiable_op( + sampled_op=lambda programs, symbol_names, symbol_values, pauli_sums, + num_samples: 1, + use_cuquantum=True) + with self.assertRaisesRegex(TypeError, expected_regex='boolean'): + WorkingDifferentiator().generate_differentiable_op( + analytic_op=lambda programs, symbol_names, symbol_values, + pauli_sums: 1, + use_cuquantum='junk') + with self.assertRaisesRegex(TypeError, expected_regex='boolean'): + WorkingDifferentiator().generate_differentiable_op( + sampled_op=lambda programs, symbol_names, pauli_sums: 1, + use_cuquantum='junk') + def test_single_op_link(self): """Tests if the `one-differentiator-per-op` policy is working well.""" wd = WorkingDifferentiator() diff --git a/tensorflow_quantum/python/differentiators/gradient_test.py b/tensorflow_quantum/python/differentiators/gradient_test.py index f666ad801..237c20a9f 100644 --- a/tensorflow_quantum/python/differentiators/gradient_test.py +++ b/tensorflow_quantum/python/differentiators/gradient_test.py @@ -36,6 +36,8 @@ from tensorflow_quantum.core.ops.noise import noisy_expectation_op from tensorflow_quantum.core.ops.noise import noisy_sampled_expectation_op +RANDOM_SEED = 1234 + ANALYTIC_DIFFS = [ linear_combination.ForwardDifference(grid_spacing=0.0001), linear_combination.ForwardDifference(error_order=2, grid_spacing=0.0001), @@ -57,12 +59,22 @@ circuit_execution_ops.get_expectation_op() # C++ ] +ANALYTIC_GPU_OPS = [ + circuit_execution_ops.get_expectation_op(use_cuquantum=True, + quantum_concurrent=False) +] + SAMPLED_OPS = [ circuit_execution_ops.get_sampled_expectation_op( cirq.sim.Simulator()), # WF circuit_execution_ops.get_sampled_expectation_op() # C++ ] +SAMPLED_GPU_OPS = [ + circuit_execution_ops.get_sampled_expectation_op(use_cuquantum=True, + quantum_concurrent=False) +] + NOISY_OPS = [ noisy_sampled_expectation_op.sampled_expectation, noisy_expectation_op.expectation @@ -117,19 +129,35 @@ class AnalyticGradientCorrectnessTest(tf.test.TestCase, parameterized.TestCase): @parameterized.parameters( list( - util.kwargs_cartesian_product(**{ - 'differentiator': ANALYTIC_DIFFS, - 'op': ANALYTIC_OPS - })) + [{ - 'differentiator': adjoint.Adjoint(), - 'op': circuit_execution_ops.get_expectation_op() - }]) - def test_backprop(self, differentiator, op): + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS, + 'op': ANALYTIC_OPS, + 'use_cuquantum': [False], + })) + [{ + 'differentiator': adjoint.Adjoint(), + 'op': circuit_execution_ops.get_expectation_op(), + 'use_cuquantum': False, + }] + + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS + [adjoint.Adjoint()], + 'op': ANALYTIC_GPU_OPS, + 'use_cuquantum': [True], + }))) + def test_backprop(self, differentiator, op, use_cuquantum): """Test that gradients are correctly backpropagated through a quantum circuit via comparison to analytical results. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest() differentiator.refresh() - op = differentiator.generate_differentiable_op(analytic_op=op) + op = differentiator.generate_differentiable_op( + analytic_op=op, + use_cuquantum=use_cuquantum, + ) def exact_grad(theta): new_theta = 2 * np.pi * theta @@ -164,23 +192,42 @@ def exact_grad(theta): 'n_qubits': [5], 'n_programs': [3], 'n_ops': [3], - 'symbol_names': [['a', 'b']] + 'symbol_names': [['a', 'b']], + 'use_cuquantum': [False], })) + [{ 'differentiator': adjoint.Adjoint(), 'op': circuit_execution_ops.get_expectation_op(), 'n_qubits': 10, 'n_programs': 5, 'n_ops': 3, - 'symbol_names': ['a', 'b'] - }]) + 'symbol_names': ['a', 'b'], + 'use_cuquantum': False, + }] + + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS + [adjoint.Adjoint()], + 'op': ANALYTIC_GPU_OPS, + 'n_qubits': [5], + 'n_programs': [3], + 'n_ops': [3], + 'symbol_names': [['a', 'b']], + 'use_cuquantum': [True], + }))) def test_gradients_vs_cirq_finite_difference(self, differentiator, op, n_qubits, n_programs, n_ops, - symbol_names): + symbol_names, use_cuquantum): """Compare TFQ differentiators to fine-grained noiseless cirq finite differencing. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest() differentiator.refresh() - op = differentiator.generate_differentiable_op(analytic_op=op) + op = differentiator.generate_differentiable_op( + analytic_op=op, + use_cuquantum=use_cuquantum, + ) qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ @@ -219,18 +266,39 @@ def test_gradients_vs_cirq_finite_difference(self, differentiator, op, @parameterized.parameters( list( - util.kwargs_cartesian_product(**{ - 'differentiator': ANALYTIC_DIFFS, - 'op': ANALYTIC_OPS, - })) + [{ - 'differentiator': adjoint.Adjoint(), - 'op': circuit_execution_ops.get_expectation_op(), - }]) - def test_analytic_value_with_simple_circuit(self, differentiator, op): + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS, + 'op': ANALYTIC_OPS, + 'use_cuquantum': [False], + })) + [{ + 'differentiator': adjoint.Adjoint(), + 'op': circuit_execution_ops.get_expectation_op(), + 'use_cuquantum': False, + }] + + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS + [adjoint.Adjoint()], + 'op': ANALYTIC_GPU_OPS, + 'use_cuquantum': [True], + }))) + def test_analytic_value_with_simple_circuit( + self, + differentiator, + op, + use_cuquantum, + ): """Test the value of differentiator with simple circuit.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest() # Get an expectation op, with this differentiator attached. differentiator.refresh() - op = differentiator.generate_differentiable_op(analytic_op=op) + op = differentiator.generate_differentiable_op( + analytic_op=op, + use_cuquantum=use_cuquantum, + ) qubit = cirq.GridQubit(0, 0) circuit = util.convert_to_tensor( [cirq.Circuit(cirq.X(qubit)**sympy.Symbol('alpha'))]) @@ -248,15 +316,28 @@ def test_analytic_value_with_simple_circuit(self, differentiator, op): @parameterized.parameters( list( - util.kwargs_cartesian_product(**{ - 'differentiator': ANALYTIC_DIFFS, - 'op': ANALYTIC_OPS, - })) + [{ - 'differentiator': adjoint.Adjoint(), - 'op': circuit_execution_ops.get_expectation_op(), - }]) - def test_empty_circuit_grad(self, differentiator, op): + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS, + 'op': ANALYTIC_OPS, + 'use_cuquantum': [False], + })) + [{ + 'differentiator': adjoint.Adjoint(), + 'op': circuit_execution_ops.get_expectation_op(), + 'use_cuquantum': False, + }] + + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS + [adjoint.Adjoint()], + 'op': ANALYTIC_GPU_OPS, + 'use_cuquantum': [True], + }))) + def test_empty_circuit_grad(self, differentiator, op, use_cuquantum): """Test that providing no circuits will fail gracefully.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest() differentiator.refresh() op = differentiator.generate_differentiable_op(analytic_op=op) circuit = tf.convert_to_tensor([], dtype=tf.string) @@ -283,11 +364,20 @@ class SampledGradientCorrectnessTest(tf.test.TestCase, parameterized.TestCase): **{ 'differentiator': SAMPLED_DIFFS, 'op': SAMPLED_OPS, - 'num_samples': [20000] - }))) + 'num_samples': [20000], + 'use_cuquantum': [False], + })) + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': SAMPLED_DIFFS, + 'op': SAMPLED_GPU_OPS, + 'num_samples': [20000], + 'use_cuquantum': [True], + }))) def test_sampled_value_with_simple_circuit(self, differentiator, op, - num_samples): + num_samples, use_cuquantum): """Test the value of sampled differentiator with simple circuit.""" + tf.random.set_seed(RANDOM_SEED) # Get an expectation op, with this differentiator attached. differentiator.refresh() op = differentiator.generate_differentiable_op(sampled_op=op) @@ -317,15 +407,30 @@ def test_sampled_value_with_simple_circuit(self, differentiator, op, 'n_programs': [5], 'n_ops': [2], 'symbol_names': [['a', 'b']], - 'num_samples': [30000] + 'num_samples': [30000], + 'use_cuquantum': [False], + })) + + list( + util.kwargs_cartesian_product( + **{ + 'diff_and_tol': zip(SAMPLED_DIFFS, SAMPLED_DIFFS_TOLS), + 'op': SAMPLED_GPU_OPS, + 'n_qubits': [3], + 'n_programs': [5], + 'n_ops': [2], + 'symbol_names': [['a', 'b']], + 'num_samples': [30000], + 'use_cuquantum': [True], }))) def test_approx_equality_shallow(self, diff_and_tol, op, n_qubits, symbol_names, n_ops, n_programs, - num_samples): + num_samples, use_cuquantum): """Test small circuits with limited depth.""" + tf.random.set_seed(RANDOM_SEED) differentiator, tol = diff_and_tol differentiator.refresh() - op = differentiator.generate_differentiable_op(sampled_op=op) + op = differentiator.generate_differentiable_op( + sampled_op=op, use_cuquantum=use_cuquantum) qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ @@ -368,12 +473,22 @@ def test_approx_equality_shallow(self, diff_and_tol, op, n_qubits, @parameterized.parameters( list( - util.kwargs_cartesian_product(**{ - 'differentiator': SAMPLED_DIFFS, - 'op': SAMPLED_OPS, - }))) - def test_empty_circuit_sampled_grad(self, differentiator, op): + util.kwargs_cartesian_product( + **{ + 'differentiator': SAMPLED_DIFFS, + 'op': SAMPLED_OPS, + 'use_cuquantum': [False], + })) + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': SAMPLED_DIFFS, + 'op': SAMPLED_GPU_OPS, + 'use_cuquantum': [True], + }))) + def test_empty_circuit_sampled_grad(self, differentiator, op, + use_cuquantum): """Test that providing no circuits will fail gracefully.""" + tf.random.set_seed(RANDOM_SEED) differentiator.refresh() op = differentiator.generate_differentiable_op(sampled_op=op) circuit = tf.convert_to_tensor([], dtype=tf.string) From 780061d497956b2c72e8ac79bc0f083a5b7b6652 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Thu, 4 May 2023 01:42:48 +0000 Subject: [PATCH 082/106] Add skipTest() reason --- .../python/differentiators/adjoint_test.py | 4 ++-- .../python/differentiators/gradient_test.py | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tensorflow_quantum/python/differentiators/adjoint_test.py b/tensorflow_quantum/python/differentiators/adjoint_test.py index 7bdeeb547..23ab4edde 100644 --- a/tensorflow_quantum/python/differentiators/adjoint_test.py +++ b/tensorflow_quantum/python/differentiators/adjoint_test.py @@ -47,7 +47,7 @@ def test_use_cuquantum(self, use_cuquantum): """Ensure that use_cuquantum switches to cuquantum ops well.""" if not circuit_execution_ops.is_gpu_configured(): # Ignores this test if gpu is not configured. - self.skipTest() + self.skipTest("GPU is not set. Ignoring gpu tests...") # Prepares a simple circuit. qubit = cirq.GridQubit(0, 0) circuit = util.convert_to_tensor( @@ -75,7 +75,7 @@ def test_use_cuquantum(self, use_cuquantum): g.watch(symbol_values_tensor) expectations = diff_op(circuit, tf.convert_to_tensor(['alpha']), symbol_values_tensor, psums) - grads = g.gradient(expectations, symbol_values_tensor) + _ = g.gradient(expectations, symbol_values_tensor) mock_adj.assert_called_once() def test_sample_errors(self): diff --git a/tensorflow_quantum/python/differentiators/gradient_test.py b/tensorflow_quantum/python/differentiators/gradient_test.py index 237c20a9f..f661a419b 100644 --- a/tensorflow_quantum/python/differentiators/gradient_test.py +++ b/tensorflow_quantum/python/differentiators/gradient_test.py @@ -152,7 +152,7 @@ def test_backprop(self, differentiator, op, use_cuquantum): """ if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): # GPU is not set. Ignores this sub-test. - self.skipTest() + self.skipTest("GPU is not set. Ignoring gpu tests...") differentiator.refresh() op = differentiator.generate_differentiable_op( analytic_op=op, @@ -222,7 +222,7 @@ def test_gradients_vs_cirq_finite_difference(self, differentiator, op, """ if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): # GPU is not set. Ignores this sub-test. - self.skipTest() + self.skipTest("GPU is not set. Ignoring gpu tests...") differentiator.refresh() op = differentiator.generate_differentiable_op( analytic_op=op, @@ -292,7 +292,7 @@ def test_analytic_value_with_simple_circuit( """Test the value of differentiator with simple circuit.""" if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): # GPU is not set. Ignores this sub-test. - self.skipTest() + self.skipTest("GPU is not set. Ignoring gpu tests...") # Get an expectation op, with this differentiator attached. differentiator.refresh() op = differentiator.generate_differentiable_op( @@ -337,7 +337,7 @@ def test_empty_circuit_grad(self, differentiator, op, use_cuquantum): """Test that providing no circuits will fail gracefully.""" if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): # GPU is not set. Ignores this sub-test. - self.skipTest() + self.skipTest("GPU is not set. Ignoring gpu tests...") differentiator.refresh() op = differentiator.generate_differentiable_op(analytic_op=op) circuit = tf.convert_to_tensor([], dtype=tf.string) @@ -377,6 +377,9 @@ class SampledGradientCorrectnessTest(tf.test.TestCase, parameterized.TestCase): def test_sampled_value_with_simple_circuit(self, differentiator, op, num_samples, use_cuquantum): """Test the value of sampled differentiator with simple circuit.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) # Get an expectation op, with this differentiator attached. differentiator.refresh() @@ -426,6 +429,9 @@ def test_approx_equality_shallow(self, diff_and_tol, op, n_qubits, symbol_names, n_ops, n_programs, num_samples, use_cuquantum): """Test small circuits with limited depth.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) differentiator, tol = diff_and_tol differentiator.refresh() @@ -488,6 +494,9 @@ def test_approx_equality_shallow(self, diff_and_tol, op, n_qubits, def test_empty_circuit_sampled_grad(self, differentiator, op, use_cuquantum): """Test that providing no circuits will fail gracefully.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) differentiator.refresh() op = differentiator.generate_differentiable_op(sampled_op=op) From 5c53f9f6c536f9bf99f93d516ab5050b43e4ab7d Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Thu, 4 May 2023 01:47:13 +0000 Subject: [PATCH 083/106] Add random seed for samples & sampled_expectation tests --- .../python/layers/circuit_executors/sample_test.py | 3 +++ .../layers/circuit_executors/sampled_expectation_test.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/tensorflow_quantum/python/layers/circuit_executors/sample_test.py b/tensorflow_quantum/python/layers/circuit_executors/sample_test.py index cb05d5242..16c54106e 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample_test.py @@ -29,6 +29,8 @@ from tensorflow_quantum.python.layers.circuit_executors import sample from tensorflow_quantum.python import util +RANDOM_SEED = 1234 + class SampleTest(tf.test.TestCase, parameterized.TestCase): """Tests for the Sample layer.""" @@ -188,6 +190,7 @@ def test_sample_output(self, backend, use_cuquantum, all_n_qubits, cause what is output from the layer to structurally deviate from what is expected. """ + tf.random.set_seed(RANDOM_SEED) if use_cuquantum: # If use_cuquantum is True, if backend is not None and backend != 'noiseless': diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py index e693068fc..79a42f4b9 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py @@ -31,6 +31,8 @@ from tensorflow_quantum.python.differentiators import linear_combination from tensorflow_quantum.python import util +RANDOM_SEED = 1234 + class CustomSampler(cirq.Sampler): """Wrapper for cirq.Simulator to confirm that custom samplers work.""" @@ -381,6 +383,7 @@ def test_static_cases(self, backend, use_cuquantum): def test_sampled_expectation_simple_tf_train(self): """Train a layer using standard tf (not keras).""" + tf.random.set_seed(RANDOM_SEED) bit = cirq.GridQubit(0, 0) circuit = cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) layer = sampled_expectation.SampledExpectation() @@ -417,6 +420,7 @@ def test_simple_param_value_input(self, backend, use_cuquantum): This model will put a qubit in the zero or one state from a random state given the input zero or one. """ + tf.random.set_seed(RANDOM_SEED) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') circuit = _gen_single_bit_rotation_problem( @@ -462,6 +466,7 @@ def test_simple_op_input(self, backend, use_cuquantum): Learn qubit in the z+ state using two different measurement operators. """ + tf.random.set_seed(RANDOM_SEED) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) @@ -513,6 +518,7 @@ def test_simple_op_and_param_input(self, backend, use_cuquantum): Train a NN to put a qubit in the z+ or x+ states based on a classical binary input. """ + tf.random.set_seed(RANDOM_SEED) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) @@ -568,6 +574,7 @@ def test_dnn_qnn_dnn(self, backend, use_cuquantum): Train the network to output +-5 given an input of 1 or 0. This tests that everything works when SampledExpectation layer is a middle layers. """ + tf.random.set_seed(RANDOM_SEED) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') circuits = util.convert_to_tensor([ From e9e045e7619dff570f2869cc73232b5328c93545 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Thu, 4 May 2023 02:01:27 +0000 Subject: [PATCH 084/106] Add GPU availability in 4 major keras layer tests --- .../circuit_executors/expectation_test.py | 13 +++++++ .../layers/circuit_executors/sample_test.py | 31 +++++++++++++--- .../sampled_expectation_test.py | 36 +++++++++++++++++-- .../layers/circuit_executors/state_test.py | 9 ++++- 4 files changed, 82 insertions(+), 7 deletions(-) diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py index 1b6a6a98d..264670674 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py @@ -26,6 +26,7 @@ import tensorflow as tf import cirq +from tensorflow_quantum.core.ops import circuit_execution_ops from tensorflow_quantum.python.layers.circuit_executors import expectation from tensorflow_quantum.python.differentiators import linear_combination from tensorflow_quantum.python import util @@ -327,6 +328,9 @@ def test_simple_param_value_input(self, backend, use_cuquantum): state given the input zero or one. This tests the input signature: Expectation([input_value_batch]). """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") noisy = backend == 'noisy' bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') @@ -379,6 +383,9 @@ def test_simple_op_input(self, backend, use_cuquantum): Learn qubit in the z+ state using two different measurement operators. This tests input signature Expectation([operator_batch]) """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") noisy = backend == 'noisy' bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') @@ -443,6 +450,9 @@ def test_simple_op_and_param_input(self, backend, use_cuquantum): binary input. This tests the input signature: Expectation([value_batch, operator_batch]). """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") noisy = backend == 'noisy' bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') @@ -500,6 +510,9 @@ def test_dnn_qnn_dnn(self, backend, use_cuquantum): Train the network to output +-5 given an input of 1 or 0. This tests that everything works when Expectation layer is a middle layers. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") noisy = backend == 'noisy' bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') diff --git a/tensorflow_quantum/python/layers/circuit_executors/sample_test.py b/tensorflow_quantum/python/layers/circuit_executors/sample_test.py index 16c54106e..4e466c760 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample_test.py @@ -26,6 +26,7 @@ import tensorflow as tf import cirq +from tensorflow_quantum.core.ops import circuit_execution_ops from tensorflow_quantum.python.layers.circuit_executors import sample from tensorflow_quantum.python import util @@ -109,6 +110,9 @@ def test_sample_invalid_shape_inputs(self): ]) def test_sample_invalid_combinations(self, backend, use_cuquantum): """Test with valid type inputs and valid value, but incorrect combo.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") sampler = sample.Sample(backend, use_cuquantum=use_cuquantum) symbol = sympy.Symbol('alpha') circuit = cirq.Circuit(cirq.H(cirq.GridQubit(0, 0))**symbol) @@ -151,9 +155,17 @@ def test_sample_invalid_combinations(self, backend, use_cuquantum): symbol_values=np.zeros((3, 1)), repetitions=5) - def test_sample_basic_inputs(self): + @parameterized.parameters([{ + 'use_cuquantum': False, + }, { + 'use_cuquantum': True, + }]) + def test_sample_basic_inputs(self, use_cuquantum): """Test that sample ingests inputs correctly in simple settings.""" - sampler = sample.Sample() + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + sampler = sample.Sample(use_cuquantum=use_cuquantum) sampler(cirq.Circuit(), repetitions=10) sampler([cirq.Circuit()], repetitions=10) sampler(cirq.Circuit(), @@ -165,9 +177,17 @@ def test_sample_basic_inputs(self): symbol_values=[[0.5]], repetitions=10) - def test_sample_outputs_simple(self): + @parameterized.parameters([{ + 'use_cuquantum': False, + }, { + 'use_cuquantum': True, + }]) + def test_sample_outputs_simple(self, use_cuquantum): """Test the simplest call where nothing but circuits are provided.""" - sampler = sample.Sample() + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + sampler = sample.Sample(use_cuquantum=use_cuquantum) circuit = cirq.Circuit(cirq.H(cirq.GridQubit(0, 0))) output = sampler([circuit, circuit], repetitions=5) self.assertShapeEqual(np.empty((2, 5, 1)), output.to_tensor()) @@ -190,6 +210,9 @@ def test_sample_output(self, backend, use_cuquantum, all_n_qubits, cause what is output from the layer to structurally deviate from what is expected. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) if use_cuquantum: # If use_cuquantum is True, diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py index 79a42f4b9..4736bbf56 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py @@ -26,6 +26,7 @@ import tensorflow as tf import cirq +from tensorflow_quantum.core.ops import circuit_execution_ops from tensorflow_quantum.python.layers.circuit_executors import \ sampled_expectation from tensorflow_quantum.python.differentiators import linear_combination @@ -130,6 +131,9 @@ def simulate_sweep(self): def test_sampled_expectation_type_inputs_error(self, backend, use_cuquantum): """Test that SampledExpectation errors within Keras call.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") bit = cirq.GridQubit(0, 0) symbol = sympy.Symbol('alpha') @@ -197,6 +201,10 @@ def test_sampled_expectation_type_inputs_error(self, backend, ]) def test_sampled_expectation_op_error(self, backend, use_cuquantum): """Test that expectation errors within underlying ops correctly.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + # Note the expected_regex is left blank here since there is a # discrepancy between the error strings provided between backends. bit = cirq.GridQubit(0, 0) @@ -300,6 +308,9 @@ def test_sampled_expectation_op_error(self, backend, use_cuquantum): ]) def test_static_cases(self, backend, use_cuquantum): """Run inputs through in complex cases.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") bit = cirq.GridQubit(0, 0) symbol = sympy.Symbol('alpha') @@ -381,12 +392,21 @@ def test_static_cases(self, backend, use_cuquantum): cirq.X(bit) + 2.0 * cirq.Z(bit)], repetitions=[5, 1]) - def test_sampled_expectation_simple_tf_train(self): + @parameterized.parameters([{ + 'use_cuquantum': False, + }, { + 'use_cuquantum': True, + }]) + def test_sampled_expectation_simple_tf_train(self, use_cuquantum): """Train a layer using standard tf (not keras).""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) bit = cirq.GridQubit(0, 0) circuit = cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) - layer = sampled_expectation.SampledExpectation() + layer = sampled_expectation.SampledExpectation( + use_cuquantum=use_cuquantum) optimizer = tf.optimizers.Adam(learning_rate=0.05) for _ in range(10): with tf.GradientTape() as tape: @@ -420,6 +440,9 @@ def test_simple_param_value_input(self, backend, use_cuquantum): This model will put a qubit in the zero or one state from a random state given the input zero or one. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') @@ -466,6 +489,9 @@ def test_simple_op_input(self, backend, use_cuquantum): Learn qubit in the z+ state using two different measurement operators. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') @@ -518,6 +544,9 @@ def test_simple_op_and_param_input(self, backend, use_cuquantum): Train a NN to put a qubit in the z+ or x+ states based on a classical binary input. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') @@ -574,6 +603,9 @@ def test_dnn_qnn_dnn(self, backend, use_cuquantum): Train the network to output +-5 given an input of 1 or 0. This tests that everything works when SampledExpectation layer is a middle layers. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') diff --git a/tensorflow_quantum/python/layers/circuit_executors/state_test.py b/tensorflow_quantum/python/layers/circuit_executors/state_test.py index 08980c937..6536428ee 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/state_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/state_test.py @@ -26,6 +26,7 @@ import tensorflow as tf import cirq +from tensorflow_quantum.core.ops import circuit_execution_ops from tensorflow_quantum.python.layers.circuit_executors import state from tensorflow_quantum.python import util @@ -59,7 +60,10 @@ def test_state_create(self): }]) def test_state_invalid_combinations(self, backend, use_cuquantum): """Test with valid type inputs and valid value, but incorrect combo.""" - state_calc = state.State(backend, use_cuquantum) + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + state_calc = state.State(backend, use_cuquantum=use_cuquantum) symbol = sympy.Symbol('alpha') circuit = cirq.Circuit(cirq.H(cirq.GridQubit(0, 0))**symbol) with self.assertRaisesRegex(Exception, expected_regex=""): @@ -142,6 +146,9 @@ def test_state_output(self, backend_output, use_cuquantum): post processing done inside the layers should not cause output from the layer to structurally deviate from what is expected. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") backend = backend_output[0] output = backend_output[1] state_executor = state.State( From 277a56ed6ca5c8f47ec1d46a95216f4c13d9e202 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Thu, 4 May 2023 03:17:14 +0000 Subject: [PATCH 085/106] Fix format of license / add tests fixed seed random inits --- .../scripts/benchmark_clifford_circuit.py | 2 +- benchmarks/scripts/benchmark_op_gradients.py | 2 +- .../scripts/benchmark_random_circuit.py | 2 +- benchmarks/scripts/benchmark_util.py | 2 +- benchmarks/scripts/benchmark_util_test.py | 2 +- benchmarks/scripts/flags.py | 2 +- benchmarks/scripts/flags_test.py | 2 +- benchmarks/scripts/models/__init__.py | 2 +- .../scripts/models/random_clifford_circuit.py | 2 +- .../models/random_clifford_circuit_test.py | 2 +- configure.sh | 2 +- release/build_pip_package.sh | 2 +- release/setup.py | 2 +- scripts/benchmark_all.sh | 2 +- scripts/build_docs.py | 2 +- scripts/build_pip_package_test.sh | 2 +- scripts/ci_install.sh | 2 +- scripts/ci_validate_tutorials.sh | 2 +- scripts/format_all.sh | 2 +- scripts/format_check.sh | 2 +- scripts/format_ipynb.py | 2 +- scripts/import_test.py | 2 +- scripts/lint_all.sh | 2 +- scripts/msan_test.sh | 2 +- scripts/run_example.sh | 2 +- scripts/test_all.sh | 2 +- scripts/test_benchmarks.sh | 2 +- scripts/test_tutorials.py | 2 +- tensorflow_quantum/__init__.py | 2 +- tensorflow_quantum/core/__init__.py | 2 +- tensorflow_quantum/core/ops/__init__.py | 2 +- tensorflow_quantum/core/ops/batch_util.py | 2 +- .../core/ops/batch_util_test.py | 2 +- .../core/ops/circuit_execution_ops.py | 2 +- .../core/ops/circuit_execution_ops_test.py | 2 +- tensorflow_quantum/core/ops/cirq_ops.py | 2 +- tensorflow_quantum/core/ops/cirq_ops_test.py | 2 +- tensorflow_quantum/core/ops/load_module.py | 2 +- .../core/ops/math_ops/__init__.py | 2 +- .../core/ops/math_ops/fidelity_op.py | 2 +- .../core/ops/math_ops/fidelity_op_test.py | 2 +- .../ops/math_ops/inner_product_grad_test.py | 2 +- .../core/ops/math_ops/inner_product_op.py | 2 +- .../ops/math_ops/inner_product_op_test.py | 2 +- .../core/ops/math_ops/simulate_mps.py | 2 +- .../core/ops/math_ops/simulate_mps_test.py | 2 +- tensorflow_quantum/core/ops/noise/__init__.py | 2 +- .../core/ops/noise/noisy_expectation_op.py | 2 +- .../ops/noise/noisy_expectation_op_test.py | 2 +- .../ops/noise/noisy_sampled_expectation_op.py | 2 +- .../noisy_sampled_expectation_op_test.py | 2 +- .../core/ops/noise/noisy_samples_op.py | 2 +- .../core/ops/noise/noisy_samples_op_test.py | 2 +- .../core/ops/tfq_adj_grad_op.py | 2 +- .../core/ops/tfq_adj_grad_op_cuquantum.py | 2 +- .../ops/tfq_adj_grad_op_cuquantum_test.py | 2 +- .../core/ops/tfq_adj_grad_op_test.py | 2 +- .../core/ops/tfq_ps_util_ops.py | 2 +- .../core/ops/tfq_ps_util_ops_test.py | 2 +- .../core/ops/tfq_simulate_ops.py | 2 +- .../core/ops/tfq_simulate_ops_cuquantum.py | 2 +- .../ops/tfq_simulate_ops_cuquantum_test.py | 2 +- .../core/ops/tfq_simulate_ops_test.py | 2 +- tensorflow_quantum/core/ops/tfq_unitary_op.py | 2 +- .../core/ops/tfq_unitary_op_test.py | 2 +- .../core/ops/tfq_utility_ops.py | 2 +- .../core/ops/tfq_utility_ops_test.py | 2 +- tensorflow_quantum/core/proto/__init__.py | 2 +- tensorflow_quantum/core/serialize/__init__.py | 2 +- .../core/serialize/serializer.py | 2 +- .../core/serialize/serializer_test.py | 2 +- tensorflow_quantum/datasets/__init__.py | 2 +- tensorflow_quantum/datasets/cluster_state.py | 2 +- .../datasets/cluster_state_test.py | 2 +- tensorflow_quantum/datasets/spin_system.py | 2 +- .../datasets/spin_system_test.py | 2 +- tensorflow_quantum/python/__init__.py | 2 +- .../python/differentiators/__init__.py | 2 +- .../python/differentiators/adjoint.py | 2 +- .../python/differentiators/adjoint_test.py | 2 +- .../python/differentiators/differentiator.py | 2 +- .../differentiators/differentiator_test.py | 2 +- .../python/differentiators/gradient_test.py | 2 +- .../differentiators/linear_combination.py | 2 +- .../linear_combination_test.py | 2 +- .../python/differentiators/parameter_shift.py | 2 +- .../differentiators/parameter_shift_test.py | 2 +- .../differentiators/parameter_shift_util.py | 2 +- .../parameter_shift_util_test.py | 2 +- tensorflow_quantum/python/layers/__init__.py | 2 +- .../layers/circuit_construction/__init__.py | 2 +- .../layers/circuit_construction/elementary.py | 2 +- .../circuit_construction/elementary_test.py | 2 +- .../layers/circuit_executors/__init__.py | 2 +- .../layers/circuit_executors/expectation.py | 24 ++++++++----- .../circuit_executors/expectation_test.py | 36 ++++++++++++++----- .../layers/circuit_executors/input_checks.py | 2 +- .../circuit_executors/input_checks_test.py | 2 +- .../python/layers/circuit_executors/sample.py | 21 +++++------ .../layers/circuit_executors/sample_test.py | 2 +- .../circuit_executors/sampled_expectation.py | 30 +++++++++------- .../sampled_expectation_test.py | 22 ++++++++---- .../python/layers/circuit_executors/state.py | 11 +++--- .../layers/circuit_executors/state_test.py | 2 +- .../layers/circuit_executors/unitary.py | 2 +- .../layers/circuit_executors/unitary_test.py | 2 +- .../python/layers/high_level/__init__.py | 2 +- .../layers/high_level/controlled_pqc.py | 2 +- .../layers/high_level/controlled_pqc_test.py | 2 +- .../layers/high_level/noisy_controlled_pqc.py | 2 +- .../high_level/noisy_controlled_pqc_test.py | 2 +- .../python/layers/high_level/noisy_pqc.py | 2 +- .../layers/high_level/noisy_pqc_test.py | 2 +- .../python/layers/high_level/pqc.py | 2 +- .../python/layers/high_level/pqc_test.py | 2 +- .../python/optimizers/__init__.py | 2 +- .../python/optimizers/rotosolve_minimizer.py | 2 +- .../optimizers/rotosolve_minimizer_test.py | 2 +- .../python/optimizers/spsa_minimizer.py | 2 +- .../python/optimizers/spsa_minimizer_test.py | 2 +- tensorflow_quantum/python/quantum_context.py | 2 +- .../python/quantum_context_test.py | 2 +- tensorflow_quantum/python/util.py | 2 +- tensorflow_quantum/python/util_test.py | 2 +- 124 files changed, 213 insertions(+), 167 deletions(-) diff --git a/benchmarks/scripts/benchmark_clifford_circuit.py b/benchmarks/scripts/benchmark_clifford_circuit.py index 643eff790..c71751dbc 100644 --- a/benchmarks/scripts/benchmark_clifford_circuit.py +++ b/benchmarks/scripts/benchmark_clifford_circuit.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Benchmark simulators against classically simulatable circuits.""" import os import time diff --git a/benchmarks/scripts/benchmark_op_gradients.py b/benchmarks/scripts/benchmark_op_gradients.py index 89b04cfd1..687e1b1f6 100644 --- a/benchmarks/scripts/benchmark_op_gradients.py +++ b/benchmarks/scripts/benchmark_op_gradients.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Benchmark differentiator methods.""" import os import time diff --git a/benchmarks/scripts/benchmark_random_circuit.py b/benchmarks/scripts/benchmark_random_circuit.py index 51d4ccfbf..b265237d7 100644 --- a/benchmarks/scripts/benchmark_random_circuit.py +++ b/benchmarks/scripts/benchmark_random_circuit.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Benchmark simulators against classically intractable 'supremacy' circuits.""" import os import time diff --git a/benchmarks/scripts/benchmark_util.py b/benchmarks/scripts/benchmark_util.py index 5b4bea2e5..87e903ecb 100644 --- a/benchmarks/scripts/benchmark_util.py +++ b/benchmarks/scripts/benchmark_util.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Utility functions for benchmark tools.""" import tensorflow as tf import test_log_pb2 diff --git a/benchmarks/scripts/benchmark_util_test.py b/benchmarks/scripts/benchmark_util_test.py index bece69897..951478a19 100644 --- a/benchmarks/scripts/benchmark_util_test.py +++ b/benchmarks/scripts/benchmark_util_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for utilities related to reading/running benchmarks.""" import os import tempfile diff --git a/benchmarks/scripts/flags.py b/benchmarks/scripts/flags.py index eaf7e78e2..ee173ef28 100644 --- a/benchmarks/scripts/flags.py +++ b/benchmarks/scripts/flags.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Command line flags shared between benchmarks.""" from collections import namedtuple from absl import flags as absl_flags diff --git a/benchmarks/scripts/flags_test.py b/benchmarks/scripts/flags_test.py index 6383809c6..c51a2f814 100644 --- a/benchmarks/scripts/flags_test.py +++ b/benchmarks/scripts/flags_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for benchmark command line flags.""" import tensorflow as tf diff --git a/benchmarks/scripts/models/__init__.py b/benchmarks/scripts/models/__init__.py index bf5b48863..9d181170d 100644 --- a/benchmarks/scripts/models/__init__.py +++ b/benchmarks/scripts/models/__init__.py @@ -11,4 +11,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== \ No newline at end of file +# ============================================================================= \ No newline at end of file diff --git a/benchmarks/scripts/models/random_clifford_circuit.py b/benchmarks/scripts/models/random_clifford_circuit.py index a08a667b5..09012c14e 100644 --- a/benchmarks/scripts/models/random_clifford_circuit.py +++ b/benchmarks/scripts/models/random_clifford_circuit.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= from typing import Iterable diff --git a/benchmarks/scripts/models/random_clifford_circuit_test.py b/benchmarks/scripts/models/random_clifford_circuit_test.py index c6d968ea0..bee8f5464 100644 --- a/benchmarks/scripts/models/random_clifford_circuit_test.py +++ b/benchmarks/scripts/models/random_clifford_circuit_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= from absl.testing import parameterized import cirq diff --git a/configure.sh b/configure.sh index decaaa2c6..53db1975a 100755 --- a/configure.sh +++ b/configure.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" function write_to_bazelrc() { diff --git a/release/build_pip_package.sh b/release/build_pip_package.sh index 8bed5b909..1c423c656 100755 --- a/release/build_pip_package.sh +++ b/release/build_pip_package.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= set -e set -x diff --git a/release/setup.py b/release/setup.py index c2e9fb718..109c909e9 100644 --- a/release/setup.py +++ b/release/setup.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """TensorFlow Quantum adds qauntum computing primitives to TensorFlow. TensorFlow Quantum is an open source library for high performance batch diff --git a/scripts/benchmark_all.sh b/scripts/benchmark_all.sh index cd50209c2..648d9ebad 100644 --- a/scripts/benchmark_all.sh +++ b/scripts/benchmark_all.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Testing benchmarks."; test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/...)) exit_code=$? diff --git a/scripts/build_docs.py b/scripts/build_docs.py index dc47df224..3ad066491 100644 --- a/scripts/build_docs.py +++ b/scripts/build_docs.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tool to generate external api_docs for tfq.""" from __future__ import absolute_import diff --git a/scripts/build_pip_package_test.sh b/scripts/build_pip_package_test.sh index 644338b6a..144a42cfb 100755 --- a/scripts/build_pip_package_test.sh +++ b/scripts/build_pip_package_test.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= pip install -r requirements.txt diff --git a/scripts/ci_install.sh b/scripts/ci_install.sh index 04e6b3159..860c02ecc 100755 --- a/scripts/ci_install.sh +++ b/scripts/ci_install.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= wget https://github.com/bazelbuild/bazel/releases/download/5.3.0/bazel_5.3.0-linux-x86_64.deb sudo dpkg -i bazel_5.3.0-linux-x86_64.deb pip install --upgrade pip setuptools wheel diff --git a/scripts/ci_validate_tutorials.sh b/scripts/ci_validate_tutorials.sh index e58355faf..d64361464 100755 --- a/scripts/ci_validate_tutorials.sh +++ b/scripts/ci_validate_tutorials.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= # Run the tutorials using the installed pip package pip install jupyter nbclient==0.6.5 jupyter-client==6.1.12 ipython==7.22.0 diff --git a/scripts/format_all.sh b/scripts/format_all.sh index 0e374a3cc..a30017981 100755 --- a/scripts/format_all.sh +++ b/scripts/format_all.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Doing python language formatting..." python3 -m yapf --style=google --in-place --recursive ./benchmarks python3 -m yapf --style=google --in-place --recursive ./tensorflow_quantum diff --git a/scripts/format_check.sh b/scripts/format_check.sh index 1d91427e0..d128d36b4 100755 --- a/scripts/format_check.sh +++ b/scripts/format_check.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Checking python formatting..."; ################################################################################ diff --git a/scripts/format_ipynb.py b/scripts/format_ipynb.py index fac7a8bf1..10d2e447f 100644 --- a/scripts/format_ipynb.py +++ b/scripts/format_ipynb.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Format notebook code cells using yapf google style.""" import glob import nbformat diff --git a/scripts/import_test.py b/scripts/import_test.py index 83ec24d2e..ce2c87307 100644 --- a/scripts/import_test.py +++ b/scripts/import_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests to check if importing `tfq` APIs is successful or not.""" import tensorflow_quantum as tfq diff --git a/scripts/lint_all.sh b/scripts/lint_all.sh index fb7e1c9a5..755906981 100755 --- a/scripts/lint_all.sh +++ b/scripts/lint_all.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Checking for lint in python code..."; linting_outputs=$(pylint --rcfile .pylintrc ./tensorflow_quantum ./examples); exit_code=$? diff --git a/scripts/msan_test.sh b/scripts/msan_test.sh index d47e8ccfe..398332315 100755 --- a/scripts/msan_test.sh +++ b/scripts/msan_test.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Testing All Bazel cc_tests with msan."; test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" \ --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" \ diff --git a/scripts/run_example.sh b/scripts/run_example.sh index bb86edc22..1fbdd62d7 100755 --- a/scripts/run_example.sh +++ b/scripts/run_example.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= cd .. cp quantum/scripts/import_test.py import_test.py python import_test.py \ No newline at end of file diff --git a/scripts/test_all.sh b/scripts/test_all.sh index de82f406d..ffb43d42d 100755 --- a/scripts/test_all.sh +++ b/scripts/test_all.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Testing All Bazel py_test and cc_tests."; ENABLE_CUDA=${1} diff --git a/scripts/test_benchmarks.sh b/scripts/test_benchmarks.sh index 07e3adec1..281791ec7 100644 --- a/scripts/test_benchmarks.sh +++ b/scripts/test_benchmarks.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Testing all Benchmarks."; bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/scripts:all) # test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/scripts:all)) diff --git a/scripts/test_tutorials.py b/scripts/test_tutorials.py index 1650caf15..b4463b90d 100644 --- a/scripts/test_tutorials.py +++ b/scripts/test_tutorials.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to ensure all notebooks execute without error by pytesting them.""" import glob import re diff --git a/tensorflow_quantum/__init__.py b/tensorflow_quantum/__init__.py index 5df8ae1f8..4403510f7 100644 --- a/tensorflow_quantum/__init__.py +++ b/tensorflow_quantum/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module functions for tensorflow_quantum.*""" # Import basic ops and op getters. diff --git a/tensorflow_quantum/core/__init__.py b/tensorflow_quantum/core/__init__.py index fb24ad4a8..7e43c4be5 100644 --- a/tensorflow_quantum/core/__init__.py +++ b/tensorflow_quantum/core/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Imports to tensorflow_quantum.core.* level.""" # Import getters for constructing ops. from tensorflow_quantum.core.ops import (get_expectation_op, diff --git a/tensorflow_quantum/core/ops/__init__.py b/tensorflow_quantum/core/ops/__init__.py index 062ea7499..fc687424a 100644 --- a/tensorflow_quantum/core/ops/__init__.py +++ b/tensorflow_quantum/core/ops/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.core.ops.*""" # Import getters for constructing ops. diff --git a/tensorflow_quantum/core/ops/batch_util.py b/tensorflow_quantum/core/ops/batch_util.py index 75f148424..7575ffae1 100644 --- a/tensorflow_quantum/core/ops/batch_util.py +++ b/tensorflow_quantum/core/ops/batch_util.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A module to for running Cirq objects.""" import collections diff --git a/tensorflow_quantum/core/ops/batch_util_test.py b/tensorflow_quantum/core/ops/batch_util_test.py index 6b11becd7..48eb02ed3 100644 --- a/tensorflow_quantum/core/ops/batch_util_test.py +++ b/tensorflow_quantum/core/ops/batch_util_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test parallel Cirq simulations.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index e75a4bfd5..2c87baa09 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A module for user-facing generators of tfq ops.""" import enum diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops_test.py b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py index 549901258..6a36afb4f 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops_test.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to test consistency between Cirq and TFQ circuit execution ops.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/cirq_ops.py b/tensorflow_quantum/core/ops/cirq_ops.py index 884fe98d2..808296433 100644 --- a/tensorflow_quantum/core/ops/cirq_ops.py +++ b/tensorflow_quantum/core/ops/cirq_ops.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Generators for ops that call out to cirq simulators from the tf graph.""" import functools import numbers diff --git a/tensorflow_quantum/core/ops/cirq_ops_test.py b/tensorflow_quantum/core/ops/cirq_ops_test.py index d634e671c..79a108b66 100644 --- a/tensorflow_quantum/core/ops/cirq_ops_test.py +++ b/tensorflow_quantum/core/ops/cirq_ops_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for the cirq simulation ops.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/load_module.py b/tensorflow_quantum/core/ops/load_module.py index b5002ad84..ee4f9b0b6 100644 --- a/tensorflow_quantum/core/ops/load_module.py +++ b/tensorflow_quantum/core/ops/load_module.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to load python op libraries.""" import os diff --git a/tensorflow_quantum/core/ops/math_ops/__init__.py b/tensorflow_quantum/core/ops/math_ops/__init__.py index 982e26911..9d3b92f64 100644 --- a/tensorflow_quantum/core/ops/math_ops/__init__.py +++ b/tensorflow_quantum/core/ops/math_ops/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.core.ops.math_ops.*""" from tensorflow_quantum.core.ops.math_ops.fidelity_op import fidelity diff --git a/tensorflow_quantum/core/ops/math_ops/fidelity_op.py b/tensorflow_quantum/core/ops/math_ops/fidelity_op.py index 8f2e87e44..ae2908baa 100644 --- a/tensorflow_quantum/core/ops/math_ops/fidelity_op.py +++ b/tensorflow_quantum/core/ops/math_ops/fidelity_op.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.math.fidelity op.""" import tensorflow as tf from tensorflow_quantum.core.ops.math_ops import inner_product_op diff --git a/tensorflow_quantum/core/ops/math_ops/fidelity_op_test.py b/tensorflow_quantum/core/ops/math_ops/fidelity_op_test.py index 1ab8031ea..9fe171785 100644 --- a/tensorflow_quantum/core/ops/math_ops/fidelity_op_test.py +++ b/tensorflow_quantum/core/ops/math_ops/fidelity_op_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target tfq_inner_product.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/math_ops/inner_product_grad_test.py b/tensorflow_quantum/core/ops/math_ops/inner_product_grad_test.py index 7fa74ee40..8d13974b8 100644 --- a/tensorflow_quantum/core/ops/math_ops/inner_product_grad_test.py +++ b/tensorflow_quantum/core/ops/math_ops/inner_product_grad_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target tfq_inner_product_grad.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/math_ops/inner_product_op.py b/tensorflow_quantum/core/ops/math_ops/inner_product_op.py index 5d92b7b92..54e49643e 100644 --- a/tensorflow_quantum/core/ops/math_ops/inner_product_op.py +++ b/tensorflow_quantum/core/ops/math_ops/inner_product_op.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to register python op gradient.""" import os import tensorflow as tf diff --git a/tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py b/tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py index ae83857b6..458b88560 100644 --- a/tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py +++ b/tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target tfq_inner_product.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/math_ops/simulate_mps.py b/tensorflow_quantum/core/ops/math_ops/simulate_mps.py index 812081c05..41e1fd7c2 100644 --- a/tensorflow_quantum/core/ops/math_ops/simulate_mps.py +++ b/tensorflow_quantum/core/ops/math_ops/simulate_mps.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to register MPS simulation ops.""" import os import tensorflow as tf diff --git a/tensorflow_quantum/core/ops/math_ops/simulate_mps_test.py b/tensorflow_quantum/core/ops/math_ops/simulate_mps_test.py index ee7317b6a..eee2190f7 100644 --- a/tensorflow_quantum/core/ops/math_ops/simulate_mps_test.py +++ b/tensorflow_quantum/core/ops/math_ops/simulate_mps_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target simulate_mps.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/noise/__init__.py b/tensorflow_quantum/core/ops/noise/__init__.py index 71291d4d2..d7969cec5 100644 --- a/tensorflow_quantum/core/ops/noise/__init__.py +++ b/tensorflow_quantum/core/ops/noise/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.core.ops.noise.*""" from tensorflow_quantum.core.ops.noise.noisy_expectation_op import expectation diff --git a/tensorflow_quantum/core/ops/noise/noisy_expectation_op.py b/tensorflow_quantum/core/ops/noise/noisy_expectation_op.py index e621988a0..7f801e686 100644 --- a/tensorflow_quantum/core/ops/noise/noisy_expectation_op.py +++ b/tensorflow_quantum/core/ops/noise/noisy_expectation_op.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for high performance noisy circuit simulation ops.""" import os import tensorflow as tf diff --git a/tensorflow_quantum/core/ops/noise/noisy_expectation_op_test.py b/tensorflow_quantum/core/ops/noise/noisy_expectation_op_test.py index 1e73500b8..70659f888 100644 --- a/tensorflow_quantum/core/ops/noise/noisy_expectation_op_test.py +++ b/tensorflow_quantum/core/ops/noise/noisy_expectation_op_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target noisy expectation calculation.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op.py b/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op.py index 1874c8a5e..2cc84fd47 100644 --- a/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op.py +++ b/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for high performance noisy circuit sampled epxectation ops.""" import os import tensorflow as tf diff --git a/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op_test.py b/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op_test.py index 35d1cc113..17f3d31a1 100644 --- a/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op_test.py +++ b/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target noisy expectation calculation.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/noise/noisy_samples_op.py b/tensorflow_quantum/core/ops/noise/noisy_samples_op.py index 4441d0c04..1e19b19ae 100644 --- a/tensorflow_quantum/core/ops/noise/noisy_samples_op.py +++ b/tensorflow_quantum/core/ops/noise/noisy_samples_op.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for high performance noisy circuit sampling ops""" import os import tensorflow as tf diff --git a/tensorflow_quantum/core/ops/noise/noisy_samples_op_test.py b/tensorflow_quantum/core/ops/noise/noisy_samples_op_test.py index b952e8d40..03687bdb7 100644 --- a/tensorflow_quantum/core/ops/noise/noisy_samples_op_test.py +++ b/tensorflow_quantum/core/ops/noise/noisy_samples_op_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target noisy sampling.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op.py index 04b8ff0fb..ead1e34d6 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op.py +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to register python op gradient.""" import tensorflow as tf from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.py index a96e13d23..e73775a45 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.py +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to register python op gradient.""" import tensorflow as tf from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py index 0e9848ab3..262f81728 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target tfq_unitary_op.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.py index 388bb163f..a46f2f1f7 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.py +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target tfq_unitary_op.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/tfq_ps_util_ops.py b/tensorflow_quantum/core/ops/tfq_ps_util_ops.py index ad746d045..5a90eb0b3 100644 --- a/tensorflow_quantum/core/ops/tfq_ps_util_ops.py +++ b/tensorflow_quantum/core/ops/tfq_ps_util_ops.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Expose bindings for ParameterShift C++ ops.""" from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_ps_util_ops_test.py b/tensorflow_quantum/core/ops/tfq_ps_util_ops_test.py index 14bccd9bf..187aab5c9 100644 --- a/tensorflow_quantum/core/ops/tfq_ps_util_ops_test.py +++ b/tensorflow_quantum/core/ops/tfq_ps_util_ops_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test for ParameterShift specific C++ ops.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops.py b/tensorflow_quantum/core/ops/tfq_simulate_ops.py index 17f1fd6bd..a68116c3e 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to register python op gradient.""" import tensorflow as tf from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py index ba448d27e..27165e4d6 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to register cuQuantum simulation python op.""" import tensorflow as tf from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 7922504b3..3cc8ef0b7 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target tfq_simulate_ops_cu*.""" import time import numpy as np diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_test.py index 4cdbe42e5..7b29773c8 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target tfq_simulate_ops.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/tfq_unitary_op.py b/tensorflow_quantum/core/ops/tfq_unitary_op.py index 5db7005db..775516896 100644 --- a/tensorflow_quantum/core/ops/tfq_unitary_op.py +++ b/tensorflow_quantum/core/ops/tfq_unitary_op.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to register python op gradient.""" import tensorflow as tf from tensorflow_quantum.core.ops import tfq_utility_ops diff --git a/tensorflow_quantum/core/ops/tfq_unitary_op_test.py b/tensorflow_quantum/core/ops/tfq_unitary_op_test.py index 212094056..2396bc690 100644 --- a/tensorflow_quantum/core/ops/tfq_unitary_op_test.py +++ b/tensorflow_quantum/core/ops/tfq_unitary_op_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target tfq_unitary_op.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/ops/tfq_utility_ops.py b/tensorflow_quantum/core/ops/tfq_utility_ops.py index e560f579c..2d0d45def 100644 --- a/tensorflow_quantum/core/ops/tfq_utility_ops.py +++ b/tensorflow_quantum/core/ops/tfq_utility_ops.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Expose bindings for tfq utility ops.""" import tensorflow as tf from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_utility_ops_test.py b/tensorflow_quantum/core/ops/tfq_utility_ops_test.py index 00c5ff791..050a4478c 100644 --- a/tensorflow_quantum/core/ops/tfq_utility_ops_test.py +++ b/tensorflow_quantum/core/ops/tfq_utility_ops_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for tfq utility ops.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/core/proto/__init__.py b/tensorflow_quantum/core/proto/__init__.py index bdbbd7a51..be0da7259 100644 --- a/tensorflow_quantum/core/proto/__init__.py +++ b/tensorflow_quantum/core/proto/__init__.py @@ -11,4 +11,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= diff --git a/tensorflow_quantum/core/serialize/__init__.py b/tensorflow_quantum/core/serialize/__init__.py index 6ee678723..eebbe0156 100644 --- a/tensorflow_quantum/core/serialize/__init__.py +++ b/tensorflow_quantum/core/serialize/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.core.serialize.*""" from tensorflow_quantum.core.serialize.serializer import (serialize_circuit, deserialize_circuit, diff --git a/tensorflow_quantum/core/serialize/serializer.py b/tensorflow_quantum/core/serialize/serializer.py index 73b38ee16..80ddb6672 100644 --- a/tensorflow_quantum/core/serialize/serializer.py +++ b/tensorflow_quantum/core/serialize/serializer.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A basic serializer used to serialize/deserialize Cirq circuits for tfq.""" # TODO(pmassey / anyone): determine if this should be kept as globals. import copy diff --git a/tensorflow_quantum/core/serialize/serializer_test.py b/tensorflow_quantum/core/serialize/serializer_test.py index a43da0cf0..effc4f314 100644 --- a/tensorflow_quantum/core/serialize/serializer_test.py +++ b/tensorflow_quantum/core/serialize/serializer_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to test serialization core.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/datasets/__init__.py b/tensorflow_quantum/datasets/__init__.py index de1192fd4..8ec6a1e5a 100644 --- a/tensorflow_quantum/datasets/__init__.py +++ b/tensorflow_quantum/datasets/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Experimental location for interesting quantum datasets.""" # Import to the tensorflow_quantum.datasets.* level.""" from tensorflow_quantum.datasets.cluster_state import excited_cluster_states diff --git a/tensorflow_quantum/datasets/cluster_state.py b/tensorflow_quantum/datasets/cluster_state.py index 2c7f5a909..59c35997f 100644 --- a/tensorflow_quantum/datasets/cluster_state.py +++ b/tensorflow_quantum/datasets/cluster_state.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Toy dataset showing boilerplate code for a cluster state example.""" import numpy as np import cirq diff --git a/tensorflow_quantum/datasets/cluster_state_test.py b/tensorflow_quantum/datasets/cluster_state_test.py index 49e75309d..040cc0a0a 100644 --- a/tensorflow_quantum/datasets/cluster_state_test.py +++ b/tensorflow_quantum/datasets/cluster_state_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test the cluster state dataset.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/datasets/spin_system.py b/tensorflow_quantum/datasets/spin_system.py index 4a180a68f..3d53d5eae 100644 --- a/tensorflow_quantum/datasets/spin_system.py +++ b/tensorflow_quantum/datasets/spin_system.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Quantum datasets for quantum many-body spin systems.""" from collections import namedtuple diff --git a/tensorflow_quantum/datasets/spin_system_test.py b/tensorflow_quantum/datasets/spin_system_test.py index 654b60e2a..e8c85c575 100644 --- a/tensorflow_quantum/datasets/spin_system_test.py +++ b/tensorflow_quantum/datasets/spin_system_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test the spin system dataset""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/__init__.py b/tensorflow_quantum/python/__init__.py index afc3cd168..a66da1f02 100644 --- a/tensorflow_quantum/python/__init__.py +++ b/tensorflow_quantum/python/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module definitions for tensorflow_quantum.python.util.*""" from tensorflow_quantum.python.util import ( # Utility functions. diff --git a/tensorflow_quantum/python/differentiators/__init__.py b/tensorflow_quantum/python/differentiators/__init__.py index ab386b22c..8ce0a4889 100644 --- a/tensorflow_quantum/python/differentiators/__init__.py +++ b/tensorflow_quantum/python/differentiators/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module functions for tfq.differentiators.*""" from tensorflow_quantum.python.differentiators.adjoint import ( diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index 68a06cf89..57ccd304b 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Compute gradients by combining function values linearly.""" import tensorflow as tf diff --git a/tensorflow_quantum/python/differentiators/adjoint_test.py b/tensorflow_quantum/python/differentiators/adjoint_test.py index 23ab4edde..df5ecc0ef 100644 --- a/tensorflow_quantum/python/differentiators/adjoint_test.py +++ b/tensorflow_quantum/python/differentiators/adjoint_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for the differentiator abstract class.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index cfa83d50f..72ee25e28 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Testing consistency in values across differentiation methods.""" import abc import inspect diff --git a/tensorflow_quantum/python/differentiators/differentiator_test.py b/tensorflow_quantum/python/differentiators/differentiator_test.py index 5cefce512..43c5f3286 100644 --- a/tensorflow_quantum/python/differentiators/differentiator_test.py +++ b/tensorflow_quantum/python/differentiators/differentiator_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for the differentiator abstract class.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/differentiators/gradient_test.py b/tensorflow_quantum/python/differentiators/gradient_test.py index f661a419b..8db507579 100644 --- a/tensorflow_quantum/python/differentiators/gradient_test.py +++ b/tensorflow_quantum/python/differentiators/gradient_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Testing for gradient calculation consistency in TFQ.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/differentiators/linear_combination.py b/tensorflow_quantum/python/differentiators/linear_combination.py index dabbd9e34..cee6959bd 100644 --- a/tensorflow_quantum/python/differentiators/linear_combination.py +++ b/tensorflow_quantum/python/differentiators/linear_combination.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Compute gradients by combining function values linearly.""" import numbers diff --git a/tensorflow_quantum/python/differentiators/linear_combination_test.py b/tensorflow_quantum/python/differentiators/linear_combination_test.py index f46b086e4..944b83937 100644 --- a/tensorflow_quantum/python/differentiators/linear_combination_test.py +++ b/tensorflow_quantum/python/differentiators/linear_combination_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Basic tests for the LinearCombinationDifferentiator""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/differentiators/parameter_shift.py b/tensorflow_quantum/python/differentiators/parameter_shift.py index bf1631bba..8a4ef9c3a 100644 --- a/tensorflow_quantum/python/differentiators/parameter_shift.py +++ b/tensorflow_quantum/python/differentiators/parameter_shift.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Compute analytic gradients by using general parameter-shift rule. """ import tensorflow as tf diff --git a/tensorflow_quantum/python/differentiators/parameter_shift_test.py b/tensorflow_quantum/python/differentiators/parameter_shift_test.py index 5a0846f25..99aea8288 100644 --- a/tensorflow_quantum/python/differentiators/parameter_shift_test.py +++ b/tensorflow_quantum/python/differentiators/parameter_shift_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Basic tests for the ParameterShift differentiator""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/differentiators/parameter_shift_util.py b/tensorflow_quantum/python/differentiators/parameter_shift_util.py index 266b3b68e..34889c69a 100644 --- a/tensorflow_quantum/python/differentiators/parameter_shift_util.py +++ b/tensorflow_quantum/python/differentiators/parameter_shift_util.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Util functions for general parameter-shift rule. """ import numpy as np import tensorflow as tf diff --git a/tensorflow_quantum/python/differentiators/parameter_shift_util_test.py b/tensorflow_quantum/python/differentiators/parameter_shift_util_test.py index 8c1083a10..c2d728a30 100644 --- a/tensorflow_quantum/python/differentiators/parameter_shift_util_test.py +++ b/tensorflow_quantum/python/differentiators/parameter_shift_util_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Basic tests for utility functions for ParameterShift""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/layers/__init__.py b/tensorflow_quantum/python/layers/__init__.py index 88f2e5dad..3de402f8d 100644 --- a/tensorflow_quantum/python/layers/__init__.py +++ b/tensorflow_quantum/python/layers/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module definitions for tensorflow_quantum.python.layers.*""" # Utility layers. from tensorflow_quantum.python.layers.circuit_construction import ( diff --git a/tensorflow_quantum/python/layers/circuit_construction/__init__.py b/tensorflow_quantum/python/layers/circuit_construction/__init__.py index 0c5ded5c5..765f26e83 100644 --- a/tensorflow_quantum/python/layers/circuit_construction/__init__.py +++ b/tensorflow_quantum/python/layers/circuit_construction/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.python.layers.circuit_construction.*""" # pylint: disable=line-too-long diff --git a/tensorflow_quantum/python/layers/circuit_construction/elementary.py b/tensorflow_quantum/python/layers/circuit_construction/elementary.py index 66714f800..13574c435 100644 --- a/tensorflow_quantum/python/layers/circuit_construction/elementary.py +++ b/tensorflow_quantum/python/layers/circuit_construction/elementary.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Elementary layers, such as the AddCircuit layer.""" import numpy as np import tensorflow as tf diff --git a/tensorflow_quantum/python/layers/circuit_construction/elementary_test.py b/tensorflow_quantum/python/layers/circuit_construction/elementary_test.py index 38577dbe9..e4aa63f1c 100644 --- a/tensorflow_quantum/python/layers/circuit_construction/elementary_test.py +++ b/tensorflow_quantum/python/layers/circuit_construction/elementary_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for the elementary layers.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/layers/circuit_executors/__init__.py b/tensorflow_quantum/python/layers/circuit_executors/__init__.py index 74d26d3e0..0ce744835 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/__init__.py +++ b/tensorflow_quantum/python/layers/circuit_executors/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.python.layers.circuit_executors.*""" # pylint: disable=line-too-long diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation.py b/tensorflow_quantum/python/layers/circuit_executors/expectation.py index 22e91204d..cba81e7b5 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A tf.keras.layer that ingests programs and outputs expectation values.""" import numbers @@ -285,15 +285,20 @@ def call(self, symbol_values=None, operators=None, repetitions=None, - initializer=tf.keras.initializers.RandomUniform(0, 2 * np.pi)): + initializer=None): """Keras call function. - Input options: - `inputs`, `symbol_names`, `symbol_values`: - see `input_checks.expand_circuits` - `operators`: see `input_checks.expand_operators` - - Output shape: + Args: + inputs: See `input_checks.expand_circuits. + symbol_names: See `input_checks.expand_circuits. + symbol_values: See `input_checks.expand_circuits. + operators: See `input_checks.expand_operators` + repetitions: A Python `int` or a pre-converted `tf.Tensor` + containing a single `int` entry. + initializer: The keras initializer object for weights. + Defaults to uniform distribution [0..2*pi] + + Returns: `tf.Tensor` with shape [batch_size, n_ops] that holds the expectation value for each circuit with each op applied to it (after resolving the corresponding parameters in). @@ -302,6 +307,9 @@ def call(self, if symbol_values is None: values_empty = True + if initializer is None: + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) + inputs, symbol_names, symbol_values = input_checks.expand_circuits( inputs, symbol_names, symbol_values) diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py index 264670674..b1c708bf7 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for tensorflow_quantum.layers.circuit_executors.expectation.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position @@ -48,7 +48,7 @@ def _gen_single_bit_rotation_problem(bit, symbols, noisy): return circuit -class ExpectationTest(tf.test.TestCase): +class ExpectationTest(parameterized.TestCase, tf.test.TestCase): """Basic tests for the expectation layer.""" def test_expectation_instantiate(self): @@ -283,10 +283,17 @@ def test_static_cases_noisy(self): ], [cirq.Z(bit), cirq.Z(bit), cirq.Z(bit)]], repetitions=[[1, 2, 3], [4, 5, 6]]) - def test_expectation_simple_tf_train(self): + @parameterized.parameters([{ + 'use_cuquantum': False, + }, { + 'use_cuquantum': True, + }]) + def test_expectation_simple_tf_train(self, use_cuquantum): """Train a layer using standard tf (not keras). This is a subtle test that will work since we don't use keras compile. """ + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) bit = cirq.GridQubit(0, 0) circuit = \ cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) @@ -297,7 +304,8 @@ def test_expectation_simple_tf_train(self): with tf.GradientTape() as tape: circuit_out = layer(circuit, symbol_names=['theta'], - operators=op) + operators=op, + initializer=initializer) mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) grads = tape.gradient(mse, layer.trainable_weights) optimizer.apply_gradients(zip(grads, layer.trainable_weights)) @@ -331,6 +339,8 @@ def test_simple_param_value_input(self, backend, use_cuquantum): if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) noisy = backend == 'noisy' bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') @@ -348,7 +358,8 @@ def test_simple_param_value_input(self, backend, use_cuquantum): symbol_names=symbols, operators=cirq.Z(bit), symbol_values=l2, - repetitions=reps) + repetitions=reps, + initializer=initializer) model = tf.keras.Model(inputs=[datum, inputs], outputs=outputs) data_in = np.array([[1], [0]], dtype=np.float32) @@ -386,6 +397,8 @@ def test_simple_op_input(self, backend, use_cuquantum): if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + normal_initializer = tf.keras.initializers.RandomNormal() noisy = backend == 'noisy' bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') @@ -406,7 +419,7 @@ def test_simple_op_input(self, backend, use_cuquantum): )(circuit_input, symbol_names=symbols, operators=op_input, - initializer=tf.keras.initializers.RandomNormal(), + initializer=normal_initializer, repetitions=reps) model = tf.keras.Model( @@ -453,6 +466,8 @@ def test_simple_op_and_param_input(self, backend, use_cuquantum): if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) noisy = backend == 'noisy' bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') @@ -475,7 +490,8 @@ def test_simple_op_and_param_input(self, backend, use_cuquantum): symbol_names=symbols, symbol_values=dense_2, operators=op_inp, - repetitions=reps) + repetitions=reps, + initializer=initializer) functional_model = tf.keras.Model( inputs=[data_inp, op_inp, circuit_inp], outputs=[circuit_output]) @@ -513,6 +529,9 @@ def test_dnn_qnn_dnn(self, backend, use_cuquantum): if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) + noisy = backend == 'noisy' bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') @@ -533,7 +552,8 @@ def test_dnn_qnn_dnn(self, backend, use_cuquantum): symbol_names=symbols, symbol_values=d2, operators=cirq.Z(bit), - repetitions=reps) + repetitions=reps, + initializer=initializer) d3 = tf.keras.layers.Dense(1)(quantum) model = tf.keras.Model(inputs=[circuit_input, classical_input], diff --git a/tensorflow_quantum/python/layers/circuit_executors/input_checks.py b/tensorflow_quantum/python/layers/circuit_executors/input_checks.py index b73fbde26..9855b5b74 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/input_checks.py +++ b/tensorflow_quantum/python/layers/circuit_executors/input_checks.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Input checks common to circuit execution layers.""" import numpy as np import sympy diff --git a/tensorflow_quantum/python/layers/circuit_executors/input_checks_test.py b/tensorflow_quantum/python/layers/circuit_executors/input_checks_test.py index affbd55d7..29d9f86b1 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/input_checks_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/input_checks_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for tensorflow_quantum.layers.circuit_executors.input_checks.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/layers/circuit_executors/sample.py b/tensorflow_quantum/python/layers/circuit_executors/sample.py index 80f27bafe..3ba53c6bf 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A tf.keras.layer that ingests programs and outputs bitstring samples.""" import numbers @@ -179,17 +179,18 @@ def call(self, repetitions=None): """Keras call function. - Input options: - `inputs`, `symbol_names`, `symbol_values`: - see `input_checks.expand_circuits` - `repetitions`: a Python `int` or a pre-converted - `tf.Tensor` containing a single `int` entry. + Args: + inputs: See `input_checks.expand_circuits`. + symbol_names: See `input_checks.expand_circuits`. + symbol_values: See `input_checks.expand_circuits`. + repetitions: A Python `int` or a pre-converted `tf.Tensor` + containing a single `int` entry. - Output shape: + Returns: `tf.RaggedTensor` with shape: - [batch size of symbol_values, repetitions, ] - or - [number of circuits, repetitions, ] + [batch size of symbol_values, repetitions, ] + or + [number of circuits, repetitions, ] """ if repetitions is None: raise ValueError("Number of repetitions not specified.") diff --git a/tensorflow_quantum/python/layers/circuit_executors/sample_test.py b/tensorflow_quantum/python/layers/circuit_executors/sample_test.py index 4e466c760..a5b78cb60 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for the sample layer.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py index 454fb61f1..0fdcc421f 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A tf.keras.layer that ingests programs and outputs sampled expectation values .""" import numbers @@ -280,25 +280,31 @@ def call(self, symbol_values=None, operators=None, repetitions=None, - initializer=tf.keras.initializers.RandomUniform(0, 2 * np.pi)): + initializer=None): """Keras call function. - Input options: - `inputs`, `symbol_names`, `symbol_values`: - see `input_checks.expand_circuits` - `operators`: see `input_checks.expand_operators` - `repetitions`: a Python `int` or a pre-converted - `tf.Tensor` containing a single `int` entry. - - Output shape: + Args: + inputs: See `input_checks.expand_circuits. + symbol_names: See `input_checks.expand_circuits. + symbol_values: See `input_checks.expand_circuits. + operators: See `input_checks.expand_operators` + repetitions: A Python `int` or a pre-converted `tf.Tensor` + containing a single `int` entry. + initializer: The keras initializer object for weights. + Defaults to uniform distribution [0..2*pi] + + Returns: `tf.Tensor` with shape [batch_size, n_ops] that holds the - expectation value for each circuit with each op applied to it - (after resolving the corresponding parameters in). + expectation value for each circuit with each op applied to it + (after resolving the corresponding parameters in). """ values_empty = False if symbol_values is None: values_empty = True + if initializer is None: + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) + inputs, symbol_names, symbol_values = input_checks.expand_circuits( inputs, symbol_names, symbol_values) diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py index 4736bbf56..e747ffe2c 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for tensorflow_quantum.layers.circuit_executors.sampled_expectation.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position @@ -403,6 +403,7 @@ def test_sampled_expectation_simple_tf_train(self, use_cuquantum): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi) bit = cirq.GridQubit(0, 0) circuit = cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) layer = sampled_expectation.SampledExpectation( @@ -413,7 +414,8 @@ def test_sampled_expectation_simple_tf_train(self, use_cuquantum): circuit_out = layer(circuit, symbol_names=['theta'], operators=cirq.Z(bit), - repetitions=100) + repetitions=100 + initializer=initializer) mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) grads = tape.gradient(mse, layer.trainable_weights) optimizer.apply_gradients(zip(grads, layer.trainable_weights)) @@ -444,6 +446,7 @@ def test_simple_param_value_input(self, backend, use_cuquantum): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') circuit = _gen_single_bit_rotation_problem( @@ -460,7 +463,8 @@ def test_simple_param_value_input(self, backend, use_cuquantum): symbol_names=symbols, operators=cirq.Z(bit), symbol_values=l2, - repetitions=5000) + repetitions=5000, + initializer=initializer) model = tf.keras.Model(inputs=[datum, inputs], outputs=outputs) data_in = np.array([[1], [0]], dtype=np.float32) @@ -493,6 +497,7 @@ def test_simple_op_input(self, backend, use_cuquantum): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) @@ -513,7 +518,8 @@ def test_simple_op_input(self, backend, use_cuquantum): )(circuit_inp, symbol_names=symbols, operators=op_inp, - repetitions=n_inp) + repetitions=n_inp, + initializer=initializer) model = tf.keras.Model(inputs=[circuit_inp, op_inp, n_inp], outputs=[circuit_output]) @@ -548,6 +554,7 @@ def test_simple_op_and_param_input(self, backend, use_cuquantum): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) @@ -572,7 +579,8 @@ def test_simple_op_and_param_input(self, backend, use_cuquantum): symbol_names=symbols, symbol_values=dense_2, operators=op_inp, - repetitions=n_inp) + repetitions=n_inp, + initializer=initializer) functional_model = tf.keras.Model( inputs=[circuit_inp, data_inp, op_inp, n_inp], @@ -607,6 +615,7 @@ def test_dnn_qnn_dnn(self, backend, use_cuquantum): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') circuits = util.convert_to_tensor([ @@ -627,7 +636,8 @@ def test_dnn_qnn_dnn(self, backend, use_cuquantum): symbol_names=symbols, symbol_values=d2, operators=cirq.Z(bit), - repetitions=5000) + repetitions=5000, + initializer=initializer) d3 = tf.keras.layers.Dense(1)(quantum) model = tf.keras.Model(inputs=[circuit_input, classical_input], diff --git a/tensorflow_quantum/python/layers/circuit_executors/state.py b/tensorflow_quantum/python/layers/circuit_executors/state.py index d9219fbab..456a83463 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/state.py +++ b/tensorflow_quantum/python/layers/circuit_executors/state.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A tf.keras.layer that ingests programs and parameters and outputs a state.""" import tensorflow as tf @@ -150,11 +150,12 @@ def __init__(self, backend=None, use_cuquantum=False, **kwargs): def call(self, inputs, *, symbol_names=None, symbol_values=None): """Keras call function. - Input options: - `inputs`, `symbol_names`, `symbol_values`: - see `input_checks.expand_circuits` + Args: + inputs: See `input_checks.expand_circuits. + symbol_names: See `input_checks.expand_circuits. + symbol_values: See `input_checks.expand_circuits. - Output shape: + Returns: `tf.RaggedTensor` with shape: [batch size of symbol_values, ] or diff --git a/tensorflow_quantum/python/layers/circuit_executors/state_test.py b/tensorflow_quantum/python/layers/circuit_executors/state_test.py index 6536428ee..34a5ab06c 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/state_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/state_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for tensorflow_quantum.layers.circuit_executors.state.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/layers/circuit_executors/unitary.py b/tensorflow_quantum/python/layers/circuit_executors/unitary.py index 34e9385f7..73bd40c83 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/unitary.py +++ b/tensorflow_quantum/python/layers/circuit_executors/unitary.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A tf.keras.layer that ingests programs and outputs a unitary.""" import tensorflow as tf diff --git a/tensorflow_quantum/python/layers/circuit_executors/unitary_test.py b/tensorflow_quantum/python/layers/circuit_executors/unitary_test.py index 7330c807f..aaaf968f9 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/unitary_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/unitary_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for tensorflow_quantum.layers.circuit_executors.unitary.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/layers/high_level/__init__.py b/tensorflow_quantum/python/layers/high_level/__init__.py index 2f7bd6580..19e1a000b 100644 --- a/tensorflow_quantum/python/layers/high_level/__init__.py +++ b/tensorflow_quantum/python/layers/high_level/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.python.layers.high_level.*""" # pylint: disable=line-too-long diff --git a/tensorflow_quantum/python/layers/high_level/controlled_pqc.py b/tensorflow_quantum/python/layers/high_level/controlled_pqc.py index b35e4f69b..7a781f852 100644 --- a/tensorflow_quantum/python/layers/high_level/controlled_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/controlled_pqc.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.python.layers.high_level.controlled_pqc layer.""" import numbers import numpy as np diff --git a/tensorflow_quantum/python/layers/high_level/controlled_pqc_test.py b/tensorflow_quantum/python/layers/high_level/controlled_pqc_test.py index 0d9e76e7e..ed6447d5e 100644 --- a/tensorflow_quantum/python/layers/high_level/controlled_pqc_test.py +++ b/tensorflow_quantum/python/layers/high_level/controlled_pqc_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test module for tfq.python.layers.high_level.controlled_pqc layer.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py index 203a9cc10..2d6565dfc 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.python.layers.high_level.noisy_controlled_pqc layer.""" import numbers import numpy as np diff --git a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc_test.py b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc_test.py index 57ecf6cff..ee45937aa 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc_test.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test module for tfq.python.layers.high_level.controlled_pqc layer.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py index 3cfdb6082..0c72668ce 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.python.layers.high_level.noisy_pqc layer.""" import numbers import numpy as np diff --git a/tensorflow_quantum/python/layers/high_level/noisy_pqc_test.py b/tensorflow_quantum/python/layers/high_level/noisy_pqc_test.py index 112838912..c1997daab 100644 --- a/tensorflow_quantum/python/layers/high_level/noisy_pqc_test.py +++ b/tensorflow_quantum/python/layers/high_level/noisy_pqc_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test module for tfq.python.layers.high_level.noisy_pqc layer.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/layers/high_level/pqc.py b/tensorflow_quantum/python/layers/high_level/pqc.py index 7d05cc922..a4c5c3f05 100644 --- a/tensorflow_quantum/python/layers/high_level/pqc.py +++ b/tensorflow_quantum/python/layers/high_level/pqc.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.python.layers.high_level.pqc layer.""" import numbers import numpy as np diff --git a/tensorflow_quantum/python/layers/high_level/pqc_test.py b/tensorflow_quantum/python/layers/high_level/pqc_test.py index e6d831c66..bae9e6d76 100644 --- a/tensorflow_quantum/python/layers/high_level/pqc_test.py +++ b/tensorflow_quantum/python/layers/high_level/pqc_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test module for tfq.python.layers.high_level.pqc layer.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/optimizers/__init__.py b/tensorflow_quantum/python/optimizers/__init__.py index d93023205..1a1d97d41 100755 --- a/tensorflow_quantum/python/optimizers/__init__.py +++ b/tensorflow_quantum/python/optimizers/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module definitions for tensorflow_quantum.python.optimizers.*""" # Quantum circuit specific optimizers. diff --git a/tensorflow_quantum/python/optimizers/rotosolve_minimizer.py b/tensorflow_quantum/python/optimizers/rotosolve_minimizer.py index 5bf23f6a0..3376cd20e 100755 --- a/tensorflow_quantum/python/optimizers/rotosolve_minimizer.py +++ b/tensorflow_quantum/python/optimizers/rotosolve_minimizer.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """The rotosolve minimization algorithm.""" import numpy as np import tensorflow as tf diff --git a/tensorflow_quantum/python/optimizers/rotosolve_minimizer_test.py b/tensorflow_quantum/python/optimizers/rotosolve_minimizer_test.py index b7d8a454e..ee49ba7b1 100755 --- a/tensorflow_quantum/python/optimizers/rotosolve_minimizer_test.py +++ b/tensorflow_quantum/python/optimizers/rotosolve_minimizer_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test module for tfq.python.optimizers.rotosolve_minimizer optimizer.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/optimizers/spsa_minimizer.py b/tensorflow_quantum/python/optimizers/spsa_minimizer.py index 471b46d9e..10a915ee0 100644 --- a/tensorflow_quantum/python/optimizers/spsa_minimizer.py +++ b/tensorflow_quantum/python/optimizers/spsa_minimizer.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """The SPSA minimization algorithm.""" import tensorflow as tf import numpy as np diff --git a/tensorflow_quantum/python/optimizers/spsa_minimizer_test.py b/tensorflow_quantum/python/optimizers/spsa_minimizer_test.py index a71f25101..f6769e0e4 100644 --- a/tensorflow_quantum/python/optimizers/spsa_minimizer_test.py +++ b/tensorflow_quantum/python/optimizers/spsa_minimizer_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test module for tfq.python.optimizers.spsa_minimizer optimizer.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/quantum_context.py b/tensorflow_quantum/python/quantum_context.py index 44c01cdeb..1a869bdea 100644 --- a/tensorflow_quantum/python/quantum_context.py +++ b/tensorflow_quantum/python/quantum_context.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A global singleton object for defining op execution parameters.""" import multiprocessing diff --git a/tensorflow_quantum/python/quantum_context_test.py b/tensorflow_quantum/python/quantum_context_test.py index 5b219b1dc..b0612823d 100644 --- a/tensorflow_quantum/python/quantum_context_test.py +++ b/tensorflow_quantum/python/quantum_context_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for quantum_context functions.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position diff --git a/tensorflow_quantum/python/util.py b/tensorflow_quantum/python/util.py index 92ebeabee..c736a403f 100644 --- a/tensorflow_quantum/python/util.py +++ b/tensorflow_quantum/python/util.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A collection of helper functions which are useful in places in TFQ.""" import itertools diff --git a/tensorflow_quantum/python/util_test.py b/tensorflow_quantum/python/util_test.py index 3d4e2dd76..9d12ea644 100644 --- a/tensorflow_quantum/python/util_test.py +++ b/tensorflow_quantum/python/util_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for TFQ utilities.""" # Remove PYTHONPATH collisions for protobuf. # pylint: disable=wrong-import-position From 5931af083cac592cd8aa59313e5ae254b6616f57 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Thu, 4 May 2023 22:41:23 +0000 Subject: [PATCH 086/106] Fix simple errors --- .../python/layers/circuit_executors/expectation_test.py | 2 ++ .../layers/circuit_executors/sampled_expectation_test.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py index b1c708bf7..1dce8cb98 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py @@ -31,6 +31,8 @@ from tensorflow_quantum.python.differentiators import linear_combination from tensorflow_quantum.python import util +RANDOM_SEED = 1234 + def _gen_single_bit_rotation_problem(bit, symbols, noisy): """Generate a toy problem on 1 qubit.""" diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py index e747ffe2c..1699c47b4 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py @@ -409,12 +409,12 @@ def test_sampled_expectation_simple_tf_train(self, use_cuquantum): layer = sampled_expectation.SampledExpectation( use_cuquantum=use_cuquantum) optimizer = tf.optimizers.Adam(learning_rate=0.05) - for _ in range(10): + for _ in range(20): with tf.GradientTape() as tape: circuit_out = layer(circuit, symbol_names=['theta'], operators=cirq.Z(bit), - repetitions=100 + repetitions=100, initializer=initializer) mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) grads = tape.gradient(mse, layer.trainable_weights) From 31cd871465ec2f23520018a05add6b9c343bf35d Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Fri, 5 May 2023 05:19:07 +0000 Subject: [PATCH 087/106] Add gpu wheel install path and fix install.md / configs --- configure.sh | 7 ++-- docs/install.md | 34 ++++++++++++++++--- release/setup.py | 15 +++++++- third_party/cuquantum/cuquantum_configure.bzl | 14 +++++++- 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/configure.sh b/configure.sh index 53db1975a..d199accb3 100755 --- a/configure.sh +++ b/configure.sh @@ -73,7 +73,7 @@ done # Check if we are building cuQuantum ops on top of CUDA. if [[ "$TF_NEED_CUDA" == "1" ]]; then - echo "GPU is selected, default acceleration is CUDA for TFQuantum." + echo "GPU is on." echo "Searching cuQuantum library from environment variable CUQUANTUM_ROOT..." if [[ "$CUQUANTUM_ROOT" != "" ]]; then echo " [*] cuQuantum library is detected here: CUQUANTUM_ROOT=$CUQUANTUM_ROOT." @@ -113,7 +113,8 @@ write_to_bazelrc "build --strategy=Genrule=standalone" write_to_bazelrc "build -c opt" write_to_bazelrc "build --cxxopt=\"-D_GLIBCXX_USE_CXX11_ABI=1\"" write_to_bazelrc "build --cxxopt=\"-std=c++17\"" - +write_to_bazelrc "build --cxxopt=\"-O3\"" +write_to_bazelrc "build --cxxopt=\"-march=native\"" if is_windows; then # Use pywrap_tensorflow instead of tensorflow_framework on Windows @@ -156,6 +157,8 @@ if [[ "$TF_NEED_CUDA" == "1" ]]; then write_to_bazelrc "build:cuda -c opt" write_to_bazelrc "build:cuda --cxxopt=\"-D_GLIBCXX_USE_CXX11_ABI=1\"" write_to_bazelrc "build:cuda --cxxopt=\"-std=c++17\"" + write_to_bazelrc "build:cuda --cxxopt=\"-O3\"" + write_to_bazelrc "build:cuda --cxxopt=\"-march=native\"" write_to_bazelrc "build:cuda --@local_config_cuda//:enable_cuda" write_to_bazelrc "build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain" diff --git a/docs/install.md b/docs/install.md index 3de77ecf9..608e35714 100644 --- a/docs/install.md +++ b/docs/install.md @@ -16,7 +16,7 @@ TensorFlow Quantum is supported on Python 3.7, 3.8, and 3.9 and depends directly ### Requirements -* pip 19.0 or later (requires `manylinux2010` support) +* pip 23.0 or later (requires `manylinux2014` support) * [TensorFlow == 2.11.0](https://www.tensorflow.org/install/pip) See the [TensorFlow install guide](https://www.tensorflow.org/install/pip) to @@ -187,20 +187,20 @@ We use the standard [fork and pull request workflow](https://guides.github.com/a -### 6. Build the TensorFlow Quantum pip package +### 6. Build the TensorFlow Quantum pip package for CPU Build the TensorFlow Quantum pip package and install:
-  ./configure.sh
+  ./configure.sh  # Type 'Y' for the first question.
   bazel build -c opt --cxxopt="-O3" --cxxopt="-march=native" --cxxopt="-std=c++17" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" release:build_pip_package
   bazel-bin/release/build_pip_package /tmp/tfquantum/
   python3 -m pip install /tmp/tfquantum/name_of_generated_wheel.whl
 
-To confirm that TensorFlow Quantum has successfully been installed, you can run the tests: +To confirm that TensorFlow Quantum for CPU has successfully been installed, you can run the tests:
   ./scripts/test_all.sh
@@ -208,4 +208,28 @@ To confirm that TensorFlow Quantum has successfully been installed, you can run
 
 
 
-Success: TensorFlow Quantum is now installed.
+Success: TensorFlow Quantum for CPU is now installed.
+
+### 7. Build the TensorFlow Quantum pip package for GPU
+
+Build the TensorFlow Quantum GPU pip package and install:
+
+
+
+  bazel clean --expunge  # If you got stuck `.so` related issue, please clean the cache.
+  ./configure.sh  # Type 'n' for the second question.
+  bazel build -c opt --config=cuda --cxxopt="-O3" --cxxopt="-march=native" --cxxopt="-std=c++17" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" release:build_pip_package
+  bazel-bin/release/build_pip_package /tmp/tfquantum_gpu/
+  python3 -m pip install /tmp/tfquantum_gpu/name_of_generated_wheel.whl
+
+ + +To confirm that TensorFlow Quantum for GPU has successfully been installed, you can run the tests: + +
+  ./scripts/test_all.sh gpu
+
+ + + +Success: TensorFlow Quantum for GPU is now installed. diff --git a/release/setup.py b/release/setup.py index 109c909e9..d5d0ccd3c 100644 --- a/release/setup.py +++ b/release/setup.py @@ -56,6 +56,8 @@ def finalize_options(self): 'google-auth==1.18.0', 'protobuf==3.19.5' ] +REQUIRED_GPU_PACKAGES = [] + # placed as extra to not have required overwrite existing nightly installs if # they exist. EXTRA_PACKAGES = ['tensorflow == 2.11.0'] @@ -74,11 +76,22 @@ def has_ext_modules(self): nightly = True sys.argv.remove('--nightly') +gpu = False +if '--gpu' in sys.argv: + gpu = True + sys.argv.remove('--gpu') + project_name = 'tensorflow-quantum' build_version = CUR_VERSION + +if gpu: + build_version = build_version + '.gpu' + REQUIRED_PACKAGES = REQUIRED_PACKAGES + REQUIRED_GPU_PACKAGES + if nightly: project_name = 'tfq-nightly' - build_version = CUR_VERSION + '.dev' + str(date.today()).replace('-', '') + build_version = build_version + '.dev' + str(date.today()).replace('-', '') + setup( name=project_name, diff --git a/third_party/cuquantum/cuquantum_configure.bzl b/third_party/cuquantum/cuquantum_configure.bzl index e776256da..1a301ebb0 100644 --- a/third_party/cuquantum/cuquantum_configure.bzl +++ b/third_party/cuquantum/cuquantum_configure.bzl @@ -19,6 +19,13 @@ def _fail(msg): fail("%sPython Configuration Error:%s %s\n" % (red, no_color, msg)) +def _warn(msg): + """Output warning message when auto configuration warns.""" + brown = "\033[1;33m" + no_color = "\033[0m" + print("\n%sAuto-Configuration Warning:%s %s\n" % (brown, no_color, msg)) + + def _execute( repository_ctx, cmdline, @@ -70,7 +77,7 @@ def _find_file(repository_ctx, filename): The returned string contains the parent path of the filename. """ result = repository_ctx.execute( - ["timeout", "5", "find", "/", "-name", filename, "-print", "-quit", "-not", "-path", "'*/.*'", "-quit"]).stdout + ["timeout", "10", "find", "/", "-name", filename, "-print", "-quit", "-not", "-path", "'*/.*'", "-quit"]).stdout result = result[:result.find(filename)+len(filename)] return result @@ -202,10 +209,15 @@ def _cuquantum_pip_impl(repository_ctx): repository_ctx.os.environ[_CUQUANTUM_ROOT] = "" cuquantum_root = "" if cuquantum_root == "": + # CUQUANTUM_ROOT is empty. Let's find the library root path lazily. cuquantum_header_path = _find_file(repository_ctx, "custatevec.h") cuquantum_header_path = cuquantum_header_path[:cuquantum_header_path.find("/custatevec.h")] custatevec_shared_library_path = _find_file(repository_ctx, "libcustatevec.so") cuquantum_root = custatevec_shared_library_path[:custatevec_shared_library_path.find("/lib/lib")] + if cuquantum_root == "": + _warn("'CUQUANTUM_ROOT' environment variable is not set, no library was found too. If it is CPU mode, please ignore this warning") + else: + _warn("'CUQUANTUM_ROOT' environment variable is not set, using '%s' as default" % cuquantum_root) else: cuquantum_header_path = "%s/include" % cuquantum_root custatevec_shared_library_path = "%s/lib/libcustatevec.so" % (cuquantum_root) From e629877b04ff30d811a2362e8cb5617af415b0f1 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Sun, 7 May 2023 04:18:57 +0000 Subject: [PATCH 088/106] update configure --- configure.sh | 90 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 34 deletions(-) diff --git a/configure.sh b/configure.sh index d199accb3..ac09cd652 100755 --- a/configure.sh +++ b/configure.sh @@ -49,56 +49,76 @@ function is_ppc64le() { # Remove .bazelrc if it already exist [ -e .bazelrc ] && rm .bazelrc -# Check if we are building GPU or CPU ops, default CPU -while [[ "$TF_NEED_CUDA" == "" ]]; do - read -p "Do you want to build ops again TensorFlow CPU pip package?"\ -" Y or enter for CPU (tensorflow-cpu), N for GPU (tensorflow). [Y/n] " INPUT +# Check if we are building TFQ GPU or not (TODO) +while [[ "$TFQ_NEED_CUDA" == "" ]]; do + read -p "Do you want to build TFQ against GPU ?"\ +" Y or enter for GPU, N for CPU. [Y/n] " INPUT case $INPUT in - [Yy]* ) echo "Build with CPU pip package."; TF_NEED_CUDA=0;; - [Nn]* ) echo "Build with GPU pip package."; TF_NEED_CUDA=1;; - "" ) echo "Build with CPU pip package."; TF_NEED_CUDA=0;; + [Yy]* ) echo "Build with cuQuantum support."; TFQ_NEED_CUDA=1;; + [Nn]* ) echo "Build with CPU ops only."; TFQ_NEED_CUDA=0;; + "" ) echo "Build with cuQuantum support."; TFQ_NEED_CUDA=1;; * ) echo "Invalid selection: " $INPUT;; esac done -while [[ "$TF_CUDA_VERSION" == "" ]]; do - read -p "Are you building against TensorFlow 2.11(including RCs) or newer?[Y/n] " INPUT - case $INPUT in - [Yy]* ) echo "Build against TensorFlow 2.11 or newer."; TF_CUDA_VERSION=11;; - [Nn]* ) echo "Build against TensorFlow <2.11."; TF_CUDA_VERSION=10.0;; - "" ) echo "Build against TensorFlow 2.11 or newer."; TF_CUDA_VERSION=11;; - * ) echo "Invalid selection: " $INPUT;; - esac -done +# Set the CUDA SDK version for TF +if [[ "$TFQ_NEED_CUDA" == "1" ]]; then + _DEFAULT_CUDA_VERSION=11 + while [[ "$TF_CUDA_VERSION" == "" ]]; do + read -p "Please specify the CUDA SDK major version you want to use. [Leave empty to default to CUDA $_DEFAULT_CUDA_VERSION]: " INPUT + case $INPUT in + "" ) echo "Build against CUDA $_DEFAULT_CUDA_VERSION."; TF_CUDA_VERSION=$_DEFAULT_CUDA_VERSION;; + # check if the input is a number + *[!0-9]* ) echo "Invalid selection: $INPUT";; + * ) echo "Build against CUDA $INPUT."; TF_CUDA_VERSION=$INPUT;; + esac + done +fi + +# If TFQ_NEED_CUDA then enforce building against TensorFlow 2.11 or newer. +IS_VALID_TF_VERSION=$(python -c "import tensorflow as tf; v = tf.__version__; print(float(v[:v.rfind('.')]) < 2.11)") +TF_VERSION=$(python -c "import tensorflow as tf; print(tf.__version__)") +if [[ $IS_VALID_TF_VERSION == "True" ]]; then + echo "Building against TensorFlow 2.11 or newer is required." + echo "Please upgrade your TensorFlow version." + exit 1 +elif [[ $IS_VALID_TF_VERSION == "False" ]]; then + echo "Using TensorFlow 2.11" +else + echo "Unable to determine TensorFlow version." + exit 1 +fi # Check if we are building cuQuantum ops on top of CUDA. -if [[ "$TF_NEED_CUDA" == "1" ]]; then - echo "GPU is on." - echo "Searching cuQuantum library from environment variable CUQUANTUM_ROOT..." +if [[ "$TFQ_NEED_CUDA" == "1" ]]; then if [[ "$CUQUANTUM_ROOT" != "" ]]; then echo " [*] cuQuantum library is detected here: CUQUANTUM_ROOT=$CUQUANTUM_ROOT." - write_action_env_to_bazelrc "build:cuda" "CUQUANTUM_ROOT" ${CUQUANTUM_ROOT} - write_linkopt_dir_to_bazelrc "build:cuda" "${CUQUANTUM_ROOT}/lib" else - echo " [*] cuQuantum library is NOT detected. Lazily detect it later, OR please set CUQUANTUM_ROOT environment variable." + # Prompt the user to enter the cuQuantum root path, do not allow empty input (pressing enter) + # If the user enters an invalid path, prompt again. + while true; do + read -p "Please specify the cuQuantum root directory: " INPUT + if [[ -z "$INPUT" ]]; then + echo "Input cannot be empty. Please enter a valid path." + elif [[ "$INPUT" =~ ^(/[A-Za-z0-9_-]+)+$ ]]; then + echo "Path pattern is valid: $INPUT" + CUQUANTUM_ROOT=$INPUT + break + else + echo "Invalid path pattern: $INPUT. Please enter a valid path." + fi + done fi + write_action_env_to_bazelrc "build:cuda" "CUQUANTUM_ROOT" ${CUQUANTUM_ROOT} + write_linkopt_dir_to_bazelrc "build:cuda" "${CUQUANTUM_ROOT}/lib" fi # Check if it's installed if [[ $(pip show tensorflow) == *tensorflow* ]] || [[ $(pip show tf-nightly) == *tf-nightly* ]]; then - echo 'Using installed tensorflow' + echo "Using installed tensorflow-($TF_VERSION)" else - # Uninstall CPU version if it is installed. - if [[ $(pip show tensorflow-cpu) == *tensorflow-cpu* ]]; then - echo 'Already have tensorflow non-gpu installed. Uninstalling......\n' - pip uninstall tensorflow - elif [[ $(pip show tf-nightly-cpu) == *tf-nightly-cpu* ]]; then - echo 'Already have tensorflow non-gpu installed. Uninstalling......\n' - pip uninstall tf-nightly - fi - # Install GPU version - echo 'Installing tensorflow .....\n' - pip install tensorflow + echo 'Installing tensorflow 2.11 .....\n' + pip install tensorflow==2.11.0 fi @@ -140,6 +160,8 @@ if is_windows; then SHARED_LIBRARY_NAME=${SHARED_LIBRARY_NAME//\\//} HEADER_DIR=${HEADER_DIR//\\//} fi + +TF_NEED_CUDA=${TFQ_NEED_CUDA} write_action_env_to_bazelrc "build" "TF_HEADER_DIR" ${HEADER_DIR} "" write_action_env_to_bazelrc "build" "TF_SHARED_LIBRARY_DIR" ${SHARED_LIBRARY_DIR} "" write_action_env_to_bazelrc "build" "TF_SHARED_LIBRARY_NAME" ${SHARED_LIBRARY_NAME} "" From 69e02d6475a3a2e6669752ff8b8651d022478a1d Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Tue, 9 May 2023 08:32:32 +0000 Subject: [PATCH 089/106] add benchmark tests --- benchmarks/scripts/BUILD | 13 + benchmarks/scripts/benchmark_cuquantum_ops.py | 358 ++++++++++++++++++ 2 files changed, 371 insertions(+) create mode 100644 benchmarks/scripts/benchmark_cuquantum_ops.py diff --git a/benchmarks/scripts/BUILD b/benchmarks/scripts/BUILD index 095a10d74..8f099cbc7 100644 --- a/benchmarks/scripts/BUILD +++ b/benchmarks/scripts/BUILD @@ -1,3 +1,4 @@ +load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured") package(default_visibility = ["//visibility:public"]) licenses(["notice"]) @@ -27,6 +28,18 @@ py_test( ], ) +py_test( + name = "benchmark_cuquantum_ops", + srcs = ["benchmark_cuquantum_ops.py"], + python_version = "PY3", + deps = [ + "//tensorflow_quantum/core/ops:tfq_simulate_ops_cuquantum_py", + "//tensorflow_quantum/core/ops::tfq_simulate_ops_py", + "//tensorflow_quantum/core/serialize:serializer", + "@local_config_tf//:test_log_pb2", + "//tensorflow_quantum/python:util", + ], +) py_test( name = "benchmark_op_gradients", srcs = ["benchmark_op_gradients.py"], diff --git a/benchmarks/scripts/benchmark_cuquantum_ops.py b/benchmarks/scripts/benchmark_cuquantum_ops.py new file mode 100644 index 000000000..0d5d395fa --- /dev/null +++ b/benchmarks/scripts/benchmark_cuquantum_ops.py @@ -0,0 +1,358 @@ +import os +import time +import numpy as np +from absl.testing import parameterized +import tensorflow as tf +import cirq + +from tensorflow_quantum.core.ops import tfq_simulate_ops +from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum +from tensorflow_quantum.python import util +import flags +import benchmark_util + +SEED = 63536323 +SRC = os.path.dirname(os.path.realpath(__file__)) +os.environ['TEST_REPORT_FILE_PREFIX'] = os.path.join(SRC, 'reports/') + +class SimulateExpectationCuquantumTest(tf.test.TestCase, parameterized.TestCase): + """Tests tfq_simulate_expectation.""" + + def test_simulate_expectation_cpu_vs_cuquantum(self): + """Make sure that CPU & GPU(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + cpu_avg_time, res_cpu = self._measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), + "Expectation CPU", + num_samples=100, + ) + + # Benchmark time on GPU (cuquantum) + cuquantum_avg_time, res_cuquantum = self._measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), + "Expectation cuQuantum", + num_samples=100, + ) + + extras = { + 'n_qubits': 20, + 'batch_size': 5, + 'num_samples': 100, + 'cpu_avg_time': cpu_avg_time, + 'cuquantum_avg_time': cuquantum_avg_time, + } + + name = "benchmark_simulate_expectation_cuquantum" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cuquantum_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuquantum_avg_time) + + + def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + n_samples = [[10000]] * batch_size + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + cpu_avg_time, res_cpu = self._measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_sampled_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor, + n_samples), + "SampledExpectation CPU", + num_samples=10, + result_avg=False, + ) + + cuquantum_avg_time, res_cuquantum = self._measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor, + n_samples), + "SampledExpectation cuQuantum", + num_samples=10, + result_avg=False, + ) + + extras = { + 'n_qubits': 20, + 'batch_size': 5, + 'num_samples': 100, + 'cpu_avg_time': cpu_avg_time, + 'cuquantum_avg_time': cuquantum_avg_time, + } + + name = "benchmark_simulate_sampled_expectation_cuquantum" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cuquantum_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuquantum_avg_time) + + + def test_simulate_samples_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + n_samples = [100] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cpu_avg_time, res_cpu = self._measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_samples( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), n_samples), + "Samples CPU", + num_samples=10, + result_avg=False, + ) + + cuquantum_avg_time, res_cuquantum = self._measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_samples( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), n_samples), + "Samples cuQuantum", + num_samples=10, + result_avg=False, + ) + + extras = { + 'n_qubits': 20, + 'batch_size': 5, + 'num_samples': 10, + 'cpu_avg_time': cpu_avg_time, + 'cuquantum_avg_time': cuquantum_avg_time, + } + + name = "benchmark_simulate_samples_cuquantum" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cuquantum_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuquantum_avg_time) + + res_cpu = np.average(res_cpu, axis=1) + res_cuquantum = np.average(res_cuquantum, axis=1) + + + def test_simulate_state_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cpu_avg_time, res_cpu = self._measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_state( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64)), + "State CPU", + num_samples=10, + ) + + cuquantum_avg_time, res_cuquantum = self._measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_state( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64)), + "State cuQuantum", + num_samples=10, + ) + + extras = { + 'n_qubits': n_qubits, + 'batch_size': batch_size, + 'num_samples': 10, + 'cpu_avg_time': cpu_avg_time, + 'cuquantum_avg_time': cuquantum_avg_time, + } + + name = "benchmark_simulate_state_cuquantum" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cuquantum_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuquantum_avg_time) + + + @staticmethod + def _measure_average_runtime( + self, + fn, + tag, + num_samples=10, + result_avg=False, + ): + """Measures average runtime for given function. + + Args: + fn: function. + tag: The message title. + num_samples: The number of measurements. + result_avg: True if the results are all averaged. + + Returns: + The average time and the (averaged) result. + """ + avg_time = [] + avg_res = [] + for _ in range(num_samples): + begin_time = time.time() + result = fn() + duration = time.time() - begin_time + avg_time.append(duration) + if result_avg: + avg_res.append(result) + avg_time = sum(avg_time) / float(num_samples) + print(f"\n\t{tag} time: {avg_time}\n") + if result_avg: + result = np.average(avg_res, axis=0) + return avg_time, result + +# class SimulateExpectationCuquantumBenchmark(tf.test.Benchmark): +# """Benchmark tfq_simulate_expectation.""" + +# def benchmark_simulate_expectation_cpu_vs_cuquantum(self): +# test_obj = SimulateExpectationCuquantumTest() +# cpu_avg_time, res_cpu = test_obj._measure_average_runtime( +# lambda: tfq_simulate_ops.tfq_simulate_expectation( +# test_obj.circuit_batch_tensor, test_obj.symbol_names, +# test_obj.symbol_values_array.astype(np.float64), +# test_obj.pauli_sums_tensor), +# "Expectation CPU", +# num_samples=100, +# ) + +# cuquantum_avg_time, res_cuquantum = test_obj._measure_average_runtime( +# lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( +# test_obj.circuit_batch_tensor, test_obj.symbol_names, +# test_obj.symbol_values_array.astype(np.float64), +# test_obj.pauli_sums_tensor), +# "Expectation cuQuantum", +# num_samples=100, +# ) + +# extras = { +# 'n_qubits': 20, +# 'batch_size': 5, +# 'num_samples': 100, +# 'cpu_avg_time': cpu_avg_time, +# 'cuquantum_avg_time': cuquantum_avg_time, +# } + +# name = "benchmark_simulate_expectation_cpu_vs_cuquantum" +# full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], +# "{}.{}".format(self.__class__.__name__, name)) +# if os.path.exists(full_path): +# os.remove(full_path) + +# benchmark_values = { +# "iters": 1, +# "wall_time": cuquantum_avg_time, +# "extras": extras, +# "name": name, +# } +# self.report_benchmark(**benchmark_values) +# return benchmark_values + + +if __name__ == "__main__": + tf.test.main() From dd5ecfd6830b14c568b3ff8ea0fd732daf05135d Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Tue, 9 May 2023 08:33:35 +0000 Subject: [PATCH 090/106] comment out cpu vs gpu benchmark assertions in unit tests --- .../core/ops/tfq_simulate_ops_cuquantum_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index 3cc8ef0b7..c13ce2087 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -97,7 +97,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): ) # cuQuantum op should be faster than CPU op. - self.assertGreater(cpu_avg_time, cuquantum_avg_time) + # self.assertGreater(cpu_avg_time, cuquantum_avg_time) # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, @@ -324,7 +324,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): ) # cuQuantum op should be faster than CPU op. - self.assertGreater(cpu_avg_time, cuquantum_avg_time) + # self.assertGreater(cpu_avg_time, cuquantum_avg_time) # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, @@ -571,7 +571,7 @@ def test_simulate_samples_cpu_vs_cuquantum(self): ) # cuQuantum op should be faster than CPU op. - self.assertGreater(cpu_avg_time, cuquantum_avg_time) + # self.assertGreater(cpu_avg_time, cuquantum_avg_time) res_cpu = np.average(res_cpu, axis=1) res_cuquantum = np.average(res_cuquantum, axis=1) @@ -767,7 +767,7 @@ def test_simulate_state_cpu_vs_cuquantum(self): ) # cuQuantum op should be faster than CPU op. - self.assertGreater(cpu_avg_time, cuquantum_avg_time) + # self.assertGreater(cpu_avg_time, cuquantum_avg_time) # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, From 5b85c78d8da13f3158620697a72a063cdbfaeb32 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Tue, 9 May 2023 19:08:14 +0000 Subject: [PATCH 091/106] remove commented lines --- .../ops/tfq_simulate_ops_cuquantum_test.py | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py index c13ce2087..f3854a3c8 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -80,7 +80,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) - cpu_avg_time, res_cpu = measure_average_runtime( + _, res_cpu = measure_average_runtime( lambda: tfq_simulate_ops.tfq_simulate_expectation( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor), @@ -88,7 +88,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): num_samples=100, ) - cuquantum_avg_time, res_cuquantum = measure_average_runtime( + _, res_cuquantum = measure_average_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor), @@ -96,9 +96,6 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): num_samples=100, ) - # cuQuantum op should be faster than CPU op. - # self.assertGreater(cpu_avg_time, cuquantum_avg_time) - # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, res_cuquantum, @@ -303,7 +300,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) - cpu_avg_time, res_cpu = measure_average_runtime( + _, res_cpu = measure_average_runtime( lambda: tfq_simulate_ops.tfq_simulate_sampled_expectation( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor, @@ -313,7 +310,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): result_avg=False, ) - cuquantum_avg_time, res_cuquantum = measure_average_runtime( + _, res_cuquantum = measure_average_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor, @@ -324,7 +321,6 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): ) # cuQuantum op should be faster than CPU op. - # self.assertGreater(cpu_avg_time, cuquantum_avg_time) # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, @@ -552,7 +548,7 @@ def test_simulate_samples_cpu_vs_cuquantum(self): for symbol in symbol_names] for resolver in resolver_batch]) - cpu_avg_time, res_cpu = measure_average_runtime( + _, res_cpu = measure_average_runtime( lambda: tfq_simulate_ops.tfq_simulate_samples( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), n_samples), @@ -561,7 +557,7 @@ def test_simulate_samples_cpu_vs_cuquantum(self): result_avg=False, ) - cuquantum_avg_time, res_cuquantum = measure_average_runtime( + _, res_cuquantum = measure_average_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_samples( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), n_samples), @@ -571,7 +567,6 @@ def test_simulate_samples_cpu_vs_cuquantum(self): ) # cuQuantum op should be faster than CPU op. - # self.assertGreater(cpu_avg_time, cuquantum_avg_time) res_cpu = np.average(res_cpu, axis=1) res_cuquantum = np.average(res_cuquantum, axis=1) @@ -750,7 +745,7 @@ def test_simulate_state_cpu_vs_cuquantum(self): for symbol in symbol_names] for resolver in resolver_batch]) - cpu_avg_time, res_cpu = measure_average_runtime( + _, res_cpu = measure_average_runtime( lambda: tfq_simulate_ops.tfq_simulate_state( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64)), @@ -758,7 +753,7 @@ def test_simulate_state_cpu_vs_cuquantum(self): num_samples=10, ) - cuquantum_avg_time, res_cuquantum = measure_average_runtime( + _, res_cuquantum = measure_average_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_state( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64)), @@ -767,7 +762,6 @@ def test_simulate_state_cpu_vs_cuquantum(self): ) # cuQuantum op should be faster than CPU op. - # self.assertGreater(cpu_avg_time, cuquantum_avg_time) # The result should be the similar within a tolerance. np.testing.assert_allclose(res_cpu, From b5b6f05cce16618c71c166331bbca564605a5351 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Thu, 11 May 2023 18:49:41 +0000 Subject: [PATCH 092/106] disable use_cuquantum with cirq backend --- .../core/ops/circuit_execution_ops.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index 2c87baa09..f16fcf184 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -160,6 +160,10 @@ def get_expectation_op( # TODO(zaqqwerty): remove DM check after cirq #3964 if isinstance(backend, (cirq.sim.simulator.SimulatesExpectationValues, cirq.DensityMatrixSimulator)): + if use_cuquantum: + raise ValueError( + "use_cuquantum is not supported for cirq simulator. Please \ + set use_cuquantum to False.") op = cirq_ops._get_cirq_analytical_expectation(backend) if op is not None: @@ -264,6 +268,10 @@ def get_sampling_op( op = TFQStateVectorSimulator.samples if isinstance(backend, cirq.Sampler): + if use_cuquantum: + raise ValueError( + "use_cuquantum is not supported for cirq sampler. Please \ + set use_cuquantum to False.") op = cirq_ops._get_cirq_samples(backend) if op is not None: @@ -360,6 +368,10 @@ def get_state_op( op = TFQStateVectorSimulator.state if isinstance(backend, (cirq.SimulatesFinalState)): + if use_cuquantum: + raise ValueError( + "use_cuquantum is not supported for cirq simulator. Please \ + set use_cuquantum to False.") op = cirq_ops._get_cirq_simulate_state(backend) if op is not None: @@ -478,6 +490,10 @@ def get_sampled_expectation_op( op = TFQStateVectorSimulator.sampled_expectation if isinstance(backend, cirq.Sampler): + if use_cuquantum: + raise ValueError( + "use_cuquantum is not supported for cirq sampler. Please \ + set use_cuquantum to False.") op = cirq_ops._get_cirq_sampled_expectation(backend) if op is not None: From 0eac7aa89e877ef7a11ab453903b6d77e5fe0d22 Mon Sep 17 00:00:00 2001 From: Pavan Jayasinha <70229100+Sinestro38@users.noreply.github.com> Date: Thu, 11 May 2023 12:09:45 -0700 Subject: [PATCH 093/106] fix breaking typo error --- benchmarks/scripts/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/scripts/BUILD b/benchmarks/scripts/BUILD index 8f099cbc7..8edf4e49c 100644 --- a/benchmarks/scripts/BUILD +++ b/benchmarks/scripts/BUILD @@ -34,7 +34,7 @@ py_test( python_version = "PY3", deps = [ "//tensorflow_quantum/core/ops:tfq_simulate_ops_cuquantum_py", - "//tensorflow_quantum/core/ops::tfq_simulate_ops_py", + "//tensorflow_quantum/core/ops:tfq_simulate_ops_py", "//tensorflow_quantum/core/serialize:serializer", "@local_config_tf//:test_log_pb2", "//tensorflow_quantum/python:util", From e3a14d655b2e91095a86e15456ebc18ca398e628 Mon Sep 17 00:00:00 2001 From: Pavan Jayasinha <70229100+Sinestro38@users.noreply.github.com> Date: Fri, 12 May 2023 14:15:14 -0700 Subject: [PATCH 094/106] include install instructions to set CUQUANTUM_ROOT env var --- docs/install.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/install.md b/docs/install.md index 608e35714..575354cd6 100644 --- a/docs/install.md +++ b/docs/install.md @@ -212,6 +212,11 @@ Success: TensorFlow Quantum for CPU is now installed. ### 7. Build the TensorFlow Quantum pip package for GPU +To enable GPU (cuQuantum) backend, cuStatevec must be installed, see installation guide for details. Importantly, we require that the `CUQUANTUM_ROOT` environment variable has been set by running the following with your installation path. +
+  export CUQUANTUM_ROOT=/path/to/cuquantum/installation/dir 
+
+ Build the TensorFlow Quantum GPU pip package and install: From 06062de99cdea369dd2ab92d3b83a279c25f488e Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Sun, 14 May 2023 05:31:26 +0000 Subject: [PATCH 095/106] all benchmarks passing version --- benchmarks/scripts/benchmark_cuquantum_ops.py | 528 ++++++++++++------ 1 file changed, 372 insertions(+), 156 deletions(-) diff --git a/benchmarks/scripts/benchmark_cuquantum_ops.py b/benchmarks/scripts/benchmark_cuquantum_ops.py index 0d5d395fa..a275041e6 100644 --- a/benchmarks/scripts/benchmark_cuquantum_ops.py +++ b/benchmarks/scripts/benchmark_cuquantum_ops.py @@ -9,21 +9,79 @@ from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum from tensorflow_quantum.python import util import flags -import benchmark_util +from dataclasses import dataclass SEED = 63536323 SRC = os.path.dirname(os.path.realpath(__file__)) os.environ['TEST_REPORT_FILE_PREFIX'] = os.path.join(SRC, 'reports/') -class SimulateExpectationCuquantumTest(tf.test.TestCase, parameterized.TestCase): - """Tests tfq_simulate_expectation.""" +@dataclass(frozen=True) +class BenchmarkParams: + """Frozen dataclass to store the parameters for the benchmark""" + n_qubits: int + n_moments: int + batch_size: int + n_iters: int = 100 + +_test_params_1 = BenchmarkParams(n_qubits=20, n_moments=1, batch_size=5) +_test_params_2 = BenchmarkParams(n_qubits=21, n_moments=10, batch_size=5) # more depth +_test_params_3 = BenchmarkParams(n_qubits=22, n_moments=1, batch_size=5, n_iters=10) + +TEST_PARAMS_EXPECTATION = [_test_params_1,] +TEST_PARAMS_SAMPLED_EXPECTATION = [_test_params_1,] +TEST_PARAMS_SAMPLES = [_test_params_1,] +TEST_PARAMS_STATE = [_test_params_3,] + +def _measure_median_runtime( + fn, + tag, + num_samples=10, + result_avg=False, +): + """Measures median runtime for given function. + + Args: + fn: function. + tag: The message title. + num_samples: The number of measurements. + result_avg: True if the results are all mediand. + + Returns: + The median time and the (averaged) result. + """ + median_time = [] + avg_res = [] + for _ in range(num_samples): + begin_time = time.time() + result = fn() + duration = time.time() - begin_time + median_time.append(duration) + if result_avg: + avg_res.append(result) + median_time = np.median(median_time) + print(f"\n\t{tag} time: {median_time}\n") + if result_avg: + result = np.average(avg_res, axis=0) + return median_time, result + + +class RandomCircuitBenchmark(tf.test.Benchmark): + """Benchmark cuquantum simulations against cpu.""" + + def __init__(self, params: BenchmarkParams): + """Pull in command line flags or use provided flags.""" + super(RandomCircuitBenchmark, self).__init__() + # Allow input params for testing purposes. + self.params = params - def test_simulate_expectation_cpu_vs_cuquantum(self): - """Make sure that CPU & GPU(cuquantum) ops have the same results.""" - n_qubits = 20 - batch_size = 5 + def benchmark_expectation_cpu(self): + """Benchmark expectation simulator on cpu.""" + + n_qubits = self.params.n_qubits + batch_size = self.params.batch_size + circuit_depth = self.params.n_moments symbol_names = ['alpha'] - qubits = cirq.GridQubit.rect(1, n_qubits) + qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( qubits, symbol_names, batch_size) @@ -38,32 +96,78 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) - cpu_avg_time, res_cpu = self._measure_average_runtime( + cpu_avg_time, _ = _measure_median_runtime( lambda: tfq_simulate_ops.tfq_simulate_expectation( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor), "Expectation CPU", - num_samples=100, + num_samples=self.params.n_iters, ) + extras = { + 'n_qubits': self.params.n_qubits, + 'batch_size': self.params.batch_size, + 'num_samples': self.params.n_iters, + 'median_time': cpu_avg_time, + # 'cuquantum_avg_time': cuquantum_avg_time, + } + + name = "benchmark_expectation_cpu" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cpu_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + return benchmark_values + + + def benchmark_expectation_cuquantum(self): + """Benchmark expectation simulator on cpu.""" + + n_qubits = self.params.n_qubits + batch_size = self.params.batch_size + circuit_depth = self.params.n_moments + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + # Benchmark time on GPU (cuquantum) - cuquantum_avg_time, res_cuquantum = self._measure_average_runtime( + cuquantum_avg_time, _ = _measure_median_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor), "Expectation cuQuantum", - num_samples=100, + num_samples=self.params.n_iters, ) extras = { - 'n_qubits': 20, - 'batch_size': 5, - 'num_samples': 100, - 'cpu_avg_time': cpu_avg_time, - 'cuquantum_avg_time': cuquantum_avg_time, + 'n_qubits': self.params.n_qubits, + 'batch_size': self.params.batch_size, + 'num_samples': self.params.n_iters, + 'median_time': cuquantum_avg_time, } - name = "benchmark_simulate_expectation_cuquantum" + name = "benchmark_expectation_cuquantum" full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], "{}.{}".format(self.__class__.__name__, name)) if os.path.exists(full_path): @@ -77,20 +181,19 @@ def test_simulate_expectation_cpu_vs_cuquantum(self): } self.report_benchmark(**benchmark_values) - # cuQuantum op should be faster than CPU op. - self.assertGreater(cpu_avg_time, cuquantum_avg_time) - - - def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): - """Make sure that cpu & gpu(cuquantum) ops have the same results.""" - n_qubits = 20 - batch_size = 5 + return benchmark_values + + def benchmark_sampled_expectation_cpu(self, params=None): + params = params if params else self.params + n_qubits = params.n_qubits + batch_size = params.batch_size + circuit_depth = params.n_moments symbol_names = ['alpha'] - n_samples = [[10000]] * batch_size - qubits = cirq.GridQubit.rect(1, n_qubits) + qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( qubits, symbol_names, batch_size) + n_samples = [[10000]] * batch_size circuit_batch_tensor = util.convert_to_tensor(circuit_batch) @@ -102,35 +205,81 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) - cpu_avg_time, res_cpu = self._measure_average_runtime( + cpu_avg_time, _ = _measure_median_runtime( lambda: tfq_simulate_ops.tfq_simulate_sampled_expectation( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor, n_samples), "SampledExpectation CPU", - num_samples=10, + num_samples=params.n_iters, result_avg=False, ) - cuquantum_avg_time, res_cuquantum = self._measure_average_runtime( + extras = { + 'n_qubits': params.n_qubits, + 'batch_size': params.batch_size, + 'num_samples': params.n_iters, + 'median_time': cpu_avg_time, + # 'cuquantum_avg_time': cuquantum_avg_time, + } + + name = "benchmark_sampled_expectation_cpu" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cpu_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + return benchmark_values + + def benchmark_sampled_expectation_cuquantum(self, params=None): + params = params if params else self.params + n_qubits = params.n_qubits + batch_size = params.batch_size + circuit_depth = params.n_moments + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + n_samples = [[10000]] * batch_size + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + cuquantum_avg_time, res_cuquantum = _measure_median_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), pauli_sums_tensor, n_samples), "SampledExpectation cuQuantum", - num_samples=10, + num_samples=params.n_iters, result_avg=False, ) extras = { - 'n_qubits': 20, - 'batch_size': 5, - 'num_samples': 100, - 'cpu_avg_time': cpu_avg_time, - 'cuquantum_avg_time': cuquantum_avg_time, + 'n_qubits': params.n_qubits, + 'batch_size': params.batch_size, + 'num_samples': params.n_iters, + 'median_time': cuquantum_avg_time, + # 'cuquantum_avg_time': cuquantum_avg_time, } - name = "benchmark_simulate_sampled_expectation_cuquantum" + name = "benchmark_sampled_expectation_cuquantum" full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], "{}.{}".format(self.__class__.__name__, name)) if os.path.exists(full_path): @@ -144,18 +293,17 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): } self.report_benchmark(**benchmark_values) + return benchmark_values - # cuQuantum op should be faster than CPU op. - self.assertGreater(cpu_avg_time, cuquantum_avg_time) - - - def test_simulate_samples_cpu_vs_cuquantum(self): - """Make sure that cpu & gpu(cuquantum) ops have the same results.""" - n_qubits = 20 - batch_size = 5 + def benchmark_samples_cpu(self, params=None): + params = params if params else self.params + n_qubits = params.n_qubits + batch_size = params.batch_size + circuit_depth = params.n_moments symbol_names = ['alpha'] n_samples = [100] - qubits = cirq.GridQubit.rect(1, n_qubits) + qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( qubits, symbol_names, batch_size) @@ -167,30 +315,74 @@ def test_simulate_samples_cpu_vs_cuquantum(self): for symbol in symbol_names] for resolver in resolver_batch]) - cpu_avg_time, res_cpu = self._measure_average_runtime( + cpu_avg_time, _ = _measure_median_runtime( lambda: tfq_simulate_ops.tfq_simulate_samples( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), n_samples), "Samples CPU", - num_samples=10, + num_samples=params.n_iters, result_avg=False, ) - cuquantum_avg_time, res_cuquantum = self._measure_average_runtime( + extras = { + 'n_qubits': params.n_qubits, + 'batch_size': params.batch_size, + 'num_samples': params.n_iters, + 'median_time': cpu_avg_time, + # 'cuquantum_avg_time': cuquantum_avg_time, + } + + name = "benchmark_simulate_samples_cpu" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cpu_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + return benchmark_values + + def benchmark_samples_cuquantum(self, params=None): + params = params if params else self.params + n_qubits = params.n_qubits + batch_size = params.batch_size + circuit_depth = params.n_moments + symbol_names = ['alpha'] + n_samples = [100] + qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cuquantum_avg_time, _ = _measure_median_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_samples( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64), n_samples), "Samples cuQuantum", - num_samples=10, + num_samples=params.n_iters, result_avg=False, ) extras = { - 'n_qubits': 20, - 'batch_size': 5, - 'num_samples': 10, - 'cpu_avg_time': cpu_avg_time, - 'cuquantum_avg_time': cuquantum_avg_time, + 'n_qubits': params.n_qubits, + 'batch_size': params.batch_size, + 'num_samples': params.n_iters, + 'median_time': cuquantum_avg_time, + # 'cuquantum_avg_time': cuquantum_avg_time, } name = "benchmark_simulate_samples_cuquantum" @@ -207,52 +399,90 @@ def test_simulate_samples_cpu_vs_cuquantum(self): } self.report_benchmark(**benchmark_values) - # cuQuantum op should be faster than CPU op. - self.assertGreater(cpu_avg_time, cuquantum_avg_time) - - res_cpu = np.average(res_cpu, axis=1) - res_cuquantum = np.average(res_cuquantum, axis=1) + return benchmark_values - - def test_simulate_state_cpu_vs_cuquantum(self): - """Make sure that cpu & gpu(cuquantum) ops have the same results.""" - n_qubits = 20 - batch_size = 5 + def benchmark_state_cpu(self, params=None): + params = params if params else self.params + n_qubits = params.n_qubits + batch_size = params.batch_size + circuit_depth = params.n_moments symbol_names = ['alpha'] - qubits = cirq.GridQubit.rect(1, n_qubits) + qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( qubits, symbol_names, batch_size) circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + symbol_values_array = np.array( [[resolver[symbol] for symbol in symbol_names] for resolver in resolver_batch]) - cpu_avg_time, res_cpu = self._measure_average_runtime( + cpu_avg_time, _ = _measure_median_runtime( lambda: tfq_simulate_ops.tfq_simulate_state( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64)), "State CPU", - num_samples=10, + num_samples=params.n_iters, ) - cuquantum_avg_time, res_cuquantum = self._measure_average_runtime( + extras = { + 'n_qubits': params.n_qubits, + 'batch_size': params.batch_size, + 'num_samples': params.n_iters, + 'median_time': cpu_avg_time, + } + + name = "benchmark_simulate_state_cpu" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cpu_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + return benchmark_values + + def benchmark_state_cuquantum(self, params=None): + params = params if params else self.params + n_qubits = params.n_qubits + batch_size = params.batch_size + circuit_depth = params.n_moments + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cuquantum_avg_time, _ = _measure_median_runtime( lambda: tfq_simulate_ops_cuquantum.tfq_simulate_state( circuit_batch_tensor, symbol_names, symbol_values_array.astype(np.float64)), "State cuQuantum", - num_samples=10, + num_samples=params.n_iters, ) extras = { - 'n_qubits': n_qubits, - 'batch_size': batch_size, - 'num_samples': 10, - 'cpu_avg_time': cpu_avg_time, - 'cuquantum_avg_time': cuquantum_avg_time, + 'n_qubits': params.n_qubits, + 'batch_size': params.batch_size, + 'num_samples': params.n_iters, + 'median_time': cuquantum_avg_time, } name = "benchmark_simulate_state_cuquantum" @@ -269,89 +499,75 @@ def test_simulate_state_cpu_vs_cuquantum(self): } self.report_benchmark(**benchmark_values) + return benchmark_values + + + +class SimulateExpectationCuquantumTest(tf.test.TestCase, parameterized.TestCase): + """Tests tfq_simulate_expectation.""" + + @parameterized.parameters( + TEST_PARAMS_EXPECTATION + ) + def test_simulate_expectation_cpu_vs_cuquantum(self, params): + """Make sure that cuquantum version is faster.""" + bench = RandomCircuitBenchmark(params) + + benchmark_cpu = bench.benchmark_expectation_cpu() + benchmark_gpu = bench.benchmark_expectation_cuquantum() + + cpu_median_time = benchmark_cpu['extras']['median_time'] + gpu_median_time = benchmark_gpu['extras']['median_time'] + # cuQuantum op should be faster than CPU op. - self.assertGreater(cpu_avg_time, cuquantum_avg_time) + self.assertGreater(cpu_median_time, gpu_median_time) + @parameterized.parameters( + TEST_PARAMS_SAMPLED_EXPECTATION + ) + def test_simulate_sampled_expectation_cpu_vs_cuquantum(self, params): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + bench = RandomCircuitBenchmark(params) - @staticmethod - def _measure_average_runtime( - self, - fn, - tag, - num_samples=10, - result_avg=False, - ): - """Measures average runtime for given function. - - Args: - fn: function. - tag: The message title. - num_samples: The number of measurements. - result_avg: True if the results are all averaged. - - Returns: - The average time and the (averaged) result. - """ - avg_time = [] - avg_res = [] - for _ in range(num_samples): - begin_time = time.time() - result = fn() - duration = time.time() - begin_time - avg_time.append(duration) - if result_avg: - avg_res.append(result) - avg_time = sum(avg_time) / float(num_samples) - print(f"\n\t{tag} time: {avg_time}\n") - if result_avg: - result = np.average(avg_res, axis=0) - return avg_time, result - -# class SimulateExpectationCuquantumBenchmark(tf.test.Benchmark): -# """Benchmark tfq_simulate_expectation.""" - -# def benchmark_simulate_expectation_cpu_vs_cuquantum(self): -# test_obj = SimulateExpectationCuquantumTest() -# cpu_avg_time, res_cpu = test_obj._measure_average_runtime( -# lambda: tfq_simulate_ops.tfq_simulate_expectation( -# test_obj.circuit_batch_tensor, test_obj.symbol_names, -# test_obj.symbol_values_array.astype(np.float64), -# test_obj.pauli_sums_tensor), -# "Expectation CPU", -# num_samples=100, -# ) - -# cuquantum_avg_time, res_cuquantum = test_obj._measure_average_runtime( -# lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( -# test_obj.circuit_batch_tensor, test_obj.symbol_names, -# test_obj.symbol_values_array.astype(np.float64), -# test_obj.pauli_sums_tensor), -# "Expectation cuQuantum", -# num_samples=100, -# ) - -# extras = { -# 'n_qubits': 20, -# 'batch_size': 5, -# 'num_samples': 100, -# 'cpu_avg_time': cpu_avg_time, -# 'cuquantum_avg_time': cuquantum_avg_time, -# } - -# name = "benchmark_simulate_expectation_cpu_vs_cuquantum" -# full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], -# "{}.{}".format(self.__class__.__name__, name)) -# if os.path.exists(full_path): -# os.remove(full_path) - -# benchmark_values = { -# "iters": 1, -# "wall_time": cuquantum_avg_time, -# "extras": extras, -# "name": name, -# } -# self.report_benchmark(**benchmark_values) -# return benchmark_values + benchmark_cpu = bench.benchmark_sampled_expectation_cpu() + benchmark_gpu = bench.benchmark_sampled_expectation_cuquantum() + + cpu_median_time = benchmark_cpu['extras']['median_time'] + gpu_median_time = benchmark_gpu['extras']['median_time'] + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_median_time, gpu_median_time) + + @parameterized.parameters( + TEST_PARAMS_SAMPLES + ) + def test_simulate_samples_cpu_vs_cuquantum(self, params): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + bench = RandomCircuitBenchmark(params) + + benchmark_cpu = bench.benchmark_samples_cpu() + benchmark_gpu = bench.benchmark_samples_cuquantum() + + cpu_median_time = benchmark_cpu['extras']['median_time'] + gpu_median_time = benchmark_gpu['extras']['median_time'] + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_median_time, gpu_median_time) + + @parameterized.parameters( + TEST_PARAMS_STATE + ) + def test_simulate_state_cpu_vs_cuquantum(self, params): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + bench = RandomCircuitBenchmark(params) + + benchmark_cpu = bench.benchmark_state_cpu() + benchmark_gpu = bench.benchmark_state_cuquantum() + + cpu_median_time = benchmark_cpu['extras']['median_time'] + gpu_median_time = benchmark_gpu['extras']['median_time'] + + self.assertGreater(cpu_median_time, gpu_median_time) if __name__ == "__main__": From d16aef9f016e8015315d1d838b590905f88a1b6d Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Sun, 14 May 2023 05:32:50 +0000 Subject: [PATCH 096/106] add uncomment toggle --- benchmarks/scripts/benchmark_cuquantum_ops.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/benchmarks/scripts/benchmark_cuquantum_ops.py b/benchmarks/scripts/benchmark_cuquantum_ops.py index a275041e6..824892d7e 100644 --- a/benchmarks/scripts/benchmark_cuquantum_ops.py +++ b/benchmarks/scripts/benchmark_cuquantum_ops.py @@ -27,9 +27,18 @@ class BenchmarkParams: _test_params_2 = BenchmarkParams(n_qubits=21, n_moments=10, batch_size=5) # more depth _test_params_3 = BenchmarkParams(n_qubits=22, n_moments=1, batch_size=5, n_iters=10) -TEST_PARAMS_EXPECTATION = [_test_params_1,] -TEST_PARAMS_SAMPLED_EXPECTATION = [_test_params_1,] -TEST_PARAMS_SAMPLES = [_test_params_1,] +TEST_PARAMS_EXPECTATION = [ + _test_params_1, + # _test_params_2, # uncomment for depth params + ] +TEST_PARAMS_SAMPLED_EXPECTATION = [ + _test_params_1, + # _test_params_2, # uncomment for depth params + ] +TEST_PARAMS_SAMPLES = [ + _test_params_1, + # _test_params_2, # uncomment for depth params + ] TEST_PARAMS_STATE = [_test_params_3,] def _measure_median_runtime( From cd9d928f9ec8e152f6b0bbf7ac8839262c98a008 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Sun, 14 May 2023 05:33:31 +0000 Subject: [PATCH 097/106] remove seed --- benchmarks/scripts/benchmark_cuquantum_ops.py | 1 - 1 file changed, 1 deletion(-) diff --git a/benchmarks/scripts/benchmark_cuquantum_ops.py b/benchmarks/scripts/benchmark_cuquantum_ops.py index 824892d7e..e6fd629cf 100644 --- a/benchmarks/scripts/benchmark_cuquantum_ops.py +++ b/benchmarks/scripts/benchmark_cuquantum_ops.py @@ -11,7 +11,6 @@ import flags from dataclasses import dataclass -SEED = 63536323 SRC = os.path.dirname(os.path.realpath(__file__)) os.environ['TEST_REPORT_FILE_PREFIX'] = os.path.join(SRC, 'reports/') From 0d2738d144cafc6a167c3b08077d644d9d4ab4a2 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Mon, 15 May 2023 05:35:30 +0000 Subject: [PATCH 098/106] add passing depth benchmark cases --- benchmarks/scripts/benchmark_cuquantum_ops.py | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/benchmarks/scripts/benchmark_cuquantum_ops.py b/benchmarks/scripts/benchmark_cuquantum_ops.py index e6fd629cf..6c93418b9 100644 --- a/benchmarks/scripts/benchmark_cuquantum_ops.py +++ b/benchmarks/scripts/benchmark_cuquantum_ops.py @@ -22,23 +22,25 @@ class BenchmarkParams: batch_size: int n_iters: int = 100 -_test_params_1 = BenchmarkParams(n_qubits=20, n_moments=1, batch_size=5) -_test_params_2 = BenchmarkParams(n_qubits=21, n_moments=10, batch_size=5) # more depth -_test_params_3 = BenchmarkParams(n_qubits=22, n_moments=1, batch_size=5, n_iters=10) +_test_params_1 = BenchmarkParams(n_qubits=20, n_moments=15, batch_size=5) +_test_params_2 = BenchmarkParams(n_qubits=21, n_moments=25, batch_size=5) # more depth +_test_params_3 = BenchmarkParams(n_qubits=22, n_moments=15, batch_size=5, n_iters=10) TEST_PARAMS_EXPECTATION = [ _test_params_1, - # _test_params_2, # uncomment for depth params + _test_params_2, # uncomment for depth params ] TEST_PARAMS_SAMPLED_EXPECTATION = [ _test_params_1, - # _test_params_2, # uncomment for depth params + _test_params_2, # uncomment for depth params ] TEST_PARAMS_SAMPLES = [ _test_params_1, - # _test_params_2, # uncomment for depth params + _test_params_2, # uncomment for depth params + ] +TEST_PARAMS_STATE = [ + _test_params_3, ] -TEST_PARAMS_STATE = [_test_params_3,] def _measure_median_runtime( fn, @@ -89,10 +91,10 @@ def benchmark_expectation_cpu(self): batch_size = self.params.batch_size circuit_depth = self.params.n_moments symbol_names = ['alpha'] - qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, batch_size) + qubits, symbol_names, batch_size, n_moments=circuit_depth) circuit_batch_tensor = util.convert_to_tensor(circuit_batch) @@ -144,10 +146,10 @@ def benchmark_expectation_cuquantum(self): batch_size = self.params.batch_size circuit_depth = self.params.n_moments symbol_names = ['alpha'] - qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, batch_size) + qubits, symbol_names, batch_size, n_moments=circuit_depth) circuit_batch_tensor = util.convert_to_tensor(circuit_batch) @@ -197,10 +199,10 @@ def benchmark_sampled_expectation_cpu(self, params=None): batch_size = params.batch_size circuit_depth = params.n_moments symbol_names = ['alpha'] - qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, batch_size) + qubits, symbol_names, batch_size, n_moments=circuit_depth) n_samples = [[10000]] * batch_size circuit_batch_tensor = util.convert_to_tensor(circuit_batch) @@ -253,10 +255,10 @@ def benchmark_sampled_expectation_cuquantum(self, params=None): batch_size = params.batch_size circuit_depth = params.n_moments symbol_names = ['alpha'] - qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, batch_size) + qubits, symbol_names, batch_size, n_moments=circuit_depth) n_samples = [[10000]] * batch_size circuit_batch_tensor = util.convert_to_tensor(circuit_batch) @@ -310,11 +312,11 @@ def benchmark_samples_cpu(self, params=None): circuit_depth = params.n_moments symbol_names = ['alpha'] n_samples = [100] - qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, batch_size) + qubits, symbol_names, batch_size, n_moments=circuit_depth) circuit_batch_tensor = util.convert_to_tensor(circuit_batch) @@ -363,11 +365,11 @@ def benchmark_samples_cuquantum(self, params=None): circuit_depth = params.n_moments symbol_names = ['alpha'] n_samples = [100] - qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, batch_size) + qubits, symbol_names, batch_size, n_moments=circuit_depth) circuit_batch_tensor = util.convert_to_tensor(circuit_batch) @@ -415,10 +417,10 @@ def benchmark_state_cpu(self, params=None): batch_size = params.batch_size circuit_depth = params.n_moments symbol_names = ['alpha'] - qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, batch_size) + qubits, symbol_names, batch_size, n_moments=circuit_depth) circuit_batch_tensor = util.convert_to_tensor(circuit_batch) @@ -465,10 +467,10 @@ def benchmark_state_cuquantum(self, params=None): batch_size = params.batch_size circuit_depth = params.n_moments symbol_names = ['alpha'] - qubits = cirq.GridQubit.rect(circuit_depth, n_qubits) + qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, batch_size) + qubits, symbol_names, batch_size, n_moments=circuit_depth) circuit_batch_tensor = util.convert_to_tensor(circuit_batch) From 6b845d329c0d60f74ef1c0473262b88a8964b903 Mon Sep 17 00:00:00 2001 From: Sinestro38 Date: Mon, 15 May 2023 18:13:30 +0000 Subject: [PATCH 099/106] update default cpu config --- configure.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/configure.sh b/configure.sh index ac09cd652..088df4855 100755 --- a/configure.sh +++ b/configure.sh @@ -51,12 +51,12 @@ function is_ppc64le() { # Check if we are building TFQ GPU or not (TODO) while [[ "$TFQ_NEED_CUDA" == "" ]]; do - read -p "Do you want to build TFQ against GPU ?"\ -" Y or enter for GPU, N for CPU. [Y/n] " INPUT + read -p "Do you want to build TFQ against CPU?"\ +" Y or enter for CPU, N for GPU. [Y/n] " INPUT case $INPUT in - [Yy]* ) echo "Build with cuQuantum support."; TFQ_NEED_CUDA=1;; - [Nn]* ) echo "Build with CPU ops only."; TFQ_NEED_CUDA=0;; - "" ) echo "Build with cuQuantum support."; TFQ_NEED_CUDA=1;; + [Yy]* ) echo "Build with CPU ops only."; TFQ_NEED_CUDA=0;; + [Nn]* ) echo "Build with cuQuantum support."; TFQ_NEED_CUDA=1;; + "" ) echo "Build with CPU ops only."; TFQ_NEED_CUDA=0;; * ) echo "Invalid selection: " $INPUT;; esac done From 044123d4cf0acb5c49228a6c25ac8690240bfbfa Mon Sep 17 00:00:00 2001 From: QuantumJaeYoo Date: Sun, 21 May 2023 01:58:34 +0000 Subject: [PATCH 100/106] Fix format --- benchmarks/scripts/benchmark_cuquantum_ops.py | 52 +++++++++---------- .../sampled_expectation_test.py | 10 ++-- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/benchmarks/scripts/benchmark_cuquantum_ops.py b/benchmarks/scripts/benchmark_cuquantum_ops.py index 6c93418b9..d141d4999 100644 --- a/benchmarks/scripts/benchmark_cuquantum_ops.py +++ b/benchmarks/scripts/benchmark_cuquantum_ops.py @@ -14,6 +14,7 @@ SRC = os.path.dirname(os.path.realpath(__file__)) os.environ['TEST_REPORT_FILE_PREFIX'] = os.path.join(SRC, 'reports/') + @dataclass(frozen=True) class BenchmarkParams: """Frozen dataclass to store the parameters for the benchmark""" @@ -22,25 +23,31 @@ class BenchmarkParams: batch_size: int n_iters: int = 100 + _test_params_1 = BenchmarkParams(n_qubits=20, n_moments=15, batch_size=5) -_test_params_2 = BenchmarkParams(n_qubits=21, n_moments=25, batch_size=5) # more depth -_test_params_3 = BenchmarkParams(n_qubits=22, n_moments=15, batch_size=5, n_iters=10) +_test_params_2 = BenchmarkParams(n_qubits=21, n_moments=25, + batch_size=5) # more depth +_test_params_3 = BenchmarkParams(n_qubits=22, + n_moments=15, + batch_size=5, + n_iters=10) TEST_PARAMS_EXPECTATION = [ _test_params_1, - _test_params_2, # uncomment for depth params - ] + _test_params_2, # uncomment for depth params +] TEST_PARAMS_SAMPLED_EXPECTATION = [ _test_params_1, - _test_params_2, # uncomment for depth params - ] + _test_params_2, # uncomment for depth params +] TEST_PARAMS_SAMPLES = [ _test_params_1, - _test_params_2, # uncomment for depth params - ] + _test_params_2, # uncomment for depth params +] TEST_PARAMS_STATE = [ _test_params_3, - ] +] + def _measure_median_runtime( fn, @@ -138,7 +145,6 @@ def benchmark_expectation_cpu(self): return benchmark_values - def benchmark_expectation_cuquantum(self): """Benchmark expectation simulator on cpu.""" @@ -192,7 +198,7 @@ def benchmark_expectation_cuquantum(self): self.report_benchmark(**benchmark_values) return benchmark_values - + def benchmark_sampled_expectation_cpu(self, params=None): params = params if params else self.params n_qubits = params.n_qubits @@ -248,7 +254,7 @@ def benchmark_sampled_expectation_cpu(self, params=None): self.report_benchmark(**benchmark_values) return benchmark_values - + def benchmark_sampled_expectation_cuquantum(self, params=None): params = params if params else self.params n_qubits = params.n_qubits @@ -424,7 +430,6 @@ def benchmark_state_cpu(self, params=None): circuit_batch_tensor = util.convert_to_tensor(circuit_batch) - symbol_values_array = np.array( [[resolver[symbol] for symbol in symbol_names] @@ -474,7 +479,6 @@ def benchmark_state_cuquantum(self, params=None): circuit_batch_tensor = util.convert_to_tensor(circuit_batch) - symbol_values_array = np.array( [[resolver[symbol] for symbol in symbol_names] @@ -512,13 +516,11 @@ def benchmark_state_cuquantum(self, params=None): return benchmark_values - -class SimulateExpectationCuquantumTest(tf.test.TestCase, parameterized.TestCase): +class SimulateExpectationCuquantumTest(tf.test.TestCase, + parameterized.TestCase): """Tests tfq_simulate_expectation.""" - @parameterized.parameters( - TEST_PARAMS_EXPECTATION - ) + @parameterized.parameters(TEST_PARAMS_EXPECTATION) def test_simulate_expectation_cpu_vs_cuquantum(self, params): """Make sure that cuquantum version is faster.""" bench = RandomCircuitBenchmark(params) @@ -532,9 +534,7 @@ def test_simulate_expectation_cpu_vs_cuquantum(self, params): # cuQuantum op should be faster than CPU op. self.assertGreater(cpu_median_time, gpu_median_time) - @parameterized.parameters( - TEST_PARAMS_SAMPLED_EXPECTATION - ) + @parameterized.parameters(TEST_PARAMS_SAMPLED_EXPECTATION) def test_simulate_sampled_expectation_cpu_vs_cuquantum(self, params): """Make sure that cpu & gpu(cuquantum) ops have the same results.""" bench = RandomCircuitBenchmark(params) @@ -548,9 +548,7 @@ def test_simulate_sampled_expectation_cpu_vs_cuquantum(self, params): # cuQuantum op should be faster than CPU op. self.assertGreater(cpu_median_time, gpu_median_time) - @parameterized.parameters( - TEST_PARAMS_SAMPLES - ) + @parameterized.parameters(TEST_PARAMS_SAMPLES) def test_simulate_samples_cpu_vs_cuquantum(self, params): """Make sure that cpu & gpu(cuquantum) ops have the same results.""" bench = RandomCircuitBenchmark(params) @@ -564,9 +562,7 @@ def test_simulate_samples_cpu_vs_cuquantum(self, params): # cuQuantum op should be faster than CPU op. self.assertGreater(cpu_median_time, gpu_median_time) - @parameterized.parameters( - TEST_PARAMS_STATE - ) + @parameterized.parameters(TEST_PARAMS_STATE) def test_simulate_state_cpu_vs_cuquantum(self, params): """Make sure that cpu & gpu(cuquantum) ops have the same results.""" bench = RandomCircuitBenchmark(params) diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py index c0d5a1910..0ce37fa2e 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py @@ -404,7 +404,7 @@ def test_sampled_expectation_simple_tf_train(self, use_cuquantum): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) - initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) bit = cirq.GridQubit(0, 0) circuit = cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) layer = sampled_expectation.SampledExpectation( @@ -447,7 +447,7 @@ def test_simple_param_value_input(self, backend, use_cuquantum): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) - initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') circuit = _gen_single_bit_rotation_problem( @@ -498,7 +498,7 @@ def test_simple_op_input(self, backend, use_cuquantum): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) - initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) @@ -555,7 +555,7 @@ def test_simple_op_and_param_input(self, backend, use_cuquantum): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) - initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) @@ -616,7 +616,7 @@ def test_dnn_qnn_dnn(self, backend, use_cuquantum): # GPU is not set. Ignores this sub-test. self.skipTest("GPU is not set. Ignoring gpu tests...") tf.random.set_seed(RANDOM_SEED) - initializer = tf.keras.initializers.RandomUniform(0, 2*np.pi) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') circuits = util.convert_to_tensor([ From b44d90386cced91e8b1b4140bc611fe957714427 Mon Sep 17 00:00:00 2001 From: QuantumJaeYoo Date: Sun, 21 May 2023 02:00:32 +0000 Subject: [PATCH 101/106] Fix format --- release/setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/release/setup.py b/release/setup.py index d5d0ccd3c..11d9c7000 100644 --- a/release/setup.py +++ b/release/setup.py @@ -92,7 +92,6 @@ def has_ext_modules(self): project_name = 'tfq-nightly' build_version = build_version + '.dev' + str(date.today()).replace('-', '') - setup( name=project_name, version=build_version, From 0aeacf7ce4dc48385781372c63a5c72dc787f480 Mon Sep 17 00:00:00 2001 From: QuantumJaeYoo Date: Mon, 22 May 2023 08:09:12 +0000 Subject: [PATCH 102/106] Fix the sampled expectation test error --- .../core/ops/circuit_execution_ops.py | 19 +++++++++++++++---- .../sampled_expectation_test.py | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index f16fcf184..b21298ad3 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -35,6 +35,17 @@ def is_gpu_configured() -> bool: return _ENABLE_USE_CUQUANTUM +def _preprocess_use_cuquantum(use_cuquantum: bool) -> bool: + if is_gpu_configured(): + return use_cuquantum + + # GPU is not set. `use_cuquantum` becomes silent. + if use_cuquantum: + print("WARNING: cuQuantum was not set, " + "`use_cuquantum=True` option becomes effectless. Using CPU.") + return False + + class TFQStateVectorSimulator(enum.Enum): """Enum to make specifying TFQ simulators user-friendly.""" expectation = tfq_simulate_ops.tfq_simulate_expectation @@ -148,7 +159,7 @@ def get_expectation_op( """ # TODO (mbbrough): investigate how the above docstring renders. _check_quantum_concurrent(quantum_concurrent, use_cuquantum) - use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum + use_cuquantum = _preprocess_use_cuquantum(use_cuquantum) op = None if backend is None: @@ -258,7 +269,7 @@ def get_sampling_op( # TODO (mbbrough): investigate how the above docstring renders. _check_quantum_concurrent(quantum_concurrent, use_cuquantum) - use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum + use_cuquantum = _preprocess_use_cuquantum(use_cuquantum) op = None if backend is None: @@ -358,7 +369,7 @@ def get_state_op( # TODO (mbbrough): investigate how the above docstring renders. _check_quantum_concurrent(quantum_concurrent, use_cuquantum) - use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum + use_cuquantum = _preprocess_use_cuquantum(use_cuquantum) op = None if backend is None: @@ -480,7 +491,7 @@ def get_sampled_expectation_op( """ # TODO (mbbrough): investigate how the above docstring renders. _check_quantum_concurrent(quantum_concurrent, use_cuquantum) - use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum + use_cuquantum = _preprocess_use_cuquantum(use_cuquantum) op = None if backend is None: diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py index 0ce37fa2e..c13afbfd4 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py @@ -415,7 +415,7 @@ def test_sampled_expectation_simple_tf_train(self, use_cuquantum): circuit_out = layer(circuit, symbol_names=['theta'], operators=cirq.Z(bit), - repetitions=100, + repetitions=1000, initializer=initializer) mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) grads = tape.gradient(mse, layer.trainable_weights) From 129970be02e40f47e7aebf3406cea3764204d592 Mon Sep 17 00:00:00 2001 From: QuantumJaeYoo Date: Mon, 22 May 2023 08:18:50 +0000 Subject: [PATCH 103/106] Fix ipynb for cirq 1.0 --- docs/tutorials/qcnn.ipynb | 158 +++++++--------------------- docs/tutorials/research_tools.ipynb | 39 +++---- 2 files changed, 61 insertions(+), 136 deletions(-) diff --git a/docs/tutorials/qcnn.ipynb b/docs/tutorials/qcnn.ipynb index f53182701..ee3f5f60b 100644 --- a/docs/tutorials/qcnn.ipynb +++ b/docs/tutorials/qcnn.ipynb @@ -17,10 +17,7 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "iiQkM5ZgQ8r2", - "vscode": { - "languageId": "python" - } + "id": "iiQkM5ZgQ8r2" }, "outputs": [], "source": [ @@ -98,10 +95,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "Aquwcz-0aHqz", - "vscode": { - "languageId": "python" - } + "id": "Aquwcz-0aHqz" }, "outputs": [], "source": [ @@ -124,10 +118,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "3Pl5PW-ACO9J", - "vscode": { - "languageId": "python" - } + "id": "3Pl5PW-ACO9J" }, "outputs": [], "source": [ @@ -140,10 +131,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "4Ql5PW-ACO0J", - "vscode": { - "languageId": "python" - } + "id": "4Ql5PW-ACO0J" }, "outputs": [], "source": [ @@ -168,10 +156,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "QytLEAtoejW5", - "vscode": { - "languageId": "python" - } + "id": "QytLEAtoejW5" }, "outputs": [], "source": [ @@ -220,10 +205,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "FhNf0G_OPLqZ", - "vscode": { - "languageId": "python" - } + "id": "FhNf0G_OPLqZ" }, "outputs": [], "source": [ @@ -262,10 +244,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "ImRynsUN4BSG", - "vscode": { - "languageId": "python" - } + "id": "ImRynsUN4BSG" }, "outputs": [], "source": [ @@ -288,10 +267,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "tfff6dJp39Fg", - "vscode": { - "languageId": "python" - } + "id": "tfff6dJp39Fg" }, "outputs": [], "source": [ @@ -366,10 +342,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "iUrvTCU1hDgP", - "vscode": { - "languageId": "python" - } + "id": "iUrvTCU1hDgP" }, "outputs": [], "source": [ @@ -411,10 +384,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "eLJ-JHOihDgT", - "vscode": { - "languageId": "python" - } + "id": "eLJ-JHOihDgT" }, "outputs": [], "source": [ @@ -453,10 +423,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "qpQwVWKazU8g", - "vscode": { - "languageId": "python" - } + "id": "qpQwVWKazU8g" }, "outputs": [], "source": [ @@ -485,10 +452,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "9tZt0aAO4r4F", - "vscode": { - "languageId": "python" - } + "id": "9tZt0aAO4r4F" }, "outputs": [], "source": [ @@ -516,10 +480,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "oNRGOqky2exY", - "vscode": { - "languageId": "python" - } + "id": "oNRGOqky2exY" }, "outputs": [], "source": [ @@ -554,7 +515,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" ] @@ -575,10 +536,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "T5uhvF-g2rpZ", - "vscode": { - "languageId": "python" - } + "id": "T5uhvF-g2rpZ" }, "outputs": [], "source": [ @@ -601,10 +559,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "aJTdRrfS2uIo", - "vscode": { - "languageId": "python" - } + "id": "aJTdRrfS2uIo" }, "outputs": [], "source": [ @@ -627,10 +582,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "DOHRbkvH2xGK", - "vscode": { - "languageId": "python" - } + "id": "DOHRbkvH2xGK" }, "outputs": [], "source": [ @@ -655,10 +607,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "1Fa19Lzb3wnR", - "vscode": { - "languageId": "python" - } + "id": "1Fa19Lzb3wnR" }, "outputs": [], "source": [ @@ -691,10 +640,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "Bi6q2nmY3z_U", - "vscode": { - "languageId": "python" - } + "id": "Bi6q2nmY3z_U" }, "outputs": [], "source": [ @@ -720,10 +666,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "jD3fgcWO4yEU", - "vscode": { - "languageId": "python" - } + "id": "jD3fgcWO4yEU" }, "outputs": [], "source": [ @@ -754,10 +697,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "pFXow2OX47O5", - "vscode": { - "languageId": "python" - } + "id": "pFXow2OX47O5" }, "outputs": [], "source": [ @@ -785,10 +725,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "vzEsY6-n5NR0", - "vscode": { - "languageId": "python" - } + "id": "vzEsY6-n5NR0" }, "outputs": [], "source": [ @@ -852,10 +789,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "_TFkAm1sQZEN", - "vscode": { - "languageId": "python" - } + "id": "_TFkAm1sQZEN" }, "outputs": [], "source": [ @@ -890,10 +824,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "2tiCJOb5Qzcr", - "vscode": { - "languageId": "python" - } + "id": "2tiCJOb5Qzcr" }, "outputs": [], "source": [ @@ -948,10 +879,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "Ut-U1hBkQ8Fs", - "vscode": { - "languageId": "python" - } + "id": "Ut-U1hBkQ8Fs" }, "outputs": [], "source": [ @@ -1008,10 +936,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "EyYw9kYIRCE7", - "vscode": { - "languageId": "python" - } + "id": "EyYw9kYIRCE7" }, "outputs": [], "source": [ @@ -1034,10 +959,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "yL3jhGiBRJHt", - "vscode": { - "languageId": "python" - } + "id": "yL3jhGiBRJHt" }, "outputs": [], "source": [ @@ -1090,10 +1012,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "W3TkNVm9RTBj", - "vscode": { - "languageId": "python" - } + "id": "W3TkNVm9RTBj" }, "outputs": [], "source": [ @@ -1150,10 +1069,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "suRvxcAKRZK6", - "vscode": { - "languageId": "python" - } + "id": "suRvxcAKRZK6" }, "outputs": [], "source": [ @@ -1177,10 +1093,7 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "-6NR7yAQRmOU", - "vscode": { - "languageId": "python" - } + "id": "-6NR7yAQRmOU" }, "outputs": [], "source": [ @@ -1205,9 +1118,18 @@ "toc_visible": true }, "kernelspec": { - "display_name": "Python 3", + "display_name": "scratch_venv", "language": "python", "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.8.2 (default, Feb 7 2023, 07:10:44) \n[GCC 8.3.0]" + }, + "vscode": { + "interpreter": { + "hash": "561e5fc18945d9612777c7b19b2a8a5eae61ac61831e6de1174f79522f9d9cc5" + } } }, "nbformat": 4, diff --git a/docs/tutorials/research_tools.ipynb b/docs/tutorials/research_tools.ipynb index 538fcf46c..3d29aea09 100644 --- a/docs/tutorials/research_tools.ipynb +++ b/docs/tutorials/research_tools.ipynb @@ -83,25 +83,27 @@ }, "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", + "!git clone https://github.com/quantumlib/ReCirq\n", + "!cd ReCirq && pip install ." ] }, - { - "cell_type": "code", - "execution_count": 0, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "4Ql5PW-ACO0J" - }, - "outputs": [], - "source": [ - "# Update package resources to account for version changes.\n", - "import importlib, pkg_resources\n", - "importlib.reload(pkg_resources)" - ] - }, - { + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "4Ql5PW-ACO0J" + }, + "outputs": [], + "source": [ + "# Update package resources to account for version changes.\n", + "import importlib, pkg_resources\n", + "importlib.reload(pkg_resources)" + ] + }, + { "cell_type": "code", "execution_count": null, "metadata": { @@ -124,6 +126,7 @@ "import datetime\n", "import time\n", "import cirq\n", + "import recirq\n", "import tensorflow as tf\n", "import tensorflow_quantum as tfq\n", "from tensorflow.keras import layers\n", @@ -155,7 +158,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 = recirq.beyond_classical.generate_boixo_2018_supremacy_circuits_v2(\n", " qubits, cz_depth=2, seed=1234)\n", " return random_circuit\n", "\n", From cf1b87670ad9b67833569017d400def54a0bacfb Mon Sep 17 00:00:00 2001 From: QuantumJaeYoo Date: Mon, 22 May 2023 08:28:15 +0000 Subject: [PATCH 104/106] Fix qcnn.ipynb and update the version to 0.8.0 --- docs/tutorials/qcnn.ipynb | 156 ++++++++++++++++++++++++--------- release/setup.py | 2 +- tensorflow_quantum/__init__.py | 2 +- 3 files changed, 119 insertions(+), 41 deletions(-) diff --git a/docs/tutorials/qcnn.ipynb b/docs/tutorials/qcnn.ipynb index ee3f5f60b..abbb8c560 100644 --- a/docs/tutorials/qcnn.ipynb +++ b/docs/tutorials/qcnn.ipynb @@ -17,7 +17,10 @@ "cellView": "form", "colab": {}, "colab_type": "code", - "id": "iiQkM5ZgQ8r2" + "id": "iiQkM5ZgQ8r2", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -95,7 +98,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "Aquwcz-0aHqz" + "id": "Aquwcz-0aHqz", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -118,7 +124,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "3Pl5PW-ACO9J" + "id": "3Pl5PW-ACO9J", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -131,7 +140,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "4Ql5PW-ACO0J" + "id": "4Ql5PW-ACO0J", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -156,7 +168,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "QytLEAtoejW5" + "id": "QytLEAtoejW5", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -205,7 +220,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "FhNf0G_OPLqZ" + "id": "FhNf0G_OPLqZ", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -244,7 +262,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "ImRynsUN4BSG" + "id": "ImRynsUN4BSG", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -267,7 +288,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "tfff6dJp39Fg" + "id": "tfff6dJp39Fg", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -342,7 +366,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "iUrvTCU1hDgP" + "id": "iUrvTCU1hDgP", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -384,7 +411,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "eLJ-JHOihDgT" + "id": "eLJ-JHOihDgT", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -423,7 +453,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "qpQwVWKazU8g" + "id": "qpQwVWKazU8g", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -452,7 +485,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "9tZt0aAO4r4F" + "id": "9tZt0aAO4r4F", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -480,7 +516,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "oNRGOqky2exY" + "id": "oNRGOqky2exY", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -536,7 +575,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "T5uhvF-g2rpZ" + "id": "T5uhvF-g2rpZ", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -559,7 +601,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "aJTdRrfS2uIo" + "id": "aJTdRrfS2uIo", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -582,7 +627,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "DOHRbkvH2xGK" + "id": "DOHRbkvH2xGK", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -607,7 +655,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "1Fa19Lzb3wnR" + "id": "1Fa19Lzb3wnR", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -640,7 +691,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "Bi6q2nmY3z_U" + "id": "Bi6q2nmY3z_U", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -666,7 +720,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "jD3fgcWO4yEU" + "id": "jD3fgcWO4yEU", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -697,7 +754,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "pFXow2OX47O5" + "id": "pFXow2OX47O5", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -725,7 +785,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "vzEsY6-n5NR0" + "id": "vzEsY6-n5NR0", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -789,7 +852,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "_TFkAm1sQZEN" + "id": "_TFkAm1sQZEN", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -824,7 +890,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "2tiCJOb5Qzcr" + "id": "2tiCJOb5Qzcr", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -879,7 +948,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "Ut-U1hBkQ8Fs" + "id": "Ut-U1hBkQ8Fs", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -936,7 +1008,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "EyYw9kYIRCE7" + "id": "EyYw9kYIRCE7", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -959,7 +1034,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "yL3jhGiBRJHt" + "id": "yL3jhGiBRJHt", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -1012,7 +1090,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "W3TkNVm9RTBj" + "id": "W3TkNVm9RTBj", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -1069,7 +1150,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "suRvxcAKRZK6" + "id": "suRvxcAKRZK6", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -1093,7 +1177,10 @@ "metadata": { "colab": {}, "colab_type": "code", - "id": "-6NR7yAQRmOU" + "id": "-6NR7yAQRmOU", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -1118,18 +1205,9 @@ "toc_visible": true }, "kernelspec": { - "display_name": "scratch_venv", + "display_name": "Python 3", "language": "python", "name": "python3" - }, - "language_info": { - "name": "python", - "version": "3.8.2 (default, Feb 7 2023, 07:10:44) \n[GCC 8.3.0]" - }, - "vscode": { - "interpreter": { - "hash": "561e5fc18945d9612777c7b19b2a8a5eae61ac61831e6de1174f79522f9d9cc5" - } } }, "nbformat": 4, diff --git a/release/setup.py b/release/setup.py index 11d9c7000..e9deb961f 100644 --- a/release/setup.py +++ b/release/setup.py @@ -61,7 +61,7 @@ def finalize_options(self): # placed as extra to not have required overwrite existing nightly installs if # they exist. EXTRA_PACKAGES = ['tensorflow == 2.11.0'] -CUR_VERSION = '0.7.4' +CUR_VERSION = '0.8.0' class BinaryDistribution(Distribution): diff --git a/tensorflow_quantum/__init__.py b/tensorflow_quantum/__init__.py index 4403510f7..67d66f403 100644 --- a/tensorflow_quantum/__init__.py +++ b/tensorflow_quantum/__init__.py @@ -64,4 +64,4 @@ del core # pylint: enable=undefined-variable -__version__ = '0.7.3' +__version__ = '0.8.0' From 2ed81018984137e98c9cc6d2fef3afd33c63404a Mon Sep 17 00:00:00 2001 From: QuantumJaeYoo Date: Wed, 24 May 2023 07:32:00 +0000 Subject: [PATCH 105/106] Fix ReCirq import error and boixo circuit name --- docs/tutorials/research_tools.ipynb | 7 +++---- scripts/ci_validate_tutorials.sh | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/tutorials/research_tools.ipynb b/docs/tutorials/research_tools.ipynb index 3d29aea09..29c7c3752 100644 --- a/docs/tutorials/research_tools.ipynb +++ b/docs/tutorials/research_tools.ipynb @@ -84,8 +84,7 @@ "outputs": [], "source": [ "!pip install tensorflow==2.7.0 tensorflow-quantum==0.7.2 tensorboard_plugin_profile==2.4.0\n", - "!git clone https://github.com/quantumlib/ReCirq\n", - "!cd ReCirq && pip install ." + "!pip install --quiet git+https://github.com/quantumlib/ReCirq" ] }, { @@ -126,7 +125,7 @@ "import datetime\n", "import time\n", "import cirq\n", - "import recirq\n", + "from recirq import beyond_classical\n", "import tensorflow as tf\n", "import tensorflow_quantum as tfq\n", "from tensorflow.keras import layers\n", @@ -158,7 +157,7 @@ "source": [ "def generate_circuit(qubits):\n", " \"\"\"Generate a random circuit on qubits.\"\"\"\n", - " random_circuit = recirq.beyond_classical.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/scripts/ci_validate_tutorials.sh b/scripts/ci_validate_tutorials.sh index d64361464..4fe94c465 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) From 56a6d591556869cdab51dabcb082519129a4b739 Mon Sep 17 00:00:00 2001 From: Jae Yoo Date: Tue, 6 Jun 2023 23:40:51 +0000 Subject: [PATCH 106/106] Squash the commits --- .bazelversion | 1 + .github/workflows/ci.yaml | 28 +- .github/workflows/cirq_compatibility.yaml | 25 + .gitignore | 3 + WORKSPACE | 111 +- benchmarks/README.md | 4 +- benchmarks/scripts/BUILD | 13 + .../scripts/benchmark_clifford_circuit.py | 2 +- benchmarks/scripts/benchmark_cuquantum_ops.py | 580 ++++++ benchmarks/scripts/benchmark_op_gradients.py | 2 +- .../scripts/benchmark_random_circuit.py | 2 +- benchmarks/scripts/benchmark_util.py | 2 +- benchmarks/scripts/benchmark_util_test.py | 2 +- benchmarks/scripts/flags.py | 2 +- benchmarks/scripts/flags_test.py | 2 +- benchmarks/scripts/models/__init__.py | 2 +- .../scripts/models/random_clifford_circuit.py | 2 +- .../models/random_clifford_circuit_test.py | 2 +- configure.sh | 164 +- docs/_book.yaml | 6 +- docs/_index.yaml | 28 +- docs/concepts.md | 2 +- docs/design.md | 2 +- docs/install.md | 68 +- docs/tutorials/barren_plateaus.ipynb | 48 +- docs/tutorials/gradients.ipynb | 209 +-- docs/tutorials/hello_many_worlds.ipynb | 284 ++- docs/tutorials/images/gym_CartPole.gif | Bin 0 -> 1299517 bytes docs/tutorials/images/noise_1.png | Bin 0 -> 66876 bytes docs/tutorials/images/noise_2.png | Bin 0 -> 26647 bytes docs/tutorials/images/pqc_re-uploading.png | Bin 0 -> 55824 bytes docs/tutorials/mnist.ipynb | 61 +- docs/tutorials/noise.ipynb | 805 +++++++++ docs/tutorials/qcnn.ipynb | 220 ++- docs/tutorials/quantum_data.ipynb | 327 +++- .../quantum_reinforcement_learning.ipynb | 1580 +++++++++++++++++ docs/tutorials/research_tools.ipynb | 27 +- release/BUILD | 16 +- release/build_pip_package.sh | 2 +- release/setup.py | 29 +- requirements.txt | 15 +- scripts/benchmark_all.sh | 6 +- scripts/build_docs.py | 9 +- scripts/build_pip_package_test.sh | 4 +- scripts/ci_install.sh | 6 +- scripts/ci_validate_tutorials.sh | 14 +- scripts/format_all.sh | 4 +- scripts/format_check.sh | 4 +- scripts/format_ipynb.py | 2 +- scripts/import_test.py | 17 +- scripts/lint_all.sh | 2 +- scripts/msan_test.sh | 8 +- scripts/run_example.sh | 2 +- scripts/test_all.sh | 20 +- scripts/test_benchmarks.sh | 8 +- scripts/test_tutorials.py | 12 +- tensorflow_quantum/__init__.py | 7 +- tensorflow_quantum/core/BUILD | 12 + tensorflow_quantum/core/__init__.py | 5 +- tensorflow_quantum/core/ops/BUILD | 421 ++++- tensorflow_quantum/core/ops/__init__.py | 5 +- tensorflow_quantum/core/ops/batch_util.py | 472 ++--- .../core/ops/batch_util_test.py | 47 +- .../core/ops/circuit_execution_ops.py | 138 +- .../core/ops/circuit_execution_ops_test.py | 194 +- tensorflow_quantum/core/ops/cirq_ops.py | 41 +- tensorflow_quantum/core/ops/cirq_ops_test.py | 67 +- tensorflow_quantum/core/ops/load_module.py | 2 +- tensorflow_quantum/core/ops/math_ops/BUILD | 70 +- .../core/ops/math_ops/__init__.py | 5 +- .../core/ops/math_ops/fidelity_op.py | 94 + .../core/ops/math_ops/fidelity_op_test.py | 320 ++++ .../ops/math_ops/inner_product_grad_test.py | 394 ++++ .../core/ops/math_ops/inner_product_op.py | 78 +- .../ops/math_ops/inner_product_op_test.py | 198 ++- .../core/ops/math_ops/simulate_mps.py | 152 ++ .../core/ops/math_ops/simulate_mps_test.py | 1023 +++++++++++ .../core/ops/math_ops/tfq_inner_product.cc | 40 +- .../ops/math_ops/tfq_inner_product_grad.cc | 496 ++++++ .../math_ops/tfq_simulate_1d_expectation.cc | 253 +++ .../tfq_simulate_1d_sampled_expectation.cc | 297 ++++ .../ops/math_ops/tfq_simulate_1d_samples.cc | 248 +++ tensorflow_quantum/core/ops/noise/BUILD | 135 ++ tensorflow_quantum/core/ops/noise/__init__.py | 20 + .../core/ops/noise/noisy_expectation_op.py | 98 + .../ops/noise/noisy_expectation_op_test.py | 345 ++++ .../ops/noise/noisy_sampled_expectation_op.py | 97 + .../noisy_sampled_expectation_op_test.py | 345 ++++ .../core/ops/noise/noisy_samples_op.py | 71 + .../core/ops/noise/noisy_samples_op_test.py | 300 ++++ .../core/ops/noise/tfq_noisy_expectation.cc | 424 +++++ .../noise/tfq_noisy_sampled_expectation.cc | 430 +++++ .../core/ops/noise/tfq_noisy_samples.cc | 349 ++++ tensorflow_quantum/core/ops/parse_context.cc | 121 +- tensorflow_quantum/core/ops/parse_context.h | 34 +- .../core/ops/tfq_adj_grad_op.cc | 95 +- .../core/ops/tfq_adj_grad_op.py | 2 +- .../core/ops/tfq_adj_grad_op_cuquantum.cu.cc | 342 ++++ .../core/ops/tfq_adj_grad_op_cuquantum.py | 48 + .../ops/tfq_adj_grad_op_cuquantum_test.py | 490 +++++ .../core/ops/tfq_adj_grad_op_test.py | 35 +- .../core/ops/tfq_calculate_unitary_op.cc | 31 +- .../core/ops/tfq_circuit_append_op.cc | 8 +- .../core/ops/tfq_ps_decompose_op.cc | 52 +- .../core/ops/tfq_ps_symbol_replace_op.cc | 22 +- .../core/ops/tfq_ps_util_ops.py | 2 +- .../core/ops/tfq_ps_util_ops_test.py | 105 +- .../ops/tfq_ps_weights_from_symbols_op.cc | 24 +- .../core/ops/tfq_resolve_parameters_op.cc | 13 +- .../core/ops/tfq_simulate_expectation_op.cc | 36 +- ...fq_simulate_expectation_op_cuquantum.cu.cc | 220 +++ .../core/ops/tfq_simulate_ops.py | 2 +- .../core/ops/tfq_simulate_ops_cuquantum.py | 134 ++ .../ops/tfq_simulate_ops_cuquantum_test.py | 918 ++++++++++ .../core/ops/tfq_simulate_ops_gpu_test.py | 139 ++ .../core/ops/tfq_simulate_ops_test.py | 59 +- .../tfq_simulate_sampled_expectation_op.cc | 84 +- ...ate_sampled_expectation_op_cuquantum.cu.cc | 256 +++ .../core/ops/tfq_simulate_samples_op.cc | 50 +- .../tfq_simulate_samples_op_cuquantum.cu.cc | 232 +++ .../core/ops/tfq_simulate_state_op.cc | 25 +- .../ops/tfq_simulate_state_op_cuquantum.cu.cc | 217 +++ tensorflow_quantum/core/ops/tfq_unitary_op.py | 2 +- .../core/ops/tfq_unitary_op_test.py | 29 +- .../core/ops/tfq_utility_ops.py | 2 +- .../core/ops/tfq_utility_ops_test.py | 90 +- tensorflow_quantum/core/proto/BUILD | 37 +- tensorflow_quantum/core/proto/__init__.py | 2 +- tensorflow_quantum/core/proto/program.proto | 170 ++ .../core/proto/projector_sum.proto | 23 + tensorflow_quantum/core/serialize/BUILD | 76 + tensorflow_quantum/core/serialize/__init__.py | 2 +- .../core/serialize/op_deserializer.py | 243 +++ .../core/serialize/op_deserializer_test.py | 425 +++++ .../core/serialize/op_serializer.py | 250 +++ .../core/serialize/op_serializer_test.py | 447 +++++ .../core/serialize/serializable_gate_set.py | 253 +++ .../serialize/serializable_gate_set_test.py | 450 +++++ .../core/serialize/serializer.py | 743 ++++++-- .../core/serialize/serializer_test.py | 624 +++++-- tensorflow_quantum/core/src/BUILD | 87 +- tensorflow_quantum/core/src/adj_util.cc | 12 +- .../core/src/circuit_parser_qsim.cc | 472 ++++- .../core/src/circuit_parser_qsim.h | 17 +- .../core/src/circuit_parser_qsim_test.cc | 1029 ++++++++++- .../core/src/program_resolution.cc | 269 ++- .../core/src/program_resolution.h | 16 +- .../core/src/program_resolution_test.cc | 891 ++++++---- tensorflow_quantum/core/src/util_qsim.h | 239 ++- tensorflow_quantum/core/src/util_qsim_test.cc | 227 ++- tensorflow_quantum/datasets/BUILD | 13 + tensorflow_quantum/datasets/__init__.py | 2 +- tensorflow_quantum/datasets/cluster_state.py | 2 +- .../datasets/cluster_state_test.py | 10 +- tensorflow_quantum/datasets/spin_system.py | 6 +- .../datasets/spin_system_test.py | 16 +- tensorflow_quantum/python/BUILD | 21 +- tensorflow_quantum/python/__init__.py | 3 +- .../python/differentiators/BUILD | 30 +- .../python/differentiators/__init__.py | 2 +- .../python/differentiators/adjoint.py | 95 +- .../python/differentiators/adjoint_test.py | 61 +- .../python/differentiators/differentiator.py | 218 ++- .../differentiators/differentiator_test.py | 38 +- .../python/differentiators/gradient_test.py | 389 +++- .../differentiators/linear_combination.py | 380 +--- .../linear_combination_test.py | 95 +- .../python/differentiators/parameter_shift.py | 314 +--- .../differentiators/parameter_shift_test.py | 132 +- .../differentiators/parameter_shift_util.py | 7 +- .../parameter_shift_util_test.py | 10 +- tensorflow_quantum/python/layers/BUILD | 11 + tensorflow_quantum/python/layers/__init__.py | 4 +- .../python/layers/circuit_construction/BUILD | 10 + .../layers/circuit_construction/__init__.py | 2 +- .../layers/circuit_construction/elementary.py | 2 +- .../circuit_construction/elementary_test.py | 22 +- .../python/layers/circuit_executors/BUILD | 26 +- .../layers/circuit_executors/__init__.py | 2 +- .../layers/circuit_executors/expectation.py | 137 +- .../circuit_executors/expectation_test.py | 329 +++- .../layers/circuit_executors/input_checks.py | 28 +- .../circuit_executors/input_checks_test.py | 28 +- .../python/layers/circuit_executors/sample.py | 51 +- .../layers/circuit_executors/sample_test.py | 101 +- .../circuit_executors/sampled_expectation.py | 82 +- .../sampled_expectation_test.py | 552 ++++-- .../python/layers/circuit_executors/state.py | 32 +- .../layers/circuit_executors/state_test.py | 54 +- .../layers/circuit_executors/unitary.py | 2 +- .../layers/circuit_executors/unitary_test.py | 10 +- .../python/layers/high_level/BUILD | 60 + .../python/layers/high_level/__init__.py | 5 +- .../layers/high_level/controlled_pqc.py | 50 +- .../layers/high_level/controlled_pqc_test.py | 39 +- .../layers/high_level/noisy_controlled_pqc.py | 267 +++ .../high_level/noisy_controlled_pqc_test.py | 182 ++ .../python/layers/high_level/noisy_pqc.py | 303 ++++ .../layers/high_level/noisy_pqc_test.py | 267 +++ .../python/layers/high_level/pqc.py | 48 +- .../python/layers/high_level/pqc_test.py | 37 +- tensorflow_quantum/python/optimizers/BUILD | 28 +- .../python/optimizers/__init__.py | 4 +- .../python/optimizers/rotosolve_minimizer.py | 537 +++--- .../optimizers/rotosolve_minimizer_test.py | 16 +- .../python/optimizers/spsa_minimizer.py | 309 ++++ .../python/optimizers/spsa_minimizer_test.py | 274 +++ tensorflow_quantum/python/quantum_context.py | 2 +- .../python/quantum_context_test.py | 9 +- tensorflow_quantum/python/util.py | 374 +++- tensorflow_quantum/python/util_test.py | 265 ++- third_party/cuquantum/BUILD | 0 third_party/cuquantum/BUILD.tpl | 23 + third_party/cuquantum/cuquantum_configure.bzl | 257 +++ third_party/tf/auditwheel | 2 +- 215 files changed, 26342 insertions(+), 3757 deletions(-) create mode 100644 .bazelversion create mode 100644 .github/workflows/cirq_compatibility.yaml create mode 100644 benchmarks/scripts/benchmark_cuquantum_ops.py create mode 100644 docs/tutorials/images/gym_CartPole.gif create mode 100644 docs/tutorials/images/noise_1.png create mode 100644 docs/tutorials/images/noise_2.png create mode 100644 docs/tutorials/images/pqc_re-uploading.png create mode 100644 docs/tutorials/noise.ipynb create mode 100644 docs/tutorials/quantum_reinforcement_learning.ipynb create mode 100644 tensorflow_quantum/core/ops/math_ops/fidelity_op.py create mode 100644 tensorflow_quantum/core/ops/math_ops/fidelity_op_test.py create mode 100644 tensorflow_quantum/core/ops/math_ops/inner_product_grad_test.py create mode 100644 tensorflow_quantum/core/ops/math_ops/simulate_mps.py create mode 100644 tensorflow_quantum/core/ops/math_ops/simulate_mps_test.py create mode 100644 tensorflow_quantum/core/ops/math_ops/tfq_inner_product_grad.cc create mode 100644 tensorflow_quantum/core/ops/math_ops/tfq_simulate_1d_expectation.cc create mode 100644 tensorflow_quantum/core/ops/math_ops/tfq_simulate_1d_sampled_expectation.cc create mode 100644 tensorflow_quantum/core/ops/math_ops/tfq_simulate_1d_samples.cc create mode 100644 tensorflow_quantum/core/ops/noise/BUILD create mode 100644 tensorflow_quantum/core/ops/noise/__init__.py create mode 100644 tensorflow_quantum/core/ops/noise/noisy_expectation_op.py create mode 100644 tensorflow_quantum/core/ops/noise/noisy_expectation_op_test.py create mode 100644 tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op.py create mode 100644 tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op_test.py create mode 100644 tensorflow_quantum/core/ops/noise/noisy_samples_op.py create mode 100644 tensorflow_quantum/core/ops/noise/noisy_samples_op_test.py create mode 100644 tensorflow_quantum/core/ops/noise/tfq_noisy_expectation.cc create mode 100644 tensorflow_quantum/core/ops/noise/tfq_noisy_sampled_expectation.cc create mode 100644 tensorflow_quantum/core/ops/noise/tfq_noisy_samples.cc create mode 100644 tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc create mode 100644 tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.py create mode 100644 tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc create mode 100644 tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc create mode 100644 tensorflow_quantum/core/proto/program.proto create mode 100644 tensorflow_quantum/core/proto/projector_sum.proto create mode 100644 tensorflow_quantum/core/serialize/op_deserializer.py create mode 100644 tensorflow_quantum/core/serialize/op_deserializer_test.py create mode 100644 tensorflow_quantum/core/serialize/op_serializer.py create mode 100644 tensorflow_quantum/core/serialize/op_serializer_test.py create mode 100644 tensorflow_quantum/core/serialize/serializable_gate_set.py create mode 100644 tensorflow_quantum/core/serialize/serializable_gate_set_test.py create mode 100644 tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py create mode 100644 tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc_test.py create mode 100644 tensorflow_quantum/python/layers/high_level/noisy_pqc.py create mode 100644 tensorflow_quantum/python/layers/high_level/noisy_pqc_test.py create mode 100644 tensorflow_quantum/python/optimizers/spsa_minimizer.py create mode 100644 tensorflow_quantum/python/optimizers/spsa_minimizer_test.py create mode 100644 third_party/cuquantum/BUILD create mode 100644 third_party/cuquantum/BUILD.tpl create mode 100644 third_party/cuquantum/cuquantum_configure.bzl diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 000000000..03f488b07 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +5.3.0 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 572e36d0b..387b7d6a4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,27 +5,27 @@ on: [pull_request] jobs: lint: name: Lint check - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v1 - uses: actions/setup-python@v1 with: - python-version: '3.6' + python-version: '3.8' architecture: 'x64' - name: Install Lint tools - run: pip install --upgrade pylint + run: pip install --upgrade pip setuptools; pip install -r requirements.txt; - name: Lint All run: ./scripts/lint_all.sh format: name: Formatting check - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v1 - uses: actions/setup-python@v1 with: - python-version: '3.6' + python-version: '3.8' architecture: 'x64' - name: Install Format tools run: pip install --upgrade pip setuptools; pip install -r requirements.txt; sudo apt-get install -y clang-format-6.0 @@ -34,13 +34,13 @@ jobs: wheel-build: name: Wheel test - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v1 - uses: actions/setup-python@v1 with: - python-version: '3.6' + python-version: '3.8' architecture: 'x64' - name: Install Bazel on CI run: ./scripts/ci_install.sh @@ -53,14 +53,14 @@ jobs: bazel-tests: name: Library tests - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 needs: [lint, format] steps: - uses: actions/checkout@v1 - uses: actions/setup-python@v1 with: - python-version: '3.6' + python-version: '3.8' architecture: 'x64' - name: Install Bazel on CI run: ./scripts/ci_install.sh @@ -71,14 +71,14 @@ jobs: leak-tests: name: Memory Leak tests - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 needs: [lint, format] steps: - uses: actions/checkout@v1 - uses: actions/setup-python@v1 with: - python-version: '3.6' + python-version: '3.8' architecture: 'x64' - name: Install Bazel on CI run: ./scripts/ci_install.sh @@ -89,14 +89,14 @@ jobs: tutorials-test: name: Tutorial tests - runs-on: ubuntu-16.04 + runs-on: ubuntu-20.04 needs: [lint, format, wheel-build] steps: - uses: actions/checkout@v1 - uses: actions/setup-python@v1 with: - python-version: '3.6' + python-version: '3.8' architecture: 'x64' - name: Install notebook dependencies run: pip install --upgrade pip seaborn==0.10.0 @@ -107,4 +107,4 @@ jobs: - name: Build Wheel run: ./scripts/build_pip_package_test.sh - name: Test Notebooks - run: ./scripts/ci_validate_tutorials.sh \ No newline at end of file + run: ./scripts/ci_validate_tutorials.sh diff --git a/.github/workflows/cirq_compatibility.yaml b/.github/workflows/cirq_compatibility.yaml new file mode 100644 index 000000000..ee8e26f94 --- /dev/null +++ b/.github/workflows/cirq_compatibility.yaml @@ -0,0 +1,25 @@ + +name: Cirq Compatibility + +on: + schedule: + - cron: "0 0 * * *" + +jobs: + consistency: + name: Nightly Compatibility + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-python@v1 + with: + python-version: '3.8' + architecture: 'x64' + - name: Install Bazel on CI + run: ./scripts/ci_install.sh + - name: Configure CI TF + run: echo "Y\n" | ./configure.sh + - name: Install Cirq nightly + run: pip install -U cirq --pre + - name: Nightly tests + run: ./scripts/test_all.sh diff --git a/.gitignore b/.gitignore index b7d978897..7f25e7e0e 100644 --- a/.gitignore +++ b/.gitignore @@ -47,4 +47,7 @@ venv/* # ignore emacs temp files *# + +# vscode +.vscode/* *~ diff --git a/WORKSPACE b/WORKSPACE index 0eeaac3f0..e28452a8d 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,100 +1,61 @@ # This file includes external dependencies that are required to compile the -# TensorFlow op. Maybe of them are specific versions used by the TensorFlow -# binary used. These are extracted from TF v2.3.1, tensorflow/workspace.bzl. +# TensorFlow op. load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -http_archive( - name = "com_google_absl", - sha256 = "f368a8476f4e2e0eccf8a7318b98dafbe30b2600f4e3cf52636e5eb145aba06a", - strip_prefix = "abseil-cpp-df3ea785d8c30a9503321a3d35ee7d35808f190d", - urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/github.com/abseil/abseil-cpp/archive/df3ea785d8c30a9503321a3d35ee7d35808f190d.tar.gz", - "https://github.com/abseil/abseil-cpp/archive/df3ea785d8c30a9503321a3d35ee7d35808f190d.tar.gz", - ], -) +EIGEN_COMMIT = "3bb6a48d8c171cf20b5f8e48bfb4e424fbd4f79e" +EIGEN_SHA256 = "eca9847b3fe6249e0234a342b78f73feec07d29f534e914ba5f920f3e09383a3" + http_archive( - name = "com_google_googletest", - sha256 = "ff7a82736e158c077e76188232eac77913a15dac0b22508c390ab3f88e6d6d86", - strip_prefix = "googletest-b6cd405286ed8635ece71c72f118e659f4ade3fb", - urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/github.com/google/googletest/archive/b6cd405286ed8635ece71c72f118e659f4ade3fb.zip", - "https://github.com/google/googletest/archive/b6cd405286ed8635ece71c72f118e659f4ade3fb.zip", - ], + name = "eigen", + build_file_content = """ +cc_library( + name = "eigen3", + textual_hdrs = glob(["Eigen/**", "unsupported/**"]), + visibility = ["//visibility:public"], +) + """, + sha256 = EIGEN_SHA256, + strip_prefix = "eigen-{commit}".format(commit = EIGEN_COMMIT), + urls = [ + "https://storage.googleapis.com/mirror.tensorflow.org/gitlab.com/libeigen/eigen/-/archive/{commit}/eigen-{commit}.tar.gz".format(commit = EIGEN_COMMIT), + "https://gitlab.com/libeigen/eigen/-/archive/{commit}/eigen-{commit}.tar.gz".format(commit = EIGEN_COMMIT), + ], ) http_archive( - name = "com_google_protobuf", - sha256 = "cfcba2df10feec52a84208693937c17a4b5df7775e1635c1e3baffc487b24c9b", - strip_prefix = "protobuf-3.9.2", - urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/github.com/protocolbuffers/protobuf/archive/v3.9.2.zip", - "https://github.com/protocolbuffers/protobuf/archive/v3.9.2.zip", - ], + name = "qsim", + sha256 = "f7f410a07543a51b254f7a5810b5153e196a4c7b4ec89dc8faf86f9c77eec97b", + strip_prefix = "qsim-0.16.1", + urls = ["https://github.com/quantumlib/qsim/archive/refs/tags/v0.16.1.zip"], ) -# Use this zlib rule that depends on github since it is more reliable than zlib.net. http_archive( - name = "zlib", - build_file = "@com_google_protobuf//:third_party/zlib.BUILD", - sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1", - strip_prefix = "zlib-1.2.11", + name = "org_tensorflow", + sha256 = "e52cda3bae45f0ae0fccd4055e9fa29892b414f70e2df94df9a3a10319c75fff", + strip_prefix = "tensorflow-2.11.0", urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/zlib.net/zlib-1.2.11.tar.gz", - "https://zlib.net/zlib-1.2.11.tar.gz", + "https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.11.0.zip", ], ) -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") -protobuf_deps() +load("@org_tensorflow//tensorflow:workspace3.bzl", "workspace") -# com_google_protobuf depends on @bazel_skylib ?? -http_archive( - name = "bazel_skylib", - sha256 = "bbccf674aa441c266df9894182d80de104cabd19be98be002f6d478aaa31574d", - strip_prefix = "bazel-skylib-2169ae1c374aab4a09aa90e65efe1a3aad4e279b", - urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"], -) +workspace() -http_archive( - name = "cirq", - sha256 = "418cb7ff9c223e1e32516ab0ccc578385734af833528d6f5d903260b322d3362", - strip_prefix = "Cirq-0.9.1", - urls = ["https://github.com/quantumlib/Cirq/archive/v0.9.1.zip"], -) +load("@org_tensorflow//tensorflow:workspace2.bzl", "workspace") -http_archive( - name = "qsim", - sha256 = "f390ee72cf88c48d81c98262c599dc45d660a2a9308a9ee903bfa73aec08a9b4", - strip_prefix = "qsim-0.6.0", - urls = ["https://github.com/quantumlib/qsim/archive/v0.6.0.zip"], -) +workspace() -# Added for crosstool in tensorflow. -http_archive( - name = "io_bazel_rules_closure", - sha256 = "5b00383d08dd71f28503736db0500b6fb4dda47489ff5fc6bed42557c07c6ba9", - strip_prefix = "rules_closure-308b05b2419edb5c8ee0471b67a40403df940149", - urls = [ - "https://storage.googleapis.com/mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz", - "https://github.com/bazelbuild/rules_closure/archive/308b05b2419edb5c8ee0471b67a40403df940149.tar.gz", # 2019-06-13 - ], -) +load("@org_tensorflow//tensorflow:workspace1.bzl", "workspace") -http_archive( - name = "org_tensorflow", - sha256 = "6f063636673d6ef4ac60febd2541e3ad3516a57c18339a680c794b736798d054", - strip_prefix = "tensorflow-2.3.1", - urls = [ - "https://github.com/tensorflow/tensorflow/archive/v2.3.1.zip", - ], -) +workspace() -load("@org_tensorflow//tensorflow:workspace.bzl", "tf_workspace") +load("@org_tensorflow//tensorflow:workspace0.bzl", "workspace") -tf_workspace(tf_repo_name = "@org_tensorflow") +workspace() load("//third_party/tf:tf_configure.bzl", "tf_configure") @@ -111,3 +72,7 @@ bind( name = "six", actual = "@six_archive//:six", ) + +load("//third_party/cuquantum:cuquantum_configure.bzl", "cuquantum_configure") + +cuquantum_configure(name = "local_config_cuquantum") diff --git a/benchmarks/README.md b/benchmarks/README.md index b71bd1b04..4e71f8de2 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -24,7 +24,7 @@ Some notes on benchmark configuration: For example, to benchmark a dense depth-10 Clifford circuit over 5 qubits call: ``` -bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" \ +bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" \ --cxxopt="-msse3" --cxxopt="-msse4" \ benchmarks/scripts:benchmark_clifford_circuit -- \ --n_moments 5 --n_qubits 4 \ @@ -39,7 +39,7 @@ benchmarks/scripts/reports/CliffordBenchmarks.benchmark_clifford_circuit_4_5_1 To benchmark the parameter shift differentiation method on a random depth-10 4-qubit circuit with 10 parameters call, where the circuit will be differentiated over 50 trials, each time over a batch of 10 circuits. ``` -bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" \ +bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" \ --cxxopt="-msse3" --cxxopt="-msse4" \ benchmarks/scripts:benchmark_op_gradients -- \ --n_moments 10 --n_qubits 4 --n_symbols 10 \ diff --git a/benchmarks/scripts/BUILD b/benchmarks/scripts/BUILD index 095a10d74..8edf4e49c 100644 --- a/benchmarks/scripts/BUILD +++ b/benchmarks/scripts/BUILD @@ -1,3 +1,4 @@ +load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured") package(default_visibility = ["//visibility:public"]) licenses(["notice"]) @@ -27,6 +28,18 @@ py_test( ], ) +py_test( + name = "benchmark_cuquantum_ops", + srcs = ["benchmark_cuquantum_ops.py"], + python_version = "PY3", + deps = [ + "//tensorflow_quantum/core/ops:tfq_simulate_ops_cuquantum_py", + "//tensorflow_quantum/core/ops:tfq_simulate_ops_py", + "//tensorflow_quantum/core/serialize:serializer", + "@local_config_tf//:test_log_pb2", + "//tensorflow_quantum/python:util", + ], +) py_test( name = "benchmark_op_gradients", srcs = ["benchmark_op_gradients.py"], diff --git a/benchmarks/scripts/benchmark_clifford_circuit.py b/benchmarks/scripts/benchmark_clifford_circuit.py index 643eff790..c71751dbc 100644 --- a/benchmarks/scripts/benchmark_clifford_circuit.py +++ b/benchmarks/scripts/benchmark_clifford_circuit.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Benchmark simulators against classically simulatable circuits.""" import os import time diff --git a/benchmarks/scripts/benchmark_cuquantum_ops.py b/benchmarks/scripts/benchmark_cuquantum_ops.py new file mode 100644 index 000000000..d141d4999 --- /dev/null +++ b/benchmarks/scripts/benchmark_cuquantum_ops.py @@ -0,0 +1,580 @@ +import os +import time +import numpy as np +from absl.testing import parameterized +import tensorflow as tf +import cirq + +from tensorflow_quantum.core.ops import tfq_simulate_ops +from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum +from tensorflow_quantum.python import util +import flags +from dataclasses import dataclass + +SRC = os.path.dirname(os.path.realpath(__file__)) +os.environ['TEST_REPORT_FILE_PREFIX'] = os.path.join(SRC, 'reports/') + + +@dataclass(frozen=True) +class BenchmarkParams: + """Frozen dataclass to store the parameters for the benchmark""" + n_qubits: int + n_moments: int + batch_size: int + n_iters: int = 100 + + +_test_params_1 = BenchmarkParams(n_qubits=20, n_moments=15, batch_size=5) +_test_params_2 = BenchmarkParams(n_qubits=21, n_moments=25, + batch_size=5) # more depth +_test_params_3 = BenchmarkParams(n_qubits=22, + n_moments=15, + batch_size=5, + n_iters=10) + +TEST_PARAMS_EXPECTATION = [ + _test_params_1, + _test_params_2, # uncomment for depth params +] +TEST_PARAMS_SAMPLED_EXPECTATION = [ + _test_params_1, + _test_params_2, # uncomment for depth params +] +TEST_PARAMS_SAMPLES = [ + _test_params_1, + _test_params_2, # uncomment for depth params +] +TEST_PARAMS_STATE = [ + _test_params_3, +] + + +def _measure_median_runtime( + fn, + tag, + num_samples=10, + result_avg=False, +): + """Measures median runtime for given function. + + Args: + fn: function. + tag: The message title. + num_samples: The number of measurements. + result_avg: True if the results are all mediand. + + Returns: + The median time and the (averaged) result. + """ + median_time = [] + avg_res = [] + for _ in range(num_samples): + begin_time = time.time() + result = fn() + duration = time.time() - begin_time + median_time.append(duration) + if result_avg: + avg_res.append(result) + median_time = np.median(median_time) + print(f"\n\t{tag} time: {median_time}\n") + if result_avg: + result = np.average(avg_res, axis=0) + return median_time, result + + +class RandomCircuitBenchmark(tf.test.Benchmark): + """Benchmark cuquantum simulations against cpu.""" + + def __init__(self, params: BenchmarkParams): + """Pull in command line flags or use provided flags.""" + super(RandomCircuitBenchmark, self).__init__() + # Allow input params for testing purposes. + self.params = params + + def benchmark_expectation_cpu(self): + """Benchmark expectation simulator on cpu.""" + + n_qubits = self.params.n_qubits + batch_size = self.params.batch_size + circuit_depth = self.params.n_moments + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, n_moments=circuit_depth) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + cpu_avg_time, _ = _measure_median_runtime( + lambda: tfq_simulate_ops.tfq_simulate_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), + "Expectation CPU", + num_samples=self.params.n_iters, + ) + + extras = { + 'n_qubits': self.params.n_qubits, + 'batch_size': self.params.batch_size, + 'num_samples': self.params.n_iters, + 'median_time': cpu_avg_time, + # 'cuquantum_avg_time': cuquantum_avg_time, + } + + name = "benchmark_expectation_cpu" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cpu_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + return benchmark_values + + def benchmark_expectation_cuquantum(self): + """Benchmark expectation simulator on cpu.""" + + n_qubits = self.params.n_qubits + batch_size = self.params.batch_size + circuit_depth = self.params.n_moments + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, n_moments=circuit_depth) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + # Benchmark time on GPU (cuquantum) + cuquantum_avg_time, _ = _measure_median_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), + "Expectation cuQuantum", + num_samples=self.params.n_iters, + ) + + extras = { + 'n_qubits': self.params.n_qubits, + 'batch_size': self.params.batch_size, + 'num_samples': self.params.n_iters, + 'median_time': cuquantum_avg_time, + } + + name = "benchmark_expectation_cuquantum" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cuquantum_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + return benchmark_values + + def benchmark_sampled_expectation_cpu(self, params=None): + params = params if params else self.params + n_qubits = params.n_qubits + batch_size = params.batch_size + circuit_depth = params.n_moments + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, n_moments=circuit_depth) + n_samples = [[10000]] * batch_size + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + cpu_avg_time, _ = _measure_median_runtime( + lambda: tfq_simulate_ops.tfq_simulate_sampled_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor, + n_samples), + "SampledExpectation CPU", + num_samples=params.n_iters, + result_avg=False, + ) + + extras = { + 'n_qubits': params.n_qubits, + 'batch_size': params.batch_size, + 'num_samples': params.n_iters, + 'median_time': cpu_avg_time, + # 'cuquantum_avg_time': cuquantum_avg_time, + } + + name = "benchmark_sampled_expectation_cpu" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cpu_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + return benchmark_values + + def benchmark_sampled_expectation_cuquantum(self, params=None): + params = params if params else self.params + n_qubits = params.n_qubits + batch_size = params.batch_size + circuit_depth = params.n_moments + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, n_moments=circuit_depth) + n_samples = [[10000]] * batch_size + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + cuquantum_avg_time, res_cuquantum = _measure_median_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor, + n_samples), + "SampledExpectation cuQuantum", + num_samples=params.n_iters, + result_avg=False, + ) + + extras = { + 'n_qubits': params.n_qubits, + 'batch_size': params.batch_size, + 'num_samples': params.n_iters, + 'median_time': cuquantum_avg_time, + # 'cuquantum_avg_time': cuquantum_avg_time, + } + + name = "benchmark_sampled_expectation_cuquantum" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cuquantum_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + return benchmark_values + + def benchmark_samples_cpu(self, params=None): + params = params if params else self.params + n_qubits = params.n_qubits + batch_size = params.batch_size + circuit_depth = params.n_moments + symbol_names = ['alpha'] + n_samples = [100] + qubits = cirq.GridQubit.rect(1, n_qubits) + + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, n_moments=circuit_depth) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cpu_avg_time, _ = _measure_median_runtime( + lambda: tfq_simulate_ops.tfq_simulate_samples( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), n_samples), + "Samples CPU", + num_samples=params.n_iters, + result_avg=False, + ) + + extras = { + 'n_qubits': params.n_qubits, + 'batch_size': params.batch_size, + 'num_samples': params.n_iters, + 'median_time': cpu_avg_time, + # 'cuquantum_avg_time': cuquantum_avg_time, + } + + name = "benchmark_simulate_samples_cpu" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cpu_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + return benchmark_values + + def benchmark_samples_cuquantum(self, params=None): + params = params if params else self.params + n_qubits = params.n_qubits + batch_size = params.batch_size + circuit_depth = params.n_moments + symbol_names = ['alpha'] + n_samples = [100] + qubits = cirq.GridQubit.rect(1, n_qubits) + + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, n_moments=circuit_depth) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cuquantum_avg_time, _ = _measure_median_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_samples( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), n_samples), + "Samples cuQuantum", + num_samples=params.n_iters, + result_avg=False, + ) + + extras = { + 'n_qubits': params.n_qubits, + 'batch_size': params.batch_size, + 'num_samples': params.n_iters, + 'median_time': cuquantum_avg_time, + # 'cuquantum_avg_time': cuquantum_avg_time, + } + + name = "benchmark_simulate_samples_cuquantum" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cuquantum_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + return benchmark_values + + def benchmark_state_cpu(self, params=None): + params = params if params else self.params + n_qubits = params.n_qubits + batch_size = params.batch_size + circuit_depth = params.n_moments + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, n_moments=circuit_depth) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cpu_avg_time, _ = _measure_median_runtime( + lambda: tfq_simulate_ops.tfq_simulate_state( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64)), + "State CPU", + num_samples=params.n_iters, + ) + + extras = { + 'n_qubits': params.n_qubits, + 'batch_size': params.batch_size, + 'num_samples': params.n_iters, + 'median_time': cpu_avg_time, + } + + name = "benchmark_simulate_state_cpu" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cpu_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + return benchmark_values + + def benchmark_state_cuquantum(self, params=None): + params = params if params else self.params + n_qubits = params.n_qubits + batch_size = params.batch_size + circuit_depth = params.n_moments + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, n_moments=circuit_depth) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cuquantum_avg_time, _ = _measure_median_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_state( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64)), + "State cuQuantum", + num_samples=params.n_iters, + ) + + extras = { + 'n_qubits': params.n_qubits, + 'batch_size': params.batch_size, + 'num_samples': params.n_iters, + 'median_time': cuquantum_avg_time, + } + + name = "benchmark_simulate_state_cuquantum" + full_path = os.path.join(os.environ['TEST_REPORT_FILE_PREFIX'], + "{}.{}".format(self.__class__.__name__, name)) + if os.path.exists(full_path): + os.remove(full_path) + + benchmark_values = { + "iters": 1, + "wall_time": cuquantum_avg_time, + "extras": extras, + "name": name, + } + self.report_benchmark(**benchmark_values) + + return benchmark_values + + +class SimulateExpectationCuquantumTest(tf.test.TestCase, + parameterized.TestCase): + """Tests tfq_simulate_expectation.""" + + @parameterized.parameters(TEST_PARAMS_EXPECTATION) + def test_simulate_expectation_cpu_vs_cuquantum(self, params): + """Make sure that cuquantum version is faster.""" + bench = RandomCircuitBenchmark(params) + + benchmark_cpu = bench.benchmark_expectation_cpu() + benchmark_gpu = bench.benchmark_expectation_cuquantum() + + cpu_median_time = benchmark_cpu['extras']['median_time'] + gpu_median_time = benchmark_gpu['extras']['median_time'] + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_median_time, gpu_median_time) + + @parameterized.parameters(TEST_PARAMS_SAMPLED_EXPECTATION) + def test_simulate_sampled_expectation_cpu_vs_cuquantum(self, params): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + bench = RandomCircuitBenchmark(params) + + benchmark_cpu = bench.benchmark_sampled_expectation_cpu() + benchmark_gpu = bench.benchmark_sampled_expectation_cuquantum() + + cpu_median_time = benchmark_cpu['extras']['median_time'] + gpu_median_time = benchmark_gpu['extras']['median_time'] + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_median_time, gpu_median_time) + + @parameterized.parameters(TEST_PARAMS_SAMPLES) + def test_simulate_samples_cpu_vs_cuquantum(self, params): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + bench = RandomCircuitBenchmark(params) + + benchmark_cpu = bench.benchmark_samples_cpu() + benchmark_gpu = bench.benchmark_samples_cuquantum() + + cpu_median_time = benchmark_cpu['extras']['median_time'] + gpu_median_time = benchmark_gpu['extras']['median_time'] + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_median_time, gpu_median_time) + + @parameterized.parameters(TEST_PARAMS_STATE) + def test_simulate_state_cpu_vs_cuquantum(self, params): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + bench = RandomCircuitBenchmark(params) + + benchmark_cpu = bench.benchmark_state_cpu() + benchmark_gpu = bench.benchmark_state_cuquantum() + + cpu_median_time = benchmark_cpu['extras']['median_time'] + gpu_median_time = benchmark_gpu['extras']['median_time'] + + self.assertGreater(cpu_median_time, gpu_median_time) + + +if __name__ == "__main__": + tf.test.main() diff --git a/benchmarks/scripts/benchmark_op_gradients.py b/benchmarks/scripts/benchmark_op_gradients.py index 89b04cfd1..687e1b1f6 100644 --- a/benchmarks/scripts/benchmark_op_gradients.py +++ b/benchmarks/scripts/benchmark_op_gradients.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Benchmark differentiator methods.""" import os import time diff --git a/benchmarks/scripts/benchmark_random_circuit.py b/benchmarks/scripts/benchmark_random_circuit.py index 51d4ccfbf..b265237d7 100644 --- a/benchmarks/scripts/benchmark_random_circuit.py +++ b/benchmarks/scripts/benchmark_random_circuit.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Benchmark simulators against classically intractable 'supremacy' circuits.""" import os import time diff --git a/benchmarks/scripts/benchmark_util.py b/benchmarks/scripts/benchmark_util.py index 5b4bea2e5..87e903ecb 100644 --- a/benchmarks/scripts/benchmark_util.py +++ b/benchmarks/scripts/benchmark_util.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Utility functions for benchmark tools.""" import tensorflow as tf import test_log_pb2 diff --git a/benchmarks/scripts/benchmark_util_test.py b/benchmarks/scripts/benchmark_util_test.py index bece69897..951478a19 100644 --- a/benchmarks/scripts/benchmark_util_test.py +++ b/benchmarks/scripts/benchmark_util_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for utilities related to reading/running benchmarks.""" import os import tempfile diff --git a/benchmarks/scripts/flags.py b/benchmarks/scripts/flags.py index eaf7e78e2..ee173ef28 100644 --- a/benchmarks/scripts/flags.py +++ b/benchmarks/scripts/flags.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Command line flags shared between benchmarks.""" from collections import namedtuple from absl import flags as absl_flags diff --git a/benchmarks/scripts/flags_test.py b/benchmarks/scripts/flags_test.py index 6383809c6..c51a2f814 100644 --- a/benchmarks/scripts/flags_test.py +++ b/benchmarks/scripts/flags_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for benchmark command line flags.""" import tensorflow as tf diff --git a/benchmarks/scripts/models/__init__.py b/benchmarks/scripts/models/__init__.py index bf5b48863..9d181170d 100644 --- a/benchmarks/scripts/models/__init__.py +++ b/benchmarks/scripts/models/__init__.py @@ -11,4 +11,4 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== \ No newline at end of file +# ============================================================================= \ No newline at end of file diff --git a/benchmarks/scripts/models/random_clifford_circuit.py b/benchmarks/scripts/models/random_clifford_circuit.py index a08a667b5..09012c14e 100644 --- a/benchmarks/scripts/models/random_clifford_circuit.py +++ b/benchmarks/scripts/models/random_clifford_circuit.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= from typing import Iterable diff --git a/benchmarks/scripts/models/random_clifford_circuit_test.py b/benchmarks/scripts/models/random_clifford_circuit_test.py index c6d968ea0..bee8f5464 100644 --- a/benchmarks/scripts/models/random_clifford_circuit_test.py +++ b/benchmarks/scripts/models/random_clifford_circuit_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= from absl.testing import parameterized import cirq diff --git a/configure.sh b/configure.sh index bd2d89b52..088df4855 100755 --- a/configure.sh +++ b/configure.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= PLATFORM="$(uname -s | tr 'A-Z' 'a-z')" function write_to_bazelrc() { @@ -20,11 +20,11 @@ function write_to_bazelrc() { } function write_action_env_to_bazelrc() { - write_to_bazelrc "build --action_env $1=\"$2\"" + write_to_bazelrc "$1 --action_env $2=\"$3\"" } function write_linkopt_dir_to_bazelrc() { - write_to_bazelrc "build --linkopt -Wl,-rpath,$1" >> .bazelrc + write_to_bazelrc "$1 --linkopt -Wl,-rpath,$2" >> .bazelrc } @@ -49,85 +49,92 @@ function is_ppc64le() { # Remove .bazelrc if it already exist [ -e .bazelrc ] && rm .bazelrc -# Check if we are building GPU or CPU ops, default CPU -while [[ "$TF_NEED_CUDA" == "" ]]; do - read -p "Do you want to build ops again TensorFlow CPU pip package?"\ -" Y or enter for CPU (tensorflow), N for GPU (tensorflow-gpu). [Y/n] " INPUT +# Check if we are building TFQ GPU or not (TODO) +while [[ "$TFQ_NEED_CUDA" == "" ]]; do + read -p "Do you want to build TFQ against CPU?"\ +" Y or enter for CPU, N for GPU. [Y/n] " INPUT case $INPUT in - [Yy]* ) echo "Build with CPU pip package."; TF_NEED_CUDA=0;; - [Nn]* ) echo "Build with GPU pip package."; TF_NEED_CUDA=1;; - "" ) echo "Build with CPU pip package."; TF_NEED_CUDA=0;; - * ) echo "Invalid selection: " $INPUT;; - esac -done - -while [[ "$TF_CUDA_VERSION" == "" ]]; do - read -p "Are you building against TensorFlow 2.1(including RCs) or newer?[Y/n] " INPUT - case $INPUT in - [Yy]* ) echo "Build against TensorFlow 2.1 or newer."; TF_CUDA_VERSION=10.1;; - [Nn]* ) echo "Build against TensorFlow <2.1."; TF_CUDA_VERSION=10.0;; - "" ) echo "Build against TensorFlow 2.1 or newer."; TF_CUDA_VERSION=10.1;; + [Yy]* ) echo "Build with CPU ops only."; TFQ_NEED_CUDA=0;; + [Nn]* ) echo "Build with cuQuantum support."; TFQ_NEED_CUDA=1;; + "" ) echo "Build with CPU ops only."; TFQ_NEED_CUDA=0;; * ) echo "Invalid selection: " $INPUT;; esac done +# Set the CUDA SDK version for TF +if [[ "$TFQ_NEED_CUDA" == "1" ]]; then + _DEFAULT_CUDA_VERSION=11 + while [[ "$TF_CUDA_VERSION" == "" ]]; do + read -p "Please specify the CUDA SDK major version you want to use. [Leave empty to default to CUDA $_DEFAULT_CUDA_VERSION]: " INPUT + case $INPUT in + "" ) echo "Build against CUDA $_DEFAULT_CUDA_VERSION."; TF_CUDA_VERSION=$_DEFAULT_CUDA_VERSION;; + # check if the input is a number + *[!0-9]* ) echo "Invalid selection: $INPUT";; + * ) echo "Build against CUDA $INPUT."; TF_CUDA_VERSION=$INPUT;; + esac + done +fi -# CPU -if [[ "$TF_NEED_CUDA" == "0" ]]; then +# If TFQ_NEED_CUDA then enforce building against TensorFlow 2.11 or newer. +IS_VALID_TF_VERSION=$(python -c "import tensorflow as tf; v = tf.__version__; print(float(v[:v.rfind('.')]) < 2.11)") +TF_VERSION=$(python -c "import tensorflow as tf; print(tf.__version__)") +if [[ $IS_VALID_TF_VERSION == "True" ]]; then + echo "Building against TensorFlow 2.11 or newer is required." + echo "Please upgrade your TensorFlow version." + exit 1 +elif [[ $IS_VALID_TF_VERSION == "False" ]]; then + echo "Using TensorFlow 2.11" +else + echo "Unable to determine TensorFlow version." + exit 1 +fi - # Check if it's installed - if [[ $(pip show tensorflow) == *tensorflow* ]] || [[ $(pip show tf-nightly) == *tf-nightly* ]] ; then - echo 'Using installed tensorflow' +# Check if we are building cuQuantum ops on top of CUDA. +if [[ "$TFQ_NEED_CUDA" == "1" ]]; then + if [[ "$CUQUANTUM_ROOT" != "" ]]; then + echo " [*] cuQuantum library is detected here: CUQUANTUM_ROOT=$CUQUANTUM_ROOT." else - # Uninstall GPU version if it is installed. - if [[ $(pip show tensorflow-gpu) == *tensorflow-gpu* ]]; then - echo 'Already have gpu version of tensorflow installed. Uninstalling......\n' - pip uninstall tensorflow-gpu - elif [[ $(pip show tf-nightly-gpu) == *tf-nightly-gpu* ]]; then - echo 'Already have gpu version of tensorflow installed. Uninstalling......\n' - pip uninstall tf-nightly-gpu - fi - # Install CPU version - echo 'Installing tensorflow......\n' - pip install tensorflow + # Prompt the user to enter the cuQuantum root path, do not allow empty input (pressing enter) + # If the user enters an invalid path, prompt again. + while true; do + read -p "Please specify the cuQuantum root directory: " INPUT + if [[ -z "$INPUT" ]]; then + echo "Input cannot be empty. Please enter a valid path." + elif [[ "$INPUT" =~ ^(/[A-Za-z0-9_-]+)+$ ]]; then + echo "Path pattern is valid: $INPUT" + CUQUANTUM_ROOT=$INPUT + break + else + echo "Invalid path pattern: $INPUT. Please enter a valid path." + fi + done fi + write_action_env_to_bazelrc "build:cuda" "CUQUANTUM_ROOT" ${CUQUANTUM_ROOT} + write_linkopt_dir_to_bazelrc "build:cuda" "${CUQUANTUM_ROOT}/lib" +fi +# Check if it's installed +if [[ $(pip show tensorflow) == *tensorflow* ]] || [[ $(pip show tf-nightly) == *tf-nightly* ]]; then + echo "Using installed tensorflow-($TF_VERSION)" else - - # Check if it's installed - if [[ $(pip show tensorflow-gpu) == *tensorflow-gpu* ]] || [[ $(pip show tf-nightly-gpu) == *tf-nightly-gpu* ]]; then - echo 'Using installed tensorflow-gpu' - else - # Uninstall CPU version if it is installed. - if [[ $(pip show tensorflow) == *tensorflow* ]]; then - echo 'Already have tensorflow non-gpu installed. Uninstalling......\n' - pip uninstall tensorflow - elif [[ $(pip show tf-nightly) == *tf-nightly* ]]; then - echo 'Already have tensorflow non-gpu installed. Uninstalling......\n' - pip uninstall tf-nightly - fi - # Install CPU version - echo 'Installing tensorflow-gpu .....\n' - pip install tensorflow-gpu - fi + echo 'Installing tensorflow 2.11 .....\n' + pip install tensorflow==2.11.0 fi + TF_CFLAGS=( $(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_compile_flags()))') ) TF_LFLAGS="$(python -c 'import tensorflow as tf; print(" ".join(tf.sysconfig.get_link_flags()))')" -write_to_bazelrc "build:cuda --define=using_cuda=true --define=using_cuda_nvcc=true" -if [[ "$PIP_MANYLINUX2010" == "0" ]]; then - write_to_bazelrc "build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain" -fi - +write_to_bazelrc "build --experimental_repo_remote_exec" write_to_bazelrc "build --spawn_strategy=standalone" write_to_bazelrc "build --strategy=Genrule=standalone" -write_to_bazelrc "build --experimental_repo_remote_exec" write_to_bazelrc "build -c opt" -write_to_bazelrc "build --cxxopt=\"-D_GLIBCXX_USE_CXX11_ABI=0\"" - +write_to_bazelrc "build --cxxopt=\"-D_GLIBCXX_USE_CXX11_ABI=1\"" +write_to_bazelrc "build --cxxopt=\"-std=c++17\"" +write_to_bazelrc "build --cxxopt=\"-O3\"" +write_to_bazelrc "build --cxxopt=\"-march=native\"" if is_windows; then # Use pywrap_tensorflow instead of tensorflow_framework on Windows @@ -153,25 +160,38 @@ if is_windows; then SHARED_LIBRARY_NAME=${SHARED_LIBRARY_NAME//\\//} HEADER_DIR=${HEADER_DIR//\\//} fi -write_action_env_to_bazelrc "TF_HEADER_DIR" ${HEADER_DIR} -write_action_env_to_bazelrc "TF_SHARED_LIBRARY_DIR" ${SHARED_LIBRARY_DIR} -write_action_env_to_bazelrc "TF_SHARED_LIBRARY_NAME" ${SHARED_LIBRARY_NAME} -write_action_env_to_bazelrc "TF_NEED_CUDA" ${TF_NEED_CUDA} + +TF_NEED_CUDA=${TFQ_NEED_CUDA} +write_action_env_to_bazelrc "build" "TF_HEADER_DIR" ${HEADER_DIR} "" +write_action_env_to_bazelrc "build" "TF_SHARED_LIBRARY_DIR" ${SHARED_LIBRARY_DIR} "" +write_action_env_to_bazelrc "build" "TF_SHARED_LIBRARY_NAME" ${SHARED_LIBRARY_NAME} "" +write_action_env_to_bazelrc "build" "TF_NEED_CUDA" ${TF_NEED_CUDA} "" if ! is_windows; then - write_linkopt_dir_to_bazelrc ${SHARED_LIBRARY_DIR} + write_linkopt_dir_to_bazelrc "build" ${SHARED_LIBRARY_DIR} "" fi # TODO(yifeif): do not hardcode path if [[ "$TF_NEED_CUDA" == "1" ]]; then - write_action_env_to_bazelrc "TF_CUDA_VERSION" ${TF_CUDA_VERSION} - write_action_env_to_bazelrc "TF_CUDNN_VERSION" "7" + write_to_bazelrc "build:cuda --experimental_repo_remote_exec" + write_to_bazelrc "build:cuda --spawn_strategy=standalone" + write_to_bazelrc "build:cuda --strategy=Genrule=standalone" + write_to_bazelrc "build:cuda -c opt" + write_to_bazelrc "build:cuda --cxxopt=\"-D_GLIBCXX_USE_CXX11_ABI=1\"" + write_to_bazelrc "build:cuda --cxxopt=\"-std=c++17\"" + write_to_bazelrc "build:cuda --cxxopt=\"-O3\"" + write_to_bazelrc "build:cuda --cxxopt=\"-march=native\"" + write_to_bazelrc "build:cuda --@local_config_cuda//:enable_cuda" + write_to_bazelrc "build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain" + + write_action_env_to_bazelrc "build:cuda" "TF_CUDA_VERSION" ${TF_CUDA_VERSION} + write_action_env_to_bazelrc "build:cuda" "TF_CUDNN_VERSION" "8" if is_windows; then - write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${TF_CUDA_VERSION}" - write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${TF_CUDA_VERSION}" + write_action_env_to_bazelrc "build:cuda" "CUDNN_INSTALL_PATH" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${TF_CUDA_VERSION}" + write_action_env_to_bazelrc "build:cuda" "CUDA_TOOLKIT_PATH" "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v${TF_CUDA_VERSION}" else - write_action_env_to_bazelrc "CUDNN_INSTALL_PATH" "/usr/lib/x86_64-linux-gnu" - write_action_env_to_bazelrc "CUDA_TOOLKIT_PATH" "/usr/local/cuda" + write_action_env_to_bazelrc "build:cuda" "CUDNN_INSTALL_PATH" "/usr/lib/x86_64-linux-gnu" + write_action_env_to_bazelrc "build:cuda" "CUDA_TOOLKIT_PATH" "/usr/local/cuda" fi write_to_bazelrc "build --config=cuda" write_to_bazelrc "test --config=cuda" diff --git a/docs/_book.yaml b/docs/_book.yaml index 00bd8c29b..967d8ee7f 100644 --- a/docs/_book.yaml +++ b/docs/_book.yaml @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= upper_tabs: # Tabs left of dropdown menu - include: /_upper_tabs_left.yaml @@ -48,8 +48,12 @@ upper_tabs: path: /quantum/tutorials/barren_plateaus - title: "Quantum CNN" path: /quantum/tutorials/qcnn + - title: "Noise" + path: /quantum/tutorials/noise - title: "Research tools" path: /quantum/tutorials/research_tools + - title: "Quantum reinforcement learning" + path: /quantum/tutorials/quantum_reinforcement_learning - name: API skip_translation: true diff --git a/docs/_index.yaml b/docs/_index.yaml index 5d6f2e6d8..fb1fc5876 100644 --- a/docs/_index.yaml +++ b/docs/_index.yaml @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= book_path: /quantum/_book.yaml project_path: /quantum/_project.yaml description: > @@ -64,12 +64,38 @@ landing_page: - classname: devsite-landing-row-cards items: + - heading: "Distributed TensorFlow Quantum" + path: https://blog.tensorflow.org/2021/06/training-with-multiple-workers-using-tensorflow-quantum.html + image_path: /resources/images/tf-logo-card-16x9.png + buttons: + - label: "Read on TensorFlow blog" + path: https://blog.tensorflow.org/2021/06/training-with-multiple-workers-using-tensorflow-quantum.html + - heading: "Power of quantum data" + path: https://blog.tensorflow.org/2020/11/characterizing-quantum-advantage-in.html + image_path: /resources/images/tf-logo-card-16x9.png + buttons: + - label: "Read on TensorFlow blog" + path: https://blog.tensorflow.org/2020/11/characterizing-quantum-advantage-in.html + - heading: "User Journey: Owen" + path: https://blog.tensorflow.org/2020/11/my-experience-with-tensorflow-quantum.html + image_path: /resources/images/tf-logo-card-16x9.png + buttons: + - label: "Read on TensorFlow blog" + path: https://blog.tensorflow.org/2020/11/my-experience-with-tensorflow-quantum.html - heading: "Announcing
TensorFlow Quantum" image_path: /resources/images/google-research-card-16x9.png path: https://ai.googleblog.com/2020/03/announcing-tensorflow-quantum-open.html buttons: - label: "Read on the Google AI blog" path: https://ai.googleblog.com/2020/03/announcing-tensorflow-quantum-open.html + - classname: devsite-landing-row-cards + items: + - heading: "TensorFlow Quantum
Research Snippets" + image_path: /resources/images/github-card-16x9.png + path: https://github.com/tensorflow/quantum/tree/research + buttons: + - label: "View on GitHub" + path: https://github.com/tensorflow/quantum/tree/research - heading: "TensorFlow Quantum (TF Dev Summit '20)" youtube_id: -o9AhIz1uvo buttons: diff --git a/docs/concepts.md b/docs/concepts.md index 028816859..d1485a5b6 100644 --- a/docs/concepts.md +++ b/docs/concepts.md @@ -1,7 +1,7 @@ # Quantum machine learning concepts Google's -quantum supremacy experiment +quantum beyond-classical experiment used 53 *noisy* qubits to demonstrate it could perform a calculation in 200 seconds on a quantum computer that would take 10,000 years on the largest classical computer using existing algorithms. This marks the beginning of the diff --git a/docs/design.md b/docs/design.md index a152ecc62..a82bc9716 100644 --- a/docs/design.md +++ b/docs/design.md @@ -70,7 +70,7 @@ challenges: For performance reasons, Eigen (the C++ library used in many TensorFlow ops) is not well suited for quantum circuit simulation. Instead, the circuit simulators used in the -quantum supremacy experiment +quantum beyond-classical experiment are used as verifiers and extended as the foundation of TFQ ops (all written with AVX2 and SSE instructions). Ops with identical functional signatures were created that use a physical quantum computer. Switching between a simulated and diff --git a/docs/install.md b/docs/install.md index a3ee62a6c..575354cd6 100644 --- a/docs/install.md +++ b/docs/install.md @@ -10,14 +10,14 @@ There are a few ways to set up your environment to use TensorFlow Quantum (TFQ): Python's pip package manager. * Or build TensorFlow Quantum from source. -TensorFlow Quantum is supported on Python 3.6, 3.7, and 3.8 and depends directly on [Cirq](https://github.com/quantumlib/Cirq). +TensorFlow Quantum is supported on Python 3.7, 3.8, and 3.9 and depends directly on [Cirq](https://github.com/quantumlib/Cirq). ## Pip package ### Requirements -* pip 19.0 or later (requires `manylinux2010` support) -* [TensorFlow == 2.3.1](https://www.tensorflow.org/install/pip) +* pip 23.0 or later (requires `manylinux2014` support) +* [TensorFlow == 2.11.0](https://www.tensorflow.org/install/pip) See the [TensorFlow install guide](https://www.tensorflow.org/install/pip) to set up your Python development environment and an (optional) virtual environment. @@ -27,7 +27,7 @@ Upgrade `pip` and install TensorFlow
   pip3 install --upgrade pip
-  pip3 install tensorflow==2.3.1
+  pip3 install tensorflow==2.11.0
 
@@ -43,7 +43,7 @@ Install the latest stable release of TensorFlow Quantum: Success: TensorFlow Quantum is now installed. -Install the latest nightly version of TensorFlow Quantum: +Nightly builds which might depend on newer version of TensorFlow can be installed with:
@@ -84,7 +84,7 @@ As noted in the TensorFlow
 guide, the Bazel
 build system will be required.
 
-To ensure compatibility with TensorFlow 2.3.1, we use `bazel` version 3.1.0. To remove any existing version of Bazel:
+Our latest source builds use TensorFlow 2.11.0. To ensure compatibility we use `bazel` version 5.3.0. To remove any existing version of Bazel:
 
 
 
@@ -92,13 +92,13 @@ To ensure compatibility with TensorFlow 2.3.1, we use `bazel` version 3.1.0. To
 
-Download and install `bazel` version 3.1.0: +Download and install `bazel` version 5.3.0:
-  wget https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel_3.1.0-linux-x86_64.deb
+  wget https://github.com/bazelbuild/bazel/releases/download/5.3.0/bazel_5.3.0-linux-x86_64.deb
 
-  sudo dpkg -i bazel_3.1.0-linux-x86_64.deb
+  sudo dpkg -i bazel_5.3.0-linux-x86_64.deb
 
@@ -122,7 +122,7 @@ Finally, confirm installation of the correct `bazel` version: ### 4. Build TensorFlow from source Here we adapt instructions from the TensorFlow [build from source](https://www.tensorflow.org/install/source) -guide, see the link for further details. TensorFlow Quantum is compatible with TensorFlow version 2.3. +guide, see the link for further details. TensorFlow Quantum is compatible with TensorFlow version 2.11.0. Download the TensorFlow source code: @@ -131,7 +131,7 @@ Download the
   git clone https://github.com/tensorflow/tensorflow.git
   cd tensorflow
-  git checkout v2.3.1
+  git checkout v2.11.0
 
Be sure the virtual environment you created in step 2 is activated. Then, install the TensorFlow dependencies: @@ -141,7 +141,8 @@ Be sure the virtual environment you created in step 2 is activated. Then, instal pip install -U pip six numpy wheel setuptools mock 'future>=0.17.1' pip install -U keras_applications --no-deps pip install -U keras_preprocessing --no-deps - pip install numpy==1.18.0 + pip install numpy==1.24.2 + pip install packaging requests
@@ -153,11 +154,11 @@ Configure the TensorFlow build. When asked for the Python interpreter and librar
-Build the TensorFlow package: +Build the TensorFlow package (Since TF v2.8, `_GLIBCXX_USE_CXX11_ABI` is set to 1, and the c++ codes are all compiled with `-std=c++17`):
-  bazel build -c opt --cxxopt="-O3" --cxxopt="-march=native" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" //tensorflow/tools/pip_package:build_pip_package
+  bazel build -c opt --cxxopt="-O3" --cxxopt="-march=native" --cxxopt="-std=c++17" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" //tensorflow/tools/pip_package:build_pip_package
 
@@ -186,20 +187,20 @@ We use the standard [fork and pull request workflow](https://guides.github.com/a -### 6. Build the TensorFlow Quantum pip package +### 6. Build the TensorFlow Quantum pip package for CPU Build the TensorFlow Quantum pip package and install:
-  ./configure.sh
-  bazel build -c opt --cxxopt="-O3" --cxxopt="-march=native" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" release:build_pip_package
+  ./configure.sh  # Type 'Y' for the first question.
+  bazel build -c opt --cxxopt="-O3" --cxxopt="-march=native" --cxxopt="-std=c++17" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" release:build_pip_package
   bazel-bin/release/build_pip_package /tmp/tfquantum/
   python3 -m pip install /tmp/tfquantum/name_of_generated_wheel.whl
 
-To confirm that TensorFlow Quantum has successfully been installed, you can run the tests: +To confirm that TensorFlow Quantum for CPU has successfully been installed, you can run the tests:
   ./scripts/test_all.sh
@@ -207,4 +208,33 @@ To confirm that TensorFlow Quantum has successfully been installed, you can run
 
 
 
-Success: TensorFlow Quantum is now installed.
+Success: TensorFlow Quantum for CPU is now installed.
+
+### 7. Build the TensorFlow Quantum pip package for GPU
+
+To enable GPU (cuQuantum) backend, cuStatevec must be installed, see installation guide for details. Importantly, we require that the `CUQUANTUM_ROOT` environment variable has been set by running the following with your installation path.
+
+  export CUQUANTUM_ROOT=/path/to/cuquantum/installation/dir 
+
+ +Build the TensorFlow Quantum GPU pip package and install: + + +
+  bazel clean --expunge  # If you got stuck `.so` related issue, please clean the cache.
+  ./configure.sh  # Type 'n' for the second question.
+  bazel build -c opt --config=cuda --cxxopt="-O3" --cxxopt="-march=native" --cxxopt="-std=c++17" --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" release:build_pip_package
+  bazel-bin/release/build_pip_package /tmp/tfquantum_gpu/
+  python3 -m pip install /tmp/tfquantum_gpu/name_of_generated_wheel.whl
+
+ + +To confirm that TensorFlow Quantum for GPU has successfully been installed, you can run the tests: + +
+  ./scripts/test_all.sh gpu
+
+ + + +Success: TensorFlow Quantum for GPU is now installed. diff --git a/docs/tutorials/barren_plateaus.ipynb b/docs/tutorials/barren_plateaus.ipynb index a9eefa81e..3c9176eaa 100644 --- a/docs/tutorials/barren_plateaus.ipynb +++ b/docs/tutorials/barren_plateaus.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "cellView": "form", "colab": {}, @@ -89,7 +89,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -97,7 +97,7 @@ }, "outputs": [], "source": [ - "!pip install tensorflow==2.3.1" + "!pip install tensorflow==2.7.0" ] }, { @@ -112,7 +112,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -120,7 +120,22 @@ }, "outputs": [], "source": [ - "!pip install tensorflow-quantum" + "!pip install tensorflow-quantum==0.7.2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "4Ql5PW-ACO0J" + }, + "outputs": [], + "source": [ + "# Update package resources to account for version changes.\n", + "import importlib, pkg_resources\n", + "importlib.reload(pkg_resources)" ] }, { @@ -135,7 +150,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -187,7 +202,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -263,7 +278,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -312,7 +327,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -339,6 +354,7 @@ "plt.semilogy(n_qubits, theta_var)\n", "plt.title('Gradient Variance in QNNs')\n", "plt.xlabel('n_qubits')\n", + "plt.xticks(n_qubits)\n", "plt.ylabel('$\\\\partial \\\\theta$ variance')\n", "plt.show()" ] @@ -383,7 +399,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -439,7 +455,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -467,6 +483,7 @@ "plt.semilogy(n_qubits, heuristic_theta_var)\n", "plt.title('Heuristic vs. Random')\n", "plt.xlabel('n_qubits')\n", + "plt.xticks(n_qubits)\n", "plt.ylabel('$\\\\partial \\\\theta$ variance')\n", "plt.show()" ] @@ -494,6 +511,15 @@ "display_name": "Python 3", "language": "python", "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.10.9 (main, Dec 7 2022, 13:47:07) [GCC 12.2.0]" + }, + "vscode": { + "interpreter": { + "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1" + } } }, "nbformat": 4, diff --git a/docs/tutorials/gradients.ipynb b/docs/tutorials/gradients.ipynb index e7a371163..072718bcf 100644 --- a/docs/tutorials/gradients.ipynb +++ b/docs/tutorials/gradients.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "cellView": "form", "colab": {}, @@ -91,7 +91,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -99,7 +99,7 @@ }, "outputs": [], "source": [ - "!pip install tensorflow==2.3.1" + "!pip install tensorflow==2.7.0" ] }, { @@ -114,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -122,7 +122,22 @@ }, "outputs": [], "source": [ - "!pip install tensorflow-quantum" + "!pip install tensorflow-quantum==0.7.2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "4Ql5PW-ACO0J" + }, + "outputs": [], + "source": [ + "# Update package resources to account for version changes.\n", + "import importlib, pkg_resources\n", + "importlib.reload(pkg_resources)" ] }, { @@ -137,7 +152,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -172,7 +187,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -197,7 +212,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -221,7 +236,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -254,7 +269,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -287,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -316,7 +331,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -346,7 +361,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -375,7 +390,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -424,7 +439,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -479,7 +494,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -503,7 +518,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -533,7 +548,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -562,7 +577,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -603,15 +618,25 @@ }, "source": [ "## 4. Advanced usage\n", - "Here you will learn how to define your own custom differentiation routines for quantum circuits.\n", - "All differentiators that exist inside of TensorFlow Quantum subclass `tfq.differentiators.Differentiator`. A differentiator must implement `differentiate_analytic` and `differentiate_sampled`.\n", + "All differentiators that exist inside of TensorFlow Quantum subclass `tfq.differentiators.Differentiator`. To implement a differentiator, a user must implement one of two interfaces. The standard is to implement `get_gradient_circuits`, which tells the base class which circuits to measure to obtain an estimate of the gradient. Alternatively, you can overload `differentiate_analytic` and `differentiate_sampled`; the class `tfq.differentiators.Adjoint` takes this route.\n", "\n", - "The following uses TensorFlow Quantum constructs to implement the closed form solution from the first part of this tutorial." + "The following uses TensorFlow Quantum to implement the gradient of a circuit. You will use a small example of parameter shifting." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "J1xN6Ln5mB9N" + }, + "source": [ + "Recall the circuit you defined above, $|\\alpha⟩ = Y^{\\alpha}|0⟩$. As before, you can define a function as the expectation value of this circuit against the $X$ observable, $f(\\alpha) = ⟨\\alpha|X|\\alpha⟩$. Using [parameter shift rules](https://pennylane.ai/qml/glossary/parameter_shift.html), for this circuit, you can find that the derivative is\n", + "$$\\frac{\\partial}{\\partial \\alpha} f(\\alpha) = \\frac{\\pi}{2} f\\left(\\alpha + \\frac{1}{2}\\right) - \\frac{ \\pi}{2} f\\left(\\alpha - \\frac{1}{2}\\right)$$\n", + "The `get_gradient_circuits` function returns the components of this derivative." ] }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -625,107 +650,36 @@ " def __init__(self):\n", " pass\n", "\n", - " @tf.function\n", " def get_gradient_circuits(self, programs, symbol_names, symbol_values):\n", " \"\"\"Return circuits to compute gradients for given forward pass circuits.\n", " \n", - " When implementing a gradient, it is often useful to describe the\n", - " intermediate computations in terms of transformed versions of the input\n", - " circuits. The details are beyond the scope of this tutorial, but interested\n", - " users should check out the differentiator implementations in the TFQ library\n", - " for examples.\n", - " \"\"\"\n", - " raise NotImplementedError(\n", - " \"Gradient circuits are not implemented in this tutorial.\")\n", - "\n", - " @tf.function\n", - " def _compute_gradient(self, symbol_values):\n", - " \"\"\"Compute the gradient based on symbol_values.\"\"\"\n", - "\n", - " # f(x) = sin(pi * x)\n", - " # f'(x) = pi * cos(pi * x)\n", - " return tf.cast(tf.cos(symbol_values * np.pi) * np.pi, tf.float32)\n", - "\n", - " @tf.function\n", - " def differentiate_analytic(self, programs, symbol_names, symbol_values,\n", - " pauli_sums, forward_pass_vals, grad):\n", - " \"\"\"Specify how to differentiate a circuit with analytical expectation.\n", - "\n", - " This is called at graph runtime by TensorFlow. `differentiate_analytic`\n", - " should calculate the gradient of a batch of circuits and return it\n", - " formatted as indicated below. See\n", - " `tfq.differentiators.ForwardDifference` for an example.\n", - "\n", - " Args:\n", - " programs: `tf.Tensor` of strings with shape [batch_size] containing\n", - " the string representations of the circuits to be executed.\n", - " symbol_names: `tf.Tensor` of strings with shape [n_params], which\n", - " is used to specify the order in which the values in\n", - " `symbol_values` should be placed inside of the circuits in\n", - " `programs`.\n", - " symbol_values: `tf.Tensor` of real numbers with shape\n", - " [batch_size, n_params] specifying parameter values to resolve\n", - " into the circuits specified by programs, following the ordering\n", - " dictated by `symbol_names`.\n", - " pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops]\n", - " containing the string representation of the operators that will\n", - " be used on all of the circuits in the expectation calculations.\n", - " forward_pass_vals: `tf.Tensor` of real numbers with shape\n", - " [batch_size, n_ops] containing the output of the forward pass\n", - " through the op you are differentiating.\n", - " grad: `tf.Tensor` of real numbers with shape [batch_size, n_ops]\n", - " representing the gradient backpropagated to the output of the\n", - " op you are differentiating through.\n", - "\n", - " Returns:\n", - " A `tf.Tensor` with the same shape as `symbol_values` representing\n", - " the gradient backpropagated to the `symbol_values` input of the op\n", - " you are differentiating through.\n", + " Every gradient on a quantum computer can be computed via measurements\n", + " of transformed quantum circuits. Here, you implement a custom gradient\n", + " for a specific circuit. For a real differentiator, you will need to\n", + " implement this function in a more general way. See the differentiator\n", + " implementations in the TFQ library for examples.\n", " \"\"\"\n", "\n", - " # Computing gradients just based off of symbol_values.\n", - " return self._compute_gradient(symbol_values) * grad\n", - "\n", - " @tf.function\n", - " def differentiate_sampled(self, programs, symbol_names, symbol_values,\n", - " pauli_sums, num_samples, forward_pass_vals, grad):\n", - " \"\"\"Specify how to differentiate a circuit with sampled expectation.\n", - "\n", - " This is called at graph runtime by TensorFlow. `differentiate_sampled`\n", - " should calculate the gradient of a batch of circuits and return it\n", - " formatted as indicated below. See\n", - " `tfq.differentiators.ForwardDifference` for an example.\n", - "\n", - " Args:\n", - " programs: `tf.Tensor` of strings with shape [batch_size] containing\n", - " the string representations of the circuits to be executed.\n", - " symbol_names: `tf.Tensor` of strings with shape [n_params], which\n", - " is used to specify the order in which the values in\n", - " `symbol_values` should be placed inside of the circuits in\n", - " `programs`.\n", - " symbol_values: `tf.Tensor` of real numbers with shape\n", - " [batch_size, n_params] specifying parameter values to resolve\n", - " into the circuits specified by programs, following the ordering\n", - " dictated by `symbol_names`.\n", - " pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops]\n", - " containing the string representation of the operators that will\n", - " be used on all of the circuits in the expectation calculations.\n", - " num_samples: `tf.Tensor` of positive integers representing the\n", - " number of samples per term in each term of pauli_sums used\n", - " during the forward pass.\n", - " forward_pass_vals: `tf.Tensor` of real numbers with shape\n", - " [batch_size, n_ops] containing the output of the forward pass\n", - " through the op you are differentiating.\n", - " grad: `tf.Tensor` of real numbers with shape [batch_size, n_ops]\n", - " representing the gradient backpropagated to the output of the\n", - " op you are differentiating through.\n", - "\n", - " Returns:\n", - " A `tf.Tensor` with the same shape as `symbol_values` representing\n", - " the gradient backpropagated to the `symbol_values` input of the op\n", - " you are differentiating through.\n", - " \"\"\"\n", - " return self._compute_gradient(symbol_values) * grad" + " # The two terms in the derivative are the same circuit...\n", + " batch_programs = tf.stack([programs, programs], axis=1)\n", + "\n", + " # ... with shifted parameter values.\n", + " shift = tf.constant(1/2)\n", + " forward = symbol_values + shift\n", + " backward = symbol_values - shift\n", + " batch_symbol_values = tf.stack([forward, backward], axis=1)\n", + " \n", + " # Weights are the coefficients of the terms in the derivative.\n", + " num_program_copies = tf.shape(batch_programs)[0]\n", + " batch_weights = tf.tile(tf.constant([[[np.pi/2, -np.pi/2]]]),\n", + " [num_program_copies, 1, 1])\n", + "\n", + " # The index map simply says which weights go with which circuits.\n", + " batch_mapper = tf.tile(\n", + " tf.constant([[[0, 1]]]), [num_program_copies, 1, 1])\n", + "\n", + " return (batch_programs, symbol_names, batch_symbol_values,\n", + " batch_weights, batch_mapper)" ] }, { @@ -735,12 +689,12 @@ "id": "bvEgw2m6NUAI" }, "source": [ - "This new differentiator can now be used with existing `tfq.layer` objects:" + "The `Differentiator` base class uses the components returned from `get_gradient_circuits` to calculate the derivative, as in the parameter shift formula you saw above. This new differentiator can now be used with existing `tfq.layer` objects:" ] }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -796,7 +750,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -818,7 +772,7 @@ "circuit_tensor = tfq.convert_to_tensor([my_circuit])\n", "op_tensor = tfq.convert_to_tensor([[pauli_x]])\n", "single_value = tf.convert_to_tensor([[my_alpha]])\n", - "num_samples_tensor = tf.convert_to_tensor([[1000]])\n", + "num_samples_tensor = tf.convert_to_tensor([[5000]])\n", "\n", "with tf.GradientTape() as g:\n", " g.watch(single_value)\n", @@ -858,6 +812,15 @@ "display_name": "Python 3", "language": "python", "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.10.9 (main, Dec 7 2022, 13:47:07) [GCC 12.2.0]" + }, + "vscode": { + "interpreter": { + "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1" + } } }, "nbformat": 4, diff --git a/docs/tutorials/hello_many_worlds.ipynb b/docs/tutorials/hello_many_worlds.ipynb index 96b414b87..801d388de 100644 --- a/docs/tutorials/hello_many_worlds.ipynb +++ b/docs/tutorials/hello_many_worlds.ipynb @@ -12,12 +12,15 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "cellView": "form", "colab": {}, "colab_type": "code", - "id": "iiQkM5ZgQ8r2" + "id": "iiQkM5ZgQ8r2", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -89,15 +92,18 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "TorxE5tnkvb2" + "id": "TorxE5tnkvb2", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ - "!pip install tensorflow==2.3.1" + "!pip install tensorflow==2.7.0" ] }, { @@ -112,15 +118,36 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "saFHsRDpkvkH" + "id": "saFHsRDpkvkH", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ - "!pip install tensorflow-quantum" + "!pip install tensorflow-quantum==0.7.2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "4Ql5PW-ACO0J", + "vscode": { + "languageId": "python" + } + }, + "outputs": [], + "source": [ + "# Update package resources to account for version changes.\n", + "import importlib, pkg_resources\n", + "importlib.reload(pkg_resources)" ] }, { @@ -135,11 +162,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "enZ300Bflq80" + "id": "enZ300Bflq80", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -182,11 +212,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "2yQdmhQLCrzQ" + "id": "2yQdmhQLCrzQ", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -205,11 +238,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "Ps-pd2mndXs7" + "id": "Ps-pd2mndXs7", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -219,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)" ] @@ -236,11 +272,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "VMq7EayNRyQb" + "id": "VMq7EayNRyQb", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -262,12 +301,15 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "hrSnOCi3ehr_", - "scrolled": true + "scrolled": true, + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -280,11 +322,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "OZ0lWFXv6pII" + "id": "OZ0lWFXv6pII", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -307,12 +352,15 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "1gLQjA02mIyy", - "scrolled": true + "scrolled": true, + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -335,11 +383,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "aX_vEmCKmpQS" + "id": "aX_vEmCKmpQS", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -366,15 +417,18 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "1fsVZhF5lIXp" + "id": "1fsVZhF5lIXp", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ - "batch_vals = np.array(np.random.uniform(0, 2 * np.pi, (5, 2)), dtype=np.float32)" + "batch_vals = np.array(np.random.uniform(0, 2 * np.pi, (5, 2)), dtype=float)" ] }, { @@ -389,11 +443,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "RsfF53UCJtr9" + "id": "RsfF53UCJtr9", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -424,11 +481,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "kGZVdcZ6y9lC" + "id": "kGZVdcZ6y9lC", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -461,7 +521,7 @@ "id": "NlyxF3Q-6pIe" }, "source": [ - "For the implementation of this tutorial, this is architecture is split into 3 parts:\n", + "For the implementation of this tutorial, this architecture is split into 3 parts:\n", "\n", "- The *input circuit* or *datapoint circuit*: The first three $R$ gates.\n", "- The *controlled circuit*: The other three $R$ gates.\n", @@ -482,11 +542,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "N-j7SCl-51-q" + "id": "N-j7SCl-51-q", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -517,11 +580,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "1v4CK2jD6pIj" + "id": "1v4CK2jD6pIj", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -546,11 +612,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "kZbYRTe16pIm" + "id": "kZbYRTe16pIm", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -583,11 +652,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "UfHF8NNE6pIr" + "id": "UfHF8NNE6pIr", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -615,11 +687,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "Zvt2YGmZ6pIu" + "id": "Zvt2YGmZ6pIu", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -644,11 +719,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "Xs6EMhah6pIz" + "id": "Xs6EMhah6pIz", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -672,11 +750,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "ERXNPe4F6pI4" + "id": "ERXNPe4F6pI4", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -715,11 +796,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "ciMIJAuH6pJA" + "id": "ciMIJAuH6pJA", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -755,11 +839,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "_VYfzHffWo7n" + "id": "_VYfzHffWo7n", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -786,11 +873,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "6nk2Yr3e6pJJ" + "id": "6nk2Yr3e6pJJ", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -819,11 +909,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "Lwphqvs96pJO" + "id": "Lwphqvs96pJO", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -842,11 +935,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "dtPYqbNi8zeZ" + "id": "dtPYqbNi8zeZ", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -861,11 +957,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "azE-qV0OaC1o" + "id": "azE-qV0OaC1o", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -899,11 +998,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "RoIlb7r7j5SY" + "id": "RoIlb7r7j5SY", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -920,11 +1022,11 @@ " full_circuit,\n", " {s:v for (s,v) in zip(control_params, params_to_prepare_output[index])}\n", " ).final_state_vector\n", - " expectation = z0.expectation_from_state_vector(state, {qubit: 0}).real\n", + " expt = cirq.Z(qubit).expectation_from_state_vector(state, {qubit: 0}).real\n", " print(f'For a desired output (expectation) of {desired_values[index]} with'\n", " f' noisy preparation, the controller\\nnetwork found the following '\n", " f'values for theta: {params_to_prepare_output[index]}\\nWhich gives an'\n", - " f' actual expectation of: {expectation}\\n')\n", + " f' actual expectation of: {expt}\\n')\n", "\n", "\n", "check_error(commands, expected_outputs)" @@ -942,11 +1044,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "aYskLTacs8Ku" + "id": "aYskLTacs8Ku", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -983,11 +1088,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "hta0G3Nc6pJY" + "id": "hta0G3Nc6pJY", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -1016,11 +1124,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "n_aTG4g3-y0F" + "id": "n_aTG4g3-y0F", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -1043,11 +1154,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "IMHjiKit6pJg" + "id": "IMHjiKit6pJg", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -1081,11 +1195,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "4gw_L3JG0_G0" + "id": "4gw_L3JG0_G0", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -1113,11 +1230,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "nFuGA73MAA4p" + "id": "nFuGA73MAA4p", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -1135,11 +1255,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "Cf_G-GdturLL" + "id": "Cf_G-GdturLL", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -1172,11 +1295,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "uXmH0TQ76pJt" + "id": "uXmH0TQ76pJt", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ diff --git a/docs/tutorials/images/gym_CartPole.gif b/docs/tutorials/images/gym_CartPole.gif new file mode 100644 index 0000000000000000000000000000000000000000..75f5cd2b5e667769fbead70bc66191299bf1fe3a GIT binary patch literal 1299517 zcmeF4cU%D)xemx`1GzX%tH=s9;55tc;>!K{Qc!ZGgtgx)yd7 zH7a&pdl>}_AY(%WBqItcO+*j`OW4{HzP3cTEfH%=RA|0z>r43h65+l?tS?ca z`EJ{A!Z(}<4<};7i3-h&ZDR@FSRy=@h>ayGH1B0wLHJe>;T1$|1y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luW z>GHJ(1{h*LWP^8)&3<64)EIR|ZG%d8G2>Vp<5-rJ`ik0!^P8sA?1x#P*~504`Oxf# zJE8Dcv%V_!LpRXu)nz|iQA@s{+8irFM|C#G;KR(fGrEi8pxMKi&9NN>bqW53b#xbS zbX#?Qou7a{%R)BSBjw=8gT|oQ!%|O7xxUR}=lr5HI7*J)>F1pt_lL$yy)UnsxpDbC zm(O$geBFGWE2)07B~@MakpFc`s<&A~{-276;MUA;eBCv(Y1hTSIh_;oeVH}07#(}D zQciB|&8(S?l>1Z)=8Mu*Yi3?}w0}9jT$foh(++CrKj$g6!;D!oyQ3T(wba6SKC@=F z%Utj}=cd$j8M9_~(5^%u($$jZ%$iw+_+5FqR*%q2f7EXZYi1|g%2sRYN)|OT2}f&Y zL#$VtK)MP;{ztTC7Azhj>!)K3Lq1wFyV)WzAp|G?c|QN&lvKA@caxo;TOj$Wc!&TF z50OWO_Lu5UV)FU8pxS)iQkBmKf6C`Cs`7b2_tXsemsd1k@_8#s-I~UYLq4#hMPbV| mJI?{%Xf4TJj9psa*%y8VVY5Fksp5ZANmZRIseZYnYW{z0Xy#x5 literal 0 HcmV?d00001 diff --git a/docs/tutorials/images/noise_1.png b/docs/tutorials/images/noise_1.png new file mode 100644 index 0000000000000000000000000000000000000000..a24e62c653165d016c821e933f52482249c560d9 GIT binary patch literal 66876 zcmeFa2{@GP|2I5Hwk)L>N~KM*u?i=QY23SCuc))3VdTU@&@xOXsh_ zV6;dWY?}i0cJP-4%G@j%%nzn;{;ZmN$B(WYD~{nZ=?VVkR96&2HvFEye;=lGOo|GTIRyndOW zIL>2m%KzjXm55uf#Ql27`l%;b(hJ+brvLu@D}n!+67Y=;YxHaqic*P{Yf^B6BCRIFL`&T~s^}O=+)n|ZxNWgwf zfWd}DvBRR^`PIxq8#g2?wyfAx(V{Dv{IBPG(CpP>XdbFR8BTd-7}6VU7*6pQIapMc z0~S?72Ged9)7}k(aa4FXV{}oGo0Gl$H@%cmt9O$MWWP6Qav-P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swsUJ7?X$S^pFF}2EmrWeV3 z>jbgFuf*sL%7@v6Fg0vL()j^ZE0gQ`kCUM9leczzuo-eCId45AF@{9FAw%uvT}^Z9 z#Ql6gK|82<4 zR|-a0x6W%rqnppA!fU8oCU5>>xv9@0eVKK4&Lz4mgRM-1(ss@@@F9SkkJOE=M()=wxYk2bkksr@fw zO#nlM|9fztSH-h54|pMsku}umhUsG)Xh1NU?;R~?!7A-n`K`d`vXaC3gxR0!S-xiQn6rX?We zOju`YNx~q5kUSp|fO&;Vr^T7`Pz5Uj`YFjBP}&Lw3SKl0@~({oiW`?w;R}+)fV>v$ zT+710puPags;U_gJ=*y9q*>%GRjo;-Ak5idXfNOMGpIDszgR%^yIJtWbAOft$~)#B z`Y(S^^MvhMc71ey28;%VBU)Lv(7R^*0%Uof7BKtb&q2}+0VgW>DZB2eJ1i&cDDd+i zj%;5q5HW<(fq%X~VcM2S!^`&p$!_Tq_y$df9A;8!bBg*;z)HYd|3%=qd_wI*K_G?y zKIlJ_1A>YHDVYP})@&P4DAmo}tADfaKt3_@CIDNI%!1wdAriAZ|HT2-1fORpgTHIW@?XPt($4>Ln7jYqlU)C!ELAQ)%XHEc5SIVV g>CK%c_=;mbJC!F7KOhp8Pg?x+v4(QVL$i1P12-bFrvLx| literal 0 HcmV?d00001 diff --git a/docs/tutorials/mnist.ipynb b/docs/tutorials/mnist.ipynb index 31578ce38..91405ed26 100644 --- a/docs/tutorials/mnist.ipynb +++ b/docs/tutorials/mnist.ipynb @@ -97,7 +97,7 @@ }, "outputs": [], "source": [ - "!pip install tensorflow==2.3.1" + "!pip install tensorflow==2.7.0" ] }, { @@ -112,7 +112,7 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", @@ -120,7 +120,22 @@ }, "outputs": [], "source": [ - "!pip install tensorflow-quantum" + "!pip install tensorflow-quantum==0.7.2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "4Ql5PW-ACO0J" + }, + "outputs": [], + "source": [ + "# Update package resources to account for version changes.\n", + "import importlib, pkg_resources\n", + "importlib.reload(pkg_resources)" ] }, { @@ -382,32 +397,35 @@ "source": [ "def remove_contradicting(xs, ys):\n", " mapping = collections.defaultdict(set)\n", + " orig_x = {}\n", " # Determine the set of labels for each unique image:\n", " for x,y in zip(xs,ys):\n", + " orig_x[tuple(x.flatten())] = x\n", " mapping[tuple(x.flatten())].add(y)\n", " \n", " new_x = []\n", " new_y = []\n", - " for x,y in zip(xs, ys):\n", - " labels = mapping[tuple(x.flatten())]\n", + " for flatten_x in mapping:\n", + " x = orig_x[flatten_x]\n", + " labels = mapping[flatten_x]\n", " if len(labels) == 1:\n", " new_x.append(x)\n", - " new_y.append(labels.pop())\n", + " new_y.append(next(iter(labels)))\n", " else:\n", " # Throw out images that match more than one label.\n", " pass\n", " \n", - " num_3 = sum(1 for value in mapping.values() if True in value)\n", - " num_6 = sum(1 for value in mapping.values() if False in value)\n", - " num_both = sum(1 for value in mapping.values() if len(value) == 2)\n", + " num_uniq_3 = sum(1 for value in mapping.values() if len(value) == 1 and True in value)\n", + " num_uniq_6 = sum(1 for value in mapping.values() if len(value) == 1 and False in value)\n", + " num_uniq_both = sum(1 for value in mapping.values() if len(value) == 2)\n", "\n", " print(\"Number of unique images:\", len(mapping.values()))\n", - " print(\"Number of 3s: \", num_3)\n", - " print(\"Number of 6s: \", num_6)\n", - " print(\"Number of contradictory images: \", num_both)\n", + " print(\"Number of unique 3s: \", num_uniq_3)\n", + " print(\"Number of unique 6s: \", num_uniq_6)\n", + " print(\"Number of unique contradicting labels (both 3 and 6): \", num_uniq_both)\n", " print()\n", - " print(\"Initial number of examples: \", len(xs))\n", - " print(\"Remaining non-contradictory examples: \", len(new_x))\n", + " print(\"Initial number of images: \", len(xs))\n", + " print(\"Remaining non-contradicting unique images: \", len(new_x))\n", " \n", " return np.array(new_x), np.array(new_y)" ] @@ -445,7 +463,7 @@ "id": "SlJ5NVaPojhT" }, "source": [ - "### 1.3 Encode the data as quantum circuits\n", + "### 1.4 Encode the data as quantum circuits\n", "\n", "To process images using a quantum computer, Farhi et al. proposed representing each pixel with a qubit, with the state depending on the value of the pixel. The first step is to convert to a binary encoding." ] @@ -1082,8 +1100,8 @@ "cnn_accuracy = cnn_results[1]\n", "fair_nn_accuracy = fair_nn_results[1]\n", "\n", - "sns.barplot([\"Quantum\", \"Classical, full\", \"Classical, fair\"],\n", - " [qnn_accuracy, cnn_accuracy, fair_nn_accuracy])" + "sns.barplot(x=[\"Quantum\", \"Classical, full\", \"Classical, fair\"],\n", + " y=[qnn_accuracy, cnn_accuracy, fair_nn_accuracy])" ] } ], @@ -1099,6 +1117,15 @@ "display_name": "Python 3", "language": "python", "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.10.9 (main, Dec 7 2022, 13:47:07) [GCC 12.2.0]" + }, + "vscode": { + "interpreter": { + "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1" + } } }, "nbformat": 4, diff --git a/docs/tutorials/noise.ipynb b/docs/tutorials/noise.ipynb new file mode 100644 index 000000000..0a0ebc290 --- /dev/null +++ b/docs/tutorials/noise.ipynb @@ -0,0 +1,805 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "xLOXFOT5Q40E" + }, + "source": [ + "##### Copyright 2020 The TensorFlow Authors." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "iiQkM5ZgQ8r2" + }, + "outputs": [], + "source": [ + "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n", + "# you may not use this file except in compliance with the License.\n", + "# You may obtain a copy of the License at\n", + "#\n", + "# https://www.apache.org/licenses/LICENSE-2.0\n", + "#\n", + "# Unless required by applicable law or agreed to in writing, software\n", + "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", + "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", + "# See the License for the specific language governing permissions and\n", + "# limitations under the License." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "UndbWF_UpN-X" + }, + "source": [ + "# Noise" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "i9Jcnb8bQQyd" + }, + "source": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " View on TensorFlow.org\n", + " \n", + " Run in Google Colab\n", + " \n", + " View source on GitHub\n", + " \n", + " Download notebook\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fHHaKIG06Iv_" + }, + "source": [ + "Noise is present in modern day quantum computers. Qubits are susceptible to interference from the surrounding environment, imperfect fabrication, TLS and sometimes even [gamma rays](https://arxiv.org/abs/2104.05219). Until large scale error correction is reached, the algorithms of today must be able to remain functional in the presence of noise. This makes testing algorithms under noise an important step for validating quantum algorithms / models will function on the quantum computers of today.\n", + "\n", + "In this tutorial you will explore the basics of noisy circuit simulation in TFQ via the high level `tfq.layers` API.\n", + "\n", + "## Setup" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "J2CRbYRqrLdt" + }, + "outputs": [], + "source": [ + "!pip install tensorflow==2.7.0 tensorflow-quantum==0.7.2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "QStNslxBwgte" + }, + "outputs": [], + "source": [ + "!pip install -q git+https://github.com/tensorflow/docs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "4Ql5PW-ACO0J" + }, + "outputs": [], + "source": [ + "# Update package resources to account for version changes.\n", + "import importlib, pkg_resources\n", + "importlib.reload(pkg_resources)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "iRU07S4o8B52" + }, + "outputs": [], + "source": [ + "import random\n", + "import cirq\n", + "import sympy\n", + "import tensorflow_quantum as tfq\n", + "import tensorflow as tf\n", + "import numpy as np\n", + "# Plotting\n", + "import matplotlib.pyplot as plt\n", + "import tensorflow_docs as tfdocs\n", + "import tensorflow_docs.plots" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "CVnAGxZyruv8" + }, + "source": [ + "## 1. Understanding quantum noise\n", + "\n", + "### 1.1 Basic circuit noise\n", + "\n", + "Noise on a quantum computer impacts the bitstring samples you are able to measure from it. One intuitive way you can start to think about this is that a noisy quantum computer will \"insert\", \"delete\" or \"replace\" gates in random places like the diagram below:\n", + "\n", + "\n", + "\n", + "Building off of this intuition, when dealing with noise, you are no longer using a single pure state $|\\psi \\rangle$ but instead dealing with an *ensemble* of all possible noisy realizations of your desired circuit: $\\rho = \\sum_j p_j |\\psi_j \\rangle \\langle \\psi_j |$ . Where $p_j$ gives the probability that the system is in $|\\psi_j \\rangle$ .\n", + "\n", + "Revisiting the above picture, if we knew beforehand that 90% of the time our system executed perfectly, or errored 10% of the time with just this one mode of failure, then our ensemble would be: \n", + "\n", + "$\\rho = 0.9 |\\psi_\\text{desired} \\rangle \\langle \\psi_\\text{desired}| + 0.1 |\\psi_\\text{noisy} \\rangle \\langle \\psi_\\text{noisy}| $\n", + "\n", + "If there was more than just one way that our circuit could error, then the ensemble $\\rho$ would contain more than just two terms (one for each new noisy realization that could happen). $\\rho$ is referred to as the [density matrix](https://en.wikipedia.org/wiki/Density_matrix) describing your noisy system.\n", + "\n", + "### 1.2 Using channels to model circuit noise\n", + "\n", + "Unfortunately in practice it's nearly impossible to know all the ways your circuit might error and their exact probabilities. A simplifying assumption you can make is that after each operation in your circuit there is some kind of [channel](https://quantumai.google/cirq/noise) that roughly captures how that operation might error. You can quickly create a circuit with some noise:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Eu_vpHbfrQKQ" + }, + "outputs": [], + "source": [ + "def x_circuit(qubits):\n", + " \"\"\"Produces an X wall circuit on `qubits`.\"\"\"\n", + " return cirq.Circuit(cirq.X.on_each(*qubits))\n", + "\n", + "def make_noisy(circuit, p):\n", + " \"\"\"Add a depolarization channel to all qubits in `circuit` before measurement.\"\"\"\n", + " return circuit + cirq.Circuit(cirq.depolarize(p).on_each(*circuit.all_qubits()))\n", + "\n", + "my_qubits = cirq.GridQubit.rect(1, 2)\n", + "my_circuit = x_circuit(my_qubits)\n", + "my_noisy_circuit = make_noisy(my_circuit, 0.5)\n", + "my_circuit" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "1B7vmyPm_TQ7" + }, + "outputs": [], + "source": [ + "my_noisy_circuit" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "EejhXc2e9Cl8" + }, + "source": [ + "You can examine the noiseless density matrix $\\rho$ with:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "0QN9W69U8v_V" + }, + "outputs": [], + "source": [ + "rho = cirq.final_density_matrix(my_circuit)\n", + "np.round(rho, 3)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "RHHBeizr-DEo" + }, + "source": [ + "And the noisy density matrix $\\rho$ with:\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "zSD9H8SC9IJ1" + }, + "outputs": [], + "source": [ + "rho = cirq.final_density_matrix(my_noisy_circuit)\n", + "np.round(rho, 3)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "2YWiejLl-a0Z" + }, + "source": [ + "Comparing the two different $ \\rho $ 's you can see that the noise has impacted the amplitudes of the state (and consequently sampling probabilities). In the noiseless case you would always expect to sample the $ |11\\rangle $ state. But in the noisy state there is now a nonzero probability of sampling $ |00\\rangle $ or $ |01\\rangle $ or $ |10\\rangle $ as well:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Z4uj-Zs0AE3n" + }, + "outputs": [], + "source": [ + "\"\"\"Sample from my_noisy_circuit.\"\"\"\n", + "def plot_samples(circuit):\n", + " samples = cirq.sample(circuit + cirq.measure(*circuit.all_qubits(), key='bits'), repetitions=1000)\n", + " freqs, _ = np.histogram(samples.data['bits'], bins=[i+0.01 for i in range(-1,2** len(my_qubits))])\n", + " plt.figure(figsize=(10,5))\n", + " plt.title('Noisy Circuit Sampling')\n", + " plt.xlabel('Bitstring')\n", + " plt.ylabel('Frequency')\n", + " plt.bar([i for i in range(2** len(my_qubits))], freqs, tick_label=['00','01','10','11'])\n", + "\n", + "plot_samples(my_noisy_circuit)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IpPh1Y0HEOWs" + }, + "source": [ + "Without any noise you will always get $|11\\rangle$:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "NRCOhTVpEJzz" + }, + "outputs": [], + "source": [ + "\"\"\"Sample from my_circuit.\"\"\"\n", + "plot_samples(my_circuit)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "EMbJBXAiT9GH" + }, + "source": [ + "If you increase the noise a little further it will become harder and harder to distinguish the desired behavior (sampling $|11\\rangle$ ) from the noise:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "D2Fg-FUdUJQx" + }, + "outputs": [], + "source": [ + "my_really_noisy_circuit = make_noisy(my_circuit, 0.75)\n", + "plot_samples(my_really_noisy_circuit)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "oV-0WV5Z7FQ8" + }, + "source": [ + "Note: Try experimenting with different channels in your circuit to generate noise. Common channels supported in both Cirq and TFQ can be found [here](https://github.com/quantumlib/Cirq/blob/master/cirq-core/cirq/ops/common_channels.py)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "atzsYj5qScn0" + }, + "source": [ + "## 2. Basic noise in TFQ\n", + "With this understanding of how noise can impact circuit execution, you can explore how noise works in TFQ. TensorFlow Quantum uses monte-carlo / trajectory based simulation as an alternative to density matrix simulation. This is because the memory complexity of density matrix simulation limits large simulations to being <= 20 qubits with traditional full density matrix simulation methods. Monte-carlo / trajectory trades this cost in memory for additional cost in time. The `backend='noisy'` option available to all `tfq.layers.Sample`, `tfq.layers.SampledExpectation` and `tfq.layers.Expectation` (In the case of `Expectation` this does add a required `repetitions` parameter).\n", + "\n", + "### 2.1 Noisy sampling in TFQ\n", + "To recreate the above plots using TFQ and trajectory simulation you can use `tfq.layers.Sample`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "byVI5nbNQ4_b" + }, + "outputs": [], + "source": [ + "\"\"\"Draw bitstring samples from `my_noisy_circuit`\"\"\"\n", + "bitstrings = tfq.layers.Sample(backend='noisy')(my_noisy_circuit, repetitions=1000)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "ncl0ruCZrd2s" + }, + "outputs": [], + "source": [ + "numeric_values = np.einsum('ijk,k->ij', bitstrings.to_tensor().numpy(), [1, 2])[0]\n", + "freqs, _ = np.histogram(numeric_values, bins=[i+0.01 for i in range(-1,2** len(my_qubits))])\n", + "plt.figure(figsize=(10,5))\n", + "plt.title('Noisy Circuit Sampling')\n", + "plt.xlabel('Bitstring')\n", + "plt.ylabel('Frequency')\n", + "plt.bar([i for i in range(2** len(my_qubits))], freqs, tick_label=['00','01','10','11'])" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "QfHq13RwuLlF" + }, + "source": [ + "### 2.2 Noisy sample based expectation\n", + "To do noisy sample based expectation calculation you can use `tfq.layers.SampleExpectation`:\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "ep45G-09rfrA" + }, + "outputs": [], + "source": [ + "some_observables = [cirq.X(my_qubits[0]), cirq.Z(my_qubits[0]), 3.0 * cirq.Y(my_qubits[1]) + 1]\n", + "some_observables" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ur4iF_PGv0Xf" + }, + "source": [ + "Compute the noiseless expectation estimates via sampling from the circuit:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "jL6wJ3LCvNcn" + }, + "outputs": [], + "source": [ + "noiseless_sampled_expectation = tfq.layers.SampledExpectation(backend='noiseless')(\n", + " my_circuit, operators=some_observables, repetitions=10000\n", + ")\n", + "noiseless_sampled_expectation.numpy()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "c6hHgNtEv40i" + }, + "source": [ + "Compare those with the noisy versions:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "8U4Gm-LGvYqa" + }, + "outputs": [], + "source": [ + "noisy_sampled_expectation = tfq.layers.SampledExpectation(backend='noisy')(\n", + " [my_noisy_circuit, my_really_noisy_circuit], operators=some_observables, repetitions=10000\n", + ")\n", + "noisy_sampled_expectation.numpy()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "CqQ_2c7XwMku" + }, + "source": [ + "You can see that the noise has particularly impacted the $\\langle \\psi | Z | \\psi \\rangle$ accuracy, with `my_really_noisy_circuit` concentrating very quickly towards 0.\n", + "\n", + "### 2.3 Noisy analytic expectation calculation\n", + "Doing noisy analytic expectation calculations is nearly identical to above:\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "pGXKlyCywAfj" + }, + "outputs": [], + "source": [ + "noiseless_analytic_expectation = tfq.layers.Expectation(backend='noiseless')(\n", + " my_circuit, operators=some_observables\n", + ")\n", + "noiseless_analytic_expectation.numpy()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "6FUkJ7aOyTlI" + }, + "outputs": [], + "source": [ + "noisy_analytic_expectation = tfq.layers.Expectation(backend='noisy')(\n", + " [my_noisy_circuit, my_really_noisy_circuit], operators=some_observables, repetitions=10000\n", + ")\n", + "noisy_analytic_expectation.numpy()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "5KHvORT42XFV" + }, + "source": [ + "## 3. Hybrid models and quantum data noise\n", + "Now that you have implemented some noisy circuit simulations in TFQ, you can experiment with how noise impacts quantum and hybrid quantum classical models, by comparing and contrasting their noisy vs noiseless performance. A good first check to see if a model or algorithm is robust to noise is to test under a circuit wide depolarizing model which looks something like this:\n", + "\n", + "\n", + "\n", + "Where each time slice of the circuit (sometimes referred to as moment) has a depolarizing channel appended after each gate operation in that time slice. The depolarizing channel with apply one of $\\{X, Y, Z \\}$ with probability $p$ or apply nothing (keep the original operation) with probability $1-p$.\n", + "\n", + "### 3.1 Data\n", + "For this example you can use some prepared circuits in the `tfq.datasets` module as training data:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "_ZqVLEji2WUx" + }, + "outputs": [], + "source": [ + "qubits = cirq.GridQubit.rect(1, 8)\n", + "circuits, labels, pauli_sums, _ = tfq.datasets.xxz_chain(qubits, 'closed')\n", + "circuits[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "MFgNU_nBGeTm" + }, + "source": [ + "Writing a small helper function will help to generate the data for the noisy vs noiseless case:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "zkQofAqqGibQ" + }, + "outputs": [], + "source": [ + "def get_data(qubits, depolarize_p=0.):\n", + " \"\"\"Return quantum data circuits and labels in `tf.Tensor` form.\"\"\"\n", + " circuits, labels, pauli_sums, _ = tfq.datasets.xxz_chain(qubits, 'closed')\n", + " if depolarize_p >= 1e-5:\n", + " circuits = [circuit.with_noise(cirq.depolarize(depolarize_p)) for circuit in circuits]\n", + " tmp = list(zip(circuits, labels))\n", + " random.shuffle(tmp)\n", + " circuits_tensor = tfq.convert_to_tensor([x[0] for x in tmp])\n", + " labels_tensor = tf.convert_to_tensor([x[1] for x in tmp])\n", + "\n", + " return circuits_tensor, labels_tensor" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FtJrfsLCF9Z3" + }, + "source": [ + "### 3.2 Define a model circuit\n", + "Now that you have quantum data in the form of circuits, you will need a circuit to model this data, like with the data you can write a helper function to generate this circuit optionally containing noise:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "TwryFaFIG2Ya" + }, + "outputs": [], + "source": [ + "def modelling_circuit(qubits, depth, depolarize_p=0.):\n", + " \"\"\"A simple classifier circuit.\"\"\"\n", + " dim = len(qubits)\n", + " ret = cirq.Circuit(cirq.H.on_each(*qubits))\n", + "\n", + " for i in range(depth):\n", + " # Entangle layer.\n", + " ret += cirq.Circuit(cirq.CX(q1, q2) for (q1, q2) in zip(qubits[::2], qubits[1::2]))\n", + " ret += cirq.Circuit(cirq.CX(q1, q2) for (q1, q2) in zip(qubits[1::2], qubits[2::2]))\n", + " # Learnable rotation layer.\n", + " # i_params = sympy.symbols(f'layer-{i}-0:{dim}')\n", + " param = sympy.Symbol(f'layer-{i}')\n", + " single_qb = cirq.X\n", + " if i % 2 == 1:\n", + " single_qb = cirq.Y\n", + " ret += cirq.Circuit(single_qb(q) ** param for q in qubits)\n", + " \n", + " if depolarize_p >= 1e-5:\n", + " ret = ret.with_noise(cirq.depolarize(depolarize_p))\n", + "\n", + " return ret, [op(q) for q in qubits for op in [cirq.X, cirq.Y, cirq.Z]]\n", + "\n", + "modelling_circuit(qubits, 3)[0]" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "U-ZMaCpJI9TH" + }, + "source": [ + "### 3.3 Model building and training\n", + "With your data and model circuit built, the final helper function you will need is one that can assemble both a noisy or a noiseless hybrid quantum `tf.keras.Model`:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "r09CT5N9DWa_" + }, + "outputs": [], + "source": [ + "def build_keras_model(qubits, depolarize_p=0.):\n", + " \"\"\"Prepare a noisy hybrid quantum classical Keras model.\"\"\"\n", + " spin_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string)\n", + "\n", + " circuit_and_readout = modelling_circuit(qubits, 4, depolarize_p)\n", + " if depolarize_p >= 1e-5:\n", + " quantum_model = tfq.layers.NoisyPQC(*circuit_and_readout, sample_based=False, repetitions=10)(spin_input)\n", + " else:\n", + " quantum_model = tfq.layers.PQC(*circuit_and_readout)(spin_input)\n", + "\n", + " intermediate = tf.keras.layers.Dense(4, activation='sigmoid')(quantum_model)\n", + " post_process = tf.keras.layers.Dense(1)(intermediate)\n", + "\n", + " return tf.keras.Model(inputs=[spin_input], outputs=[post_process])" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "QbMtT7BZmhfm" + }, + "source": [ + "## 4. Compare performance\n", + "\n", + "### 4.1 Noiseless baseline\n", + "\n", + "With your data generation and model building code, you can now compare and contrast model performance in the noiseless and noisy settings, first you can run a reference noiseless training:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "QAgpq9c-EakW" + }, + "outputs": [], + "source": [ + "training_histories = dict()\n", + "depolarize_p = 0.\n", + "n_epochs = 50\n", + "phase_classifier = build_keras_model(qubits, depolarize_p)\n", + "\n", + "phase_classifier.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.02),\n", + " loss=tf.keras.losses.BinaryCrossentropy(from_logits=True),\n", + " metrics=['accuracy'])\n", + "\n", + "\n", + "# Show the keras plot of the model\n", + "tf.keras.utils.plot_model(phase_classifier, show_shapes=True, dpi=70)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "9tKimWRMlVfL" + }, + "outputs": [], + "source": [ + "noiseless_data, noiseless_labels = get_data(qubits, depolarize_p)\n", + "training_histories['noiseless'] = phase_classifier.fit(x=noiseless_data,\n", + " y=noiseless_labels,\n", + " batch_size=16,\n", + " epochs=n_epochs,\n", + " validation_split=0.15,\n", + " verbose=1)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "A9oql6Synv3f" + }, + "source": [ + "And explore the results and accuracy:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "TG87YNUWKKLY" + }, + "outputs": [], + "source": [ + "loss_plotter = tfdocs.plots.HistoryPlotter(metric = 'loss', smoothing_std=10)\n", + "loss_plotter.plot(training_histories)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "O2ZwM18YUxxm" + }, + "outputs": [], + "source": [ + "acc_plotter = tfdocs.plots.HistoryPlotter(metric = 'accuracy', smoothing_std=10)\n", + "acc_plotter.plot(training_histories)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JlOwBxvSnzid" + }, + "source": [ + "### 4.2 Noisy comparison\n", + "Now you can build a new model with noisy structure and compare to the above, the code is nearly identical:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "0jy54uWpgwhi" + }, + "outputs": [], + "source": [ + "depolarize_p = 0.001\n", + "n_epochs = 50\n", + "noisy_phase_classifier = build_keras_model(qubits, depolarize_p)\n", + "\n", + "noisy_phase_classifier.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.02),\n", + " loss=tf.keras.losses.BinaryCrossentropy(from_logits=True),\n", + " metrics=['accuracy'])\n", + "\n", + "\n", + "# Show the keras plot of the model\n", + "tf.keras.utils.plot_model(noisy_phase_classifier, show_shapes=True, dpi=70)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "r-vYU6S3oN-J" + }, + "source": [ + "Note: in the model diagram there is now a `tfq.layers.NoisyPQC` instead of a `tfq.layers.PQC` since the depolarization probability is no longer zero. Training will take significantly longer since noisy simulation is far more expensive than noiseless." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "210cLP5AoClJ" + }, + "outputs": [], + "source": [ + "noisy_data, noisy_labels = get_data(qubits, depolarize_p)\n", + "training_histories['noisy'] = noisy_phase_classifier.fit(x=noisy_data,\n", + " y=noisy_labels,\n", + " batch_size=16,\n", + " epochs=n_epochs,\n", + " validation_split=0.15,\n", + " verbose=1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "eQ8pknNdohzy" + }, + "outputs": [], + "source": [ + "loss_plotter.plot(training_histories)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "nBtgnKWtuWRR" + }, + "outputs": [], + "source": [ + "acc_plotter.plot(training_histories)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "r86TeFxlubls" + }, + "source": [ + "Success: The noisy model still managed to train under some mild depolarization noise. Try experimenting with different noise models to see how and when training might fail. Also look out for noisy functionality under `tfq.layers` and `tfq.noise`." + ] + } + ], + "metadata": { + "colab": { + "name": "noise.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} diff --git a/docs/tutorials/qcnn.ipynb b/docs/tutorials/qcnn.ipynb index c3174b7de..abbb8c560 100644 --- a/docs/tutorials/qcnn.ipynb +++ b/docs/tutorials/qcnn.ipynb @@ -12,12 +12,15 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "cellView": "form", "colab": {}, "colab_type": "code", - "id": "iiQkM5ZgQ8r2" + "id": "iiQkM5ZgQ8r2", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -91,15 +94,18 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "Aquwcz-0aHqz" + "id": "Aquwcz-0aHqz", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ - "!pip install tensorflow==2.3.1" + "!pip install tensorflow==2.7.0" ] }, { @@ -114,15 +120,36 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "3Pl5PW-ACO9J" + "id": "3Pl5PW-ACO9J", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ - "!pip install tensorflow-quantum" + "!pip install tensorflow-quantum==0.7.2" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "4Ql5PW-ACO0J", + "vscode": { + "languageId": "python" + } + }, + "outputs": [], + "source": [ + "# Update package resources to account for version changes.\n", + "import importlib, pkg_resources\n", + "importlib.reload(pkg_resources)" ] }, { @@ -137,11 +164,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "QytLEAtoejW5" + "id": "QytLEAtoejW5", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -186,11 +216,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "FhNf0G_OPLqZ" + "id": "FhNf0G_OPLqZ", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -225,11 +258,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "ImRynsUN4BSG" + "id": "ImRynsUN4BSG", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -248,11 +284,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "tfff6dJp39Fg" + "id": "tfff6dJp39Fg", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -323,11 +362,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "iUrvTCU1hDgP" + "id": "iUrvTCU1hDgP", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -365,11 +407,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "eLJ-JHOihDgT" + "id": "eLJ-JHOihDgT", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -404,11 +449,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "qpQwVWKazU8g" + "id": "qpQwVWKazU8g", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -433,11 +481,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "9tZt0aAO4r4F" + "id": "9tZt0aAO4r4F", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -461,11 +512,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "oNRGOqky2exY" + "id": "oNRGOqky2exY", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -500,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" ] @@ -517,11 +571,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "T5uhvF-g2rpZ" + "id": "T5uhvF-g2rpZ", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -540,11 +597,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "aJTdRrfS2uIo" + "id": "aJTdRrfS2uIo", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -563,11 +623,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "DOHRbkvH2xGK" + "id": "DOHRbkvH2xGK", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -588,11 +651,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "1Fa19Lzb3wnR" + "id": "1Fa19Lzb3wnR", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -621,11 +687,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "Bi6q2nmY3z_U" + "id": "Bi6q2nmY3z_U", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -647,11 +716,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "jD3fgcWO4yEU" + "id": "jD3fgcWO4yEU", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -678,11 +750,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "pFXow2OX47O5" + "id": "pFXow2OX47O5", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -706,11 +781,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "vzEsY6-n5NR0" + "id": "vzEsY6-n5NR0", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -770,11 +848,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "_TFkAm1sQZEN" + "id": "_TFkAm1sQZEN", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -805,11 +886,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "2tiCJOb5Qzcr" + "id": "2tiCJOb5Qzcr", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -860,11 +944,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "Ut-U1hBkQ8Fs" + "id": "Ut-U1hBkQ8Fs", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -917,11 +1004,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "EyYw9kYIRCE7" + "id": "EyYw9kYIRCE7", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -940,11 +1030,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "yL3jhGiBRJHt" + "id": "yL3jhGiBRJHt", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -993,11 +1086,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "W3TkNVm9RTBj" + "id": "W3TkNVm9RTBj", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -1050,11 +1146,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "suRvxcAKRZK6" + "id": "suRvxcAKRZK6", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ @@ -1074,11 +1173,14 @@ }, { "cell_type": "code", - "execution_count": 0, + "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", - "id": "-6NR7yAQRmOU" + "id": "-6NR7yAQRmOU", + "vscode": { + "languageId": "python" + } }, "outputs": [], "source": [ diff --git a/docs/tutorials/quantum_data.ipynb b/docs/tutorials/quantum_data.ipynb index bde41c697..9e78b9493 100644 --- a/docs/tutorials/quantum_data.ipynb +++ b/docs/tutorials/quantum_data.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "cellView": "form", "colab": {}, @@ -91,7 +91,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -99,14 +99,39 @@ "id": "X3Y5vLL9K_Ai", "outputId": "60d15a69-5a45-449f-bf63-29a5af8d8ffc" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.\r\n", + "Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.\r\n", + "To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.\r\n" + ] + } + ], "source": [ - "!pip -q install tensorflow==2.3.1 tensorflow-quantum" + "!pip install tensorflow==2.7.0 tensorflow-quantum==0.7.2" ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "4Ql5PW-ACO0J" + }, + "outputs": [], + "source": [ + "# Update package resources to account for version changes.\n", + "import importlib, pkg_resources\n", + "importlib.reload(pkg_resources)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, "metadata": { "id": "FTKfetslL5eE" }, @@ -149,7 +174,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -157,12 +182,21 @@ "id": "VTKmzeH3MBvR", "outputId": "cc705254-3db0-4c53-8b4c-e543f69fae31" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of original training examples: 60000\n", + "Number of original test examples: 10000\n" + ] + } + ], "source": [ "(x_train, y_train), (x_test, y_test) = tf.keras.datasets.fashion_mnist.load_data()\n", "\n", "# Rescale the images from [0,255] to the [0.0,1.0] range.\n", - "x_train, x_test = x_train[..., np.newaxis]/255.0, x_test[..., np.newaxis]/255.0\n", + "x_train, x_test = x_train/255.0, x_test/255.0\n", "\n", "print(\"Number of original training examples:\", len(x_train))\n", "print(\"Number of original test examples:\", len(x_test))" @@ -174,12 +208,12 @@ "id": "jq3eeFv2PyQz" }, "source": [ - "Filter the dataset to keep just the shirts and dresses, remove the other classes. At the same time convert the label, `y`, to boolean: True for 0 and False for 3." + "Filter the dataset to keep just the T-shirts/tops and dresses, remove the other classes. At the same time convert the label, `y`, to boolean: True for 0 and False for 3." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "LmprnNbDP4Z6" }, @@ -194,7 +228,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -202,7 +236,16 @@ "id": "KycvXPllQH-t", "outputId": "7dd10133-1fa3-48ba-e7d9-1cf350107c01" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of filtered training examples: 12000\n", + "Number of filtered test examples: 2000\n" + ] + } + ], "source": [ "x_train, y_train = filter_03(x_train, y_train)\n", "x_test, y_test = filter_03(x_test, y_test)\n", @@ -213,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -222,11 +265,41 @@ "id": "c-2Fx9E1O63h", "outputId": "a8cc82ef-de3a-44ee-a3d9-14b3d30c9758" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + }, + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAS4AAAD8CAYAAADJwUnTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAbxUlEQVR4nO3df5Ac9Xnn8fezq139BgSLhCzJgLEoWxAMjg7s4IvlYDuCSowpuzDynQ8n2HJc1lWc+FxHfFfA4boU9gWIr4rgWwcdkLLBXGwHOSebUJxjHBILSZgCCYJRZBEkCwnxS0LS/pp57o8Zmdkf/Xxnd2a3u1efV9WUZvrp7vlqdvbZ7m8//f2auyMiUiYdeTdARGS8lLhEpHSUuESkdJS4RKR0lLhEpHSUuESkdJS4RGTSmNl6M9tvZtsy4mZm/9PMdpjZE2b2zmb2q8QlIpPpTmB1EL8UWF5/rAVub2anSlwiMmnc/WHg5WCVy4G7veanwElmtji13xntamAzum2mz2LuVL7l9DB3dhiesWwgM3b01VnxtkfiOyesmrizIhEempP9t9FOHIq3HYi/nrN+2R/GfSje/3TUx2EGvN9a2cdvv2+uv/Rypal1tz7Rvx3oa1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xWuT8n2DHD87M+uilhy+6e7frS/O/bMbq11F+tzKIo/E1cwtALkws7n1TlPMbC7wQWBbvNWUa7w94mrg/hzbMsyxpFB3BTl9dvUhUe4Annb3WxpCuX52We0qyudWJrlUztcv9/45b9wC8N+nvBFjMLO3UDvKgtrtUN/Ks21mdg+witoQI/uA64G/Ae4D3kxtiKAr3X3KO8kz2raK2umOA7uAzzT0KU1l294D/AR4Ejg22t2XqPUn5fbZBe1aQwE+tzLRLT8iUjrqnBeR0lHiEpHSUeISkdJR4hKR0lHiEpHSUeISkdJR4hKR0vn/wFthozecl4IAAAAASUVORK5CYII=", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], "source": [ "print(y_train[0])\n", "\n", - "plt.imshow(x_train[0, :, :, 0])\n", + "plt.imshow(x_train[0, :, :])\n", "plt.colorbar()" ] }, @@ -243,7 +316,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "id": "0_EvK2kJPKDk" }, @@ -272,7 +345,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -280,7 +353,15 @@ "id": "0WhtP5RRkYSI", "outputId": "cfbfdd7b-7a5f-46fb-b998-4f9d79835b0b" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "New datapoint dimension: 10\n" + ] + } + ], "source": [ "DATASET_DIM = 10\n", "x_train, x_test = truncate_x(x_train, x_test, n_components=DATASET_DIM)\n", @@ -298,7 +379,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "EMxlW2kZDtvn" }, @@ -312,7 +393,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -320,7 +401,16 @@ "id": "P7vqUjDMGF2S", "outputId": "e4bae463-23a6-43fd-c12e-28ba30e616bf" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "New number of training examples: 1000\n", + "New number of test examples: 200\n" + ] + } + ], "source": [ "print(\"New number of training examples:\", len(x_train))\n", "print(\"New number of test examples:\", len(x_test))" @@ -355,7 +445,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { "id": "hVTlHdGvEuaT" }, @@ -382,7 +472,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -391,7 +481,19 @@ "id": "tfJkWj88Fqwl", "outputId": "b1f802ea-2220-46ed-9bb5-5975290756b0" }, - "outputs": [], + "outputs": [ + { + "data": { + "image/svg+xml": "(0, 0): (0, 1): (0, 2): (0, 3): X^0.192X^(11/14)X^0.276X^0.876Y^0.622Y^0.78Y^0.802Y^(5/14)Z^(7/16)Z^(3/11)Z^0.958Z^0.501", + "text/plain": [ + "" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "SVGCircuit(single_qubit_wall(\n", " cirq.GridQubit.rect(1,4), np.random.uniform(size=(4, 3))))" @@ -408,7 +510,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "id": "4w2em6c0HOIO" }, @@ -436,7 +538,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -445,7 +547,26 @@ "id": "r7YIeOrzJDlT", "outputId": "b2c5a762-558f-4974-9661-598ef20179e5" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Symbols found in circuit:[ref_0]\n" + ] + }, + { + "data": { + "image/svg+xml": "(0, 0): (0, 1): HHXRz(2.0*ref_0)XHHRx(0.5Ï€)Rx(0.5Ï€)XRz(2.0*ref_0)XRx(-0.5Ï€)Rx(-0.5Ï€)XRz(2.0*ref_0)X", + "text/plain": [ + "" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "test_circuit, test_symbols = v_theta(cirq.GridQubit.rect(1, 2))\n", "print(f'Symbols found in circuit:{test_symbols}')\n", @@ -463,7 +584,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "id": "LReAUF6CSwn5" }, @@ -500,12 +621,12 @@ "id": "yNliqKFdYacD" }, "source": [ - "Chooe some qubits and prepare the data encoding circuits:" + "Choose some qubits and prepare the data encoding circuits:" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "id": "5F47SaRERKx_" }, @@ -527,7 +648,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "id": "cEGko5t-SZ14" }, @@ -546,7 +667,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -554,7 +675,16 @@ "id": "xZOEdNMzS8hW", "outputId": "5d8f40b0-af85-4afe-dc25-599cd3966385" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "New PQK training dataset has shape: (1000, 11, 3)\n", + "New PQK testing dataset has shape: (200, 11, 3)\n" + ] + } + ], "source": [ "x_train_pqk = get_pqk_features(qubits, q_x_train_circuits)\n", "x_test_pqk = get_pqk_features(qubits, q_x_test_circuits)\n", @@ -583,7 +713,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": { "id": "BLyGksxvGINl" }, @@ -605,7 +735,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -613,7 +743,42 @@ "id": "a4AxcKa4RRJr", "outputId": "049fc8ce-0ff7-442c-8b7f-861bea0fb658" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Eigenvectors of pqk kernel matrix: tf.Tensor(\n", + "[[-2.09569391e-02 1.05973557e-02 2.16634180e-02 ... 2.80352887e-02\n", + " 1.55521873e-02 2.82677952e-02]\n", + " [-2.29303762e-02 4.66355234e-02 7.91163836e-03 ... -6.14174758e-04\n", + " -7.07804322e-01 2.85902526e-02]\n", + " [-1.77853629e-02 -3.00758495e-03 -2.55225878e-02 ... -2.40783971e-02\n", + " 2.11018627e-03 2.69009806e-02]\n", + " ...\n", + " [ 6.05797209e-02 1.32483775e-02 2.69536003e-02 ... -1.38843581e-02\n", + " 3.05043962e-02 3.85345481e-02]\n", + " [ 6.33309558e-02 -3.04112374e-03 9.77444276e-03 ... 7.48321265e-02\n", + " 3.42793856e-03 3.67484428e-02]\n", + " [ 5.86028099e-02 5.84433973e-03 2.64811981e-03 ... 2.82612257e-02\n", + " -3.80136147e-02 3.29943895e-02]], shape=(1200, 1200), dtype=float32)\n", + "Eigenvectors of original kernel matrix: tf.Tensor(\n", + "[[ 0.03835681 0.0283473 -0.01169789 ... 0.02343717 0.0211248\n", + " 0.03206972]\n", + " [-0.04018159 0.00888097 -0.01388255 ... 0.00582427 0.717551\n", + " 0.02881948]\n", + " [-0.0166719 0.01350376 -0.03663862 ... 0.02467175 -0.00415936\n", + " 0.02195409]\n", + " ...\n", + " [-0.03015648 -0.01671632 -0.01603392 ... 0.00100583 -0.00261221\n", + " 0.02365689]\n", + " [ 0.0039777 -0.04998879 -0.00528336 ... 0.01560401 -0.04330755\n", + " 0.02782002]\n", + " [-0.01665728 -0.00818616 -0.0432341 ... 0.00088256 0.00927396\n", + " 0.01875088]], shape=(1200, 1200), dtype=float32)\n" + ] + } + ], "source": [ "S_pqk, V_pqk = get_spectrum(\n", " tf.reshape(tf.concat([x_train_pqk, x_test_pqk], 0), [-1, len(qubits) * 3]))\n", @@ -647,7 +812,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": { "id": "g-D_939PZoOH" }, @@ -673,7 +838,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": { "id": "3IkuiFmZRUby" }, @@ -705,7 +870,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -713,8 +878,30 @@ "id": "eK94tGyf--q2", "outputId": "36ee9f7f-3532-440d-de23-ebcba8c76976" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Model: \"sequential\"\n", + "_________________________________________________________________\n", + "Layer (type) Output Shape Param # \n", + "=================================================================\n", + "dense (Dense) (None, 32) 1088 \n", + "_________________________________________________________________\n", + "dense_1 (Dense) (None, 16) 528 \n", + "_________________________________________________________________\n", + "dense_2 (Dense) (None, 1) 17 \n", + "=================================================================\n", + "Total params: 1,633\n", + "Trainable params: 1,633\n", + "Non-trainable params: 0\n", + "_________________________________________________________________\n" + ] + } + ], "source": [ + "#docs_infra: no_execute\n", "def create_pqk_model():\n", " model = tf.keras.Sequential()\n", " model.add(tf.keras.layers.Dense(32, activation='sigmoid', input_shape=[len(qubits) * 3,]))\n", @@ -732,12 +919,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": { "id": "QUL8ygMn_zOB" }, "outputs": [], "source": [ + "#docs_infra: no_execute\n", "pqk_history = pqk_model.fit(tf.reshape(x_train_pqk, [N_TRAIN, -1]),\n", " y_train_new,\n", " batch_size=32,\n", @@ -758,7 +946,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -766,8 +954,30 @@ "id": "uHhUYWVh9kGE", "outputId": "f586fd89-1157-4a7e-b382-71157a894519" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Model: \"sequential_1\"\n", + "_________________________________________________________________\n", + "Layer (type) Output Shape Param # \n", + "=================================================================\n", + "dense_3 (Dense) (None, 32) 352 \n", + "_________________________________________________________________\n", + "dense_4 (Dense) (None, 16) 528 \n", + "_________________________________________________________________\n", + "dense_5 (Dense) (None, 1) 17 \n", + "=================================================================\n", + "Total params: 897\n", + "Trainable params: 897\n", + "Non-trainable params: 0\n", + "_________________________________________________________________\n" + ] + } + ], "source": [ + "#docs_infra: no_execute\n", "def create_fair_classical_model():\n", " model = tf.keras.Sequential()\n", " model.add(tf.keras.layers.Dense(32, activation='sigmoid', input_shape=[DATASET_DIM,]))\n", @@ -785,12 +995,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": { "id": "8N54jMau-1L5" }, "outputs": [], "source": [ + "#docs_infra: no_execute\n", "classical_history = model.fit(x_train,\n", " y_train_new,\n", " batch_size=32,\n", @@ -811,7 +1022,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -819,8 +1030,32 @@ "id": "t9CDiHTmAEu-", "outputId": "18d3ba86-969c-4f65-a0b1-aa86efc6212a" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmEAAAE9CAYAAABDUbVaAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAAC3PUlEQVR4nOyddZhTV/6H3xvPuCKDDe5WoFCsAtSVurvsVre/drfbtbq7u7srLS0tlLYUirW46yBjjEv0/v44uclNJslkZpIROO/zzDPJ1RO793O+qqiqikQikUgkEomkdTG09QAkEolEIpFIDkSkCJNIJBKJRCJpA6QIk0gkEolEImkDpAiTSCQSiUQiaQOkCJNIJBKJRCJpA6QIk0gkEolEImkDTG09gKaSk5Oj5ufnt/UwJBKJRCKRSBpl6dKlJaqq5oZb1+FEWH5+PkuWLGnrYUgkEolEIpE0iqIo2yOtk+5IiUQikUgkkjZAijCJRCKRSCSSNkCKMIlEIpFIJJI2QIowiUQikUgkkjZA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AQgJ9++olRo0YxatQoRo8eTVVVFXv27GHq1KmMGjWKYcOG8fPPPwOQn59PSUkJAG+88QYjRoxg5MiRnH/++VHP0RHo2PI4wciYMElHw1tTAzS0hIVzqZtyclplTBJJe+b2L1ezZnd823gNyUvjfycMbXS7V155haysLOrq6hg3bhwnnXQSl19+OfPnz6d3797s27cPgDvvvJP09HRWrlwJQFlZWaPHLigoYMGCBRiNRiorK/n5558xmUzMmTOHW2+9lY8//pgXXniBbdu28ccff2Aymdi3bx+ZmZn89a9/pbi4mNzcXF599VUuueSSsOcoLi4OO149kydPZuHChSiKwksvvcQDDzzAww8/zEMPPcTTTz/NpEmTqK6uxmaz8cILL3DUUUfxr3/9C4/HQ21tbdCxVq9ezV133cWCBQvIycnxny/SOToCUoRFQ8aESToYWjsib30gQ7J6/ny8FRUkT5pE8sRDKHrwIQCM2dISJpG0JU888QSffvopADt37uSFF15g6tSp/jpTWVlZAMyZM4f33nvPv19mZmajxz799NMx+sIQKioquPDCC9m4cSOKouDyhS3MmTOHq666yu+u1M53/vnn89Zbb3HxxRfz22+/8cYbb4Q9x8KFC8OOV09BQQFnnnkme/bswel0+redNGkSN954I+eeey4zZ86ke/fujBs3jksuuQSXy8XJJ5/MqFGjgo71448/cvrpp5Pjm0Bq54t0jo6AFGHRkDFhkg6Eqqp4qkT9L80SVr9+AzuvuBIA+8iRZF96Kd66ekqeegpTmAumRHKgEYvFKhHMmzePOXPm8Ntvv5GUlMRhhx3GqFGjWLduXczH0JdECK1PlZyc7H/8n//8h8MPP5xPP/2Ubdu2cdhhh0U97sUXX8wJJ5yAzWbj9NNPb1FM2bXXXsuNN97IiSeeyLx587jtttsAuOWWWzjuuOOYNWsWkyZNYvbs2UydOpX58+fz9ddfc9FFF3HjjTdywQUXNPscHQEZExYNGRMm6UCoDgdogfm+mLCq777zr9dqguVeczWD1q5B6eDBuhJJR6aiooLMzEySkpJYt24dCxcupL6+nvnz57N161YAv7ttxowZPP300/59NXdk586dWbt2LV6v129Ri3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FpGngHwgxSp/ElgoIg9jr/H6LXC8sYNXSrUc2idMKdUiWH3CYo0xp1wdi1JKgTZHKqWUUkq5hNaEKaWUUkq5gNaEKaWUUkq5gCZhSimllFIuoEmYUkoppZQLaBKmlFJKKeUCmoQppZRSSrmAJmFKKaWUUi7w/wHvnB5cNJf+XAAAAABJRU5ErkJggg==", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], "source": [ + "#docs_infra: no_execute\n", "plt.figure(figsize=(10,5))\n", "plt.plot(classical_history.history['accuracy'], label='accuracy_classical')\n", "plt.plot(classical_history.history['val_accuracy'], label='val_accuracy_classical')\n", @@ -878,7 +1113,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.5" + "version": "3.8.6" } }, "nbformat": 4, diff --git a/docs/tutorials/quantum_reinforcement_learning.ipynb b/docs/tutorials/quantum_reinforcement_learning.ipynb new file mode 100644 index 000000000..fba0291e6 --- /dev/null +++ b/docs/tutorials/quantum_reinforcement_learning.ipynb @@ -0,0 +1,1580 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "2kWo-GNlwpT6" + }, + "source": [ + "##### Copyright 2021 The TensorFlow Authors." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "5w2rucWZwpUA" + }, + "outputs": [], + "source": [ + "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n", + "# you may not use this file except in compliance with the License.\n", + "# You may obtain a copy of the License at\n", + "#\n", + "# https://www.apache.org/licenses/LICENSE-2.0\n", + "#\n", + "# Unless required by applicable law or agreed to in writing, software\n", + "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", + "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", + "# See the License for the specific language governing permissions and\n", + "# limitations under the License." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "GHebkma_wpUC" + }, + "source": [ + "# Parametrized Quantum Circuits for Reinforcement Learning" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "xQf8eEUewpUD" + }, + "source": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " View on TensorFlow.org\n", + " \n", + " Run in Google Colab\n", + " \n", + " View source on GitHub\n", + " \n", + " Download notebook\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "8NJTIUX_wpUE" + }, + "source": [ + "Quantum computers have been shown to provide computational advantages in certain problem areas. The field of quantum reinforcement learning (QRL) aims to harness this boost by designing RL agents that rely on quantum models of computation.\n", + "\n", + "In this tutorial, you will implement two reinforcement learning algorithms based on parametrized/variational quantum circuits (PQCs or VQCs), namely a policy-gradient and a deep Q-learning implementation. These algorithms were introduced by [[1] Jerbi et al.](https://arxiv.org/abs/2103.05577) and [[2] Skolik et al.](https://arxiv.org/abs/2103.15084), respectively." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "bYkcUIu4wpUF" + }, + "source": [ + "You will implement a PQC with data re-uploading in TFQ, and use it as:\n", + "1. an RL policy trained with a policy-gradient method,\n", + "2. a Q-function approximator trained with deep Q-learning,\n", + "\n", + "each solving [CartPole-v1](http://gym.openai.com/envs/CartPole-v1/), a benchmarking task from OpenAI Gym. Note that, as showcased in [[1]](https://arxiv.org/abs/2103.05577) and [[2]](https://arxiv.org/abs/2103.15084), these agents can also be used to solve other task-environment from OpenAI Gym, such as [FrozenLake-v0](http://gym.openai.com/envs/FrozenLake-v0/), [MountainCar-v0](http://gym.openai.com/envs/MountainCar-v0/) or [Acrobot-v1](http://gym.openai.com/envs/Acrobot-v1/)." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "gw0D-uwmwpUF" + }, + "source": [ + "Features of this implementation:\n", + "- you will learn how to use a `tfq.layers.ControlledPQC` to implement a PQC with data re-uploading, appearing in many applications of QML. This implementation also naturally allows using trainable scaling parameters at the input of the PQC, to increase its expressivity,\n", + "- you will learn how to implement observables with trainable weights at the output of a PQC, to allow a flexible range of output values,\n", + "- you will learn how a `tf.keras.Model` can be trained with non-trivial ML loss functions, i.e., that are not compatible with `model.compile` and `model.fit`, using a `tf.GradientTape`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "kLSoeBdTwpUF" + }, + "source": [ + "## Setup" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "pgTTkiY0wpUG" + }, + "source": [ + "Install TensorFlow:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "bPTH8ScrwpUG" + }, + "outputs": [], + "source": [ + "!pip install tensorflow==2.7.0" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "jlbSE9jXwpUH" + }, + "source": [ + "Install TensorFlow Quantum:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "MZeJimx6wpUI" + }, + "outputs": [], + "source": [ + "!pip install tensorflow-quantum==0.7.2" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "xLEu0I6qwpUI" + }, + "source": [ + "Install Gym:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "6A2JRKhMwpUJ" + }, + "outputs": [], + "source": [ + "!pip install gym==0.18.0" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Id8vB7FiwpUJ" + }, + "source": [ + "Now import TensorFlow and the module dependencies:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "4Ql5PW-ACO0J" + }, + "outputs": [], + "source": [ + "# Update package resources to account for version changes.\n", + "import importlib, pkg_resources\n", + "importlib.reload(pkg_resources)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "RIIYRJ79wpUK" + }, + "outputs": [], + "source": [ + "import tensorflow as tf\n", + "import tensorflow_quantum as tfq\n", + "\n", + "import gym, cirq, sympy\n", + "import numpy as np\n", + "from functools import reduce\n", + "from collections import deque, defaultdict\n", + "import matplotlib.pyplot as plt\n", + "from cirq.contrib.svg import SVGCircuit\n", + "tf.get_logger().setLevel('ERROR')" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "jxWGru_NwpUK" + }, + "source": [ + "## 1. Build a PQC with data re-uploading" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "85woLQQswpUL" + }, + "source": [ + "At the core of both RL algorithms you are implementing is a PQC that takes as input the agent's state $s$ in the environment (i.e., a numpy array) and outputs a vector of expectation values. These expectation values are then post-processed, either to produce an agent's policy $\\pi(a|s)$ or approximate Q-values $Q(s,a)$. In this way, the PQCs are playing an analog role to that of deep neural networks in modern deep RL algorithms.\n", + "\n", + "A popular way to encode an input vector in a PQC is through the use of single-qubit rotations, where rotation angles are controlled by the components of this input vector. In order to get a [highly-expressive model](https://arxiv.org/abs/2008.08605), these single-qubit encodings are not performed only once in the PQC, but in several \"[re-uploadings](https://quantum-journal.org/papers/q-2020-02-06-226/)\", interlayed with variational gates. The layout of such a PQC is depicted below:\n", + "\n", + "" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "vxw3Rz0awpUL" + }, + "source": [ + "As discussed in [[1]](https://arxiv.org/abs/2103.05577) and [[2]](https://arxiv.org/abs/2103.15084), a way to further enhance the expressivity and trainability of data re-uploading PQCs is to use trainable input-scaling parameters $\\boldsymbol{\\lambda}$ for each encoding gate of the PQC, and trainable observable weights $\\boldsymbol{w}$ at its output." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "rNSjI-OywpUM" + }, + "source": [ + "### 1.1 Cirq circuit for ControlledPQC" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "OCYrUUwswpUM" + }, + "source": [ + "The first step is to implement in Cirq the quantum circuit to be used as the PQC. For this, start by defining basic unitaries to be applied in the circuits, namely an arbitrary single-qubit rotation and an entangling layer of CZ gates:" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "X4P5EORYwpUM" + }, + "outputs": [], + "source": [ + "def one_qubit_rotation(qubit, symbols):\n", + " \"\"\"\n", + " Returns Cirq gates that apply a rotation of the bloch sphere about the X,\n", + " Y and Z axis, specified by the values in `symbols`.\n", + " \"\"\"\n", + " return [cirq.rx(symbols[0])(qubit),\n", + " cirq.ry(symbols[1])(qubit),\n", + " cirq.rz(symbols[2])(qubit)]\n", + "\n", + "def entangling_layer(qubits):\n", + " \"\"\"\n", + " Returns a layer of CZ entangling gates on `qubits` (arranged in a circular topology).\n", + " \"\"\"\n", + " cz_ops = [cirq.CZ(q0, q1) for q0, q1 in zip(qubits, qubits[1:])]\n", + " cz_ops += ([cirq.CZ(qubits[0], qubits[-1])] if len(qubits) != 2 else [])\n", + " return cz_ops" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cTgpkm6iwpUM" + }, + "source": [ + "Now, use these functions to generate the Cirq circuit:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "PEicpzq9wpUN" + }, + "outputs": [], + "source": [ + "def generate_circuit(qubits, n_layers):\n", + " \"\"\"Prepares a data re-uploading circuit on `qubits` with `n_layers` layers.\"\"\"\n", + " # Number of qubits\n", + " n_qubits = len(qubits)\n", + " \n", + " # Sympy symbols for variational angles\n", + " params = sympy.symbols(f'theta(0:{3*(n_layers+1)*n_qubits})')\n", + " params = np.asarray(params).reshape((n_layers + 1, n_qubits, 3))\n", + " \n", + " # Sympy symbols for encoding angles\n", + " inputs = sympy.symbols(f'x(0:{n_layers})'+f'_(0:{n_qubits})')\n", + " inputs = np.asarray(inputs).reshape((n_layers, n_qubits))\n", + " \n", + " # Define circuit\n", + " circuit = cirq.Circuit()\n", + " for l in range(n_layers):\n", + " # Variational layer\n", + " circuit += cirq.Circuit(one_qubit_rotation(q, params[l, i]) for i, q in enumerate(qubits))\n", + " circuit += entangling_layer(qubits)\n", + " # Encoding layer\n", + " circuit += cirq.Circuit(cirq.rx(inputs[l, i])(q) for i, q in enumerate(qubits))\n", + "\n", + " # Last varitional layer\n", + " circuit += cirq.Circuit(one_qubit_rotation(q, params[n_layers, i]) for i,q in enumerate(qubits))\n", + " \n", + " return circuit, list(params.flat), list(inputs.flat)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ZL8MvT21wpUN" + }, + "source": [ + "Check that this produces a circuit that is alternating between variational and encoding layers." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 188 + }, + "id": "M4LFL2bQwpUO", + "outputId": "e446c0c0-f844-4d63-9f29-d01f8aeed411" + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "findfont: Font family ['Arial'] not found. Falling back to DejaVu Sans.\n" + ] + }, + { + "data": { + "image/svg+xml": "(0, 0): (0, 1): (0, 2): Rx(theta0)Rx(theta3)Rx(theta6)Ry(theta1)Ry(theta4)Ry(theta7)Rz(theta2)Rz(theta5)Rz(theta8)Rx(x0_0)Rx(x0_1)Rx(x0_2)Rx(theta9)Rx(theta12)Rx(theta15)Ry(theta10)Ry(theta13)Ry(theta16)Rz(theta11)Rz(theta14)Rz(theta17)", + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "n_qubits, n_layers = 3, 1\n", + "qubits = cirq.GridQubit.rect(1, n_qubits)\n", + "circuit, _, _ = generate_circuit(qubits, n_layers)\n", + "SVGCircuit(circuit)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "-RrFUkT3wpUP" + }, + "source": [ + "### 1.2 ReUploadingPQC layer using ControlledPQC\n", + "\n", + "To construct the re-uploading PQC from the figure above, you can create a custom Keras layer. This layer will manage the trainable parameters (variational angles $\\boldsymbol{\\theta}$ and input-scaling parameters $\\boldsymbol{\\lambda}$) and resolve the input values (input state $s$) into the appropriate symbols in the circuit." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "id": "7XJvWgQ4wpUP" + }, + "outputs": [], + "source": [ + "class ReUploadingPQC(tf.keras.layers.Layer):\n", + " \"\"\"\n", + " Performs the transformation (s_1, ..., s_d) -> (theta_1, ..., theta_N, lmbd[1][1]s_1, ..., lmbd[1][M]s_1,\n", + " ......., lmbd[d][1]s_d, ..., lmbd[d][M]s_d) for d=input_dim, N=theta_dim and M=n_layers.\n", + " An activation function from tf.keras.activations, specified by `activation` ('linear' by default) is\n", + " then applied to all lmbd[i][j]s_i.\n", + " All angles are finally permuted to follow the alphabetical order of their symbol names, as processed\n", + " by the ControlledPQC.\n", + " \"\"\"\n", + "\n", + " def __init__(self, qubits, n_layers, observables, activation=\"linear\", name=\"re-uploading_PQC\"):\n", + " super(ReUploadingPQC, self).__init__(name=name)\n", + " self.n_layers = n_layers\n", + " self.n_qubits = len(qubits)\n", + "\n", + " circuit, theta_symbols, input_symbols = generate_circuit(qubits, n_layers)\n", + "\n", + " theta_init = tf.random_uniform_initializer(minval=0.0, maxval=np.pi)\n", + " self.theta = tf.Variable(\n", + " initial_value=theta_init(shape=(1, len(theta_symbols)), dtype=\"float32\"),\n", + " trainable=True, name=\"thetas\"\n", + " )\n", + " \n", + " lmbd_init = tf.ones(shape=(self.n_qubits * self.n_layers,))\n", + " self.lmbd = tf.Variable(\n", + " initial_value=lmbd_init, dtype=\"float32\", trainable=True, name=\"lambdas\"\n", + " )\n", + " \n", + " # Define explicit symbol order.\n", + " symbols = [str(symb) for symb in theta_symbols + input_symbols]\n", + " self.indices = tf.constant([symbols.index(a) for a in sorted(symbols)])\n", + " \n", + " self.activation = activation\n", + " self.empty_circuit = tfq.convert_to_tensor([cirq.Circuit()])\n", + " self.computation_layer = tfq.layers.ControlledPQC(circuit, observables) \n", + "\n", + " def call(self, inputs):\n", + " # inputs[0] = encoding data for the state.\n", + " batch_dim = tf.gather(tf.shape(inputs[0]), 0)\n", + " tiled_up_circuits = tf.repeat(self.empty_circuit, repeats=batch_dim)\n", + " tiled_up_thetas = tf.tile(self.theta, multiples=[batch_dim, 1])\n", + " tiled_up_inputs = tf.tile(inputs[0], multiples=[1, self.n_layers])\n", + " scaled_inputs = tf.einsum(\"i,ji->ji\", self.lmbd, tiled_up_inputs)\n", + " squashed_inputs = tf.keras.layers.Activation(self.activation)(scaled_inputs)\n", + "\n", + " joined_vars = tf.concat([tiled_up_thetas, squashed_inputs], axis=1)\n", + " joined_vars = tf.gather(joined_vars, self.indices, axis=1)\n", + " \n", + " return self.computation_layer([tiled_up_circuits, joined_vars])" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "_u3QBKbvwpUP" + }, + "source": [ + "## 2. Policy-gradient RL with PQC policies" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4deMRl86wpUP" + }, + "source": [ + "In this section, you will implement the policy-gradient algorithm presented in [1]. For this, you will start by constructing, out of the PQC that was just defined, the `softmax-VQC` policy (where VQC stands for variational quantum circuit):\n", + "$$ \\pi_\\theta(a|s) = \\frac{e^{\\beta \\langle O_a \\rangle_{s,\\theta}}}{\\sum_{a'} e^{\\beta \\langle O_{a'} \\rangle_{s,\\theta}}} $$\n", + "where $\\langle O_a \\rangle_{s,\\theta}$ are expectation values of observables $O_a$ (one per action) measured at the output of the PQC, and $\\beta$ is a tunable inverse-temperature parameter. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Wb7zQF5AwpUQ" + }, + "source": [ + "You can adopt the same observables used in [1] for CartPole, namely a global $Z_0Z_1Z_2Z_3$ Pauli product acting on all qubits, weighted by an action-specific weight for each action. To implement the weighting of the Pauli product, you can use an extra `tf.keras.layers.Layer` that stores the action-specific weights and applies them multiplicatively on the expectation value $\\langle Z_0Z_1Z_2Z_3 \\rangle_{s,\\theta}$." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "kPLHsGRewpUQ" + }, + "outputs": [], + "source": [ + "class Alternating(tf.keras.layers.Layer):\n", + " def __init__(self, output_dim):\n", + " super(Alternating, self).__init__()\n", + " self.w = tf.Variable(\n", + " initial_value=tf.constant([[(-1.)**i for i in range(output_dim)]]), dtype=\"float32\",\n", + " trainable=True, name=\"obs-weights\")\n", + "\n", + " def call(self, inputs):\n", + " return tf.matmul(inputs, self.w)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "HdyTMNPTwpUQ" + }, + "source": [ + "Prepare the definition of your PQC:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "id": "l3yZCMhywpUQ" + }, + "outputs": [], + "source": [ + "n_qubits = 4 # Dimension of the state vectors in CartPole\n", + "n_layers = 5 # Number of layers in the PQC\n", + "n_actions = 2 # Number of actions in CartPole\n", + "\n", + "qubits = cirq.GridQubit.rect(1, n_qubits)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "NMGNUCmOwpUR" + }, + "source": [ + "and its observables:" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "qMAc2_--wpUR" + }, + "outputs": [], + "source": [ + "ops = [cirq.Z(q) for q in qubits]\n", + "observables = [reduce((lambda x, y: x * y), ops)] # Z_0*Z_1*Z_2*Z_3" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "px9D6vE8wpUR" + }, + "source": [ + "With this, define a `tf.keras.Model` that applies, sequentially, the `ReUploadingPQC` layer previously defined, followed by a post-processing layer that computes the weighted observables using `Alternating`, which are then fed into a `tf.keras.layers.Softmax` layer that outputs the `softmax-VQC` policy of the agent." + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "-ivAvce6wpUR" + }, + "outputs": [], + "source": [ + "def generate_model_policy(qubits, n_layers, n_actions, beta, observables):\n", + " \"\"\"Generates a Keras model for a data re-uploading PQC policy.\"\"\"\n", + "\n", + " input_tensor = tf.keras.Input(shape=(len(qubits), ), dtype=tf.dtypes.float32, name='input')\n", + " re_uploading_pqc = ReUploadingPQC(qubits, n_layers, observables)([input_tensor])\n", + " process = tf.keras.Sequential([\n", + " Alternating(n_actions),\n", + " tf.keras.layers.Lambda(lambda x: x * beta),\n", + " tf.keras.layers.Softmax()\n", + " ], name=\"observables-policy\")\n", + " policy = process(re_uploading_pqc)\n", + " model = tf.keras.Model(inputs=[input_tensor], outputs=policy)\n", + "\n", + " return model\n", + "\n", + "model = generate_model_policy(qubits, n_layers, n_actions, 1.0, observables)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 232 + }, + "id": "ANysIOrswpUS", + "outputId": "131f0db1-8525-4cfa-a6c5-2b0c8573bdb1" + }, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW8AAADXCAYAAADV0tC4AAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nO3de1xU9bo/8M9wm2FmkIaLgELi1oOXvJV5rL19bT1mpYGXOgTeTUjpRip2RBETkbxUWwsSyRRLwrJMPVFi3iIvidYuM2+kQoYKiKCCM+AMw/P7wx/rMDI3YJgLPO/Xi9dr8123Z63v7nGx1nq+XxERERhjjDmSlU62joAxxljzcfJmjDEH5GLrAKyhrq4OpaWltg6DMdbG3N3d4e3tbeswrKJDJO9Lly5hwIABCAoKsnUorJVqamqg1Wohl8ttHUqbICJUVFTAx8fH1qE4HJVKhcceeww7duywdShW0SGSNwD07t0bv/32m63DYK2UmpqKK1eu4O2337Z1KG1CpVIhMDAQFy9etHUoDmf37t3YuHGjrcOwGn7mzRhjDoiTN2OMOSBO3owx5oA4ebMOYcyYMVi3bp2tw7AYuVwOkUgEkUiE8+fPC+0ajQarVq1CbGyssM6aNWuE5UeOHEFgYCDc3Nwwc+ZMW4SuY86cOVi4cCEAYPv27cjNzdVZnpSUJJznCy+8YIMI7Rcnb9Yh5Obm4tVXX23TYyxduhRXrlxp02M0lpOTg+vXr6N3794AAK1Wi4iICDzxxBNIS0vDqlWrEBwcjJSUFFRWVgIAhg0bhvz8fEyfPh2bN2+2Wqz6/PTTT8jKyhJ+Dw8Px5EjR5CZmSm0JSYmoqioCK+88ootQrRrnLwZs5Bt27ZZ9Xj9+vWDr6+v8PuKFSvQuXNnDBkyRGhLTk6GRCLB8uXLrRqbKXV1dcjMzMSYMWN02hM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UFhYSEeeOABTJ06VVjOs8ezVsnKygIR4cqVK1YZx+Kzzz5DdXU1kpKS2vxY+pw+fRpEhI8//tgmx7d3lpwBvi1nk3eE2eN9fHyQkZEBDw8PKBQKREVF4aeffoJWqxXW4dnjGWM6DA1p0JwZ4Fs6k7y+fVlyJnlHnT1eqVTC29tb5+sqnj2e+IUl6xjMeWFpakgDNGMG+JbMJG9oX+Zor7PHExHFxcVRbGxsk3aePZ4xBsD8GdLNZW8zyTvi7PHFxcXYs2cPli1b1mQZzx7PGAPQ8iENzGEPM8k72uzxDcMibN++Xe8Y/Tx7PGMMQMuHNDCF7GQmeUeaPb66uhpRUVFYu3atwdlyePZ4xhgA00MaNHcG+ObOJG9sX5bgKLPHV1VVITo6GitXrjQ6zRnPHs8vLFkHYG6FpaEhDYiaNwN8S2eSv39f5s4k355mj9+4cSMBaPJz+PBhnfV49nhO3qwDsHZ5vLWHTuDZ4/Xjr00YY81mj1O18ezxbY+TN2MOytpDJzRHw+zxBw4cQFFRkc3iiI2NRXp6Otzd3Zu9bcPs8bYYd8UcdjUZA2PMfPY+kzzPHt+2+M6bMcYcECdvxhhzQJy8GWPMAVntmbezszMOHDhgd1VKjFlSfX09RCIR5syZY+tQ2gQRob6+nv871qPx8LfWICKys9FWGGOMmbKSH5swxpgD4uTNGGMOyAVAoa2DYIwx1iw3/x+s8Q7fEAM2XQAAAABJRU5ErkJggg==", + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": { + "tags": [] + }, + "output_type": "execute_result" + } + ], + "source": [ + "tf.keras.utils.plot_model(model, show_shapes=True, dpi=70)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Ec-s2ECYwpUS" + }, + "source": [ + "You can now train the PQC policy on CartPole-v1, using, e.g., the basic `REINFORCE` algorithm (see Alg. 1 in [1]). Pay attention to the following points:\n", + "1. Because scaling parameters, variational angles and observables weights are trained with different learning rates, it is convenient to define 3 separate optimizers with their own learning rates, each updating one of these groups of parameters.\n", + "2. The loss function in policy-gradient RL is\n", + " $$ \\mathcal{L}(\\theta) = -\\frac{1}{|\\mathcal{B}|}\\sum_{s_0,a_0,r_1,s_1,a_1, \\ldots \\in \\mathcal{B}} \\left(\\sum_{t=0}^{H-1} \\log(\\pi_\\theta(a_t|s_t)) \\sum_{t'=1}^{H-t} \\gamma^{t'} r_{t+t'} \\right)$$\n", + "for a batch $\\mathcal{B}$ of episodes $(s_0,a_0,r_1,s_1,a_1, \\ldots)$ of interactions in the environment following the policy $\\pi_\\theta$. This is different from a supervised learning loss with fixed target values that the model should fit, which make it impossible to use a simple function call like `model.fit` to train the policy. Instead, using a `tf.GradientTape` allows to keep track of the computations involving the PQC (i.e., policy sampling) and store their contributions to the loss during the interaction. After running a batch of episodes, you can then apply backpropagation on these computations to get the gradients of the loss with respect to the PQC parameters and use the optimizers to update the policy-model." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "LHS7UlTHwpUS" + }, + "source": [ + "Start by defining a function that gathers episodes of interaction with the environment:" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "id": "dYepv83JwpUT" + }, + "outputs": [], + "source": [ + "def gather_episodes(state_bounds, n_actions, model, n_episodes, env_name):\n", + " \"\"\"Interact with environment in batched fashion.\"\"\"\n", + "\n", + " trajectories = [defaultdict(list) for _ in range(n_episodes)]\n", + " envs = [gym.make(env_name) for _ in range(n_episodes)]\n", + "\n", + " done = [False for _ in range(n_episodes)]\n", + " states = [e.reset() for e in envs]\n", + "\n", + " while not all(done):\n", + " unfinished_ids = [i for i in range(n_episodes) if not done[i]]\n", + " normalized_states = [s/state_bounds for i, s in enumerate(states) if not done[i]]\n", + "\n", + " for i, state in zip(unfinished_ids, normalized_states):\n", + " trajectories[i]['states'].append(state)\n", + "\n", + " # Compute policy for all unfinished envs in parallel\n", + " states = tf.convert_to_tensor(normalized_states)\n", + " action_probs = model([states])\n", + "\n", + " # Store action and transition all environments to the next state\n", + " states = [None for i in range(n_episodes)]\n", + " for i, policy in zip(unfinished_ids, action_probs.numpy()):\n", + " action = np.random.choice(n_actions, p=policy)\n", + " states[i], reward, done[i], _ = envs[i].step(action)\n", + " trajectories[i]['actions'].append(action)\n", + " trajectories[i]['rewards'].append(reward)\n", + "\n", + " return trajectories" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TJRGD1g1wpUT" + }, + "source": [ + "and a function that computes discounted returns $\\sum_{t'=1}^{H-t} \\gamma^{t'} r_{t+t'}$ out of the rewards $r_t$ collected in an episode:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "id": "KGDLrNN1wpUT" + }, + "outputs": [], + "source": [ + "def compute_returns(rewards_history, gamma):\n", + " \"\"\"Compute discounted returns with discount factor `gamma`.\"\"\"\n", + " returns = []\n", + " discounted_sum = 0\n", + " for r in rewards_history[::-1]:\n", + " discounted_sum = r + gamma * discounted_sum\n", + " returns.insert(0, discounted_sum)\n", + "\n", + " # Normalize them for faster and more stable learning\n", + " returns = np.array(returns)\n", + " returns = (returns - np.mean(returns)) / (np.std(returns) + 1e-8)\n", + " returns = returns.tolist()\n", + " \n", + " return returns" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "xkuUMdskwpUT" + }, + "source": [ + "Define the hyperparameters:" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "id": "QUuSU1LRwpUU" + }, + "outputs": [], + "source": [ + "state_bounds = np.array([2.4, 2.5, 0.21, 2.5])\n", + "gamma = 1\n", + "batch_size = 10\n", + "n_episodes = 1000" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "PM8uFSLMwpUU" + }, + "source": [ + "Prepare the optimizers:" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "id": "2fxGvCKpwpUU" + }, + "outputs": [], + "source": [ + "optimizer_in = tf.keras.optimizers.Adam(learning_rate=0.1, amsgrad=True)\n", + "optimizer_var = tf.keras.optimizers.Adam(learning_rate=0.01, amsgrad=True)\n", + "optimizer_out = tf.keras.optimizers.Adam(learning_rate=0.1, amsgrad=True)\n", + "\n", + "# Assign the model parameters to each optimizer\n", + "w_in, w_var, w_out = 1, 0, 2" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JbVHz19-wpUU" + }, + "source": [ + "Implement a function that updates the policy using states, actions and returns:" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "id": "zLfbu8Q2wpUV" + }, + "outputs": [], + "source": [ + "@tf.function\n", + "def reinforce_update(states, actions, returns, model):\n", + " states = tf.convert_to_tensor(states)\n", + " actions = tf.convert_to_tensor(actions)\n", + " returns = tf.convert_to_tensor(returns)\n", + "\n", + " with tf.GradientTape() as tape:\n", + " tape.watch(model.trainable_variables)\n", + " logits = model(states)\n", + " p_actions = tf.gather_nd(logits, actions)\n", + " log_probs = tf.math.log(p_actions)\n", + " loss = tf.math.reduce_sum(-log_probs * returns) / batch_size\n", + " grads = tape.gradient(loss, model.trainable_variables)\n", + " for optimizer, w in zip([optimizer_in, optimizer_var, optimizer_out], [w_in, w_var, w_out]):\n", + " optimizer.apply_gradients([(grads[w], model.trainable_variables[w])])" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "rrPlDlqLwpUV" + }, + "source": [ + "Now implement the main training loop of the agent." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "95Foz1XewpUV" + }, + "source": [ + "Note: This agent may need to simulate several million quantum circuits and can take as much as ~20 minutes to finish training." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "cYSDSNGlwpUW", + "outputId": "ae603811-b930-4484-a002-d26c4673fa06" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Finished episode 10 Average rewards: 22.3\n", + "Finished episode 20 Average rewards: 27.4\n", + "Finished episode 30 Average rewards: 24.7\n", + "Finished episode 40 Average rewards: 21.2\n", + "Finished episode 50 Average rewards: 33.9\n", + "Finished episode 60 Average rewards: 31.3\n", + "Finished episode 70 Average rewards: 37.3\n", + "Finished episode 80 Average rewards: 34.4\n", + "Finished episode 90 Average rewards: 58.4\n", + "Finished episode 100 Average rewards: 33.2\n", + "Finished episode 110 Average rewards: 67.9\n", + "Finished episode 120 Average rewards: 63.9\n", + "Finished episode 130 Average rewards: 83.5\n", + "Finished episode 140 Average rewards: 88.0\n", + "Finished episode 150 Average rewards: 142.9\n", + "Finished episode 160 Average rewards: 204.7\n", + "Finished episode 170 Average rewards: 138.1\n", + "Finished episode 180 Average rewards: 183.0\n", + "Finished episode 190 Average rewards: 196.0\n", + "Finished episode 200 Average rewards: 302.0\n", + "Finished episode 210 Average rewards: 374.4\n", + "Finished episode 220 Average rewards: 329.1\n", + "Finished episode 230 Average rewards: 307.8\n", + "Finished episode 240 Average rewards: 359.6\n", + "Finished episode 250 Average rewards: 400.7\n", + "Finished episode 260 Average rewards: 414.4\n", + "Finished episode 270 Average rewards: 394.9\n", + "Finished episode 280 Average rewards: 470.7\n", + "Finished episode 290 Average rewards: 459.7\n", + "Finished episode 300 Average rewards: 428.7\n", + "Finished episode 310 Average rewards: 500.0\n" + ] + } + ], + "source": [ + "env_name = \"CartPole-v1\"\n", + "\n", + "# Start training the agent\n", + "episode_reward_history = []\n", + "for batch in range(n_episodes // batch_size):\n", + " # Gather episodes\n", + " episodes = gather_episodes(state_bounds, n_actions, model, batch_size, env_name)\n", + " \n", + " # Group states, actions and returns in numpy arrays\n", + " states = np.concatenate([ep['states'] for ep in episodes])\n", + " actions = np.concatenate([ep['actions'] for ep in episodes])\n", + " rewards = [ep['rewards'] for ep in episodes]\n", + " returns = np.concatenate([compute_returns(ep_rwds, gamma) for ep_rwds in rewards])\n", + " returns = np.array(returns, dtype=np.float32)\n", + "\n", + " id_action_pairs = np.array([[i, a] for i, a in enumerate(actions)])\n", + " \n", + " # Update model parameters.\n", + " reinforce_update(states, id_action_pairs, returns, model)\n", + "\n", + " # Store collected rewards\n", + " for ep_rwds in rewards:\n", + " episode_reward_history.append(np.sum(ep_rwds))\n", + " \n", + " avg_rewards = np.mean(episode_reward_history[-10:])\n", + "\n", + " print('Finished episode', (batch + 1) * batch_size,\n", + " 'Average rewards: ', avg_rewards)\n", + " \n", + " if avg_rewards >= 500.0:\n", + " break" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "8E7Be2SqwpUW" + }, + "source": [ + "Plot the learning history of the agent:" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 334 + }, + "id": "51RzNBZqwpUX", + "outputId": "36b2eae1-7113-4d21-f39e-7d1bab291401", + "scrolled": true + }, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmQAAAE9CAYAAACleH4eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9abgt11ke+K5Vtfc+wx11JVmWZFsSyAgbbAFiCrYbbAZjBhOSEHAGcJNAJx0zNQTTIR0InU7g6QeCCQ8B48aQhISEDsFM7hhbxmCDB+EB21IseZAloVm6w7nnnL1rWP2j1rfWt1atql17n3PuuXef730ePWfv2rWrVtW+UK/f7/3eTxljIBAIBAKBQCA4POjDXoBAIBAIBALBUYcQMoFAIBAIBIJDhhAygUAgEAgEgkOGEDKBQCAQCASCQ4YQMoFAIBAIBIJDhhAygUAgEAgEgkNGftgL2Auuvvpqc9NNNx32MgQCgUAgEAjm4q677nrCGHNN6rMrmpDddNNNeN/73nfYyxAIBAKBQCCYC6XU/V2fSclSIBAIBAKB4JAhhEwgEAgEAoHgkCGETCAQCAQCgeCQIYRMIBAIBAKB4JAhhEwgEAgEAoHgkCGETCAQCAQCgeCQIYRMIBAIBAKB4JBxoIRMKfUppdRfKKU+oJR6n912lVLqLUqpe+3f03a7Ukq9Til1n1LqQ0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rNZ1AEAI2QbgnQCu4QOQXQDvWdiXqNFozkb06CSNRnM2UeBCqBb/onz9a/79QwC+wsfUfKvGY64F8HYAoJT+iDtj/QBeBeBt/PjdhJBpfv/rAbwMwON8dFgc/uBtjUajqYsWZBqN5lyBhr+nlP4GIeQqAG8A8AQh5GXzfA4C4A5K6UfneR6NRnOOoUuWGo3mXOGdytdHAIAQsolS+iil9A8BTABYG3rMT8BLjoSQ1wCYpJSmATwA4N38+E0Ahvj97wNwCyFkjN82TAhZ37FXpNFozhq0Q6bRaM4m4oSQp5Sff0ApFdEXQ4SQZwCUANzKj32aELIFzNm6D8DTAF6tPP6PAHyZPy7//7dzxzQIBUEABd9iFAFYoEENHhCAA+jBBsWnQQLJETJTbnfdy16y1f4zP1XnmblV1+pZtW3bfWaO1WVmdtWrOlSP7z4T+DfOXgB/z1kK4Nf5sgQAWMyGDABgMRsyAIDFBBkAwGKCDABgMUEGALCYIAMAWEyQAQAs9gZAaI79kP3u0QAAAABJRU5ErkJggg==", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light", + "tags": [] + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.figure(figsize=(10,5))\n", + "plt.plot(episode_reward_history)\n", + "plt.xlabel('Epsiode')\n", + "plt.ylabel('Collected rewards')\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Qfdf4DBkwpUX" + }, + "source": [ + "Congratulations, you have trained a quantum policy gradient model on Cartpole! The plot above shows the rewards collected by the agent per episode throughout its interaction with the environment. You should see that after a few hundred episodes, the performance of the agent gets close to optimal, i.e., 500 rewards per episode. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YtaBfoERwpUX" + }, + "source": [ + "You can now visualize the performance of your agent using `env.render()` in a sample episode (uncomment/run the following cell only if your notebook has access to a display):" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "-VpROTJ1wpUX" + }, + "outputs": [], + "source": [ + "# from PIL import Image\n", + "\n", + "# env = gym.make('CartPole-v1')\n", + "# state = env.reset()\n", + "# frames = []\n", + "# for t in range(500):\n", + "# im = Image.fromarray(env.render(mode='rgb_array'))\n", + "# frames.append(im)\n", + "# policy = model([tf.convert_to_tensor([state/state_bounds])])\n", + "# action = np.random.choice(n_actions, p=policy.numpy()[0])\n", + "# state, _, done, _ = env.step(action)\n", + "# if done:\n", + "# break\n", + "# env.close()\n", + "# frames[1].save('./images/gym_CartPole.gif',\n", + "# save_all=True, append_images=frames[2:], optimize=False, duration=40, loop=0)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "i0iA0nubwpUX" + }, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "iAO1TBxqwpUX" + }, + "source": [ + "## 3. Deep Q-learning with PQC Q-function approximators" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "9uEimdpHwpUY" + }, + "source": [ + "In this section, you will move to the implementation of the deep Q-learning algorithm presented in [2]. As opposed to a policy-gradient approach, the deep Q-learning method uses a PQC to approximate the Q-function of the agent. That is, the PQC defines a function approximator:\n", + "$$ Q_\\theta(s,a) = \\langle O_a \\rangle_{s,\\theta} $$\n", + "where $\\langle O_a \\rangle_{s,\\theta}$ are expectation values of observables $O_a$ (one per action) measured at the ouput of the PQC.\n", + "\n", + "These Q-values are updated using a loss function derived from Q-learning:\n", + "$$ \\mathcal{L}(\\theta) = \\frac{1}{|\\mathcal{B}|}\\sum_{s,a,r,s' \\in \\mathcal{B}} \\left(Q_\\theta(s,a) - [r +\\max_{a'} Q_{\\theta'}(s',a')]\\right)^2$$\n", + "for a batch $\\mathcal{B}$ of $1$-step interactions $(s,a,r,s')$ with the environment, sampled from the replay memory, and parameters $\\theta'$ specifying the target PQC (i.e., a copy of the main PQC, whose parameters are sporadically copied from the main PQC throughout learning)." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nTyRzuDYwpUY" + }, + "source": [ + "You can adopt the same observables used in [2] for CartPole, namely a $Z_0Z_1$ Pauli product for action $0$ and a $Z_2Z_3$ Pauli product for action $1$. Both observables are re-scaled so their expectation values are in $[0,1]$ and weighted by an action-specific weight. To implement the re-scaling and weighting of the Pauli products, you can define again an extra `tf.keras.layers.Layer` that stores the action-specific weights and applies them multiplicatively on the expectation values $\\left(1+\\langle Z_0Z_1 \\rangle_{s,\\theta}\\right)/2$ and $\\left(1+\\langle Z_2Z_3 \\rangle_{s,\\theta}\\right)/2$." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "MX5l96qywpUY" + }, + "outputs": [], + "source": [ + "class Rescaling(tf.keras.layers.Layer):\n", + " def __init__(self, input_dim):\n", + " super(Rescaling, self).__init__()\n", + " self.input_dim = input_dim\n", + " self.w = tf.Variable(\n", + " initial_value=tf.ones(shape=(1,input_dim)), dtype=\"float32\",\n", + " trainable=True, name=\"obs-weights\")\n", + "\n", + " def call(self, inputs):\n", + " return tf.math.multiply((inputs+1)/2, tf.repeat(self.w,repeats=tf.shape(inputs)[0],axis=0))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "oesnEQa7wpUY" + }, + "source": [ + "Prepare the definition of your PQC and its observables:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "id": "cpV0PxZqwpUY" + }, + "outputs": [], + "source": [ + "n_qubits = 4 # Dimension of the state vectors in CartPole\n", + "n_layers = 5 # Number of layers in the PQC\n", + "n_actions = 2 # Number of actions in CartPole\n", + "\n", + "qubits = cirq.GridQubit.rect(1, n_qubits)\n", + "ops = [cirq.Z(q) for q in qubits]\n", + "observables = [ops[0]*ops[1], ops[2]*ops[3]] # Z_0*Z_1 for action 0 and Z_2*Z_3 for action 1" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JLMvQBXFwpUZ" + }, + "source": [ + "Define a `tf.keras.Model` that, similarly to the PQC-policy model, constructs a Q-function approximator that is used to generate the main and target models of our Q-learning agent." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "PBGM6RHIwpUZ" + }, + "outputs": [], + "source": [ + "def generate_model_Qlearning(qubits, n_layers, n_actions, observables, target):\n", + " \"\"\"Generates a Keras model for a data re-uploading PQC Q-function approximator.\"\"\"\n", + "\n", + " input_tensor = tf.keras.Input(shape=(len(qubits), ), dtype=tf.dtypes.float32, name='input')\n", + " re_uploading_pqc = ReUploadingPQC(qubits, n_layers, observables, activation='tanh')([input_tensor])\n", + " process = tf.keras.Sequential([Rescaling(len(observables))], name=target*\"Target\"+\"Q-values\")\n", + " Q_values = process(re_uploading_pqc)\n", + " model = tf.keras.Model(inputs=[input_tensor], outputs=Q_values)\n", + "\n", + " return model\n", + "\n", + "model = generate_model_Qlearning(qubits, n_layers, n_actions, observables, False)\n", + "model_target = generate_model_Qlearning(qubits, n_layers, n_actions, observables, True)\n", + "\n", + "model_target.set_weights(model.get_weights())" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 232 + }, + "id": "57TxgIN5wpUZ", + "outputId": "da6a3aee-1722-40b3-fae5-2972d8c2ed88" + }, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW8AAADXCAYAAADV0tC4AAAABmJLR0QA/wD/AP+gvaeTAAAgAElEQVR4nO3de1xU9bo/8M8gMMPMoA13FBLTg5dUzHLbaXuObrWOBip1CFS8JKTYhVQ8RxQxEcmg3daCRDRFk7AoU4+UmJfCW+Jld1NRvIDmBRBFBWfE4fL8/vDH2ozAzHAZFjM879eL12vzXbdnrbV7XHzXer5fCRERGGOMmZMPrMSOgDHGWNNx8maMMTNkLXYAbaGqqgpFRUVih8EYMzE7Ozs4OjqKHUab6BDJ+9KlSxg4cCA8PT3FDoW10IMHD1BdXQ2lUil2KCZBRLh9+zacnJzEDsXsaDQaPP/889i2bZvYobSJDpG8AaBPnz74/fffxQ6DtVBiYiKuXbuGDz/8UOxQTEKj0cDDwwMXL14UOxSzs2vXLqxfv17sMNoM93kzxpgZ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UpvCTXRv8rEAeiUpjflejamOeN5mxMLLwNvNgu/LlweX1dpaSleeOEFqNVqbNq0CX/729+EJ+qOrLi4GG5ubnjw4IFZjuRm6vJ4sXG3ScMs/LpweXxdDg4O2L9/P/r06QNfX1+MHz9e7JDaBQv8973D4tnjLQcn78d069YNe/fuRUVFBb777juxw2kXar8WmT17tsiRtE+tNQO8qWeS59njLQsnb2bQ6dOnQUTYtGmT2KG0S601A7ypZ5Ln2eMtCydvxqB/hvSmzACvbzZ5MWeS59njLZC4L0xNgydjYHUZ+trEmBnS0YQZ4PXNJt+U/RiLZ49vmKV/bcJP3qzDa8oM6cZqb7PJ8+zxloeTN+vwWjJDujHaw2zyPHu85eHkzTq8lsyQbgi1k9nkefZ4y8PJm3V4xsyQ3tQZ4BubTV6smeR59ngLJGqXu4nwC0tWlzHl8fpmSCdq2gzw+maTN8VM8jx7fPOvixnj8nhm+dq6PL6tZ5Pn2eMbxuXxjLEma49TtfHs8ZaFkzdjrajubPK//PKL2OHoqJ09fv/+/SgoKBAtjvDwcCQnJ8POzq5J29XOHi/GmCvtUYedjIExU2jvs8nz7PGWg5+8GWPMDHHyZowxM8TJmzHGzJBF9nlLJBJoNJoOX4HFHmnKnJ/miP5/9eLatWvFDqXdqR2h0RJZZPK2s7Pr8OMeMMYsG3ebMMaYGeLkzRhjZsgaQL7YQTDGGGuSO/8PRRbG9FW9bh4AAAAASUVORK5CYII=", + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": { + "tags": [] + }, + "output_type": "execute_result" + } + ], + "source": [ + "tf.keras.utils.plot_model(model, show_shapes=True, dpi=70)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 232 + }, + "id": "jHp42R4twpUa", + "outputId": "69a20e50-fde4-4634-897b-01edaeab420a" + }, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW8AAADXCAYAAADV0tC4AAAABmJLR0QA/w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msZc6cOQMiwubNm8UOxWKZaxb41pxNnmePtxwdOnkzZm76Zkg3NhxAw/L++tExmzqT/MP7mTNnjllnkufZ4y2M2E/dH8aTMTBLZMoLS2MzpEPPcABEjcv7mzOTvK79NAXPHq8bv7BkrJ0zdYZ0U1naTPI8e7xl4eTNmJm0ZIZ0YyxhJnmePd6ycPJmzExaMkO6IWQhM8nz7PGWhZM3Y2ZibIZ0fcMBALrL+5s6k7y+/ZgLzx5vYUR95K4Dv7BklsjUCkt9M6QTGR4OgEi7vL+5M8k/vJ+mzCTPs8c377qIhGePZ8wUbTF7fENizCTPs8frxrPHM8aaxBKnauPZ4y0HJ2/GLIwlzyTPs8dbjnY5GQNj1szSZ5Ln2eMtA995M8aYFeLkzRhjVoiTN2OMWSGLe+ZtZ2eHmJiYRpP5MiYm+v+VfdZajWcKjUYDLy8vscOwSJZYyGNx33kzxhgzir/zZowxa8TJmzHGrJAtgCtiB8EYY6xJ7vw/T3w+d9/DBZgAAAAASUVORK5CYII=", + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": { + "tags": [] + }, + "output_type": "execute_result" + } + ], + "source": [ + "tf.keras.utils.plot_model(model_target, show_shapes=True, dpi=70)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "vricJOvXwpUa" + }, + "source": [ + "You can now implement the deep Q-learning algorithm and test it on the CartPole-v1 environment. For the policy of the agent, you can use an $\\varepsilon$-greedy policy:\n", + "$$ \\pi(a|s) =\n", + "\\begin{cases}\n", + "\\delta_{a,\\text{argmax}_{a'} Q_\\theta(s,a')}\\quad \\text{w.p.}\\quad 1 - \\varepsilon\\\\\n", + "\\frac{1}{\\text{num_actions}}\\quad \\quad \\quad \\quad \\text{w.p.}\\quad \\varepsilon\n", + "\\end{cases} $$\n", + "where $\\varepsilon$ is multiplicatively decayed at each episode of interaction." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "sMteuedswpUb" + }, + "source": [ + "Start by defining a function that performs an interaction step in the environment:" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "id": "0L9cV26PwpUb" + }, + "outputs": [], + "source": [ + "def interact_env(state, model, epsilon, n_actions, env):\n", + " # Preprocess state\n", + " state_array = np.array(state) \n", + " state = tf.convert_to_tensor([state_array])\n", + "\n", + " # Sample action\n", + " coin = np.random.random()\n", + " if coin > epsilon:\n", + " q_vals = model([state])\n", + " action = int(tf.argmax(q_vals[0]).numpy())\n", + " else:\n", + " action = np.random.choice(n_actions)\n", + "\n", + " # Apply sampled action in the environment, receive reward and next state\n", + " next_state, reward, done, _ = env.step(action)\n", + " \n", + " interaction = {'state': state_array, 'action': action, 'next_state': next_state.copy(),\n", + " 'reward': reward, 'done':np.float32(done)}\n", + " \n", + " return interaction" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "oDiw3iJywpUb" + }, + "source": [ + "and a function that updates the Q-function using a batch of interactions:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "id": "RR2DjesVwpUb" + }, + "outputs": [], + "source": [ + "@tf.function\n", + "def Q_learning_update(states, actions, rewards, next_states, done, model, gamma, n_actions):\n", + " states = tf.convert_to_tensor(states)\n", + " actions = tf.convert_to_tensor(actions)\n", + " rewards = tf.convert_to_tensor(rewards)\n", + " next_states = tf.convert_to_tensor(next_states)\n", + " done = tf.convert_to_tensor(done)\n", + "\n", + " # Compute their target q_values and the masks on sampled actions\n", + " future_rewards = model_target([next_states])\n", + " target_q_values = rewards + (gamma * tf.reduce_max(future_rewards, axis=1)\n", + " * (1.0 - done))\n", + " masks = tf.one_hot(actions, n_actions)\n", + "\n", + " # Train the model on the states and target Q-values\n", + " with tf.GradientTape() as tape:\n", + " tape.watch(model.trainable_variables)\n", + " q_values = model([states])\n", + " q_values_masked = tf.reduce_sum(tf.multiply(q_values, masks), axis=1)\n", + " loss = tf.keras.losses.Huber()(target_q_values, q_values_masked)\n", + "\n", + " # Backpropagation\n", + " grads = tape.gradient(loss, model.trainable_variables)\n", + " for optimizer, w in zip([optimizer_in, optimizer_var, optimizer_out], [w_in, w_var, w_out]):\n", + " optimizer.apply_gradients([(grads[w], model.trainable_variables[w])])" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tfXHhqaPwpUb" + }, + "source": [ + "Define the hyperparameters:" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "id": "SQ937aYPwpUc" + }, + "outputs": [], + "source": [ + "gamma = 0.99\n", + "n_episodes = 2000\n", + "\n", + "# Define replay memory\n", + "max_memory_length = 10000 # Maximum replay length\n", + "replay_memory = deque(maxlen=max_memory_length)\n", + "\n", + "epsilon = 1.0 # Epsilon greedy parameter\n", + "epsilon_min = 0.01 # Minimum epsilon greedy parameter\n", + "decay_epsilon = 0.99 # Decay rate of epsilon greedy parameter\n", + "batch_size = 16\n", + "steps_per_update = 10 # Train the model every x steps\n", + "steps_per_target_update = 30 # Update the target model every x steps" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "AHsHnuHmwpUc" + }, + "source": [ + "Prepare the optimizers:" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "id": "713nl3oUwpUc" + }, + "outputs": [], + "source": [ + "optimizer_in = tf.keras.optimizers.Adam(learning_rate=0.001, amsgrad=True)\n", + "optimizer_var = tf.keras.optimizers.Adam(learning_rate=0.001, amsgrad=True)\n", + "optimizer_out = tf.keras.optimizers.Adam(learning_rate=0.1, amsgrad=True)\n", + "\n", + "# Assign the model parameters to each optimizer\n", + "w_in, w_var, w_out = 1, 0, 2" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "AwE0buDowpUd" + }, + "source": [ + "Now implement the main training loop of the agent." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TjjTamvywpUd" + }, + "source": [ + "Note: This agent may need to simulate several million quantum circuits and can take as much as ~40 minutes to finish training." + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "er9fXHH_wpUd", + "outputId": "b165066b-c239-4bf0-b444-7c710640241c", + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Episode 10/2000, average last 10 rewards 22.1\n", + "Episode 20/2000, average last 10 rewards 27.9\n", + "Episode 30/2000, average last 10 rewards 31.5\n", + "Episode 40/2000, average last 10 rewards 23.3\n", + "Episode 50/2000, average last 10 rewards 25.4\n", + "Episode 60/2000, average last 10 rewards 19.7\n", + "Episode 70/2000, average last 10 rewards 12.5\n", + "Episode 80/2000, average last 10 rewards 11.7\n", + "Episode 90/2000, average last 10 rewards 14.9\n", + "Episode 100/2000, average last 10 rewards 15.3\n", + "Episode 110/2000, average last 10 rewards 14.6\n", + "Episode 120/2000, average last 10 rewards 20.4\n", + "Episode 130/2000, average last 10 rewards 14.2\n", + "Episode 140/2000, average last 10 rewards 21.6\n", + "Episode 150/2000, average last 10 rewards 30.4\n", + "Episode 160/2000, average last 10 rewards 27.6\n", + "Episode 170/2000, average last 10 rewards 18.5\n", + "Episode 180/2000, average last 10 rewards 30.6\n", + "Episode 190/2000, average last 10 rewards 12.2\n", + "Episode 200/2000, average last 10 rewards 27.2\n", + "Episode 210/2000, average last 10 rewards 27.2\n", + "Episode 220/2000, average last 10 rewards 15.3\n", + "Episode 230/2000, average last 10 rewards 128.4\n", + "Episode 240/2000, average last 10 rewards 68.3\n", + "Episode 250/2000, average last 10 rewards 44.0\n", + "Episode 260/2000, average last 10 rewards 119.8\n", + "Episode 270/2000, average last 10 rewards 135.3\n", + "Episode 280/2000, average last 10 rewards 90.6\n", + "Episode 290/2000, average last 10 rewards 120.9\n", + "Episode 300/2000, average last 10 rewards 125.3\n", + "Episode 310/2000, average last 10 rewards 141.7\n", + "Episode 320/2000, average last 10 rewards 144.7\n", + "Episode 330/2000, average last 10 rewards 165.7\n", + "Episode 340/2000, average last 10 rewards 26.1\n", + "Episode 350/2000, average last 10 rewards 9.7\n", + "Episode 360/2000, average last 10 rewards 9.6\n", + "Episode 370/2000, average last 10 rewards 9.7\n", + "Episode 380/2000, average last 10 rewards 9.4\n", + "Episode 390/2000, average last 10 rewards 11.3\n", + "Episode 400/2000, average last 10 rewards 11.6\n", + "Episode 410/2000, average last 10 rewards 165.4\n", + "Episode 420/2000, average last 10 rewards 170.5\n", + "Episode 430/2000, average last 10 rewards 25.1\n", + "Episode 440/2000, average last 10 rewards 74.1\n", + "Episode 450/2000, average last 10 rewards 214.7\n", + "Episode 460/2000, average last 10 rewards 139.1\n", + "Episode 470/2000, average last 10 rewards 265.1\n", + "Episode 480/2000, average last 10 rewards 296.7\n", + "Episode 490/2000, average last 10 rewards 101.7\n", + "Episode 500/2000, average last 10 rewards 146.6\n", + "Episode 510/2000, average last 10 rewards 325.6\n", + "Episode 520/2000, average last 10 rewards 45.9\n", + "Episode 530/2000, average last 10 rewards 263.5\n", + "Episode 540/2000, average last 10 rewards 223.3\n", + "Episode 550/2000, average last 10 rewards 73.1\n", + "Episode 560/2000, average last 10 rewards 115.0\n", + "Episode 570/2000, average last 10 rewards 148.3\n", + "Episode 580/2000, average last 10 rewards 41.6\n", + "Episode 590/2000, average last 10 rewards 266.7\n", + "Episode 600/2000, average last 10 rewards 275.2\n", + "Episode 610/2000, average last 10 rewards 253.9\n", + "Episode 620/2000, average last 10 rewards 282.2\n", + "Episode 630/2000, average last 10 rewards 348.3\n", + "Episode 640/2000, average last 10 rewards 162.2\n", + "Episode 650/2000, average last 10 rewards 276.0\n", + "Episode 660/2000, average last 10 rewards 234.6\n", + "Episode 670/2000, average last 10 rewards 187.4\n", + "Episode 680/2000, average last 10 rewards 285.0\n", + "Episode 690/2000, average last 10 rewards 362.8\n", + "Episode 700/2000, average last 10 rewards 316.0\n", + "Episode 710/2000, average last 10 rewards 436.0\n", + "Episode 720/2000, average last 10 rewards 366.1\n", + "Episode 730/2000, average last 10 rewards 305.0\n", + "Episode 740/2000, average last 10 rewards 273.2\n", + "Episode 750/2000, average last 10 rewards 236.8\n", + "Episode 760/2000, average last 10 rewards 260.2\n", + "Episode 770/2000, average last 10 rewards 443.9\n", + "Episode 780/2000, average last 10 rewards 494.2\n", + "Episode 790/2000, average last 10 rewards 333.1\n", + "Episode 800/2000, average last 10 rewards 367.1\n", + "Episode 810/2000, average last 10 rewards 317.8\n", + "Episode 820/2000, average last 10 rewards 396.6\n", + "Episode 830/2000, average last 10 rewards 494.1\n", + "Episode 840/2000, average last 10 rewards 500.0\n" + ] + } + ], + "source": [ + "env = gym.make(\"CartPole-v1\")\n", + " \n", + "episode_reward_history = []\n", + "step_count = 0\n", + "for episode in range(n_episodes):\n", + " episode_reward = 0\n", + " state = env.reset()\n", + " \n", + " while True:\n", + " # Interact with env\n", + " interaction = interact_env(state, model, epsilon, n_actions, env)\n", + " \n", + " # Store interaction in the replay memory\n", + " replay_memory.append(interaction)\n", + " \n", + " state = interaction['next_state']\n", + " episode_reward += interaction['reward']\n", + " step_count += 1\n", + " \n", + " # Update model\n", + " if step_count % steps_per_update == 0:\n", + " # Sample a batch of interactions and update Q_function\n", + " training_batch = np.random.choice(replay_memory, size=batch_size)\n", + " Q_learning_update(np.asarray([x['state'] for x in training_batch]),\n", + " np.asarray([x['action'] for x in training_batch]),\n", + " np.asarray([x['reward'] for x in training_batch], dtype=np.float32),\n", + " np.asarray([x['next_state'] for x in training_batch]),\n", + " np.asarray([x['done'] for x in training_batch], dtype=np.float32),\n", + " model, gamma, n_actions)\n", + " \n", + " # Update target model\n", + " if step_count % steps_per_target_update == 0:\n", + " model_target.set_weights(model.get_weights())\n", + " \n", + " # Check if the episode is finished\n", + " if interaction['done']:\n", + " break\n", + "\n", + " # Decay epsilon\n", + " epsilon = max(epsilon * decay_epsilon, epsilon_min)\n", + " episode_reward_history.append(episode_reward)\n", + " if (episode+1)%10 == 0:\n", + " avg_rewards = np.mean(episode_reward_history[-10:])\n", + " print(\"Episode {}/{}, average last 10 rewards {}\".format(\n", + " episode+1, n_episodes, avg_rewards))\n", + " if avg_rewards >= 500.0:\n", + " break" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "BG8BWOSYwpUd" + }, + "source": [ + "Plot the learning history of the agent:" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 334 + }, + "id": "sSRMtk-swpUe", + "outputId": "a2a4c5a8-92cf-495a-da9d-6be0e8f673a2" + }, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmQAAAE9CAYAAACleH4eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOy9d7wsR3UtvHbPzDnn5qSLcrgKIAkQEsgyshBJJotgG3g2/ADzZDC2wQQbkE0wfvh7FtggjI39EAZbZEwQCIQEQigASugq53iF7lW4OZ4woev7o7u6q6qruqt7Zs6ZPmcvfmJmqrurq3v6Tq2z96q1SQgBBoPBYDAYDMbcIZjrATAYDAaDwWAsdDAhYzAYDAaDwZhjMCFjMBgMBoPBmGMwIWMwGAwGg8GYYzAhYzAYDAaDwZhjMCFjMBgMBoPBmGM053oA/WC//fYTRxxxxFwPg8FgMBgMBqMQ69ev3yqEWGvbVmtCdsQRR+CGG26Y62EwGAwGg8FgFIKIHnZt45Qlg8FgMBgMxhyDCRmDwWAwGAzGHIMJGYPBYDAYDMYcgwkZg8FgMBgMxhyDCRmDwWAwGAzGHIMJGYPBYDAYDMYcgwkZg8FgMBgMxhxjqISMiDYQ0W1EdDMR3RC3rSaiS4novvh1VdxORPRZIrqfiG4lomcOc2wMBoPBYDAYo4LZiJC9QAhxohDi5Pjz2QAuE0IcA+Cy+DMAvAzAMfF/bwfwH7MwNgaDwWAwGIw5x1w49b8awPPj9+cDuALAB+P2LwshBIBriWglER0ohHhsDsbIYDAYs44d+9rYuGMKTz9kxVwPZaSwb6aLi29/HCcfvgp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alPaCIIg+D6WlIAii2CGXJUEQBEEQRIEhCxlBEARBEESBIQsZQRAEQRBEgSFBRhAEQRAEUWBIkBEEQRAEQRQYEmQEQRAEQRAFhgQZQRAEQRBEgSFBRhAEQRAEUWD+P4OVq5z/8Mn0AAAAAElFTkSuQmCC", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light", + "tags": [] + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.figure(figsize=(10,5))\n", + "plt.plot(episode_reward_history)\n", + "plt.xlabel('Epsiode')\n", + "plt.ylabel('Collected rewards')\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "f_7rJf0iwpUe" + }, + "source": [ + "Similarly to the plot above, you should see that after ~1000 episodes, the performance of the agent gets close to optimal, i.e., 500 rewards per episode. Learning takes longer for Q-learning agents since the Q-function is a \"richer\" function to be learned than the policy." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "X8X49f8owpUe" + }, + "source": [ + "## 4. Exercise\n", + "\n", + "Now that you have trained two different types of models, try experimenting with different environments (and different numbers of qubits and layers). You could also try combining the PQC models of the last two sections into an [actor-critic agent](https://lilianweng.github.io/lil-log/2018/04/08/policy-gradient-algorithms.html#actor-critic)." + ] + } + ], + "metadata": { + "colab": { + "collapsed_sections": [ + "jxWGru_NwpUK", + "_u3QBKbvwpUP", + "X8X49f8owpUe" + ], + "name": "quantum_reinforcement_learning.ipynb", + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.9 (main, Dec 7 2022, 13:47:07) [GCC 12.2.0]" + }, + "vscode": { + "interpreter": { + "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1" + } + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/docs/tutorials/research_tools.ipynb b/docs/tutorials/research_tools.ipynb index d8d6c4d60..29c7c3752 100644 --- a/docs/tutorials/research_tools.ipynb +++ b/docs/tutorials/research_tools.ipynb @@ -83,7 +83,23 @@ }, "outputs": [], "source": [ - "!pip install -q tensorflow==2.3.1 tensorflow-quantum tensorboard_plugin_profile==2.3.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" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "4Ql5PW-ACO0J" + }, + "outputs": [], + "source": [ + "# Update package resources to account for version changes.\n", + "import importlib, pkg_resources\n", + "importlib.reload(pkg_resources)" ] }, { @@ -109,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", @@ -140,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", @@ -489,9 +506,9 @@ " tf.summary.histogram(\n", " 'New round of True samples', data=bits_to_ints(random_new_distribution), step=epoch)\n", "\n", - " if epoch % 10 == 0:\n", - " print('Epoch {}, took {}(s)'.format(epoch, time.time() - t))\n", - " t = time.time()" + " if epoch % 10 == 0:\n", + " print('Epoch {}, took {}(s)'.format(epoch, time.time() - t))\n", + " t = time.time()" ] }, { diff --git a/release/BUILD b/release/BUILD index dff6e9b7d..ff3db2ba0 100644 --- a/release/BUILD +++ b/release/BUILD @@ -1,3 +1,5 @@ +load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured") + licenses(["notice"]) sh_binary( @@ -13,6 +15,7 @@ sh_binary( "//tensorflow_quantum/core:__init__.py", "//tensorflow_quantum/core/ops:__init__.py", "//tensorflow_quantum/core/ops/math_ops:__init__.py", + "//tensorflow_quantum/core/ops/noise:__init__.py", "//tensorflow_quantum/core/proto:__init__.py", "//tensorflow_quantum/core/serialize:__init__.py", @@ -38,7 +41,12 @@ sh_binary( "//tensorflow_quantum/core/ops:tfq_unitary_op_py", "//tensorflow_quantum/core/ops:tfq_utility_ops_py", "//tensorflow_quantum/core/ops:tfq_simulate_ops_py", + "//tensorflow_quantum/core/ops/math_ops:fidelity_op_py", "//tensorflow_quantum/core/ops/math_ops:inner_product_op_py", + "//tensorflow_quantum/core/ops/math_ops:simulate_mps_py", + "//tensorflow_quantum/core/ops/noise:noisy_samples_op_py", + "//tensorflow_quantum/core/ops/noise:noisy_expectation_op_py", + "//tensorflow_quantum/core/ops/noise:noisy_sampled_expectation_op_py", "//tensorflow_quantum/core/serialize:serializer", "//tensorflow_quantum/datasets:cluster_state", "//tensorflow_quantum/datasets:spin_system", @@ -53,9 +61,15 @@ sh_binary( "//tensorflow_quantum/python/layers/circuit_executors:sampled_expectation", "//tensorflow_quantum/python/layers/circuit_executors:unitary", "//tensorflow_quantum/python/layers/high_level:controlled_pqc", + "//tensorflow_quantum/python/layers/high_level:noisy_controlled_pqc", + "//tensorflow_quantum/python/layers/high_level:noisy_pqc", "//tensorflow_quantum/python/layers/high_level:pqc", "//tensorflow_quantum/python:quantum_context", "//tensorflow_quantum/python:util", "//tensorflow_quantum/python/optimizers:rotosolve_minimizer", - ], + "//tensorflow_quantum/python/optimizers:spsa_minimizer", + ] + if_cuda_is_configured([ + "//tensorflow_quantum/core/ops:tfq_simulate_ops_cuquantum_py", + "//tensorflow_quantum/core/ops:tfq_adj_grad_op_cuquantum_py", + ]), ) diff --git a/release/build_pip_package.sh b/release/build_pip_package.sh index 8bed5b909..1c423c656 100755 --- a/release/build_pip_package.sh +++ b/release/build_pip_package.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= set -e set -x diff --git a/release/setup.py b/release/setup.py index 155d835b3..e9deb961f 100644 --- a/release/setup.py +++ b/release/setup.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """TensorFlow Quantum adds qauntum computing primitives to TensorFlow. TensorFlow Quantum is an open source library for high performance batch @@ -50,12 +50,18 @@ def finalize_options(self): self.install_lib = self.install_platlib -REQUIRED_PACKAGES = ['cirq == 0.9.1', 'sympy == 1.5'] +REQUIRED_PACKAGES = [ + '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.5' +] + +REQUIRED_GPU_PACKAGES = [] # placed as extra to not have required overwrite existing nightly installs if # they exist. -EXTRA_PACKAGES = ['tensorflow == 2.3.1'] -CUR_VERSION = '0.5.0' +EXTRA_PACKAGES = ['tensorflow == 2.11.0'] +CUR_VERSION = '0.8.0' class BinaryDistribution(Distribution): @@ -70,11 +76,21 @@ def has_ext_modules(self): nightly = True sys.argv.remove('--nightly') +gpu = False +if '--gpu' in sys.argv: + gpu = True + sys.argv.remove('--gpu') + project_name = 'tensorflow-quantum' build_version = CUR_VERSION + +if gpu: + build_version = build_version + '.gpu' + REQUIRED_PACKAGES = REQUIRED_PACKAGES + REQUIRED_GPU_PACKAGES + if nightly: project_name = 'tfq-nightly' - build_version = CUR_VERSION + '.dev' + str(date.today()).replace('-', '') + build_version = build_version + '.dev' + str(date.today()).replace('-', '') setup( name=project_name, @@ -100,8 +116,9 @@ def has_ext_modules(self): 'Intended Audience :: Education', 'Intended Audience :: Science/Research', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', 'Topic :: Scientific/Engineering', 'Topic :: Scientific/Engineering :: Artificial Intelligence', 'Topic :: Scientific/Engineering :: Mathematics', diff --git a/requirements.txt b/requirements.txt index 28deb4362..f899bfc5b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,15 @@ -cirq==0.9.1 -sympy==1.5 -nbconvert==5.6.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 pylint==2.4.4 yapf==0.28.0 -tensorflow==2.3.1 +tensorflow==2.11.0 +# Needed for compatibility with cirq program protos. +googleapis-common-protos==1.52.0 +google-api-core==1.21.0 +google-auth==1.18.0 google-api-python-client==1.8.0 +grpcio==1.34.1 +protobuf==3.19.5 diff --git a/scripts/benchmark_all.sh b/scripts/benchmark_all.sh index 9fbf73387..648d9ebad 100644 --- a/scripts/benchmark_all.sh +++ b/scripts/benchmark_all.sh @@ -12,9 +12,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Testing benchmarks."; -test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/...)) +test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/...)) exit_code=$? if [ "$exit_code" == "0" ]; then @@ -26,5 +26,5 @@ else fi echo "Running preconfigured benchmarks."; -bazel_run=${bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4"} +bazel_run=${bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4"} bazel_run benchmarks/scripts:benchmark_clifford_circuit -- --op_density 1 --n_moments 10 --n_qubits 4 \ No newline at end of file diff --git a/scripts/build_docs.py b/scripts/build_docs.py index 2a4cdf9c3..3ad066491 100644 --- a/scripts/build_docs.py +++ b/scripts/build_docs.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tool to generate external api_docs for tfq.""" from __future__ import absolute_import @@ -67,12 +67,17 @@ def main(unused_argv): "parameter_shift_util", "adjoint" ], "tfq.datasets": ["cluster_state"], - "tfq.optimizers": ["rotosolve_minimizer"], + "tfq.optimizers": ["rotosolve_minimizer", "spsa_minimizer"], "tfq.util": [ "from_tensor", "convert_to_tensor", "exp_identity", "check_commutability", "kwargs_cartesian_product", "random_circuit_resolver_batch", "random_pauli_sums", "random_symbol_circuit", "random_symbol_circuit_resolver_batch" + ], + "tfq.math": ["fidelity_op", "inner_product_op"], + "tfq.noise": [ + "noisy_expectation_op", "noisy_sampled_expectation_op", + "noisy_samples_op" ] }) diff --git a/scripts/build_pip_package_test.sh b/scripts/build_pip_package_test.sh index 1adc7a7e9..144a42cfb 100755 --- a/scripts/build_pip_package_test.sh +++ b/scripts/build_pip_package_test.sh @@ -12,14 +12,14 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= pip install -r requirements.txt # cd tensorflow_quantum echo "Y\n" | ./configure.sh -bazel build -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" release:build_pip_package +bazel build -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" release:build_pip_package rm /tmp/tensorflow_quantum/* || echo ok bazel-bin/release/build_pip_package /tmp/tensorflow_quantum/ pip install -U /tmp/tensorflow_quantum/*.whl diff --git a/scripts/ci_install.sh b/scripts/ci_install.sh index 710b8f545..860c02ecc 100755 --- a/scripts/ci_install.sh +++ b/scripts/ci_install.sh @@ -12,8 +12,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== -wget https://github.com/bazelbuild/bazel/releases/download/3.1.0/bazel_3.1.0-linux-x86_64.deb -sudo dpkg -i bazel_3.1.0-linux-x86_64.deb +# ============================================================================= +wget https://github.com/bazelbuild/bazel/releases/download/5.3.0/bazel_5.3.0-linux-x86_64.deb +sudo dpkg -i bazel_5.3.0-linux-x86_64.deb pip install --upgrade pip setuptools wheel pip install -r requirements.txt \ No newline at end of file diff --git a/scripts/ci_validate_tutorials.sh b/scripts/ci_validate_tutorials.sh index 5e9905a7a..4fe94c465 100755 --- a/scripts/ci_validate_tutorials.sh +++ b/scripts/ci_validate_tutorials.sh @@ -12,12 +12,20 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= # Run the tutorials using the installed pip package -pip install jupyter nbformat==4.4.0 nbconvert==5.6.1 +pip install jupyter nbclient==0.6.5 jupyter-client==6.1.12 ipython==7.22.0 # Workaround for ipykernel - see https://github.com/ipython/ipykernel/issues/422 pip install ipykernel==5.1.1 +# OpenAI Gym pip package needed for the quantum reinforcement learning tutorial +pip install gym==0.24.1 +# seaborn has also numpy dependency, it requires version >= 0.12.0. +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) @@ -28,4 +36,4 @@ else echo "Tutorials failed to run to completion:" echo "{$examples_output}" exit 64; -fi \ No newline at end of file +fi diff --git a/scripts/format_all.sh b/scripts/format_all.sh index 0e374a3cc..2a57c0747 100755 --- a/scripts/format_all.sh +++ b/scripts/format_all.sh @@ -12,13 +12,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Doing python language formatting..." python3 -m yapf --style=google --in-place --recursive ./benchmarks python3 -m yapf --style=google --in-place --recursive ./tensorflow_quantum echo -e "Done! \nDoing notebook formatting..." python3 ./scripts/format_ipynb.py echo -e "Done! \nDoing C++ formatting..." -find tensorflow_quantum/ -iname *.h -o -iname *.cc | xargs clang-format -i -style=google +find tensorflow_quantum/ -iname *.h -o -iname *.cc | xargs clang-format-6.0 -i -style=google echo "Done!" exit 0; diff --git a/scripts/format_check.sh b/scripts/format_check.sh index 1d91427e0..fb5b21ca1 100755 --- a/scripts/format_check.sh +++ b/scripts/format_check.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Checking python formatting..."; ################################################################################ @@ -92,7 +92,7 @@ else fi echo "Checking C++ formatting..."; -formatting_outputs=$(find tensorflow_quantum/ -iname *.h -o -iname *.cc | xargs clang-format -style=google -output-replacements-xml); +formatting_outputs=$(find tensorflow_quantum/ -iname *.h -o -iname *.cc | xargs clang-format-6.0 -style=google -output-replacements-xml); CFORMATCHECK=0 while read -r formatting_outputs; do if [ "$formatting_outputs" != "" ] && [ "$formatting_outputs" != "" ] && [ "$formatting_outputs" != "" ] && [ "$formatting_outputs" != " " ]; then diff --git a/scripts/format_ipynb.py b/scripts/format_ipynb.py index fac7a8bf1..10d2e447f 100644 --- a/scripts/format_ipynb.py +++ b/scripts/format_ipynb.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Format notebook code cells using yapf google style.""" import glob import nbformat diff --git a/scripts/import_test.py b/scripts/import_test.py index 5f4cb1850..ce2c87307 100644 --- a/scripts/import_test.py +++ b/scripts/import_test.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests to check if importing `tfq` APIs is successful or not.""" import tensorflow_quantum as tfq @@ -36,12 +36,22 @@ def test_imports(): # Math ops. _ = tfq.math.inner_product + _ = tfq.math.fidelity + _ = tfq.math.mps_1d_expectation + _ = tfq.math.mps_1d_sample + _ = tfq.math.mps_1d_sampled_expectation + + # Noisy simulation ops. + _ = tfq.noise.expectation + _ = tfq.noise.sampled_expectation + _ = tfq.noise.samples # Util functions. _ = tfq.convert_to_tensor _ = tfq.get_quantum_concurrent_op_mode _ = tfq.from_tensor _ = tfq.set_quantum_concurrent_op_mode + _ = tfq.util.get_supported_channels _ = tfq.util.get_supported_gates _ = tfq.util.exponential @@ -51,7 +61,11 @@ def test_imports(): _ = tfq.layers.Sample _ = tfq.layers.State _ = tfq.layers.SampledExpectation + + # High level Keras layers. _ = tfq.layers.ControlledPQC + _ = tfq.layers.NoisyControlledPQC + _ = tfq.layers.NoisyPQC _ = tfq.layers.PQC # Differentiators. @@ -69,6 +83,7 @@ def test_imports(): #Optimizers _ = tfq.optimizers.rotosolve_minimize + _ = tfq.optimizers.spsa_minimize if __name__ == "__main__": diff --git a/scripts/lint_all.sh b/scripts/lint_all.sh index fb7e1c9a5..755906981 100755 --- a/scripts/lint_all.sh +++ b/scripts/lint_all.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Checking for lint in python code..."; linting_outputs=$(pylint --rcfile .pylintrc ./tensorflow_quantum ./examples); exit_code=$? diff --git a/scripts/msan_test.sh b/scripts/msan_test.sh index 021b2e9c6..398332315 100755 --- a/scripts/msan_test.sh +++ b/scripts/msan_test.sh @@ -12,21 +12,21 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Testing All Bazel cc_tests with msan."; -test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \ +test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" \ --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" \ --cxxopt="-fsanitize=address" --linkopt="-fsanitize=address" \ --cxxopt="-g" --cxxopt="-O0" \ --notest_keep_going --test_output=errors \ //tensorflow_quantum/core/src:all && \ - bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \ + bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" \ --cxxopt="-mavx2" --cxxopt="-mavx" --cxxopt="-mfma" \ --cxxopt="-fsanitize=address" --linkopt="-fsanitize=address" \ --cxxopt="-g" --cxxopt="-O0" \ --notest_keep_going --test_output=errors \ //tensorflow_quantum/core/src:all && \ - bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" \ + bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" \ --cxxopt="-fsanitize=address" --linkopt="-fsanitize=address" \ --cxxopt="-g" --cxxopt="-O0" \ --notest_keep_going --test_output=errors \ diff --git a/scripts/run_example.sh b/scripts/run_example.sh index bb86edc22..1fbdd62d7 100755 --- a/scripts/run_example.sh +++ b/scripts/run_example.sh @@ -12,7 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= cd .. cp quantum/scripts/import_test.py import_test.py python import_test.py \ No newline at end of file diff --git a/scripts/test_all.sh b/scripts/test_all.sh index e5513bb12..ffb43d42d 100755 --- a/scripts/test_all.sh +++ b/scripts/test_all.sh @@ -12,9 +12,23 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Testing All Bazel py_test and cc_tests."; -test_outputs=$(bazel test -c opt --experimental_repo_remote_exec --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --notest_keep_going --test_output=errors //tensorflow_quantum/...) +ENABLE_CUDA=${1} + +if [[ ${ENABLE_CUDA} == "gpu" ]]; then + echo "GPU mode. CUDA config is set." + CUDA_CONFIG="--config=cuda" + # Tests all including cuquantum ops. + TAG_FILTER="" +else + echo "CPU mode." + CUDA_CONFIG="" + # Tests cpu only excluding cuquantum ops. + TAG_FILTER="--test_tag_filters=-cuquantum --build_tag_filters=-cuquantum" +fi + +test_outputs=$(bazel test -c opt ${CUDA_CONFIG} ${TAG_FILTER} --experimental_repo_remote_exec --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-std=c++17" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors //tensorflow_quantum/...) exit_code=$? if [ "$exit_code" == "0" ]; then echo "Testing Complete!"; @@ -23,4 +37,4 @@ else echo "Testing failed, please correct errors before proceeding." echo "{$test_outputs}" exit 64; -fi \ No newline at end of file +fi diff --git a/scripts/test_benchmarks.sh b/scripts/test_benchmarks.sh index d969a0d29..281791ec7 100644 --- a/scripts/test_benchmarks.sh +++ b/scripts/test_benchmarks.sh @@ -12,12 +12,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= echo "Testing all Benchmarks."; -bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/scripts:all) -# test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/scripts:all)) +bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/scripts:all) +# test_outputs=$(bazel test -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors $(bazel query //benchmarks/scripts:all)) bench_outputs=$() -# bench_outputs=$(bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors //benchmarks/scripts:benchmark_clifford_circuit) +# bench_outputs=$(bazel run -c opt --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=1" --cxxopt="-msse2" --cxxopt="-msse3" --cxxopt="-msse4" --test_output=errors //benchmarks/scripts:benchmark_clifford_circuit) exit_code=$? if [ "$exit_code" == "0" ]; then echo "Testing Complete!"; diff --git a/scripts/test_tutorials.py b/scripts/test_tutorials.py index 3db40ac03..b4463b90d 100644 --- a/scripts/test_tutorials.py +++ b/scripts/test_tutorials.py @@ -11,14 +11,14 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to ensure all notebooks execute without error by pytesting them.""" import glob import re from absl.testing import parameterized import nbformat -import nbconvert +import nbclient import tensorflow as tf # Must be run from the directory containing `quantum` repo. @@ -40,11 +40,13 @@ def test_notebook(self, path): src = re.sub(r'\!(?!=)', r'#!', src) # For mnist.ipynb to reduce runtime in test. src = re.sub('NUM_EXAMPLES ?= ?.*', 'NUM_EXAMPLES = 10', src) + # For quantum_reinforcement_learning.ipynb to reduce runtime in test. + src = re.sub('n_episodes ?= ?.*', 'n_episodes = 50', src) + # For noise.ipynb to reduce runtime in test. + src = re.sub('n_epochs ?= ?.*', 'n_epochs = 2', src) cell['source'] = src - _ = nbconvert.preprocessors.execute.executenb(nb, - timeout=900, - kernel_name="python3") + _ = nbclient.execute(nb, timeout=900, kernel_name="python3") if __name__ == "__main__": diff --git a/tensorflow_quantum/__init__.py b/tensorflow_quantum/__init__.py index e4f62ea17..67d66f403 100644 --- a/tensorflow_quantum/__init__.py +++ b/tensorflow_quantum/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module functions for tensorflow_quantum.*""" # Import basic ops and op getters. @@ -24,6 +24,9 @@ # Import math ops. from tensorflow_quantum.core import math_ops as math +# Import noise ops. +from tensorflow_quantum.core import noise + # Re-label python module as layers module. import tensorflow_quantum.python.layers as layers @@ -61,4 +64,4 @@ del core # pylint: enable=undefined-variable -__version__ = '0.5.0' +__version__ = '0.8.0' diff --git a/tensorflow_quantum/core/BUILD b/tensorflow_quantum/core/BUILD index fd4e75c2e..a7268b652 100644 --- a/tensorflow_quantum/core/BUILD +++ b/tensorflow_quantum/core/BUILD @@ -4,3 +4,15 @@ licenses(["notice"]) # Export for the PIP package. exports_files(["__init__.py"]) + +py_library( + name = "core", + srcs = ["__init__.py"], + srcs_version = "PY3", + deps = [ + "//tensorflow_quantum/core/ops", + "//tensorflow_quantum/core/proto:pauli_sum_py_proto", + "//tensorflow_quantum/core/proto:projector_sum_py_proto", + "//tensorflow_quantum/core/serialize", + ], +) diff --git a/tensorflow_quantum/core/__init__.py b/tensorflow_quantum/core/__init__.py index 94dd5fc2c..7e43c4be5 100644 --- a/tensorflow_quantum/core/__init__.py +++ b/tensorflow_quantum/core/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Imports to tensorflow_quantum.core.* level.""" # Import getters for constructing ops. from tensorflow_quantum.core.ops import (get_expectation_op, @@ -23,3 +23,6 @@ padded_to_ragged2d, resolve_parameters) # Import math ops. from tensorflow_quantum.core.ops import math_ops + +# Import noise ops. +from tensorflow_quantum.core.ops import noise diff --git a/tensorflow_quantum/core/ops/BUILD b/tensorflow_quantum/core/ops/BUILD index b6332409b..cb764f25c 100644 --- a/tensorflow_quantum/core/ops/BUILD +++ b/tensorflow_quantum/core/ops/BUILD @@ -1,3 +1,5 @@ +load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured") + package(default_visibility = ["//visibility:public"]) licenses(["notice"]) @@ -10,6 +12,47 @@ config_setting( constraint_values = ["@bazel_tools//platforms:windows"], ) +cc_library( + name = "cuda", + data = [ + "@local_config_cuda//cuda:cudart", + ], + linkopts = select({ + ":windows": [], + "//conditions:default": [ + "-Wl,-rpath,../local_config_cuda/cuda/lib64", + "-Wl,-rpath,../local_config_cuda/cuda/extras/CUPTI/lib64", + ], + }), + deps = [ + "@local_config_cuda//cuda:cudart", + ], +) + +py_library( + name = "ops", + srcs = ["__init__.py"], + srcs_version = "PY3", + deps = [ + ":batch_util", + ":circuit_execution_ops", + ":cirq_ops", + ":load_module", + ":tfq_adj_grad_op_py", + ":tfq_ps_util_ops_py", + ":tfq_simulate_ops_py", + ":tfq_unitary_op_py", + ":tfq_utility_ops_py", + # test addons + "//tensorflow_quantum/core/ops/math_ops:inner_product_op_py", + "//tensorflow_quantum/core/ops/math_ops:fidelity_op_py", + "//tensorflow_quantum/core/ops/noise:noisy_expectation_op_py", + ] + if_cuda_is_configured([ + ":tfq_simulate_ops_cuquantum_py", + ":tfq_adj_grad_op_cuquantum_py", + ]), +) + cc_binary( name = "_tfq_adj_grad.so", srcs = [ @@ -32,7 +75,7 @@ cc_binary( "-DNOGDI", "/d2ReducedOptimizeHugeFunctions", "/arch:AVX", - "/std:c++14", + "/std:c++17", "-DTENSORFLOW_MONOLITHIC_BUILD", "/DPLATFORM_WINDOWS", "/DEIGEN_HAS_C99_MATH", @@ -46,8 +89,8 @@ cc_binary( ], "//conditions:default": [ "-pthread", - "-std=c++11", - "-D_GLIBCXX_USE_CXX11_ABI=0", + "-std=c++17", + "-D_GLIBCXX_USE_CXX11_ABI=1", ], }), features = select({ @@ -57,11 +100,17 @@ cc_binary( linkshared = 1, deps = [ ":parse_context", + # cirq cc proto + # pauli sum cc proto + # projector sum cc proto ":tfq_simulate_utils", - "//tensorflow_quantum/core/src:util_qsim", - "//tensorflow_quantum/core/src:circuit_parser_qsim", "//tensorflow_quantum/core/src:adj_util", + "//tensorflow_quantum/core/src:circuit_parser_qsim", + "//tensorflow_quantum/core/src:util_qsim", "@qsim//lib:qsim_lib", + # tensorflow core framework + # tensorflow core lib + # tensorflow core protos ], ) @@ -89,7 +138,7 @@ cc_binary( "-DNOGDI", "/d2ReducedOptimizeHugeFunctions", "/arch:AVX", - "/std:c++14", + "/std:c++17", "-DTENSORFLOW_MONOLITHIC_BUILD", "/DPLATFORM_WINDOWS", "/DEIGEN_HAS_C99_MATH", @@ -103,8 +152,8 @@ cc_binary( ], "//conditions:default": [ "-pthread", - "-std=c++11", - "-D_GLIBCXX_USE_CXX11_ABI=0", + "-std=c++17", + "-D_GLIBCXX_USE_CXX11_ABI=1", ], }), features = select({ @@ -115,6 +164,7 @@ cc_binary( deps = [ ":parse_context", ":tfq_simulate_utils", + # cirq cc proto "//tensorflow_quantum/core/proto:program_cc_proto", "@local_config_tf//:libtensorflow_framework", "@local_config_tf//:tf_header_lib", @@ -125,9 +175,9 @@ cc_binary( name = "_tfq_simulate_ops.so", srcs = [ "tfq_simulate_expectation_op.cc", - "tfq_simulate_samples_op.cc", "tfq_simulate_sampled_expectation_op.cc", - "tfq_simulate_state_op.cc" + "tfq_simulate_samples_op.cc", + "tfq_simulate_state_op.cc", ], copts = select({ ":windows": [ @@ -146,7 +196,7 @@ cc_binary( "-DNOGDI", "/d2ReducedOptimizeHugeFunctions", "/arch:AVX", - "/std:c++14", + "/std:c++17", "-DTENSORFLOW_MONOLITHIC_BUILD", "/DPLATFORM_WINDOWS", "/DEIGEN_HAS_C99_MATH", @@ -160,8 +210,8 @@ cc_binary( ], "//conditions:default": [ "-pthread", - "-std=c++11", - "-D_GLIBCXX_USE_CXX11_ABI=0", + "-std=c++17", + "-D_GLIBCXX_USE_CXX11_ABI=1", ], }), features = select({ @@ -172,20 +222,20 @@ cc_binary( deps = [ ":parse_context", ":tfq_simulate_utils", - - "//tensorflow_quantum/core/src:util_qsim", - "//tensorflow_quantum/core/src:circuit_parser_qsim", - "@qsim//lib:qsim_lib", - + # cirq cc proto "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", "//tensorflow_quantum/core/proto:program_cc_proto", + "//tensorflow_quantum/core/proto:projector_sum_cc_proto", + "//tensorflow_quantum/core/src:circuit_parser_qsim", "//tensorflow_quantum/core/src:program_resolution", + "//tensorflow_quantum/core/src:util_qsim", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:inlined_vector", "@com_google_absl//absl/types:optional", "@com_google_absl//absl/types:span", "@local_config_tf//:libtensorflow_framework", "@local_config_tf//:tf_header_lib", + "@qsim//lib:qsim_lib", ], ) @@ -212,7 +262,7 @@ cc_binary( "-DNOGDI", "/d2ReducedOptimizeHugeFunctions", "/arch:AVX", - "/std:c++14", + "/std:c++17", "-DTENSORFLOW_MONOLITHIC_BUILD", "/DPLATFORM_WINDOWS", "/DEIGEN_HAS_C99_MATH", @@ -226,8 +276,8 @@ cc_binary( ], "//conditions:default": [ "-pthread", - "-std=c++11", - "-D_GLIBCXX_USE_CXX11_ABI=0", + "-std=c++17", + "-D_GLIBCXX_USE_CXX11_ABI=1", ], }), features = select({ @@ -238,7 +288,9 @@ cc_binary( deps = [ ":parse_context", ":tfq_simulate_utils", + # cirq cc proto "//tensorflow_quantum/core/proto:program_cc_proto", + "//tensorflow_quantum/core/src:program_resolution", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:inlined_vector", "@com_google_absl//absl/types:optional", @@ -252,10 +304,46 @@ cc_library( name = "parse_context", srcs = ["parse_context.cc"], hdrs = ["parse_context.h"], + copts = select({ + ":windows": [ + "/D__CLANG_SUPPORT_DYN_ANNOTATION__", + "/D_USE_MATH_DEFINES", + "/DEIGEN_MPL2_ONLY", + "/DEIGEN_MAX_ALIGN_BYTES=64", + "/DEIGEN_HAS_TYPE_TRAITS=0", + "/DTF_USE_SNAPPY", + "/showIncludes", + "/MD", + "/O2", + "/DNDEBUG", + "/w", + "-DWIN32_LEAN_AND_MEAN", + "-DNOGDI", + "/d2ReducedOptimizeHugeFunctions", + "/arch:AVX", + "/std:c++17", + "-DTENSORFLOW_MONOLITHIC_BUILD", + "/DPLATFORM_WINDOWS", + "/DEIGEN_HAS_C99_MATH", + "/DTENSORFLOW_USE_EIGEN_THREADPOOL", + "/DEIGEN_AVOID_STL_ARRAY", + "/Iexternal/gemmlowp", + "/wd4018", + "/wd4577", + "/DNOGDI", + "/UTF_COMPILE_LIBRARY", + ], + "//conditions:default": [ + "-pthread", + "-std=c++17", + "-D_GLIBCXX_USE_CXX11_ABI=1", + ], + }), deps = [ ":tfq_simulate_utils", "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", "//tensorflow_quantum/core/proto:program_cc_proto", + "//tensorflow_quantum/core/proto:projector_sum_cc_proto", "//tensorflow_quantum/core/src:program_resolution", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:inlined_vector", @@ -267,7 +355,7 @@ cc_library( cc_binary( name = "_tfq_calculate_unitary_op.so", srcs = [ - "tfq_calculate_unitary_op.cc" + "tfq_calculate_unitary_op.cc", ], copts = select({ ":windows": [ @@ -286,7 +374,7 @@ cc_binary( "-DNOGDI", "/d2ReducedOptimizeHugeFunctions", "/arch:AVX", - "/std:c++14", + "/std:c++17", "-DTENSORFLOW_MONOLITHIC_BUILD", "/DPLATFORM_WINDOWS", "/DEIGEN_HAS_C99_MATH", @@ -300,8 +388,8 @@ cc_binary( ], "//conditions:default": [ "-pthread", - "-std=c++11", - "-D_GLIBCXX_USE_CXX11_ABI=0", + "-std=c++17", + "-D_GLIBCXX_USE_CXX11_ABI=1", ], }), features = select({ @@ -311,10 +399,12 @@ cc_binary( linkshared = 1, deps = [ ":parse_context", + # cirq cc proto "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", "//tensorflow_quantum/core/proto:program_cc_proto", - "//tensorflow_quantum/core/src:util_qsim", + "//tensorflow_quantum/core/proto:projector_sum_cc_proto", "//tensorflow_quantum/core/src:circuit_parser_qsim", + "//tensorflow_quantum/core/src:util_qsim", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:inlined_vector", "@com_google_absl//absl/types:optional", @@ -329,6 +419,41 @@ cc_library( name = "tfq_simulate_utils", srcs = ["tfq_simulate_utils.cc"], hdrs = ["tfq_simulate_utils.h"], + copts = select({ + ":windows": [ + "/D__CLANG_SUPPORT_DYN_ANNOTATION__", + "/D_USE_MATH_DEFINES", + "/DEIGEN_MPL2_ONLY", + "/DEIGEN_MAX_ALIGN_BYTES=64", + "/DEIGEN_HAS_TYPE_TRAITS=0", + "/DTF_USE_SNAPPY", + "/showIncludes", + "/MD", + "/O2", + "/DNDEBUG", + "/w", + "-DWIN32_LEAN_AND_MEAN", + "-DNOGDI", + "/d2ReducedOptimizeHugeFunctions", + "/arch:AVX", + "/std:c++17", + "-DTENSORFLOW_MONOLITHIC_BUILD", + "/DPLATFORM_WINDOWS", + "/DEIGEN_HAS_C99_MATH", + "/DTENSORFLOW_USE_EIGEN_THREADPOOL", + "/DEIGEN_AVOID_STL_ARRAY", + "/Iexternal/gemmlowp", + "/wd4018", + "/wd4577", + "/DNOGDI", + "/UTF_COMPILE_LIBRARY", + ], + "//conditions:default": [ + "-pthread", + "-std=c++17", + "-D_GLIBCXX_USE_CXX11_ABI=1", + ], + }), deps = [ "@local_config_tf//:libtensorflow_framework", "@local_config_tf//:tf_header_lib", @@ -339,16 +464,22 @@ py_library( name = "tfq_adj_grad_op_py", srcs = ["tfq_adj_grad_op.py"], data = [":_tfq_adj_grad.so"], + srcs_version = "PY3", deps = [ ":load_module", - ] + # pauli sum cc proto + # projector sum cc proto + # tensorflow framework for wrappers + ], ) py_library( name = "tfq_unitary_op_py", srcs = ["tfq_unitary_op.py"], data = [":_tfq_calculate_unitary_op.so"], + srcs_version = "PY3", deps = [ + # tensorflow framework for wrappers ":load_module", ":tfq_utility_ops_py", "//tensorflow_quantum/python:quantum_context", @@ -362,11 +493,12 @@ py_test( deps = [ ":tfq_adj_grad_op_py", "//tensorflow_quantum/python:util", - ] + ], ) py_test( name = "tfq_unitary_op_test", + timeout = "long", srcs = ["tfq_unitary_op_test.py"], python_version = "PY3", deps = [ @@ -379,7 +511,9 @@ py_library( name = "tfq_simulate_ops_py", srcs = ["tfq_simulate_ops.py"], data = [":_tfq_simulate_ops.so"], + srcs_version = "PY3", deps = [ + # tensorflow framework for wrappers ":load_module", ], ) @@ -397,12 +531,15 @@ py_test( py_library( name = "circuit_execution_ops", srcs = ["circuit_execution_ops.py"], + srcs_version = "PY3", deps = [ ":cirq_ops", ":tfq_simulate_ops_py", ":tfq_utility_ops_py", "//tensorflow_quantum/python:quantum_context", - ], + ] + if_cuda_is_configured([ + ":tfq_simulate_ops_cuquantum_py", + ]), ) py_test( @@ -419,8 +556,12 @@ py_test( py_library( name = "cirq_ops", srcs = ["cirq_ops.py"], + srcs_version = "PY3", deps = [ ":batch_util", + "//tensorflow_quantum/core/proto:program_py_proto", + "//tensorflow_quantum/core/proto:pauli_sum_py_proto", + "//tensorflow_quantum/core/proto:projector_sum_py_proto", "//tensorflow_quantum/core/serialize:serializer", ], ) @@ -440,6 +581,7 @@ py_test( py_library( name = "batch_util", srcs = ["batch_util.py"], + srcs_version = "PY3", deps = [ "//tensorflow_quantum/core/serialize:serializer", ], @@ -460,7 +602,9 @@ py_library( name = "tfq_ps_util_ops_py", srcs = ["tfq_ps_util_ops.py"], data = [":_tfq_ps_utils.so"], + srcs_version = "PY3", deps = [ + # tensorflow framework for wrappers ":load_module", ], ) @@ -479,7 +623,9 @@ py_library( name = "tfq_utility_ops_py", srcs = ["tfq_utility_ops.py"], data = [":_tfq_utility_ops.so"], + srcs_version = "PY3", deps = [ + # tensorflow framework for wrappers ":load_module", ], ) @@ -495,8 +641,225 @@ py_test( ], ) +py_library( + name = "tfq_simulate_ops_cuquantum_py", + srcs = ["tfq_simulate_ops_cuquantum.py"], + data = [ + ":_tfq_simulate_ops_cuquantum.so", + ], + srcs_version = "PY3", + deps = [ + # tensorflow framework for wrappers + ":load_module", + ], + tags = ["cuquantum"], +) + +py_test( + name = "tfq_simulate_ops_cuquantum_test", + timeout = "long", + srcs = ["tfq_simulate_ops_cuquantum_test.py"], + deps = [ + ":tfq_simulate_ops_cuquantum_py", + ":tfq_simulate_ops_py", + "//tensorflow_quantum/python:util", + ], + srcs_version = "PY3", + tags = ["cuquantum"], +) + +cc_binary( + name = "_tfq_simulate_ops_cuquantum.so", + srcs = [ + "tfq_simulate_expectation_op_cuquantum.cu.cc", + "tfq_simulate_sampled_expectation_op_cuquantum.cu.cc", + "tfq_simulate_samples_op_cuquantum.cu.cc", + "tfq_simulate_state_op_cuquantum.cu.cc", + ], + linkshared = 1, + features = select({ + ":windows": ["windows_export_all_symbols"], + "//conditions:default": [], + }), + copts = select({ + ":windows": [ + "/D__CLANG_SUPPORT_DYN_ANNOTATION__", + "/D_USE_MATH_DEFINES", + "/DEIGEN_MPL2_ONLY", + "/DEIGEN_MAX_ALIGN_BYTES=64", + "/DEIGEN_HAS_TYPE_TRAITS=0", + "/DTF_USE_SNAPPY", + "/showIncludes", + "/MD", + "/O2", + "/DNDEBUG", + "/w", + "-DWIN32_LEAN_AND_MEAN", + "-DNOGDI", + "/d2ReducedOptimizeHugeFunctions", + "/arch:AVX", + "/std:c++17", + "-DTENSORFLOW_MONOLITHIC_BUILD", + "/DPLATFORM_WINDOWS", + "/DEIGEN_HAS_C99_MATH", + "/DTENSORFLOW_USE_EIGEN_THREADPOOL", + "/DEIGEN_AVOID_STL_ARRAY", + "/Iexternal/gemmlowp", + "/wd4018", + "/wd4577", + "/DNOGDI", + "/UTF_COMPILE_LIBRARY", + "/D__CUSTATEVEC__", + ], + "//conditions:default": [ + "-Iexternal/local_cuda/cuda/include", + "-pthread", + "-std=c++17", + "-D_GLIBCXX_USE_CXX11_ABI=1", + "-O3", + "-Iexternal/cuda_headers", + "-DNV_CUDNN_DISABLE_EXCEPTION", + # "-fpermissive", + ], + }) + if_cuda_is_configured([ + "-DTENSORFLOW_USE_NVCC=1", + "-DGOOGLE_CUDA=1", + "-x cuda", + "-nvcc_options=relaxed-constexpr", + "-nvcc_options=ftz=true", + "-D__CUSTATEVEC__", + ]), + deps = [ + # cirq cc proto + "//tensorflow_quantum/core/ops:parse_context", + "//tensorflow_quantum/core/ops:tfq_simulate_utils", + "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", + "//tensorflow_quantum/core/proto:program_cc_proto", + "//tensorflow_quantum/core/src:circuit_parser_qsim", + "//tensorflow_quantum/core/src:util_qsim", + "@eigen//:eigen3", + # "@local_cuda//:cuda_headers" + # tensorflow core framework + # tensorflow core lib + # tensorflow core protos + ] + if_cuda_is_configured([ + ":cuda", + "@local_config_cuda//cuda:cuda_headers", + "@local_config_cuquantum//:cuquantum_headers", + "@local_config_cuquantum//:libcuquantum", + "@qsim//lib:qsim_cuquantum_lib", + ]), + tags = ["cuquantum"], + # alwayslink=1, +) + +cc_binary( + name = "_tfq_adj_grad_cuquantum.so", + srcs = [ + "tfq_adj_grad_op_cuquantum.cu.cc", + ], + linkshared = 1, + features = select({ + ":windows": ["windows_export_all_symbols"], + "//conditions:default": [], + }), + copts = select({ + ":windows": [ + "/D__CLANG_SUPPORT_DYN_ANNOTATION__", + "/D_USE_MATH_DEFINES", + "/DEIGEN_MPL2_ONLY", + "/DEIGEN_MAX_ALIGN_BYTES=64", + "/DEIGEN_HAS_TYPE_TRAITS=0", + "/DTF_USE_SNAPPY", + "/showIncludes", + "/MD", + "/O2", + "/DNDEBUG", + "/w", + "-DWIN32_LEAN_AND_MEAN", + "-DNOGDI", + "/d2ReducedOptimizeHugeFunctions", + "/arch:AVX", + "/std:c++17", + "-DTENSORFLOW_MONOLITHIC_BUILD", + "/DPLATFORM_WINDOWS", + "/DEIGEN_HAS_C99_MATH", + "/DTENSORFLOW_USE_EIGEN_THREADPOOL", + "/DEIGEN_AVOID_STL_ARRAY", + "/Iexternal/gemmlowp", + "/wd4018", + "/wd4577", + "/DNOGDI", + "/UTF_COMPILE_LIBRARY", + "/D__CUSTATEVEC__", + ], + "//conditions:default": [ + "-Iexternal/local_cuda/cuda/include", + "-pthread", + "-std=c++17", + "-D_GLIBCXX_USE_CXX11_ABI=1", + "-O3", + "-Iexternal/cuda_headers", + "-DNV_CUDNN_DISABLE_EXCEPTION", + # "-fpermissive", + ], + }) + if_cuda_is_configured([ + "-DTENSORFLOW_USE_NVCC=1", + "-DGOOGLE_CUDA=1", + "-x cuda", + "-nvcc_options=relaxed-constexpr", + "-nvcc_options=ftz=true", + "-D__CUSTATEVEC__", + ]), + deps = [ + "//tensorflow_quantum/core/ops:parse_context", + "//tensorflow_quantum/core/src:util_qsim", + "//tensorflow_quantum/core/src:adj_util", + # "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", + # "//tensorflow_quantum/core/proto:program_cc_proto", + # "//tensorflow_quantum/core/src:circuit_parser_qsim", + # "@eigen//:eigen3", + ] + if_cuda_is_configured([ + ":cuda", + "@local_config_cuda//cuda:cuda_headers", + "@local_config_cuquantum//:cuquantum_headers", + "@local_config_cuquantum//:libcuquantum", + "@qsim//lib:qsim_cuquantum_lib", + ]), + tags = ["cuquantum"], + # alwayslink=1, +) + +py_library( + name = "tfq_adj_grad_op_cuquantum_py", + srcs = ["tfq_adj_grad_op_cuquantum.py"], + data = [":_tfq_adj_grad_cuquantum.so"], + srcs_version = "PY3", + deps = [ + ":load_module", + # pauli sum cc proto + # projector sum cc proto + # tensorflow framework for wrappers + ], + tags = ["cuquantum"], +) + +py_test( + name = "tfq_adj_grad_op_cuquantum_test", + srcs = ["tfq_adj_grad_op_cuquantum_test.py"], + python_version = "PY3", + deps = [ + ":tfq_adj_grad_op_cuquantum_py", + ":tfq_adj_grad_op_py", # for testing cpu vs gpu diff + "//tensorflow_quantum/python:util", + ], + srcs_version = "PY3", + tags = ["cuquantum"], +) + py_library( name = "load_module", srcs = ["load_module.py"], + srcs_version = "PY3", deps = [], ) diff --git a/tensorflow_quantum/core/ops/__init__.py b/tensorflow_quantum/core/ops/__init__.py index 8c553a74c..fc687424a 100644 --- a/tensorflow_quantum/core/ops/__init__.py +++ b/tensorflow_quantum/core/ops/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.core.ops.*""" # Import getters for constructing ops. @@ -27,3 +27,6 @@ # Import math_ops. from tensorflow_quantum.core.ops import math_ops + +# Import noise ops. +from tensorflow_quantum.core.ops import noise diff --git a/tensorflow_quantum/core/ops/batch_util.py b/tensorflow_quantum/core/ops/batch_util.py index a60c9eaa7..7575ffae1 100644 --- a/tensorflow_quantum/core/ops/batch_util.py +++ b/tensorflow_quantum/core/ops/batch_util.py @@ -11,22 +11,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== -"""A module to for running Cirq Simulators in parallel.""" -import asyncio +# ============================================================================= +"""A module to for running Cirq objects.""" import collections -import itertools -import os -import multiprocessing as mp -from multiprocessing.pool import Pool as ProcessPool import numpy as np import cirq -from tensorflow_quantum.core.serialize import serializer - -# TODO (mbbrough): Remove this workaround class once cirq.PauliSumCollector can +# TODO (#563): Remove this workaround class once cirq.PauliSumCollector can # be used end to end with engine. This current issue is that # cirq.PauliSumCollector does not produce serializable gates for basis # conversion. @@ -79,6 +72,20 @@ def on_job_result(self, job, result): self._zeros[job_id] += parities[0] self._ones[job_id] += parities[1] + def collect(self, sampler): + """Synchronus collect.""" + # See #562, this is a workaround to an event loop issue in the tutorials + # see also: + # https://stackoverflow.com/questions/55409641/asyncio-run-cannot-be-called-from-a-running-event-loop + while True: + next_job = self.next_job() + if next_job is None: + return + + bitstrings = sampler.run(next_job.circuit, + repetitions=next_job.repetitions) + self.on_job_result(next_job, bitstrings) + def estimated_energy(self): """Sums up the sampled expectations, weighted by their coefficients.""" energy = 0j @@ -108,206 +115,6 @@ def _fixed_circuit_plus_pauli_string_measurements(circuit, pauli_string): return circuit -def _make_complex_view(shape, init_val): - """Build a RawArray that will map to the real and imaginary parts of a - complex number.""" - shape = list(shape) - shape[-1] *= 2 - data = np.ones(shape, dtype=np.float32) * init_val - - flattened_size = 1 - for dim_size in shape: - flattened_size *= dim_size - shared_mem_array = mp.RawArray('f', flattened_size) - np_view = np.frombuffer(shared_mem_array, dtype=np.float32).reshape(shape) - np.copyto(np_view, data) - return shared_mem_array - - -def _convert_complex_view_to_np(view, shape): - """Get a numpy view ontop of the rawarray view. Small overhead.""" - shape = list(shape) - shape[-1] *= 2 - return np.frombuffer(view, dtype=np.float32).reshape(shape) - - -def _update_complex_np(np_view, i, to_add): - """Update the shared memory undernath the numpy view. - to_add is passed by reference since we don't do much with it.""" - np_view[i, ...] = np.pad(to_add, - (0, (np_view.shape[-1] // 2 - to_add.shape[-1])), - 'constant', - constant_values=-2).view(np.float32) - - -def _convert_complex_view_to_result(view, shape): - """Convert a rawarray view to a numpy array and reindex so that - the underlying pair of double arrays are squished together to make a - complex array of half the underlying size.""" - shape = list(shape) - shape[-1] *= 2 - np_view = np.frombuffer(view, dtype=np.float32).reshape(shape) - - # The below view will cause a re-interpretation of underlying - # memory so use sparingly. - return np_view.view(np.complex64) - - -def _make_simple_view(shape, init_val, dtype, c_code): - """Make a shared memory view for floating type.""" - data = np.ones(shape, dtype=dtype) * init_val - flattened_size = 1 - for dim_size in shape: - flattened_size *= dim_size - shared_mem_array = mp.RawArray(c_code, flattened_size) - np_view = np.frombuffer(shared_mem_array, dtype=dtype).reshape(shape) - np.copyto(np_view, data) - return shared_mem_array - - -def _convert_simple_view_to_np(view, dtype, shape): - """Create a numpy view to a float array, low overhead.""" - return np.frombuffer(view, dtype=dtype).reshape(shape) - - -def _batch_update_simple_np(np_view, i, to_add): - """Update the shared memory underneath the numpy view. - to_add is again passed by reference.""" - np_view[i, ...] = to_add - - -def _pointwise_update_simple_np(np_view, i, j, to_add): - """Do a batch and sub-batch index update to numpy view.""" - np_view[i, j, ...] = to_add - - -def _convert_simple_view_to_result(view, dtype, shape): - """Convert a RawArray view to final numpy array.""" - return np.frombuffer(view, dtype=dtype).reshape(shape) - - -def _prep_pool_input_args(indices, *args, slice_args=True): - """Break down a set of indices, and optional args into a generator - of length cpu_count.""" - block_size = int(np.ceil(len(indices) / os.cpu_count())) - for i in range(0, len(indices), block_size): - if slice_args: - yield tuple([indices[i:i + block_size]] + - [x[i:i + block_size] for x in args]) - else: - yield tuple([indices[i:i + block_size]] + [x for x in args]) - - -# process are separate from all the other processes, -# so INFO_DICTs will not step on each other. -INFO_DICT = {} - - -def _setup_dict(array_view, view_shape, simulator, post_process): - INFO_DICT['arr'] = array_view - INFO_DICT['shape'] = view_shape - INFO_DICT['sim'] = simulator - INFO_DICT['post_process'] = post_process - - -def _state_worker_func(indices, programs, params): - """Compute the state vector for each program in indices.""" - x_np = _convert_complex_view_to_np(INFO_DICT['arr'], INFO_DICT['shape']) - simulator = INFO_DICT['sim'] - - for i, index in enumerate(indices): - result = simulator.simulate(programs[i], params[i]) - final_array = INFO_DICT['post_process'](result).astype(np.complex64) - _update_complex_np(x_np, index, final_array) - - -def _analytical_expectation_worker_func(indices, programs, params, ops): - """Compute the expectation of the op[batch_index], w.r.t - circuit[batch_index] where batch_index is calculated from indices.""" - x_np = _convert_simple_view_to_np(INFO_DICT['arr'], np.float32, - INFO_DICT['shape']) - simulator = INFO_DICT['sim'] - - # TODO: remove this when picklable. - for i in range(len(ops)): - for j in range(len(ops[i])): - ops[i][j] = serializer.deserialize_paulisum(ops[i][j]) - - old_batch_index = -2 - state = -1 - for i, index_tuple in enumerate(indices): - batch_index = index_tuple[0] - op_index = index_tuple[1] - # (#679) Just ignore empty programs. - if len(programs[batch_index].all_qubits()) == 0: - continue - - if old_batch_index != batch_index: - # must compute a new state vector. - qubit_oder = dict( - zip(sorted(programs[batch_index].all_qubits()), - list(range(len(programs[batch_index].all_qubits()))))) - state = simulator.simulate(programs[batch_index], - params[batch_index]) - - result = INFO_DICT['post_process'](ops[batch_index][op_index], state, - qubit_oder) - _pointwise_update_simple_np(x_np, batch_index, op_index, result) - old_batch_index = batch_index - - -def _sample_expectation_worker_func(indices, programs, params, ops, n_samples): - x_np = _convert_simple_view_to_np(INFO_DICT['arr'], np.float32, - INFO_DICT['shape']) - simulator = INFO_DICT['sim'] - - # TODO: remove this when picklable. - for i in range(len(ops)): - for j in range(len(ops[i])): - ops[i][j] = serializer.deserialize_paulisum(ops[i][j]) - - for i, index_tuple in enumerate(indices): - batch_index = index_tuple[0] - op_index = index_tuple[1] - # (#679) Just ignore empty programs. - if len(programs[batch_index].all_qubits()) == 0: - continue - circuit = cirq.resolve_parameters(programs[batch_index], - params[batch_index]) - - sampler = TFQPauliSumCollector( - circuit, - ops[batch_index][op_index], - samples_per_term=n_samples[batch_index][op_index]) - - asyncio.set_event_loop(asyncio.new_event_loop()) - sampler.collect(simulator, concurrency=1) - result = sampler.estimated_energy().real - - _pointwise_update_simple_np(x_np, batch_index, op_index, result) - - -def _sample_worker_func(indices, programs, params, n_samples): - """Sample n_samples from progams[i] with params[i] placed in it.""" - x_np = _convert_simple_view_to_np(INFO_DICT['arr'], np.int32, - INFO_DICT['shape']) - simulator = INFO_DICT['sim'] - - for i, index in enumerate(indices): - qubits = sorted(programs[i].all_qubits()) - # (#679) Just ignore empty programs. - if len(qubits) == 0: - continue - state = simulator.simulate(programs[i], params[i]) - samples = INFO_DICT['post_process'](state, len(qubits), - n_samples[i]).astype(np.int32) - _batch_update_simple_np( - x_np, index, - np.pad(samples, ((0, 0), (x_np.shape[2] - len(qubits), 0)), - 'constant', - constant_values=-2)) - - def _validate_inputs(circuits, param_resolvers, simulator, sim_type): """Type check and sanity check inputs.""" if not isinstance(circuits, (list, tuple, np.ndarray)): @@ -333,6 +140,17 @@ def _validate_inputs(circuits, param_resolvers, simulator, sim_type): raise TypeError('For analytic operations only' ' cirq.SimulatesFinalState' ' is required. Given: {}'.format(type(simulator))) + + elif sim_type == 'expectation': + if not isinstance(simulator, + (cirq.sim.simulator.SimulatesExpectationValues, + cirq.DensityMatrixSimulator)): + # TODO(zaqqwerty): remove DM sim check once cirq #3964 is resolved. + raise TypeError('For expectation operations a ' + 'cirq.sim.simulator.SimulatesExpectationValues ' + 'or cirq.DensityMatrixSimulator' + 'is required. Given: {}'.format(type(simulator))) + elif sim_type == 'sample': if not isinstance(simulator, cirq.Sampler): raise TypeError('For sample based operations a cirq.Sampler is ' @@ -341,62 +159,67 @@ def _validate_inputs(circuits, param_resolvers, simulator, sim_type): raise ValueError('Invalid simulator type specified.') +def _check_empty(circuits): + """Returns true if circuits is the empty tensor.""" + return len(circuits) == 0 + + def batch_calculate_state(circuits, param_resolvers, simulator): - """Compute states using a given simulator using parallel processing. + """Compute states from a batch of circuits. Returns a NumPy array containing the final circuit state for each `cirq.Circuit` in `circuits`, given that the corresponding `cirq.ParamResolver` in `param_resolvers` was used to resolve any symbols in it. If simulator is a `cirq.DensityMatrixSimulator` this final state will - be a density matrix, if simulator is a `cirq.Simulator` this final state - will be a state vector. More specifically for a given `i` - `batch_calculate_state` will use `param_resolvers[i]` to resolve the symbols - in `circuits[i]` and then place the final state in the return list at index - `i`. + be a density matrix, else this final state will be a state vector. More + specifically, for a given `i`, `batch_calculate_state` will use + `param_resolvers[i]` to resolve the symbols in `circuits[i]` and then place + the final state in the return list at index `i`. Args: circuits: Python `list` of `cirq.Circuit`s. param_resolvers: Python `list` of `cirq.ParamResolver`s, where `param_resolvers[i]` is the resolver to be used with `circuits[i]`. - simulator: Simulator object. Currently - supported are `cirq.DensityMatrixSimulator` and `cirq.Simulator`. + simulator: Simulator object. Can be any `cirq.SimulatesFinalState`; + if `simulator` is not a `cirq.DensityMatrixSimulator`, this function + assumes all final states are dense state vectors. Returns: - `np.ndarray` containing the resulting state information. The array will - have dimensions: [len(circuits), ] in the - case of `cirq.Simulator`. In the case of `cirq.DensityMatrixSimulator` - the shape is - [len(circuits), , ] + `np.ndarray` containing the resulting state information. In the case of + `cirq.DensityMatrixSimulator` the shape is + [len(circuits), , ], else + the shape is [len(circuits), ]. """ _validate_inputs(circuits, param_resolvers, simulator, 'analytic') + if _check_empty(circuits): + empty_ret = np.zeros((0, 0), dtype=np.complex64) + if isinstance(simulator, cirq.DensityMatrixSimulator): + empty_ret = np.zeros((0, 0, 0), dtype=np.complex64) + return empty_ret biggest_circuit = max(len(circuit.all_qubits()) for circuit in circuits) + + # Default to state vector unless we see densitymatrix. + return_mem_shape = (len(circuits), 1 << biggest_circuit) + post_process = lambda x: x.final_state_vector if isinstance(simulator, cirq.DensityMatrixSimulator): return_mem_shape = (len(circuits), 1 << biggest_circuit, 1 << biggest_circuit) post_process = lambda x: x.final_density_matrix - elif isinstance(simulator, cirq.Simulator): - return_mem_shape = (len(circuits), 1 << biggest_circuit) - post_process = lambda x: x.final_state_vector - else: - raise TypeError('Simulator {} is not supported by ' - 'batch_calculate_state.'.format(type(simulator))) - shared_array = _make_complex_view(return_mem_shape, -2) - input_args = _prep_pool_input_args(range(len(circuits)), circuits, - param_resolvers) - with ProcessPool(processes=None, - initializer=_setup_dict, - initargs=(shared_array, return_mem_shape, simulator, - post_process)) as pool: + batch_states = np.ones(return_mem_shape, dtype=np.complex64) * -2 + for index, (program, param) in enumerate(zip(circuits, param_resolvers)): + result = simulator.simulate(program, param) + state_size = 1 << len(program.all_qubits()) + state = post_process(result).astype(np.complex64) + sub_index = (slice(None, state_size, 1),) * (batch_states.ndim - 1) + batch_states[index][sub_index] = state - pool.starmap(_state_worker_func, list(input_args)) - - return _convert_complex_view_to_result(shared_array, return_mem_shape) + return batch_states def batch_calculate_expectation(circuits, param_resolvers, ops, simulator): - """Compute expectations from circuits using parallel processing. + """Compute expectations from a batch of circuits. Returns a `np.ndarray` containing the expectation values of `ops` applied to a specific circuit in `circuits`, given that the @@ -404,8 +227,7 @@ def batch_calculate_expectation(circuits, param_resolvers, ops, simulator): any symbols in the circuit. Specifically the returned array at index `i,j` will be equal to the expectation value of `ops[i][j]` on `circuits[i]` with `param_resolvers[i]` used to resolve any symbols in `circuits[i]`. - Expectation calculations will be carried out using the simulator object - (`cirq.DensityMatrixSimulator` and `cirq.Simulator` are currently supported) + Expectation calculations will be carried out using the simulator object. Args: circuits: Python `list` of `cirq.Circuit`s. @@ -415,14 +237,19 @@ def batch_calculate_expectation(circuits, param_resolvers, ops, simulator): be used to calculate the expectation on `circuits[i]` for all `j`, after `param_resolver[i]` is used to resolve any parameters in the circuit. - simulator: Simulator object. Currently supported are - `cirq.DensityMatrixSimulator` and `cirq.Simulator`. + simulator: Simulator object. Must inherit + `cirq.sim.simulator.SimulatesExpectationValues` or + `cirq.DensityMatrixSimulator`. Returns: `np.ndarray` containing the expectation values. Shape is: [len(circuits), len(ops[0])] """ - _validate_inputs(circuits, param_resolvers, simulator, 'analytic') + _validate_inputs(circuits, param_resolvers, simulator, 'expectation') + + if _check_empty(circuits): + return np.zeros((0, 0), dtype=np.float32) + if not isinstance(ops, (list, tuple, np.ndarray)): raise TypeError('ops must be a list or array.' ' Given: {}'.format(type(ops))) @@ -438,50 +265,33 @@ def batch_calculate_expectation(circuits, param_resolvers, ops, simulator): raise TypeError('ops must contain only cirq.PauliSum objects.' ' Given: {}'.format(type(x))) - return_mem_shape = (len(circuits), len(ops[0])) - if isinstance(simulator, cirq.DensityMatrixSimulator): - post_process = lambda op, state, order: sum( - x._expectation_from_density_matrix_no_validation( - state.final_density_matrix, order) for x in op).real - elif isinstance(simulator, cirq.Simulator): - post_process = \ - lambda op, state, order: op.expectation_from_state_vector( - state.final_state_vector, order).real - else: - raise TypeError('Simulator {} is not supported by ' - 'batch_calculate_expectation.'.format(type(simulator))) - - shared_array = _make_simple_view(return_mem_shape, -2, np.float32, 'f') - - # avoid mutating ops array - ops = np.copy(ops) - # TODO (mbbrough): make cirq PauliSUms pickable at some point ? - for i in range(len(ops)): - for j in range(len(ops[i])): - ops[i][j] = serializer.serialize_paulisum(ops[i][j]) - - input_args = list( - _prep_pool_input_args(list( - itertools.product(range(len(circuits)), range(len(ops[0])))), - circuits, - param_resolvers, - ops, - slice_args=False)) - - with ProcessPool(processes=None, - initializer=_setup_dict, - initargs=(shared_array, return_mem_shape, simulator, - post_process)) as pool: - - pool.starmap(_analytical_expectation_worker_func, input_args) + all_exp_vals = np.ones(shape=(len(circuits), len(ops[0])), + dtype=np.float32) * -2 + for i, (c, p, op_row) in enumerate(zip(circuits, param_resolvers, ops)): + # Convention in TFQ is to set expectations of empty circuits to -2. + if len(c) == 0: + continue + # TODO(zaqqwerty): remove DM sim check once cirq #3964 is resolved. + if isinstance(simulator, cirq.DensityMatrixSimulator): + qubits = c.all_qubits() + pairs = zip(sorted(qubits), list(range(len(qubits)))) + qubit_order = dict(pairs) + sim_result = simulator.simulate(c, p) + for j, op in enumerate(op_row): + dm = sim_result.final_density_matrix + all_exp_vals[i][j] = op.expectation_from_density_matrix( + dm, qubit_order, check_preconditions=False) + else: + # Valid observables always have real expectation values. + all_exp_vals[i] = np.real( + np.asarray(simulator.simulate_expectation_values(c, op_row, p))) - return _convert_simple_view_to_result(shared_array, np.float32, - return_mem_shape) + return all_exp_vals def batch_calculate_sampled_expectation(circuits, param_resolvers, ops, - n_samples, simulator): - """Compute expectations from sampling circuits using parallel processing. + n_samples, sampler): + """Compute expectations from sampling a batch of circuits. Returns a `np.ndarray` containing the expectation values of `ops` applied to a specific circuit in `circuits`, given that the @@ -489,9 +299,8 @@ def batch_calculate_sampled_expectation(circuits, param_resolvers, ops, any symbols in the circuit. Specifically the returned array at index `i,j` will be equal to the expectation value of `ops[i][j]` on `circuits[i]` with `param_resolvers[i]` used to resolve any symbols in `circuits[i]`. - Expectation estimations will be carried out using the simulator object - (`cirq.DensityMatrixSimulator` and `cirq.Simulator` are currently supported) - . Expectations for ops[i][j] are estimated by drawing n_samples[i][j] + Expectation estimations will be carried out using the sampler object. + Expectations for ops[i][j] are estimated by drawing n_samples[i][j] samples. Args: @@ -505,14 +314,16 @@ def batch_calculate_sampled_expectation(circuits, param_resolvers, ops, n_samples: 2d Python `list` of `int`s where `n_samples[i][j]` is equal to the number of samples to draw in each term of `ops[i][j]` when estimating the expectation. - simulator: Simulator object. Currently supported are - `cirq.DensityMatrixSimulator` and `cirq.Simulator`. + sampler: Anything inheriting `cirq.Sampler`. Returns: `np.ndarray` containing the expectation values. Shape is: [len(circuits), len(ops[0])] """ - _validate_inputs(circuits, param_resolvers, simulator, 'sample') + _validate_inputs(circuits, param_resolvers, sampler, 'sample') + if _check_empty(circuits): + return np.zeros((0, 0), dtype=np.float32) + if not isinstance(ops, (list, tuple, np.ndarray)): raise TypeError('ops must be a list or array.' ' Given: {}'.format(type(ops))) @@ -540,38 +351,25 @@ def batch_calculate_sampled_expectation(circuits, param_resolvers, ops, raise TypeError('ops must contain only cirq.PauliSum objects.' ' Given: {}'.format(type(x))) - return_mem_shape = (len(circuits), len(ops[0])) - shared_array = _make_simple_view(return_mem_shape, -2, np.float32, 'f') - - # avoid mutating ops array - ops = np.copy(ops) - # TODO (mbbrough): make cirq PauliSums pickable at some point ? - for i in range(len(ops)): - for j in range(len(ops[i])): - ops[i][j] = serializer.serialize_paulisum(ops[i][j]) + all_exp_vals = np.full((len(circuits), len(ops[0])), -2, dtype=np.float32) - input_args = list( - _prep_pool_input_args(list( - itertools.product(range(len(circuits)), range(len(ops[0])))), - circuits, - param_resolvers, - ops, - n_samples, - slice_args=False)) - - with ProcessPool(processes=None, - initializer=_setup_dict, - initargs=(shared_array, return_mem_shape, simulator, - None)) as pool: - - pool.starmap(_sample_expectation_worker_func, input_args) + for c_index, (c, params) in enumerate(zip(circuits, param_resolvers)): + # (#679) Just ignore empty programs. + if len(c.all_qubits()) == 0: + continue + circuit = cirq.resolve_parameters(c, params) + for op_index, op in enumerate(ops[c_index]): + collector = TFQPauliSumCollector( + circuit, op, samples_per_term=n_samples[c_index][op_index]) + collector.collect(sampler) + result = collector.estimated_energy().real + all_exp_vals[c_index][op_index] = result - return _convert_simple_view_to_result(shared_array, np.float32, - return_mem_shape) + return all_exp_vals def batch_sample(circuits, param_resolvers, n_samples, simulator): - """Sample from circuits using parallel processing. + """Sample from circuits. Returns a `np.ndarray` containing n_samples samples from all the circuits in circuits given that the corresponding `cirq.ParamResolver` in @@ -602,6 +400,9 @@ def batch_sample(circuits, param_resolvers, n_samples, simulator): qubits in bitstrings mapped to -2. """ _validate_inputs(circuits, param_resolvers, simulator, 'sample') + if _check_empty(circuits): + return np.zeros((0, 0, 0), dtype=np.int8) + if not isinstance(n_samples, int): raise TypeError('n_samples must be an int.' 'Given: {}'.format(type(n_samples))) @@ -611,30 +412,17 @@ def batch_sample(circuits, param_resolvers, n_samples, simulator): biggest_circuit = max(len(circuit.all_qubits()) for circuit in circuits) return_mem_shape = (len(circuits), n_samples, biggest_circuit) - shared_array = _make_simple_view(return_mem_shape, -2, np.int32, 'i') + return_array = np.ones(return_mem_shape, dtype=np.int8) * -2 - if isinstance(simulator, cirq.DensityMatrixSimulator): - post_process = lambda state, size, n_samples: \ - cirq.sample_density_matrix( - state.final_density_matrix, [i for i in range(size)], - repetitions=n_samples) - elif isinstance(simulator, cirq.Simulator): - post_process = lambda state, size, n_samples: cirq.sample_state_vector( - state.final_state_vector, list(range(size)), repetitions=n_samples) - else: - raise TypeError('Simulator {} is not supported by batch_sample.'.format( - type(simulator))) - - input_args = list( - _prep_pool_input_args(range(len(circuits)), circuits, param_resolvers, - [n_samples] * len(circuits))) - - with ProcessPool(processes=None, - initializer=_setup_dict, - initargs=(shared_array, return_mem_shape, simulator, - post_process)) as pool: + for batch, (c, resolver) in enumerate(zip(circuits, param_resolvers)): + if len(c.all_qubits()) == 0: + continue - pool.starmap(_sample_worker_func, input_args) + qb_keys = [(q, str(i)) for i, q in enumerate(sorted(c.all_qubits()))] + c_m = c + cirq.Circuit(cirq.measure(q, key=i) for q, i in qb_keys) + run_c = cirq.resolve_parameters(c_m, resolver) + bits = simulator.sample(run_c, repetitions=n_samples) + flat_m = bits[[x[1] for x in qb_keys]].to_numpy().astype(np.int8) + return_array[batch, :, biggest_circuit - len(qb_keys):] = flat_m - return _convert_simple_view_to_result(shared_array, np.int32, - return_mem_shape) + return return_array diff --git a/tensorflow_quantum/core/ops/batch_util_test.py b/tensorflow_quantum/core/ops/batch_util_test.py index cc50fd807..16debfc0c 100644 --- a/tensorflow_quantum/core/ops/batch_util_test.py +++ b/tensorflow_quantum/core/ops/batch_util_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test parallel Cirq simulations.""" +# 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 + import numpy as np import tensorflow as tf from absl.testing import parameterized @@ -174,7 +182,7 @@ def test_batch_sample_basic(self, sim): expected_results = _sample_helper(sim, state, len(qubits), n_samples) self.assertAllEqual(expected_results, test_results[0]) - self.assertDTypeEqual(test_results, np.int32) + self.assertDTypeEqual(test_results, np.int8) @parameterized.parameters([{ 'sim': cirq.DensityMatrixSimulator() @@ -210,7 +218,7 @@ def test_batch_sample(self, sim): for a, b in zip(tfq_histograms, cirq_histograms): self.assertLess(stats.entropy(a + 1e-8, b + 1e-8), 0.005) - self.assertDTypeEqual(results, np.int32) + self.assertDTypeEqual(results, np.int8) @parameterized.parameters([{ 'sim': cirq.DensityMatrixSimulator() @@ -267,7 +275,38 @@ def test_empty_circuits(self, sim): r = _sample_helper(sim, state, len(circuit.all_qubits()), n_samples) self.assertAllClose(r, a, atol=1e-5) - self.assertDTypeEqual(results, np.int32) + self.assertDTypeEqual(results, np.int8) + + @parameterized.parameters([{ + 'sim': cirq.DensityMatrixSimulator() + }, { + 'sim': cirq.Simulator() + }]) + def test_no_circuit(self, sim): + """Test functions with no circuits and empty arrays.""" + # (1) Test expectation + results = batch_util.batch_calculate_expectation([], [], [[]], sim) + self.assertDTypeEqual(results, np.float32) + self.assertEqual(np.zeros(shape=(0, 0)).shape, results.shape) + + # (2) Test sampled_expectation + results = batch_util.batch_calculate_sampled_expectation([], [], [[]], + [[]], sim) + self.assertDTypeEqual(results, np.float32) + self.assertEqual(np.zeros(shape=(0, 0)).shape, results.shape) + + # (3) Test state + results = batch_util.batch_calculate_state([], [], sim) + self.assertDTypeEqual(results, np.complex64) + if isinstance(sim, cirq.Simulator): + self.assertEqual(np.zeros(shape=(0, 0)).shape, results.shape) + else: + self.assertEqual(np.zeros(shape=(0, 0, 0)).shape, results.shape) + + # (4) Test sampling + results = batch_util.batch_sample([], [], [], sim) + self.assertDTypeEqual(results, np.int8) + self.assertEqual(np.zeros(shape=(0, 0, 0)).shape, results.shape) if __name__ == '__main__': diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops.py b/tensorflow_quantum/core/ops/circuit_execution_ops.py index bf3889218..b21298ad3 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A module for user-facing generators of tfq ops.""" import enum @@ -21,25 +21,65 @@ tfq_utility_ops) from tensorflow_quantum.python import quantum_context +try: + from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum + _ENABLE_USE_CUQUANTUM = True +except: + # `_ENABLE_USE_CUQUANTUM = False` makes `use_cuquantum` silent. + _ENABLE_USE_CUQUANTUM = False + tfq_simulate_ops_cuquantum = tfq_simulate_ops + + +def is_gpu_configured() -> bool: + """Returns True if gpu ops are available or not.""" + return _ENABLE_USE_CUQUANTUM + + +def _preprocess_use_cuquantum(use_cuquantum: bool) -> bool: + if is_gpu_configured(): + return use_cuquantum + + # GPU is not set. `use_cuquantum` becomes silent. + if use_cuquantum: + print("WARNING: cuQuantum was not set, " + "`use_cuquantum=True` option becomes effectless. Using CPU.") + return False + class TFQStateVectorSimulator(enum.Enum): """Enum to make specifying TFQ simulators user-friendly.""" expectation = tfq_simulate_ops.tfq_simulate_expectation + expectation_cuquantum = tfq_simulate_ops_cuquantum.tfq_simulate_expectation + samples = tfq_simulate_ops.tfq_simulate_samples + samples_cuquantum = tfq_simulate_ops_cuquantum.tfq_simulate_samples + state = tfq_simulate_ops.tfq_simulate_state + state_cuquantum = tfq_simulate_ops_cuquantum.tfq_simulate_state + sampled_expectation = tfq_simulate_ops.tfq_simulate_sampled_expectation + sampled_expectation_cuquantum = ( + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation) -def _check_quantum_concurrent(quantum_concurrent): +def _check_quantum_concurrent(quantum_concurrent, use_cuquantum): if not isinstance(quantum_concurrent, bool): raise TypeError("quantum_concurrent must be type bool." " Given: {}".format(str(type(quantum_concurrent)))) + if not isinstance(use_cuquantum, bool): + raise TypeError("use_cuquantum must be type bool." + " Given: {}".format(str(type(use_cuquantum)))) + if use_cuquantum is True and quantum_concurrent is True: + raise ValueError("use_cuquantum and quantum_concurrent should " + "not be True at the same time. Please set False to " + "quantum_concurrent.") def get_expectation_op( backend=None, *, - quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): + quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode(), + use_cuquantum=False): """Get a TensorFlow op that will calculate batches of expectation values. This function produces a non-differentiable TF op that will calculate @@ -78,9 +118,10 @@ def get_expectation_op( Args: backend: Optional Python `object` that specifies what backend this op - should use when evaluating circuits. Can be any - `cirq.SimulatesFinalState`. If not provided the default C++ - analytical expectation calculation op is returned. + should use when evaluating circuits. Can be + `cirq.DensityMatrixSimulator` or any + `cirq.sim.simulator.SimulatesExpectationValues`. If not provided + the default C++ analytical expectation calculation op is returned. quantum_concurrent: Optional Python `bool`. True indicates that the returned op should not block graph level parallelism on itself when executing. False indicates that graph level parallelism on itself @@ -89,6 +130,8 @@ def get_expectation_op( (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. + use_cuquantum: Set True to turn on TFQ cuQuantum version op, which + requires `quantum_concurrent` to be False. Returns: A `callable` with the following signature: @@ -114,19 +157,28 @@ def get_expectation_op( expectation value for each circuit with each op applied to it (after resolving the corresponding parameters in). """ - # TODO (mbbrough): investigate how the above docstring renders. - _check_quantum_concurrent(quantum_concurrent) + _check_quantum_concurrent(quantum_concurrent, use_cuquantum) + use_cuquantum = _preprocess_use_cuquantum(use_cuquantum) op = None if backend is None: - op = TFQStateVectorSimulator.expectation - - if isinstance(backend, cirq.SimulatesFinalState): + if use_cuquantum: + op = TFQStateVectorSimulator.expectation_cuquantum + else: + op = TFQStateVectorSimulator.expectation + + # TODO(zaqqwerty): remove DM check after cirq #3964 + if isinstance(backend, (cirq.sim.simulator.SimulatesExpectationValues, + cirq.DensityMatrixSimulator)): + if use_cuquantum: + raise ValueError( + "use_cuquantum is not supported for cirq simulator. Please \ + set use_cuquantum to False.") op = cirq_ops._get_cirq_analytical_expectation(backend) if op is not None: - if quantum_concurrent is True: + if use_cuquantum is False and quantum_concurrent is True: # Return an op that does not block graph level parallelism. return lambda programs, symbol_names, symbol_values, pauli_sums: \ op(programs, symbol_names, symbol_values, pauli_sums) @@ -141,14 +193,16 @@ def get_expectation_op( " Use " "tf.get_sampled_expectation_op() instead.") - raise TypeError("Backend {} is invalid. Expected a Cirq.SimulatesFinalState" - " or None.".format(backend)) + raise TypeError("Backend {} is invalid. Expected a " + "cirq.sim.simulator.SimulatesExpectationValues " + "or None.".format(backend)) def get_sampling_op( backend=None, *, - quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): + quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode(), + use_cuquantum=False): """Get a Tensorflow op that produces samples from given quantum circuits. This function produces a non-differentiable op that will calculate @@ -186,6 +240,8 @@ def get_sampling_op( (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. + use_cuquantum: Set True to turn on TFQ cuQuantum version op, which + requires `quantum_concurrent` to be False. Returns: A `callable` with the following signature: @@ -212,17 +268,25 @@ def get_sampling_op( """ # TODO (mbbrough): investigate how the above docstring renders. - _check_quantum_concurrent(quantum_concurrent) + _check_quantum_concurrent(quantum_concurrent, use_cuquantum) + use_cuquantum = _preprocess_use_cuquantum(use_cuquantum) op = None if backend is None: - op = TFQStateVectorSimulator.samples + if use_cuquantum: + op = TFQStateVectorSimulator.samples_cuquantum + else: + op = TFQStateVectorSimulator.samples if isinstance(backend, cirq.Sampler): + if use_cuquantum: + raise ValueError( + "use_cuquantum is not supported for cirq sampler. Please \ + set use_cuquantum to False.") op = cirq_ops._get_cirq_samples(backend) if op is not None: - if quantum_concurrent is True: + if use_cuquantum is False and quantum_concurrent is True: # Return an op that does not block graph level parallelism. return lambda programs, symbol_names, symbol_values, num_samples: \ tfq_utility_ops.padded_to_ragged( @@ -240,7 +304,8 @@ def get_sampling_op( def get_state_op( backend=None, *, - quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): + quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode(), + use_cuquantum=False): """Get a TensorFlow op that produces states from given quantum circuits. This function produces a non-differentiable op that will calculate @@ -278,6 +343,8 @@ def get_state_op( (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. + use_cuquantum: Set True to turn on TFQ cuQuantum version op, which + requires `quantum_concurrent` to be False. Returns: A `callable` with the following signature: @@ -301,17 +368,25 @@ def get_state_op( """ # TODO (mbbrough): investigate how the above docstring renders. - _check_quantum_concurrent(quantum_concurrent) + _check_quantum_concurrent(quantum_concurrent, use_cuquantum) + use_cuquantum = _preprocess_use_cuquantum(use_cuquantum) op = None if backend is None: - op = TFQStateVectorSimulator.state + if use_cuquantum: + op = TFQStateVectorSimulator.state_cuquantum + else: + op = TFQStateVectorSimulator.state if isinstance(backend, (cirq.SimulatesFinalState)): + if use_cuquantum: + raise ValueError( + "use_cuquantum is not supported for cirq simulator. Please \ + set use_cuquantum to False.") op = cirq_ops._get_cirq_simulate_state(backend) if op is not None: - if quantum_concurrent is True: + if use_cuquantum is False and quantum_concurrent is True: # Return an op that does not block graph level parallelism. return lambda programs, symbol_names, symbol_values: \ tfq_utility_ops.padded_to_ragged( @@ -330,7 +405,8 @@ def get_state_op( def get_sampled_expectation_op( backend=None, *, - quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode()): + quantum_concurrent=quantum_context.get_quantum_concurrent_op_mode(), + use_cuquantum=False): """Get a TensorFlow op that will calculate sampled expectation values. This function produces a non-differentiable TF op that will calculate @@ -382,6 +458,8 @@ def get_sampled_expectation_op( (no blocking). This flag is only needed for advanced users when using TFQ for very large simulations, or when running on a real chip. + use_cuquantum: Set True to turn on TFQ cuQuantum version op, which + requires `quantum_concurrent` to be False. Returns: A `callable` with the following signature: @@ -412,17 +490,25 @@ def get_sampled_expectation_op( (after resolving the corresponding parameters in). """ # TODO (mbbrough): investigate how the above docstring renders. - _check_quantum_concurrent(quantum_concurrent) + _check_quantum_concurrent(quantum_concurrent, use_cuquantum) + use_cuquantum = _preprocess_use_cuquantum(use_cuquantum) op = None if backend is None: - op = TFQStateVectorSimulator.sampled_expectation + if use_cuquantum: + op = TFQStateVectorSimulator.sampled_expectation_cuquantum + else: + op = TFQStateVectorSimulator.sampled_expectation if isinstance(backend, cirq.Sampler): + if use_cuquantum: + raise ValueError( + "use_cuquantum is not supported for cirq sampler. Please \ + set use_cuquantum to False.") op = cirq_ops._get_cirq_sampled_expectation(backend) if op is not None: - if quantum_concurrent is True: + if use_cuquantum is False and quantum_concurrent is True: # Return an op that does not block graph level parallelism. return lambda programs, symbol_names, symbol_values, pauli_sums, \ num_samples: op(programs, diff --git a/tensorflow_quantum/core/ops/circuit_execution_ops_test.py b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py index 46a738613..b89c85aa5 100644 --- a/tensorflow_quantum/core/ops/circuit_execution_ops_test.py +++ b/tensorflow_quantum/core/ops/circuit_execution_ops_test.py @@ -11,14 +11,24 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to test consistency between Cirq and TFQ circuit execution ops.""" +# 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 + from unittest import mock import numpy as np import tensorflow as tf from absl.testing import parameterized 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 @@ -39,7 +49,11 @@ quantum_concurrent=True), # For timing interests C++ backend is tested in quantum_concurrent mode. circuit_execution_ops.get_expectation_op(backend=None, - quantum_concurrent=False) + quantum_concurrent=False), + # For cuQuantum op. quantum_concurrent=True is not allowed. + circuit_execution_ops.get_expectation_op(backend=None, + quantum_concurrent=False, + use_cuquantum=True) ] SAMPLING_OPS = [ @@ -51,7 +65,11 @@ quantum_concurrent=True), # For timing interests C++ backend is tested in quantum_concurrent mode. circuit_execution_ops.get_sampling_op(backend=None, - quantum_concurrent=False) + quantum_concurrent=False), + # For cuQuantum op. quantum_concurrent=True is not allowed. + circuit_execution_ops.get_sampling_op(backend=None, + quantum_concurrent=False, + use_cuquantum=True) ] STATE_OPS = [ @@ -59,8 +77,13 @@ circuit_execution_ops.get_state_op(backend=WF_SIM, quantum_concurrent=True), circuit_execution_ops.get_state_op(backend=DM_SIM, quantum_concurrent=True), # For timing interests C++ backend is tested in quantum_concurrent mode. - circuit_execution_ops.get_state_op(backend=None, quantum_concurrent=False) + circuit_execution_ops.get_state_op(backend=None, quantum_concurrent=False), + # For cuQuantum op. quantum_concurrent=True is not allowed. + circuit_execution_ops.get_state_op(backend=None, + quantum_concurrent=False, + use_cuquantum=True) ] +NO_DM_STATE_OPS = STATE_OPS[:2] + STATE_OPS[2:] SAMPLED_EXPECTATION_OPS = [ circuit_execution_ops.get_sampled_expectation_op(backend=None, @@ -72,9 +95,14 @@ # For timing interests C++ backend is tested in quantum_concurrent mode. circuit_execution_ops.get_sampled_expectation_op(backend=None, quantum_concurrent=False), + # For cuQuantum op. quantum_concurrent=True is not allowed. + circuit_execution_ops.get_sampled_expectation_op(backend=None, + quantum_concurrent=False, + use_cuquantum=True) ] -SIMS = [WF_SIM, WF_SIM, DM_SIM, WF_SIM] +SIMS = [WF_SIM, WF_SIM, DM_SIM, WF_SIM, WF_SIM] +NO_DM_SIMS = SIMS[:2] + SIMS[2:] class OpGetterInputChecks(tf.test.TestCase): @@ -89,19 +117,27 @@ 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="a Cirq.SimulatesFinalState"): + TypeError, + expected_regex="cirq.sim.simulator.SimulatesExpectationValues"): circuit_execution_ops.get_expectation_op(backend="junk") with self.assertRaisesRegex(TypeError, expected_regex="must be type bool."): circuit_execution_ops.get_expectation_op(quantum_concurrent='junk') + with self.assertRaisesRegex(TypeError, + expected_regex="must be type bool."): + circuit_execution_ops.get_expectation_op(use_cuquantum='junk') + + with self.assertRaisesRegex( + ValueError, expected_regex="not be True at the same time"): + circuit_execution_ops.get_expectation_op(quantum_concurrent=True, + use_cuquantum=True) + def test_get_sampled_expectation_inputs(self): """Test that get expectation only accepts inputs it should.""" circuit_execution_ops.get_sampled_expectation_op() @@ -109,11 +145,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") @@ -122,17 +156,25 @@ def test_get_sampled_expectation_inputs(self): circuit_execution_ops.get_sampled_expectation_op( quantum_concurrent='junk') + with self.assertRaisesRegex(TypeError, + expected_regex="must be type bool."): + circuit_execution_ops.get_sampled_expectation_op( + use_cuquantum='junk') + + with self.assertRaisesRegex( + ValueError, expected_regex="not be True at the same time"): + circuit_execution_ops.get_sampled_expectation_op( + quantum_concurrent=True, use_cuquantum=True) + def test_get_samples_inputs(self): """Test that get_samples only accepts inputs it should.""" circuit_execution_ops.get_sampling_op() 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") @@ -141,6 +183,15 @@ def test_get_samples_inputs(self): expected_regex="must be type bool."): circuit_execution_ops.get_sampling_op(quantum_concurrent='junk') + with self.assertRaisesRegex(TypeError, + expected_regex="must be type bool."): + circuit_execution_ops.get_sampling_op(use_cuquantum='junk') + + with self.assertRaisesRegex( + ValueError, expected_regex="not be True at the same time"): + circuit_execution_ops.get_sampling_op(quantum_concurrent=True, + use_cuquantum=True) + def test_get_state_inputs(self): """Test that get_states only accepts inputs it should.""" circuit_execution_ops.get_state_op() @@ -152,17 +203,23 @@ 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."): circuit_execution_ops.get_state_op(quantum_concurrent='junk') + with self.assertRaisesRegex(TypeError, + expected_regex="must be type bool."): + circuit_execution_ops.get_state_op(use_cuquantum='junk') + + with self.assertRaisesRegex( + ValueError, expected_regex="not be True at the same time"): + circuit_execution_ops.get_state_op(quantum_concurrent=True, + use_cuquantum=True) + class ExecutionOpsConsistentyTest(tf.test.TestCase, parameterized.TestCase): """Test all ops produce equivalent output to one another.""" @@ -174,7 +231,8 @@ def test_supported_gates_consistent(self, op_and_sim): """Ensure that supported gates are consistent across backends.""" op = op_and_sim[0] sim = op_and_sim[1] - qubits = cirq.GridQubit.rect(1, 5) + # mix qubit types. + qubits = cirq.GridQubit.rect(1, 4) + [cirq.LineQubit(10)] circuit_batch = [] gate_ref = util.get_supported_gates() @@ -266,9 +324,7 @@ def test_simulate_state_with_symbols(self, op_and_sim, n_qubits, util.kwargs_cartesian_product( **{ 'op_and_sim': [(op, sim) for ( - op, - sim) in zip(STATE_OPS[:-2] + - [STATE_OPS[-1]], SIMS[:-2] + [SIMS[-1]])], + op, sim) in zip(NO_DM_STATE_OPS, NO_DM_SIMS)], }))) def test_simulate_state_large(self, op_and_sim): """Test a reasonably large and complex circuit.""" @@ -276,7 +332,7 @@ def test_simulate_state_large(self, op_and_sim): symbol_names = [] circuit_batch, resolver_batch = \ util.random_circuit_resolver_batch( - cirq.GridQubit.rect(4, 4), 5) + cirq.GridQubit.rect(3, 3), 5) symbol_values_array = np.array( [[resolver[symbol] @@ -311,6 +367,23 @@ def test_simulate_state_empty(self, op_and_sim): self.assertAllClose(cirq_states, op_states, atol=1e-5, rtol=1e-5) + @parameterized.parameters( + list( + util.kwargs_cartesian_product(**{ + 'op_and_sim': [(op, sim) for (op, sim) in zip(STATE_OPS, SIMS)] + }))) + def test_simulate_state_no_circuits(self, op_and_sim): + """Test no circuits for states using cirq and tfq.""" + op = op_and_sim[0] + sim = op_and_sim[1] + + circuit_batch = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_params = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + + op_states = op(circuit_batch, [], empty_params).numpy() + cirq_states = batch_util.batch_calculate_state([], [], sim) + self.assertEqual(op_states.shape, cirq_states.shape) + @parameterized.parameters( list( util.kwargs_cartesian_product( @@ -327,7 +400,7 @@ def test_analytical_expectation(self, op_and_sim, n_qubits, symbol_names, op = op_and_sim[0] sim = op_and_sim[1] - qubits = cirq.GridQubit.rect(1, n_qubits) + qubits = cirq.LineQubit.range(n_qubits - 1) + [cirq.GridQubit(0, 0)] circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( qubits, symbol_names, BATCH_SIZE) @@ -392,6 +465,26 @@ def test_analytical_expectation_empty(self, op_and_sim, n_qubits, rtol=1e-5, atol=1e-5) + @parameterized.parameters( + list( + util.kwargs_cartesian_product( + **{ + 'op_and_sim': [(op, sim) + for (op, sim) in zip(EXPECTATION_OPS, SIMS)] + }))) + def test_analytical_expectation_no_circuits(self, op_and_sim): + """Test no circuits for states using cirq and tfq.""" + op = op_and_sim[0] + sim = op_and_sim[1] + + circuit_batch = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_params = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + empty_ops = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + + op_exp = op(circuit_batch, [], empty_params, empty_ops).numpy() + cirq_exp = batch_util.batch_calculate_expectation([], [], [[]], sim) + self.assertEqual(op_exp.shape, cirq_exp.shape) + @parameterized.parameters( list( util.kwargs_cartesian_product( @@ -479,6 +572,29 @@ def test_sampled_expectation_empty(self, op_and_sim, n_qubits, symbol_names, rtol=1e-1, atol=1e-1) + @parameterized.parameters( + list( + util.kwargs_cartesian_product( + **{ + 'op_and_sim': [(op, sim) for ( + op, sim) in zip(SAMPLED_EXPECTATION_OPS, SIMS)] + }))) + def test_sampled_expectation_no_circuits(self, op_and_sim): + """Test no circuits for states using cirq and tfq.""" + op = op_and_sim[0] + sim = op_and_sim[1] + + circuit_batch = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_params = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + empty_ops = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + empty_samples = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.int32) + + op_exp = op(circuit_batch, [], empty_params, empty_ops, + empty_samples).numpy() + cirq_exp = batch_util.batch_calculate_sampled_expectation([], [], [[]], + [], sim) + self.assertEqual(op_exp.shape, cirq_exp.shape) + # keep the qubit count low here, all computations scale exponentially @parameterized.parameters( list( @@ -498,7 +614,7 @@ def test_sampling(self, op_and_sim, n_qubits, symbol_names): circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( - qubits, symbol_names, BATCH_SIZE, 30) + qubits, symbol_names, BATCH_SIZE, n_moments=30) for i in range(BATCH_SIZE): circuit_batch[i] += cirq.Circuit( *[cirq.H(qubit) for qubit in qubits]) @@ -579,6 +695,24 @@ def test_sampling_empty(self, op_and_sim, n_qubits, symbol_names): for a, b in zip(op_histograms, cirq_histograms): self.assertLess(stats.entropy(a + 1e-8, b + 1e-8), 0.005) + @parameterized.parameters( + list( + util.kwargs_cartesian_product(**{ + 'op_and_sim': [(op, sim) + for (op, sim) in zip(SAMPLING_OPS, SIMS)] + }))) + def test_sampling_no_circuits(self, op_and_sim): + """Test no circuits for states using cirq and tfq.""" + op = op_and_sim[0] + sim = op_and_sim[1] + + circuit_batch = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_params = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + num_samples = tf.convert_to_tensor([5]) + op_states = op(circuit_batch, [], empty_params, num_samples).numpy() + cirq_samples = batch_util.batch_sample([], [], [5], sim) + self.assertEqual(op_states.shape, cirq_samples.shape) + if __name__ == '__main__': tf.test.main() diff --git a/tensorflow_quantum/core/ops/cirq_ops.py b/tensorflow_quantum/core/ops/cirq_ops.py index 7089c4467..808296433 100644 --- a/tensorflow_quantum/core/ops/cirq_ops.py +++ b/tensorflow_quantum/core/ops/cirq_ops.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Generators for ops that call out to cirq simulators from the tf graph.""" import functools import numbers @@ -19,9 +19,11 @@ import numpy as np import tensorflow as tf import cirq +import cirq_google 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 @@ -108,7 +110,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) @@ -128,7 +130,9 @@ def _get_cirq_analytical_expectation(simulator=cirq.Simulator()): values. Args: - simulator: `cirq.Simulator` object to use for circuit execution. + simulator: `cirq.Simulator` object to use for circuit execution. Can be + `cirq.DensityMatrixSimulator` or any + `cirq.sim.simulator.SimulatesExpectationValues`. Returns: `callable` that is a TensorFlow op for computing expectation. @@ -209,8 +213,11 @@ def cirq_analytical_expectation(programs, symbol_names, symbol_values, return expectations - if not isinstance(simulator, cirq.SimulatesFinalState): - raise TypeError("simulator must inherit cirq.SimulatesFinalState.") + if not isinstance(simulator, (cirq.sim.simulator.SimulatesExpectationValues, + cirq.DensityMatrixSimulator)): + raise TypeError( + "simulator must be cirq.DensityMatrixSimulator or inherit " + "cirq.sim.simulator.SimulatesExpectationValues.") @_upgrade_inputs def expectation_generator(programs_tf, symbol_names_tf, symbol_values_tf, @@ -230,7 +237,7 @@ def expectation_generator(programs_tf, symbol_names_tf, symbol_values_tf, return expectation_generator -def _get_cirq_sampled_expectation(simulator=cirq.Simulator()): +def _get_cirq_sampled_expectation(sampler=cirq.Simulator()): """Get a `callable` that is a TensorFlow op that outputs sampled expectation values. @@ -239,7 +246,7 @@ def _get_cirq_sampled_expectation(simulator=cirq.Simulator()): expectation values. Args: - simulator: `cirq.Simulator` object to use for circuit execution. + sampler: Anything inheriting `cirq.Sampler`. Returns: `callable` that is a TensorFlow op for computing expectation. @@ -305,7 +312,8 @@ def cirq_sampled_expectation(programs, symbol_names, symbol_values, _input_check_helper(programs, symbol_names, symbol_values) if not (pauli_sums.dtype == tf.dtypes.string): raise TypeError('pauli_sums tensor must be of type string.') - if not (pauli_sums.shape[0] == programs.shape[0]): + if not (pauli_sums.shape[0] == programs.shape[0]) or \ + len(pauli_sums.shape) != 2: raise TypeError('pauli_sums tensor must have the same batch shape ' 'as programs tensor.') @@ -335,11 +343,11 @@ def cirq_sampled_expectation(programs, symbol_names, symbol_values, sum_inputs.append(to_append) expectations = batch_util.batch_calculate_sampled_expectation( - programs, resolvers, sum_inputs, num_samples, simulator) + programs, resolvers, sum_inputs, num_samples, sampler) return expectations - if not isinstance(simulator, cirq.Sampler): + if not isinstance(sampler, cirq.Sampler): raise TypeError("cirq.Sampler is required for sampled expectation.") @_upgrade_inputs @@ -483,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 @@ -521,10 +529,11 @@ def _no_grad(grad): else: # All other cirq.Samplers handled here. - #TODO(zaqqwerty): replace with run_batch once Cirq #3148 is resolved cirq_results = [] - for p, r in zip(programs, resolvers): - cirq_results.append(sampler.run(p, r, num_samples)) + for results in sampler.run_batch(programs, + params_list=resolvers, + repetitions=num_samples): + cirq_results.extend(results) results = [] for r in cirq_results: @@ -563,7 +572,9 @@ def _get_cirq_simulate_state(simulator=cirq.Simulator()): of all the input circuits. Args: - simulator: `cirq.Simulator` object to use for circuit execution. + simulator: Simulator object. Can be any `cirq.SimulatesFinalState`; + if `simulator` is not a `cirq.DensityMatrixSimulator`, this function + assumes all final states are dense state vectors. Returns: `callable` that is a Tensorflow op for calculating states. diff --git a/tensorflow_quantum/core/ops/cirq_ops_test.py b/tensorflow_quantum/core/ops/cirq_ops_test.py index 31dcdb27e..a17b6f1f5 100644 --- a/tensorflow_quantum/core/ops/cirq_ops_test.py +++ b/tensorflow_quantum/core/ops/cirq_ops_test.py @@ -11,13 +11,23 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for the cirq simulation ops.""" +# 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 + from unittest import mock import numpy as np import tensorflow as tf 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 @@ -34,7 +44,7 @@ class CirqAnalyticalExpectationTest(tf.test.TestCase): def test_get_cirq_analytical_expectation_op(self): """Input check the wrapper for the cirq analytical expectation op.""" with self.assertRaisesRegex( - TypeError, "simulator must inherit cirq.SimulatesFinalState."): + TypeError, "cirq.sim.simulator.SimulatesExpectationValues."): cirq_ops._get_cirq_analytical_expectation("junk") # TODO(peterse): Tighten these tests a bit.. cirq_ops._get_cirq_analytical_expectation() @@ -95,6 +105,14 @@ def test_analytic_expectation_empty_circuit(self): cirq.Circuit()).SerializeToString() _ = test_op([test_empty_circuit], [], [[]], [[test_pauli_sum]]) + def test_analytic_expectation_no_circuit(self): + """Test empty tensors with no circuits at all.""" + test_op = cirq_ops._get_cirq_analytical_expectation(cirq.Simulator()) + empty_programs = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + empty_paulis = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + _ = test_op(empty_programs, [], empty_values, empty_paulis) + class CirqSampledExpectationTest(tf.test.TestCase): """Tests get_cirq_sampled_expectation.""" @@ -184,6 +202,15 @@ def test_sampled_expectation_empty_circuit(self): cirq.Circuit()).SerializeToString() _ = test_op([test_empty_circuit], [], [[]], [[test_pauli_sum]], [[1]]) + def test_sampled_expectation_no_circuit(self): + """Test empty tensors with no circuits at all.""" + test_op = cirq_ops._get_cirq_sampled_expectation(cirq.Simulator()) + empty_programs = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + empty_paulis = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + empty_reps = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.int32) + _ = test_op(empty_programs, [], empty_values, empty_paulis, empty_reps) + class CirqSimulateStateTest(tf.test.TestCase, parameterized.TestCase): """Tests get_cirq_simulate_state.""" @@ -296,7 +323,7 @@ def test_simulate_state_output_padding(self, op_and_sim, all_n_qubits): 'Simulator returned unknown type of result.' + str(type(result))) - self.assertAllClose(tfq_results, manual_padded_results) + self.assertAllClose(tfq_results, manual_padded_results, atol=1e-5) def test_state_empty_circuit(self): """Test empty circuits""" @@ -305,6 +332,13 @@ def test_state_empty_circuit(self): cirq.Circuit()).SerializeToString() _ = test_op([test_empty_circuit], [], [[]]) + def test_state_no_circuit(self): + """Test empty tensors with no circuits at all.""" + test_op = cirq_ops._get_cirq_simulate_state(cirq.Simulator()) + empty_programs = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + _ = test_op(empty_programs, [], empty_values) + class CirqSamplesTest(tf.test.TestCase, parameterized.TestCase): """Tests get_cirq_samples.""" @@ -316,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.""" @@ -390,8 +422,8 @@ def test_sampling_output_padding(self, op, all_n_qubits, n_samples): this_expected_output[:, :max(all_n_qubits) - n_qubits] = -2 expected_outputs.append(this_expected_output) circuits.append( - cirq.Circuit( - *cirq.X.on_each(*cirq.GridQubit.rect(1, n_qubits)))) + cirq.Circuit(*cirq.X.on_each( + *cirq.GridQubit.rect(1, n_qubits)))) results = op(util.convert_to_tensor(circuits), [], [[]] * len(circuits), [n_samples]).numpy() self.assertAllClose(expected_outputs, results) @@ -403,6 +435,13 @@ def test_sample_empty_circuit(self): cirq.Circuit()).SerializeToString() _ = test_op([test_empty_circuit], [], [[]], [10]) + def test_sample_no_circuit(self): + """Test empty tensors with no circuits at all.""" + test_op = cirq_ops._get_cirq_samples(cirq.Simulator()) + empty_programs = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + _ = test_op(empty_programs, [], empty_values, [1]) + def test_get_cirq_samples_general(self): """Tests that a general cirq.Sampler is compatible with sampling.""" @@ -412,13 +451,15 @@ class DummySampler(cirq.Sampler): def run_sweep(self, program, params, repetitions): """Returns all ones in the correct sample shape.""" return [ - cirq.TrialResult( + cirq_google.EngineResult( + job_id="1", + job_finished_time="1", params=param, measurements={ 'tfq': np.array([[1] * len(program.all_qubits())] * repetitions, - dtype=np.int32), + dtype=int), }) for param in cirq.to_resolvers(params) ] @@ -430,8 +471,8 @@ def run_sweep(self, program, params, repetitions): circuits = [] for n_qubits in all_n_qubits: circuits.append( - cirq.Circuit( - *cirq.X.on_each(*cirq.GridQubit.rect(1, n_qubits)))) + cirq.Circuit(*cirq.X.on_each( + *cirq.GridQubit.rect(1, n_qubits)))) test_results = this_op(util.convert_to_tensor(circuits), [], [[]] * len(circuits), [n_samples]).numpy() diff --git a/tensorflow_quantum/core/ops/load_module.py b/tensorflow_quantum/core/ops/load_module.py index b5002ad84..ee4f9b0b6 100644 --- a/tensorflow_quantum/core/ops/load_module.py +++ b/tensorflow_quantum/core/ops/load_module.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to load python op libraries.""" import os diff --git a/tensorflow_quantum/core/ops/math_ops/BUILD b/tensorflow_quantum/core/ops/math_ops/BUILD index 5db4c7d0c..6eb8a0320 100644 --- a/tensorflow_quantum/core/ops/math_ops/BUILD +++ b/tensorflow_quantum/core/ops/math_ops/BUILD @@ -1,3 +1,5 @@ +# load op_wrapper + package(default_visibility = ["//visibility:public"]) licenses(["notice"]) @@ -14,6 +16,10 @@ cc_binary( name = "_tfq_math_ops.so", srcs = [ "tfq_inner_product.cc", + "tfq_inner_product_grad.cc", + "tfq_simulate_1d_expectation.cc", + "tfq_simulate_1d_samples.cc", + "tfq_simulate_1d_sampled_expectation.cc", ], copts = select({ ":windows": [ @@ -32,7 +38,7 @@ cc_binary( "-DNOGDI", "/d2ReducedOptimizeHugeFunctions", "/arch:AVX", - "/std:c++14", + "/std:c++17", "-DTENSORFLOW_MONOLITHIC_BUILD", "/DPLATFORM_WINDOWS", "/DEIGEN_HAS_C99_MATH", @@ -46,8 +52,8 @@ cc_binary( ], "//conditions:default": [ "-pthread", - "-std=c++11", - "-D_GLIBCXX_USE_CXX11_ABI=0", + "-std=c++17", + "-D_GLIBCXX_USE_CXX11_ABI=1", ], }), features = select({ @@ -56,11 +62,27 @@ cc_binary( }), linkshared = 1, deps = [ + # cirq cc proto "//tensorflow_quantum/core/ops:parse_context", "//tensorflow_quantum/core/ops:tfq_simulate_utils", - "//tensorflow_quantum/core/src:util_qsim", + "//tensorflow_quantum/core/src:adj_util", "//tensorflow_quantum/core/src:circuit_parser_qsim", + "//tensorflow_quantum/core/src:util_qsim", + "@qsim//lib:mps_simulator", + "@qsim//lib:mps_statespace", "@qsim//lib:qsim_lib", + "@eigen//:eigen3", + # tensorflow core framework + # tensorflow core lib + # tensorflow core protos + ], +) + +py_library( + name = "fidelity_op_py", + srcs = ["fidelity_op.py"], + deps = [ + ":inner_product_op_py", ], ) @@ -82,3 +104,43 @@ py_test( "//tensorflow_quantum/python:util", ], ) + +py_test( + name = "fidelity_op_test", + srcs = ["fidelity_op_test.py"], + deps = [ + ":fidelity_op_py", + "//tensorflow_quantum/python:util", + ], +) + +py_test( + name = "inner_product_grad_test", + srcs = ["inner_product_grad_test.py"], + python_version = "PY3", + deps = [ + ":inner_product_op_py", + "//tensorflow_quantum/python:util", + ], +) + +py_library( + name = "simulate_mps_py", + srcs = ["simulate_mps.py"], + data = [":_tfq_math_ops.so"], + deps = [ + "//tensorflow_quantum/core/ops:batch_util", + "//tensorflow_quantum/core/ops:load_module", + "//tensorflow_quantum/core/ops:tfq_utility_ops_py", + ], +) + +py_test( + name = "simulate_mps_test", + srcs = ["simulate_mps_test.py"], + python_version = "PY3", + deps = [ + ":simulate_mps_py", + "//tensorflow_quantum/python:util", + ], +) diff --git a/tensorflow_quantum/core/ops/math_ops/__init__.py b/tensorflow_quantum/core/ops/math_ops/__init__.py index 7842b8784..9d3b92f64 100644 --- a/tensorflow_quantum/core/ops/math_ops/__init__.py +++ b/tensorflow_quantum/core/ops/math_ops/__init__.py @@ -11,7 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.core.ops.math_ops.*""" +from tensorflow_quantum.core.ops.math_ops.fidelity_op import fidelity from tensorflow_quantum.core.ops.math_ops.inner_product_op import inner_product +from tensorflow_quantum.core.ops.math_ops.simulate_mps import ( + mps_1d_expectation, mps_1d_sample, mps_1d_sampled_expectation) diff --git a/tensorflow_quantum/core/ops/math_ops/fidelity_op.py b/tensorflow_quantum/core/ops/math_ops/fidelity_op.py new file mode 100644 index 000000000..ae2908baa --- /dev/null +++ b/tensorflow_quantum/core/ops/math_ops/fidelity_op.py @@ -0,0 +1,94 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Module for tfq.math.fidelity op.""" +import tensorflow as tf +from tensorflow_quantum.core.ops.math_ops import inner_product_op + + +@tf.function +@tf.custom_gradient +def fidelity(programs, symbol_names, symbol_values, other_programs): + """Calculate the fidelity between circuits. + + Compute (potentially many) fidelities between the given circuits and + the symbol free comparison circuits. + + Calculates out[i][j] = $ | \langle \psi_{\text{programs[i]}} \\ + (\text{symbol\_values[i]}) | \psi_{\text{other\_programs[j]}} \rangle \\ + |^2 $ + + + >>> symbols = sympy.symbols('alpha beta') + >>> qubits = cirq.GridQubit.rect(1, 2) + >>> reference_circuits = [ + ... cirq.Circuit((cirq.H**symbols[0]).on_each(qubits)), + ... cirq.Circuit( + ... cirq.X(qubits[0]) ** symbols[0], + ... cirq.Y(qubits[1]) ** symbols[1]) + ... ] + >>> other_circuits = [ + ... cirq.Circuit(cirq.X.on_each(qubits)), + ... cirq.Circuit((cirq.Y**0.125).on_each(qubits)), + ... cirq.Circuit((cirq.X**0.5).on_each(qubits)) + ... ] + >>> reference_tensor = tfq.convert_to_tensor(reference_circuits) + >>> symbol_tensor = tf.convert_to_tensor([s.name for s in symbols]) + >>> values_tensor = tf.convert_to_tensor(np.arange(4).reshape(2, 2)) + >>> other_tensor = tfq.convert_to_tensor([other_circuits, other_circuits]) + >>> fid = tfq.math.fidelity(reference_tensor, symbol_tensor, + ... values_tensor, other_tensor) + >>> fid + tf.Tensor( + [[ 0., 0.925, 0.25], + [ 0., 0.036, 0.25]],shape=(2, 3), dtype=float32) + + + + Note: `other_programs` must not contain any free symbols. These can + be resolved beforehand with `tfq.resolve_parameters`. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + other_programs: `tf.Tensor` of strings with shape [batch_size, n_others] + containing the string representations of the circuits with which to + compute the overlap on `programs` with. Must not contain any free + symbols. + Returns: + `tf.Tensor` with shape [batch_size, n_others] where `out[i][j]` is equal + to the fidelity of `programs[i]` with `symbol_values[i]` + resolved in and `other_programs[i][j]`. + """ + f32_vals = tf.cast(symbol_values, tf.float32) + ip = inner_product_op.inner_product(programs, symbol_names, f32_vals, + other_programs) + + def grad(dy): + ret_zero = tf.equal(tf.size(symbol_names), 0) + inner_prod_grad = tf.cond( + ret_zero, lambda: tf.zeros_like(symbol_values, dtype=tf.float32), + lambda: tf.math.real(2. * ip * inner_product_op._inner_product_grad( + programs, symbol_names, symbol_values, other_programs, dy))) + return [None, None, inner_prod_grad, None] + + return tf.math.abs(ip)**2, grad diff --git a/tensorflow_quantum/core/ops/math_ops/fidelity_op_test.py b/tensorflow_quantum/core/ops/math_ops/fidelity_op_test.py new file mode 100644 index 000000000..a17011bd3 --- /dev/null +++ b/tensorflow_quantum/core/ops/math_ops/fidelity_op_test.py @@ -0,0 +1,320 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Tests that specifically target tfq_inner_product.""" +# 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 + +import copy +import numpy as np +from absl.testing import parameterized +import tensorflow as tf +import cirq + +from tensorflow_quantum.core.ops.math_ops import fidelity_op +from tensorflow_quantum.python import util + + +class FidelityTest(tf.test.TestCase, parameterized.TestCase): + """Tests tfq_fidelity_op.""" + + @parameterized.parameters([ + { + 'n_qubits': 5, + 'batch_size': 1, + 'inner_dim_size': 5 + }, + { + 'n_qubits': 5, + 'batch_size': 10, + 'inner_dim_size': 1 + }, + { + 'n_qubits': 10, + 'batch_size': 10, + 'inner_dim_size': 2 + }, + { + 'n_qubits': 5, + 'batch_size': 10, + 'inner_dim_size': 5 + }, + ]) + def test_correctness_with_symbols(self, n_qubits, batch_size, + inner_dim_size): + """Tests that inner_product works with symbols.""" + symbol_names = ['alpha', 'beta', 'gamma'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + other_batch = [ + util.random_circuit_resolver_batch(qubits, inner_dim_size)[0] + for i in range(batch_size) + ] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + programs = util.convert_to_tensor(circuit_batch) + other_programs = util.convert_to_tensor(other_batch) + symbol_names = tf.convert_to_tensor(symbol_names, + dtype=tf.dtypes.string) + symbol_values = tf.convert_to_tensor(symbol_values_array) + + out = fidelity_op.fidelity(programs, symbol_names, symbol_values, + other_programs) + + out_arr = np.empty((batch_size, inner_dim_size), dtype=np.complex64) + for i in range(batch_size): + final_circuit = cirq.resolve_parameters(circuit_batch[i], + resolver_batch[i]) + final_wf = cirq.final_state_vector(final_circuit) + for j in range(inner_dim_size): + internal_wf = cirq.final_state_vector(other_batch[i][j]) + out_arr[i][j] = np.abs(np.vdot(final_wf, internal_wf))**2 + + self.assertAllClose(out, out_arr, atol=1e-5) + self.assertDTypeEqual(out, tf.float32.as_numpy_dtype) + + @parameterized.parameters([ + { + 'n_qubits': 5, + 'batch_size': 1, + 'inner_dim_size': 5 + }, + { + 'n_qubits': 5, + 'batch_size': 2, + 'inner_dim_size': 1 + }, + { + 'n_qubits': 10, + 'batch_size': 3, + 'inner_dim_size': 2 + }, + { + 'n_qubits': 5, + 'batch_size': 10, + 'inner_dim_size': 5 + }, + ]) + def test_correctness_without_symbols(self, n_qubits, batch_size, + inner_dim_size): + """Tests that inner_product works without symbols.""" + qubits = cirq.LineQubit.range(n_qubits) + circuit_batch, _ = \ + util.random_circuit_resolver_batch( + qubits, batch_size) + + other_batch = [ + util.random_circuit_resolver_batch(qubits, inner_dim_size)[0] + for i in range(batch_size) + ] + + programs = util.convert_to_tensor(circuit_batch) + other_programs = util.convert_to_tensor(other_batch) + symbol_names = tf.convert_to_tensor([], dtype=tf.dtypes.string) + symbol_values = tf.convert_to_tensor([[] for _ in range(batch_size)]) + + out = fidelity_op.fidelity(programs, symbol_names, symbol_values, + other_programs) + + out_arr = np.empty((batch_size, inner_dim_size), dtype=np.complex64) + for i in range(batch_size): + final_wf = cirq.final_state_vector(circuit_batch[i]) + for j in range(inner_dim_size): + internal_wf = cirq.final_state_vector(other_batch[i][j]) + out_arr[i][j] = np.abs(np.vdot(final_wf, internal_wf))**2 + + self.assertAllClose(out, out_arr, atol=1e-5) + self.assertDTypeEqual(out, tf.float32.as_numpy_dtype) + + def test_correctness_empty(self): + """Tests the fidelity with empty circuits.""" + + empty_circuit = util.convert_to_tensor([cirq.Circuit()]) + empty_symbols = tf.convert_to_tensor([], dtype=tf.dtypes.string) + empty_values = tf.convert_to_tensor([[]]) + other_program = util.convert_to_tensor([[cirq.Circuit()]]) + + out = fidelity_op.fidelity(empty_circuit, empty_symbols, empty_values, + other_program) + expected = np.array([[1.0]], dtype=np.complex64) + self.assertAllClose(out, expected) + self.assertDTypeEqual(out, tf.float32.as_numpy_dtype) + + qubit = cirq.GridQubit(0, 0) + non_empty_circuit = util.convert_to_tensor( + [cirq.Circuit(cirq.X(qubit))]) + empty_symbols = tf.convert_to_tensor([], dtype=tf.dtypes.string) + empty_values = tf.convert_to_tensor([[]]) + other_program = util.convert_to_tensor([[cirq.Circuit()]]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'qubits not found'): + fidelity_op.fidelity(non_empty_circuit, empty_symbols, empty_values, + other_program) + + @parameterized.parameters([ + { + 'n_qubits': 5, + 'batch_size': 1, + 'inner_dim_size': 1 + }, + { + 'n_qubits': 5, + 'batch_size': 3, + 'inner_dim_size': 1 + }, + ]) + def test_tf_gradient_correctness_with_symbols(self, n_qubits, batch_size, + inner_dim_size): + """Tests that tf.gradient of inner_product works with symbols.""" + symbol_names = ['alpha', 'beta', 'gamma'] + n_params = len(symbol_names) + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + other_batch = [0 for i in range(batch_size)] + for i in range(len(other_batch)): + other_batch[i] = copy.deepcopy(circuit_batch) + for j in range(len(other_batch[i])): + other_batch[i][j] = cirq.resolve_parameters( + circuit_batch[i], resolver_batch[i]) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + programs = util.convert_to_tensor(circuit_batch) + other_programs = util.convert_to_tensor(other_batch) + symbol_names_tensor = tf.convert_to_tensor(symbol_names, + dtype=tf.dtypes.string) + symbol_values = tf.convert_to_tensor(symbol_values_array) + + with tf.GradientTape() as tape: + tape.watch(symbol_values) + ip = fidelity_op.fidelity(programs, symbol_names_tensor, + symbol_values, other_programs) + out = tape.gradient(ip, symbol_values) + + out_arr = np.zeros((batch_size, n_params), dtype=np.complex64) + # dx came from _GRAD_EPS of core/src/adj_util.cc + dx = 5e-3 + for i in range(batch_size): + for k, name in enumerate(symbol_names): + if name in resolver_batch[i].param_dict: + new_resolver = copy.deepcopy(resolver_batch[i]) + new_resolver.param_dict[name] += dx + final_circuit_p = cirq.resolve_parameters( + circuit_batch[i], new_resolver) + new_resolver = copy.deepcopy(resolver_batch[i]) + new_resolver.param_dict[name] -= dx + final_circuit_m = cirq.resolve_parameters( + circuit_batch[i], new_resolver) + final_wf_p = cirq.final_state_vector(final_circuit_p) + final_wf_m = cirq.final_state_vector(final_circuit_m) + # Performs central finite difference. + for j in range(inner_dim_size): + internal_wf = cirq.final_state_vector(other_batch[i][j]) + fid_p = cirq.fidelity(final_wf_p, internal_wf) + fid_m = cirq.fidelity(final_wf_m, internal_wf) + grad_fid = 0.5 * (fid_p - fid_m) / dx + out_arr[i][k] += grad_fid + + self.assertAllClose(out, out_arr, atol=1e-3) + self.assertDTypeEqual(out, tf.float32.as_numpy_dtype) + + @parameterized.parameters([ + { + 'n_qubits': 5, + 'batch_size': 1, + 'inner_dim_size': 5 + }, + { + 'n_qubits': 5, + 'batch_size': 3, + 'inner_dim_size': 2 + }, + ]) + def test_tf_gradient_correctness_without_symbols(self, n_qubits, batch_size, + inner_dim_size): + """Tests that tf.gradient of inner_product works without symbols.""" + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, _ = \ + util.random_circuit_resolver_batch( + qubits, batch_size) + + other_batch = [ + util.random_circuit_resolver_batch(qubits, inner_dim_size)[0] + for i in range(batch_size) + ] + + programs = util.convert_to_tensor(circuit_batch) + other_programs = util.convert_to_tensor(other_batch) + symbol_names = tf.convert_to_tensor([], dtype=tf.dtypes.string) + symbol_values = tf.convert_to_tensor([[] for _ in range(batch_size)]) + + with tf.GradientTape() as tape: + tape.watch(symbol_values) + ip = fidelity_op.fidelity(programs, symbol_names, symbol_values, + other_programs) + out = tape.gradient(ip, symbol_values) + self.assertAllClose(out, tf.zeros_like(symbol_values), atol=1e-3) + self.assertDTypeEqual(out, tf.float32.as_numpy_dtype) + + def test_correctness_no_circuit(self): + """Test the inner product between no circuits.""" + + empty_circuit = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_symbols = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + other_program = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + + out = fidelity_op.fidelity(empty_circuit, empty_symbols, empty_values, + other_program) + self.assertShapeEqual(np.zeros((0, 0)), out) + self.assertDTypeEqual(out, tf.float32.as_numpy_dtype) + + def test_tf_gradient_correctness_no_circuit(self): + """Test the inner product grad between no circuits.""" + + empty_circuit = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_symbols = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + other_program = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + + with tf.GradientTape() as tape: + tape.watch(empty_values) + out = fidelity_op.fidelity(empty_circuit, empty_symbols, + empty_values, other_program) + + self.assertShapeEqual(np.zeros((0, 0)), out) + self.assertDTypeEqual(out, tf.float32.as_numpy_dtype) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/ops/math_ops/inner_product_grad_test.py b/tensorflow_quantum/core/ops/math_ops/inner_product_grad_test.py new file mode 100644 index 000000000..513f1eeb0 --- /dev/null +++ b/tensorflow_quantum/core/ops/math_ops/inner_product_grad_test.py @@ -0,0 +1,394 @@ +# Copyright 2021 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Tests that specifically target tfq_inner_product_grad.""" +# 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 + +import copy +import numpy as np +from absl.testing import parameterized +import tensorflow as tf +import cirq + +from tensorflow_quantum.core.ops.math_ops import inner_product_op +from tensorflow_quantum.python import util + + +class InnerProductAdjGradTest(tf.test.TestCase, parameterized.TestCase): + """Tests tfq_inner_product_grad.""" + + def test_inner_product_grad_inputs(self): + """Makes sure that inner_product_adj_grad fails on bad inputs.""" + n_qubits = 5 + batch_size = 5 + n_other_programs = 3 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + prev_grad = np.ones((batch_size, n_other_programs)) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + other_batch = [ + util.random_circuit_resolver_batch(qubits, n_other_programs)[0] + for i in range(batch_size) + ] + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # Circuit tensor has too many dimensions. + inner_product_op._inner_product_grad( + util.convert_to_tensor([circuit_batch]), + symbol_names, symbol_values_array, + util.convert_to_tensor(other_batch), prev_grad) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1.'): + # symbol_names tensor has too many dimensions. + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), + np.array([symbol_names]), symbol_values_array, + util.convert_to_tensor(other_batch), prev_grad) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too many dimensions. + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array]), + util.convert_to_tensor(other_batch), prev_grad) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too few dimensions. + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array[0], + util.convert_to_tensor(other_batch), prev_grad) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'other_programs must be rank 2.'): + # other_programs tensor has too few dimensions. + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + util.convert_to_tensor(circuit_batch), prev_grad) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'other_programs must be rank 2.'): + # pauli_sums tensor has too many dimensions. + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in other_batch]), prev_grad) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # circuit tensor has the right type but invalid values. + inner_product_op._inner_product_grad( + ['junk'] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor(other_batch), prev_grad) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type but invalid values. + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), + ['junk'], symbol_values_array, + util.convert_to_tensor(other_batch), prev_grad) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'not found in reference circuit'): + # other_programs tensor has the right type but operates on + # qubits that the reference ciruit doesn't have. + new_qubits = [cirq.GridQubit(5, 5), cirq.GridQubit(9, 9)] + new_circuits, _ = util.random_circuit_resolver_batch( + new_qubits, batch_size) + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in new_circuits]), prev_grad) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'not found in paired circuit'): + # other_programs tensor has the right type but operates on + # qubits that the reference ciruit doesn't have. + new_qubits = cirq.GridQubit.rect(1, n_qubits - 1) + new_circuits, _ = util.random_circuit_resolver_batch( + new_qubits, batch_size) + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in new_circuits]), prev_grad) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # circuits tensor has the wrong type. + inner_product_op._inner_product_grad( + [1.0] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor(other_batch), prev_grad) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), + [0.1234], symbol_values_array, + util.convert_to_tensor(other_batch), prev_grad) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), + symbol_names, [['junk']] * batch_size, + util.convert_to_tensor(other_batch), prev_grad) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # other_programs tensor has the wrong type. + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [[1.0]] * batch_size, prev_grad) + + with self.assertRaisesRegex(TypeError, 'missing'): + # we are missing an argument. + # pylint: disable=no-value-for-parameter + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, prev_grad) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(TypeError, 'positional arguments'): + # pylint: disable=too-many-function-args + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + util.convert_to_tensor(other_batch), prev_grad, []) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # batch programs has wrong batch size. + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor(other_batch[:int(batch_size * 0.5)]), + prev_grad) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # batch programs has wrong batch size. + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[::int(batch_size * 0.5)], + util.convert_to_tensor(other_batch), prev_grad) + + with self.assertRaisesRegex( + tf.errors.InvalidArgumentError, + expected_regex='Found symbols in other_programs'): + # other_programs has symbols. + inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in circuit_batch]), prev_grad) + + res = inner_product_op._inner_product_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array.astype(np.float64), + util.convert_to_tensor(other_batch), prev_grad) + self.assertDTypeEqual(res, np.complex64) + + @parameterized.parameters([ + { + 'n_qubits': 5, + 'batch_size': 1, + 'inner_dim_size': 5 + }, + { + 'n_qubits': 5, + 'batch_size': 10, + 'inner_dim_size': 1 + }, + { + 'n_qubits': 10, + 'batch_size': 10, + 'inner_dim_size': 2 + }, + { + 'n_qubits': 5, + 'batch_size': 10, + 'inner_dim_size': 5 + }, + ]) + def test_correctness_with_symbols(self, n_qubits, batch_size, + inner_dim_size): + """Tests that inner_product works with symbols.""" + symbol_names = ['alpha', 'beta', 'gamma'] + n_params = len(symbol_names) + qubits = cirq.LineQubit.range(n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + other_batch = [ + util.random_circuit_resolver_batch(qubits, inner_dim_size)[0] + for i in range(batch_size) + ] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + programs = util.convert_to_tensor(circuit_batch) + other_programs = util.convert_to_tensor(other_batch) + symbol_names_tensor = tf.convert_to_tensor(symbol_names, + dtype=tf.dtypes.string) + symbol_values = tf.convert_to_tensor(symbol_values_array) + prev_grad = tf.cast(tf.random.normal((batch_size, inner_dim_size)), + tf.complex64) + + out = inner_product_op._inner_product_grad(programs, + symbol_names_tensor, + symbol_values, + other_programs, prev_grad) + + out_arr = np.zeros((batch_size, n_params), dtype=np.complex64) + # dx came from _GRAD_EPS of core/src/adj_util.cc + dx = 5e-3 + for i, resolver in enumerate(resolver_batch): + for k, name in enumerate(symbol_names): + if name in resolver.param_dict: + new_resolver = copy.deepcopy(resolver) + new_resolver.param_dict[name] += dx + final_circuit_p = cirq.resolve_parameters( + circuit_batch[i], new_resolver) + new_resolver = copy.deepcopy(resolver) + new_resolver.param_dict[name] -= dx + final_circuit_m = cirq.resolve_parameters( + circuit_batch[i], new_resolver) + final_wf_p = cirq.final_state_vector(final_circuit_p) + final_wf_m = cirq.final_state_vector(final_circuit_m) + # Performs central finite difference. + final_wf_grad = 0.5 * (final_wf_p - final_wf_m) / dx + for j, other in enumerate(other_batch[i]): + internal_wf = cirq.final_state_vector(other) + out_arr[i][k] += (prev_grad[i][j] * + np.vdot(final_wf_grad, internal_wf)) + + self.assertAllClose(out, np.conj(out_arr), atol=1e-3) + + @parameterized.parameters([ + { + 'n_qubits': 5, + 'batch_size': 1, + 'inner_dim_size': 5 + }, + { + 'n_qubits': 5, + 'batch_size': 10, + 'inner_dim_size': 1 + }, + { + 'n_qubits': 10, + 'batch_size': 10, + 'inner_dim_size': 2 + }, + { + 'n_qubits': 5, + 'batch_size': 10, + 'inner_dim_size': 5 + }, + ]) + def test_correctness_without_symbols(self, n_qubits, batch_size, + inner_dim_size): + """Tests that inner_product_adj_grad works without symbols.""" + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, _ = \ + util.random_circuit_resolver_batch( + qubits, batch_size) + + other_batch = [ + util.random_circuit_resolver_batch(qubits, inner_dim_size)[0] + for i in range(batch_size) + ] + + programs = util.convert_to_tensor(circuit_batch) + other_programs = util.convert_to_tensor(other_batch) + symbol_names = tf.convert_to_tensor([], dtype=tf.dtypes.string) + symbol_values = tf.convert_to_tensor([[] for _ in range(batch_size)]) + prev_grad = np.ones((batch_size, inner_dim_size)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbols must be a positive integer'): + inner_product_op._inner_product_grad(programs, symbol_names, + symbol_values, other_programs, + prev_grad) + + def test_correctness_empty(self): + """Tests the inner product adj grad between two empty circuits.""" + symbol_names = ['alpha', 'beta'] + empty_cicuit = util.convert_to_tensor([cirq.Circuit()]) + empty_symbols = tf.convert_to_tensor([], dtype=tf.dtypes.string) + empty_values = tf.convert_to_tensor([[]]) + other_program = util.convert_to_tensor([[cirq.Circuit()]]) + prev_grad = np.ones((1, 1)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbols must be a positive integer'): + inner_product_op._inner_product_grad(empty_cicuit, empty_symbols, + empty_values, other_program, + prev_grad) + + empty_cicuit = util.convert_to_tensor([cirq.Circuit()]) + symbol_names = tf.convert_to_tensor(symbol_names, + dtype=tf.dtypes.string) + symbol_values = tf.convert_to_tensor([[0.0 for _ in range(2)]]) + other_program = util.convert_to_tensor([[cirq.Circuit()]]) + + out = inner_product_op._inner_product_grad(empty_cicuit, symbol_names, + symbol_values, other_program, + prev_grad) + expected = np.zeros((1, len(symbol_names)), dtype=np.complex64) + self.assertAllClose(out, expected) + + def test_correctness_no_circuit(self): + """Test the inner product grad between no circuits.""" + + empty_circuit = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_symbols = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + other_program = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + empty_pred_grad = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'number of symbols must be a positive'): + # When using `tf.gradients`, a user will never encounter this error + # thanks to the `tf.cond` inside of the custom gradient. + _ = inner_product_op._inner_product_grad(empty_circuit, + empty_symbols, + empty_values, + other_program, + empty_pred_grad) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/ops/math_ops/inner_product_op.py b/tensorflow_quantum/core/ops/math_ops/inner_product_op.py index 1720672cf..54e49643e 100644 --- a/tensorflow_quantum/core/ops/math_ops/inner_product_op.py +++ b/tensorflow_quantum/core/ops/math_ops/inner_product_op.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to register python op gradient.""" import os import tensorflow as tf @@ -20,14 +20,63 @@ MATH_OP_MODULE = load_module(os.path.join("math_ops", "_tfq_math_ops.so")) +def _inner_product_grad(programs, symbol_names, symbol_values, other_programs, + prev_grad): + """Calculate the adjoint gradients of the inner product between circuits. + + Compute the gradients of the (potentially many) inner products between + the given circuits and the symbol free comparison circuits. + + Calculates out[i][j][k] = $ \frac{\langle \psi_{\text{programs[i]}} \\ + (\text{symbol_values[i]})}{\partial \text{symbol_names[k]}} | \\ + \psi_{\text{other_programs[j]}} \rangle $ + + + Note: `other_programs` must not contain any free symbols. These can + be resolved beforehand with `tfq.resolve_parameters`. + + Note: len(symbol_names) (=n_params) should be a positive integer. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + other_programs: `tf.Tensor` of strings with shape [batch_size, n_others] + containing the string representations of the circuits with which to + compute the overlap on `programs` with. Must not contain any free + symbols. + prev_grad: `tf.Tensor` of real numbers with shape [batch_size, n_ops] + backprop of values from downstream in the compute graph. + + Returns: + tf.Tensor` with shape [batch_size, n_symbols] where `out[i][j]` is equal + to the gradient of the inner product between programs[i] and all + other_programs[i] w.r.t. `symbol_names[j]` and `programs[i]` is resolved + with `symbol_values[i]`. + """ + # Due to TF gradient scheme, we return complex conjugate derivative. + return tf.math.conj( + MATH_OP_MODULE.tfq_inner_product_grad( + programs, symbol_names, tf.cast(symbol_values, tf.float32), + other_programs, tf.cast(prev_grad, tf.float32))) + + +@tf.custom_gradient def inner_product(programs, symbol_names, symbol_values, other_programs): """Calculate the inner product between circuits. Compute (potentially many) inner products between the given circuits and the symbol free comparison circuits. - Calculates out[i][j] = \langle \psi_{\text{programs[i]}} \\ - (\text{symbol_values[i]}) | \psi_{\text{other_programs[j]}} \rangle + Calculates out[i][j] = $ \langle \psi_{\text{programs[i]}} \\ + (\text{symbol\_values[i]}) | \psi_{\text{other\_programs[j]}} \rangle $ >>> symbols = sympy.symbols('alpha beta') @@ -44,10 +93,11 @@ def inner_product(programs, symbol_names, symbol_values, other_programs): ... cirq.Circuit((cirq.X**0.5).on_each(qubits)) ... ] >>> reference_tensor = tfq.convert_to_tensor(reference_circuits) - >>> symbol_tensor = tf.convert_to_tensor(list(symbols)) + >>> symbol_tensor = tf.convert_to_tensor([s.name for s in symbols]) >>> values_tensor = tf.convert_to_tensor(np.arange(4).reshape(2, 2)) >>> other_tensor = tfq.convert_to_tensor([other_circuits, other_circuits]) - >>> ip = tfq.math.inner_product(reference_tensor) + >>> ip = tfq.math.inner_product(reference_tensor, symbol_tensor, + ... values_tensor, other_tensor) >>> ip tf.Tensor( [[ 0+0.j, 8.8871640e-01+0.3681184j, @@ -60,8 +110,6 @@ def inner_product(programs, symbol_names, symbol_values, other_programs): Note: `other_programs` must not contain any free symbols. These can be resolved beforehand with `tfq.resolve_parameters`. - Note: Currently this op is not differentiable. - Args: programs: `tf.Tensor` of strings with shape [batch_size] containing the string representations of the circuits @@ -81,8 +129,20 @@ def inner_product(programs, symbol_names, symbol_values, other_programs): `tf.Tensor` with shape [batch_size, n_others] where `out[i][j]` is equal to the inner product of `programs[i]` with `symbol_values[i]` resolved in and `other_programs[i][j]`. - """ + + def grad(dy): + + def _true_grad(): + return _inner_product_grad(programs, symbol_names, symbol_values, + other_programs, dy) + + ret_zero = tf.equal(tf.size(symbol_names), 0) + inner_prod_grad = tf.cond( + ret_zero, lambda: tf.zeros_like(symbol_values, dtype=tf.complex64), + _true_grad) + return [None, None, inner_prod_grad, None] + return MATH_OP_MODULE.tfq_inner_product(programs, symbol_names, tf.cast(symbol_values, tf.float32), - other_programs) + other_programs), grad diff --git a/tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py b/tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py index b9a62c116..fb4bbf5c9 100644 --- a/tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py +++ b/tensorflow_quantum/core/ops/math_ops/inner_product_op_test.py @@ -11,8 +11,17 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== -"""Tests that specifically target tfq_simulate_ops.""" +# ============================================================================= +"""Tests that specifically target tfq_inner_product.""" +# 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 + +import copy import numpy as np from absl.testing import parameterized import tensorflow as tf @@ -26,7 +35,7 @@ class InnerProductTest(tf.test.TestCase, parameterized.TestCase): """Tests tfq_inner_product.""" def test_inner_product_inputs(self): - """Make sure that inner_product fails gracefully on bad inputs.""" + """Makes sure that inner_product fails gracefully on bad inputs.""" n_qubits = 5 batch_size = 5 symbol_names = ['alpha'] @@ -190,6 +199,15 @@ def test_inner_product_inputs(self): symbol_values_array, util.convert_to_tensor([[x] for x in circuit_batch])) + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + inner_product_op.inner_product( + util.convert_to_tensor([noisy_circuit for _ in circuit_batch]), + symbol_names, symbol_values_array, + util.convert_to_tensor(other_batch)) + res = inner_product_op.inner_product( util.convert_to_tensor(circuit_batch), symbol_names, symbol_values_array.astype(np.float64), @@ -197,6 +215,11 @@ def test_inner_product_inputs(self): self.assertDTypeEqual(res, np.complex64) @parameterized.parameters([ + { + 'n_qubits': 5, + 'batch_size': 1, + 'inner_dim_size': 5 + }, { 'n_qubits': 5, 'batch_size': 10, @@ -215,9 +238,9 @@ def test_inner_product_inputs(self): ]) def test_correctness_with_symbols(self, n_qubits, batch_size, inner_dim_size): - """Test that inner_product works with symbols.""" + """Tests that inner_product works with symbols.""" symbol_names = ['alpha', 'beta', 'gamma'] - qubits = cirq.GridQubit.rect(1, n_qubits) + qubits = cirq.LineQubit.range(n_qubits) circuit_batch, resolver_batch = \ util.random_symbol_circuit_resolver_batch( qubits, symbol_names, batch_size) @@ -250,17 +273,22 @@ def test_correctness_with_symbols(self, n_qubits, batch_size, internal_wf = cirq.final_state_vector(other_batch[i][j]) out_arr[i][j] = np.vdot(final_wf, internal_wf) - self.assertAllClose(out, out_arr) + self.assertAllClose(out, out_arr, atol=1e-5) @parameterized.parameters([ { 'n_qubits': 5, - 'batch_size': 10, + 'batch_size': 1, + 'inner_dim_size': 5 + }, + { + 'n_qubits': 5, + 'batch_size': 2, 'inner_dim_size': 1 }, { 'n_qubits': 10, - 'batch_size': 10, + 'batch_size': 3, 'inner_dim_size': 2 }, { @@ -271,7 +299,7 @@ def test_correctness_with_symbols(self, n_qubits, batch_size, ]) def test_correctness_without_symbols(self, n_qubits, batch_size, inner_dim_size): - """Test that inner_product works with symbols.""" + """Tests that inner_product works without symbols.""" qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, _ = \ util.random_circuit_resolver_batch( @@ -297,21 +325,165 @@ def test_correctness_without_symbols(self, n_qubits, batch_size, internal_wf = cirq.final_state_vector(other_batch[i][j]) out_arr[i][j] = np.vdot(final_wf, internal_wf) - self.assertAllClose(out, out_arr) + self.assertAllClose(out, out_arr, atol=1e-5) def test_correctness_empty(self): - """Test the inner product between two empty circuits.""" + """Tests the inner product with empty circuits.""" - empty_cicuit = util.convert_to_tensor([cirq.Circuit()]) + empty_circuit = util.convert_to_tensor([cirq.Circuit()]) empty_symbols = tf.convert_to_tensor([], dtype=tf.dtypes.string) empty_values = tf.convert_to_tensor([[]]) other_program = util.convert_to_tensor([[cirq.Circuit()]]) - out = inner_product_op.inner_product(empty_cicuit, empty_symbols, + out = inner_product_op.inner_product(empty_circuit, empty_symbols, empty_values, other_program) expected = np.array([[1.0]], dtype=np.complex64) self.assertAllClose(out, expected) + qubit = cirq.GridQubit(0, 0) + non_empty_circuit = util.convert_to_tensor( + [cirq.Circuit(cirq.X(qubit))]) + empty_symbols = tf.convert_to_tensor([], dtype=tf.dtypes.string) + empty_values = tf.convert_to_tensor([[]]) + other_program = util.convert_to_tensor([[cirq.Circuit()]]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'qubits not found'): + inner_product_op.inner_product(non_empty_circuit, empty_symbols, + empty_values, other_program) + + @parameterized.parameters([ + { + 'n_qubits': 5, + 'batch_size': 1, + 'inner_dim_size': 5 + }, + { + 'n_qubits': 5, + 'batch_size': 3, + 'inner_dim_size': 2 + }, + ]) + def test_tf_gradient_correctness_with_symbols(self, n_qubits, batch_size, + inner_dim_size): + """Tests that tf.gradient of inner_product works with symbols.""" + symbol_names = ['alpha', 'beta', 'gamma'] + n_params = len(symbol_names) + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + other_batch = [ + util.random_circuit_resolver_batch(qubits, inner_dim_size)[0] + for i in range(batch_size) + ] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + programs = util.convert_to_tensor(circuit_batch) + other_programs = util.convert_to_tensor(other_batch) + symbol_names_tensor = tf.convert_to_tensor(symbol_names, + dtype=tf.dtypes.string) + symbol_values = tf.convert_to_tensor(symbol_values_array) + + with tf.GradientTape() as tape: + tape.watch(symbol_values) + ip = inner_product_op.inner_product(programs, symbol_names_tensor, + symbol_values, other_programs) + out = tape.gradient(ip, symbol_values) + + out_arr = np.zeros((batch_size, n_params), dtype=np.complex64) + # dx came from _GRAD_EPS of core/src/adj_util.cc + dx = 5e-3 + for i in range(batch_size): + for k, name in enumerate(symbol_names): + if name in resolver_batch[i].param_dict: + new_resolver = copy.deepcopy(resolver_batch[i]) + new_resolver.param_dict[name] += dx + final_circuit_p = cirq.resolve_parameters( + circuit_batch[i], new_resolver) + new_resolver = copy.deepcopy(resolver_batch[i]) + new_resolver.param_dict[name] -= dx + final_circuit_m = cirq.resolve_parameters( + circuit_batch[i], new_resolver) + final_wf_p = cirq.final_state_vector(final_circuit_p) + final_wf_m = cirq.final_state_vector(final_circuit_m) + # Performs central finite difference. + final_wf_grad = 0.5 * (final_wf_p - final_wf_m) / dx + for j in range(inner_dim_size): + internal_wf = cirq.final_state_vector(other_batch[i][j]) + out_arr[i][k] += np.vdot(final_wf_grad, internal_wf) + + self.assertAllClose(out, np.conj(out_arr), atol=1e-3) + + @parameterized.parameters([ + { + 'n_qubits': 5, + 'batch_size': 1, + 'inner_dim_size': 5 + }, + { + 'n_qubits': 5, + 'batch_size': 3, + 'inner_dim_size': 2 + }, + ]) + def test_tf_gradient_correctness_without_symbols(self, n_qubits, batch_size, + inner_dim_size): + """Tests that tf.gradient of inner_product works without symbols.""" + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, _ = \ + util.random_circuit_resolver_batch( + qubits, batch_size) + + other_batch = [ + util.random_circuit_resolver_batch(qubits, inner_dim_size)[0] + for i in range(batch_size) + ] + + programs = util.convert_to_tensor(circuit_batch) + other_programs = util.convert_to_tensor(other_batch) + symbol_names = tf.convert_to_tensor([], dtype=tf.dtypes.string) + symbol_values = tf.convert_to_tensor([[] for _ in range(batch_size)]) + + with tf.GradientTape() as tape: + tape.watch(symbol_values) + ip = inner_product_op.inner_product(programs, symbol_names, + symbol_values, other_programs) + out = tape.gradient(ip, symbol_values) + self.assertAllClose(out, tf.zeros_like(symbol_values), atol=1e-3) + + def test_correctness_no_circuit(self): + """Test the inner product between no circuits.""" + + empty_circuit = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_symbols = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + other_program = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + + out = inner_product_op.inner_product(empty_circuit, empty_symbols, + empty_values, other_program) + self.assertShapeEqual(np.zeros((0, 0)), out) + + def test_tf_gradient_correctness_no_circuit(self): + """Test the inner product grad between no circuits.""" + + empty_circuit = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_symbols = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + other_program = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + + with tf.GradientTape() as tape: + tape.watch(empty_values) + out = inner_product_op.inner_product(empty_circuit, empty_symbols, + empty_values, other_program) + + self.assertShapeEqual(np.zeros((0, 0)), out) + if __name__ == "__main__": tf.test.main() diff --git a/tensorflow_quantum/core/ops/math_ops/simulate_mps.py b/tensorflow_quantum/core/ops/math_ops/simulate_mps.py new file mode 100644 index 000000000..41e1fd7c2 --- /dev/null +++ b/tensorflow_quantum/core/ops/math_ops/simulate_mps.py @@ -0,0 +1,152 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Module to register MPS simulation ops.""" +import os +import tensorflow as tf +from tensorflow_quantum.core.ops.load_module import load_module +from tensorflow_quantum.core.ops import tfq_utility_ops + +MATH_OP_MODULE = load_module(os.path.join("math_ops", "_tfq_math_ops.so")) + + +def mps_1d_expectation(programs, + symbol_names, + symbol_values, + pauli_sums, + bond_dim=4): + """Calculate the expectation value of circuits wrt some operator(s) + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + From there we will then compute the expectation values of `pauli_sums` + on the final states. Note that this op requires 1D non periodic circuits. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] + containing the string representation of the operators that will + be used on all of the circuits in the expectation calculations. + bond_dim: Integer value used for the bond dimension during simulation. + + Returns: + `tf.Tensor` with shape [batch_size, n_ops] that holds the + expectation value for each circuit with each op applied to it + (after resolving the corresponding parameters in). + """ + return MATH_OP_MODULE.tfq_simulate_mps1d_expectation(programs, + symbol_names, + tf.cast( + symbol_values, + tf.float32), + pauli_sums, + bond_dim=bond_dim) + + +def mps_1d_sample(programs, + symbol_names, + symbol_values, + num_samples, + bond_dim=4): + """Generate samples using the C++ MPS simulator. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + From there we will then sample from the final state. Note that this op + requires 1D non periodic circuits. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specified by programs, following the ordering + dictated by `symbol_names`. + num_samples: `tf.Tensor` with one element indicating the number of + samples to draw. + bond_dim: Integer value used for the bond dimension during simulation. + + Returns: + A `tf.RaggedTensor` containing the samples taken from each circuit in + `programs`. + """ + padded_samples = MATH_OP_MODULE.tfq_simulate_mps1d_samples( + programs, + symbol_names, + tf.cast(symbol_values, tf.float32), + num_samples, + bond_dim=bond_dim) + + return tfq_utility_ops.padded_to_ragged(padded_samples) + + +def mps_1d_sampled_expectation(programs, + symbol_names, + symbol_values, + pauli_sums, + num_samples, + bond_dim=4): + """Calculate the expectation value of circuits using samples. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + Them, sample the resulting state `num_samples` times and use these samples + to compute expectation values of the given `pauli_sums`. Note that this op + requires 1D non periodic circuits. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] + containing the string representation of the operators that will + be used on all of the circuits in the expectation calculations. + num_samples: `tf.Tensor` with `num_samples[i][j]` is equal to the + number of samples to draw in each term of `pauli_sums[i][j]` + when estimating the expectation. Therefore, `num_samples` must + have the same shape as `pauli_sums`. + bond_dim: Integer value used for the bond dimension during simulation. + + Returns: + `tf.Tensor` with shape [batch_size, n_ops] that holds the + expectation value for each circuit with each op applied to it + (after resolving the corresponding parameters in). + """ + return MATH_OP_MODULE.tfq_simulate_mps1d_sampled_expectation( + programs, + symbol_names, + tf.cast(symbol_values, tf.float32), + pauli_sums, + tf.cast(num_samples, dtype=tf.int32), + bond_dim=bond_dim) diff --git a/tensorflow_quantum/core/ops/math_ops/simulate_mps_test.py b/tensorflow_quantum/core/ops/math_ops/simulate_mps_test.py new file mode 100644 index 000000000..3ed527ed8 --- /dev/null +++ b/tensorflow_quantum/core/ops/math_ops/simulate_mps_test.py @@ -0,0 +1,1023 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Tests that specifically target simulate_mps.""" +# 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 + +from absl.testing import parameterized +import numpy as np +import tensorflow as tf +import cirq +import cirq_google +import sympy + +from scipy import stats + +from tensorflow_quantum.core.ops import batch_util +from tensorflow_quantum.core.ops.math_ops import simulate_mps +from tensorflow_quantum.python import util + + +def _make_1d_circuit(qubits, depth): + """Create a 1d ladder circuit.""" + even_pairs = list(zip(qubits[::2], qubits[1::2])) + odd_pairs = list(zip(qubits[1::2], qubits[2::2])) + ret = cirq.Circuit() + + for _ in range(depth): + # return ret + ret += [(cirq.Y(q)**np.random.random()) for q in qubits] + ret += [ + cirq_google.SycamoreGate()(q0, q1)**np.random.random() + for q0, q1 in even_pairs + ] + ret += [(cirq.Y(q)**np.random.random()) for q in qubits] + ret += [ + cirq_google.SycamoreGate()(q1, q0)**np.random.random() + for q0, q1 in odd_pairs + ] + + return ret + + +class SimulateMPS1DExpectationTest(tf.test.TestCase): + """Tests mps_1d_expectation.""" + + def test_simulate_mps_1d_expectation_inputs(self): + """Makes sure that the op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch = [ + cirq.Circuit( + cirq.X(qubits[0])**sympy.Symbol(symbol_names[0]), + cirq.Z(qubits[1]), + cirq.CNOT(qubits[2], qubits[3]), + cirq.Y(qubits[4])**sympy.Symbol(symbol_names[0]), + ) for _ in range(batch_size) + ] + resolver_batch = [{symbol_names[0]: 0.123} for _ in range(batch_size)] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # Circuit tensor has too many dimensions. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor([circuit_batch]), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1.'): + # symbol_names tensor has too many dimensions. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too many dimensions. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array]), + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too few dimensions. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[0], + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too few dimensions. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, util.convert_to_tensor(list(pauli_sums))) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too many dimensions. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[[x]] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # circuit tensor has the right type but invalid values. + simulate_mps.mps_1d_expectation( + ['junk'] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type but invalid values. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), ['junk'], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'qubits not found in circuit'): + # pauli_sums tensor has the right type but invalid values. + new_qubits = [cirq.GridQubit(5, 5), cirq.GridQubit(9, 9)] + new_pauli_sums = util.random_pauli_sums(new_qubits, 2, batch_size) + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in new_pauli_sums])) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # circuits tensor has the wrong type. + simulate_mps.mps_1d_expectation( + [1.0] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), [0.1234], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # pauli_sums tensor has the wrong type. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [[1.0]] * batch_size) + + with self.assertRaisesRegex(TypeError, 'missing'): + # we are missing an argument. + # pylint: disable=no-value-for-parameter + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'at least minimum 4'): + # pylint: disable=too-many-function-args + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), 1) + + with self.assertRaisesRegex(TypeError, 'Expected int'): + # bond_dim should be int. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), []) + + with self.assertRaisesRegex(TypeError, 'positional arguments'): + # pylint: disable=too-many-function-args + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), 1, []) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong op size. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums + ][:int(batch_size * 0.5)])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)], + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + simulate_mps.mps_1d_expectation( + util.convert_to_tensor([noisy_circuit for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='not in 1D topology'): + # attempting to use a circuit not in 1D topology + # 0--1--2--3 + # \-4 + circuit_not_1d = cirq.Circuit( + cirq.X(qubits[0])**sympy.Symbol(symbol_names[0]), + cirq.Z(qubits[1])**sympy.Symbol(symbol_names[0]), + cirq.CNOT(qubits[2], qubits[3]), + cirq.CNOT(qubits[2], qubits[4]), + ) + simulate_mps.mps_1d_expectation( + util.convert_to_tensor([circuit_not_1d for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='not in 1D topology'): + # attempting to use a circuit in 1D topology, which looks in 2D. + # 0--1 + # \-2-\ + # 3--4 == 1--0--2--4--3 + circuit_not_1d = cirq.Circuit( + cirq.CNOT(qubits[0], qubits[1]), + cirq.CNOT(qubits[0], qubits[2]), + cirq.CNOT(qubits[2], qubits[4]), + cirq.CNOT(qubits[3], qubits[4]), + ) + simulate_mps.mps_1d_expectation( + util.convert_to_tensor([circuit_not_1d for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='Found: 3 qubit gate'): + # attempting to use 3 qubit gate + three_qb_circuit = cirq.Circuit( + cirq.ISWAP(qubits[0], qubits[1]).controlled_by(qubits[2]), + cirq.X.on_each(*qubits)) + simulate_mps.mps_1d_expectation( + util.convert_to_tensor([three_qb_circuit for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='minimum 3 qubits'): + # too few qubits. + circuit_small = cirq.Circuit(cirq.X(qubits[0]), cirq.X(qubits[1]), + cirq.X(qubits[2])) + small_pauli = cirq.Z(qubits[0]) + + simulate_mps.mps_1d_expectation( + util.convert_to_tensor([circuit_small for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[small_pauli] for _ in pauli_sums])) + + def test_simulate_mps_1d_expectation_simple(self): + """Makes sure that the op shows the same result with Cirq.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch = [ + cirq.Circuit( + cirq.X(qubits[0])**sympy.Symbol(symbol_names[0]), + cirq.Z(qubits[1]), + cirq.CNOT(qubits[2], qubits[3]), + cirq.Y(qubits[4])**sympy.Symbol(symbol_names[0]), + ) for _ in range(batch_size) + ] + resolver_batch = [{symbol_names[0]: 0.123} for _ in range(batch_size)] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = [ + cirq.Z(qubits[0]) * cirq.X(qubits[4]) for _ in range(batch_size) + ] + + cirq_result = [ + cirq.Simulator().simulate_expectation_values(c, p, r) + for c, p, r in zip(circuit_batch, pauli_sums, resolver_batch) + ] + # Default bond_dim=4 + mps_result = simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + # Expected value of 0.349... + self.assertAllClose(mps_result, cirq_result) + + def test_complex_equality(self): + """Check moderate sized 1d random circuits.""" + batch_size = 10 + qubits = cirq.GridQubit.rect(1, 8) + circuit_batch = [_make_1d_circuit(qubits, 3) for _ in range(batch_size)] + + pauli_sums = [[ + cirq.Z(qubits[0]), + cirq.Z(qubits[-1]), + cirq.Z(qubits[0]) * cirq.Z(qubits[-1]), + cirq.Z(qubits[0]) + cirq.Z(qubits[-1]) + ] for _ in range(batch_size)] + symbol_names = [] + resolver_batch = [{} for _ in range(batch_size)] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cirq_result = [ + cirq.Simulator().simulate_expectation_values(c, p, r) + for c, p, r in zip(circuit_batch, pauli_sums, resolver_batch) + ] + mps_result = simulate_mps.mps_1d_expectation( + util.convert_to_tensor(circuit_batch), + symbol_names, + symbol_values_array, + util.convert_to_tensor(pauli_sums), + bond_dim=32) + self.assertAllClose(mps_result, cirq_result, atol=1e-5) + + def test_correctness_empty(self): + """Tests the mps op with empty circuits.""" + + empty_circuit = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_symbols = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + empty_paulis = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + + out = simulate_mps.mps_1d_expectation(empty_circuit, empty_symbols, + empty_values, empty_paulis, 32) + + self.assertShapeEqual(np.zeros((0, 0)), out) + + +class SimulateMPS1DSamplesTest(tf.test.TestCase, parameterized.TestCase): + """Tests tfq_simulate_mps1d_samples.""" + + def test_simulate_mps1d_samples_inputs(self): + """Make sure the sample op fails gracefully on bad inputs.""" + n_qubits = 5 + num_samples = 10 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch = [ + cirq.Circuit( + cirq.X(qubits[0])**sympy.Symbol(symbol_names[0]), + cirq.Z(qubits[1]), + cirq.CNOT(qubits[2], qubits[3]), + cirq.Y(qubits[4])**sympy.Symbol(symbol_names[0]), + ) for _ in range(batch_size) + ] + resolver_batch = [{symbol_names[0]: 0.123} for _ in range(batch_size)] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 1. Got rank 2'): + # programs tensor has the wrong shape. + simulate_mps.mps_1d_sample(util.convert_to_tensor([circuit_batch]), + symbol_names, symbol_values_array, + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 1. Got rank 2'): + # symbol_names tensor has the wrong shape. + simulate_mps.mps_1d_sample(util.convert_to_tensor(circuit_batch), + np.array([symbol_names]), + symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 2. Got rank 3'): + # symbol_values tensor has the wrong shape. + simulate_mps.mps_1d_sample(util.convert_to_tensor(circuit_batch), + symbol_names, + np.array([symbol_values_array]), + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 2. Got rank 1'): + # symbol_values tensor has the wrong shape 2. + simulate_mps.mps_1d_sample(util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array[0], + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 1. Got rank 2'): + # num_samples tensor has the wrong shape. + simulate_mps.mps_1d_sample(util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + [[num_samples]]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type, but invalid value. + simulate_mps.mps_1d_sample(util.convert_to_tensor(circuit_batch), + ['junk'], symbol_values_array, + [num_samples]) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # programs tensor has the wrong type. + simulate_mps.mps_1d_sample([1] * batch_size, symbol_names, + symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # programs tensor has the wrong type. + simulate_mps.mps_1d_sample(util.convert_to_tensor(circuit_batch), + [1], symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, + 'Cast string to float is not supported'): + # programs tensor has the wrong type. + simulate_mps.mps_1d_sample(util.convert_to_tensor(circuit_batch), + symbol_names, [['junk']] * batch_size, + [num_samples]) + + with self.assertRaisesRegex(Exception, 'junk'): + # num_samples tensor has the wrong shape. + simulate_mps.mps_1d_sample(util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + ['junk']) + + with self.assertRaisesRegex(TypeError, 'missing'): + # too few tensors. + # pylint: disable=no-value-for-parameter + simulate_mps.mps_1d_sample(util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + simulate_mps.mps_1d_sample( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)], num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + simulate_mps.mps_1d_sample( + util.convert_to_tensor([noisy_circuit for _ in circuit_batch]), + symbol_names, symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'at least minimum 4'): + # pylint: disable=too-many-function-args + simulate_mps.mps_1d_sample(util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + [num_samples], 1) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='not in 1D topology'): + # attempting to use a circuit not in 1D topology + # 0--1--2--3 + # \-4 + circuit_not_1d = cirq.Circuit( + cirq.X(qubits[0])**sympy.Symbol(symbol_names[0]), + cirq.Z(qubits[1])**sympy.Symbol(symbol_names[0]), + cirq.CNOT(qubits[2], qubits[3]), + cirq.CNOT(qubits[2], qubits[4]), + ) + simulate_mps.mps_1d_sample( + util.convert_to_tensor([circuit_not_1d for _ in circuit_batch]), + symbol_names, symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='not in 1D topology'): + # attempting to use a circuit in 1D topology, which looks in 2D. + # 0--1 + # \-2-\ + # 3--4 == 1--0--2--4--3 + circuit_not_1d = cirq.Circuit( + cirq.CNOT(qubits[0], qubits[1]), + cirq.CNOT(qubits[0], qubits[2]), + cirq.CNOT(qubits[2], qubits[4]), + cirq.CNOT(qubits[3], qubits[4]), + ) + simulate_mps.mps_1d_sample( + util.convert_to_tensor([circuit_not_1d for _ in circuit_batch]), + symbol_names, symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='minimum 3 qubits'): + # too few qubits. + circuit_small = cirq.Circuit(cirq.X(qubits[0]), cirq.X(qubits[1]), + cirq.X(qubits[2])) + + simulate_mps.mps_1d_sample( + util.convert_to_tensor([circuit_small for _ in circuit_batch]), + symbol_names, symbol_values_array, [num_samples]) + + @parameterized.parameters([ + { + 'all_n_qubits': [4, 5], + 'n_samples': 10 + }, + { + 'all_n_qubits': [4, 5, 8], + 'n_samples': 10 + }, + ]) + def test_sampling_output_padding(self, all_n_qubits, n_samples): + """Check that the sampling ops pad outputs correctly""" + op = simulate_mps.mps_1d_sample + circuits = [] + expected_outputs = [] + for n_qubits in all_n_qubits: + expected_outputs.append(np.ones((n_samples, n_qubits))) + circuits.append( + cirq.Circuit(cirq.X.on_each(*cirq.GridQubit.rect(1, n_qubits)))) + results = op(util.convert_to_tensor(circuits), [], [[]] * len(circuits), + [n_samples]).to_list() + for a, b in zip(expected_outputs, results): + self.assertAllClose(a, b) + + def test_ghz_state(self): + """Test a simple GHZ-like state.""" + op = simulate_mps.mps_1d_sample + qubits = cirq.GridQubit.rect(1, 6) + circuit = cirq.Circuit(cirq.I.on_each(*qubits)) + circuit += [ + cirq.X(qubits[0]), + cirq.H(qubits[1]), + cirq.CNOT(qubits[1], qubits[2]) + ] + + circuit_batch = [circuit] + resolver_batch = [cirq.ParamResolver({})] + n_samples = 1000 + + cirq_samples = batch_util.batch_sample(circuit_batch, resolver_batch, + n_samples, cirq.Simulator()) + + op_samples = np.array( + op(util.convert_to_tensor(circuit_batch), [], [[]], [n_samples], + bond_dim=16).to_list()) + self.assertAllClose(np.mean(op_samples, axis=1), + np.mean(cirq_samples, axis=1), + atol=1e-1) + + def test_sampling_fuzz(self): + """Compare sampling with tfq ops and Cirq.""" + op = simulate_mps.mps_1d_sample + batch_size = 10 + n_qubits = 6 + qubits = cirq.GridQubit.rect(1, n_qubits) + symbol_names = [] + n_samples = 10_000 + + circuit_batch = [_make_1d_circuit(qubits, 1) for _ in range(batch_size)] + resolver_batch = [cirq.ParamResolver({}) for _ in range(batch_size)] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + op_samples = np.array( + op(util.convert_to_tensor(circuit_batch), + symbol_names, + symbol_values_array, [n_samples], + bond_dim=16).to_list()) + + op_histograms = [ + np.histogram( + sample.dot(1 << np.arange(sample.shape[-1] - 1, -1, -1)), + range=(0, 2**len(qubits)), + bins=2**len(qubits))[0] for sample in op_samples + ] + + cirq_samples = batch_util.batch_sample(circuit_batch, resolver_batch, + n_samples, cirq.Simulator()) + + cirq_histograms = [ + np.histogram( + sample.dot(1 << np.arange(sample.shape[-1] - 1, -1, -1)), + range=(0, 2**len(qubits)), + bins=2**len(qubits))[0] for sample in cirq_samples + ] + + for a, b in zip(op_histograms, cirq_histograms): + self.assertLess(stats.entropy(a + 1e-8, b + 1e-8), 0.05) + + +class SimulateMPS1DSampledExpectationTest(tf.test.TestCase): + """Tests tfq_simulate_mps1d_sampled_expectation.""" + + def test_simulate_mps1d_sampled_expectation_inputs(self): + """Make sure sampled expectation op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch = [ + cirq.Circuit( + cirq.X(qubits[0])**sympy.Symbol(symbol_names[0]), + cirq.Z(qubits[1]), + cirq.CNOT(qubits[2], qubits[3]), + cirq.Y(qubits[4])**sympy.Symbol(symbol_names[0]), + ) for _ in range(batch_size) + ] + resolver_batch = [{symbol_names[0]: 0.123} for _ in range(batch_size)] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + num_samples = [[10]] * batch_size + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # Circuit tensor has too many dimensions. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor([circuit_batch]), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1.'): + # symbol_names tensor has too many dimensions. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too many dimensions. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array]), + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too few dimensions. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[0], + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too few dimensions. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + util.convert_to_tensor(list(pauli_sums)), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too many dimensions. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + [util.convert_to_tensor([[x] for x in pauli_sums])], + num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'num_samples must be rank 2'): + # num_samples tensor has the wrong shape. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'num_samples must be rank 2'): + # num_samples tensor has the wrong shape. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + num_samples[0]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # circuit tensor has the right type but invalid values. + simulate_mps.mps_1d_sampled_expectation( + ['junk'] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type but invalid values. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), ['junk'], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'qubits not found in circuit'): + # pauli_sums tensor has the right type but invalid values. + new_qubits = [cirq.GridQubit(5, 5), cirq.GridQubit(9, 9)] + new_pauli_sums = util.random_pauli_sums(new_qubits, 2, batch_size) + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in new_pauli_sums]), + num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # pauli_sums tensor has the right type but invalid values 2. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [['junk']] * batch_size, num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # circuits tensor has the wrong type. + simulate_mps.mps_1d_sampled_expectation( + [1.0] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), [0.1234], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # pauli_sums tensor has the wrong type. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [[1.0]] * batch_size, num_samples) + + with self.assertRaisesRegex(TypeError, 'missing'): + # we are missing an argument. + # pylint: disable=no-value-for-parameter + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, num_samples) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong op size. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor([cirq.Circuit()]), symbol_names, + symbol_values_array.astype(np.float64), + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'minimum 4'): + # pylint: disable=too-many-function-args + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), + symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + num_samples, + bond_dim=-10) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)], + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor([noisy_circuit for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'at least minimum 4'): + # pylint: disable=too-many-function-args + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples, + 1) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='not in 1D topology'): + # attempting to use a circuit not in 1D topology + # 0--1--2--3 + # \-4 + circuit_not_1d = cirq.Circuit( + cirq.X(qubits[0])**sympy.Symbol(symbol_names[0]), + cirq.Z(qubits[1])**sympy.Symbol(symbol_names[0]), + cirq.CNOT(qubits[2], qubits[3]), + cirq.CNOT(qubits[2], qubits[4]), + ) + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor([circuit_not_1d for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='not in 1D topology'): + # attempting to use a circuit in 1D topology, which looks in 2D. + # 0--1 + # \-2-\ + # 3--4 == 1--0--2--4--3 + circuit_not_1d = cirq.Circuit( + cirq.CNOT(qubits[0], qubits[1]), + cirq.CNOT(qubits[0], qubits[2]), + cirq.CNOT(qubits[2], qubits[4]), + cirq.CNOT(qubits[3], qubits[4]), + ) + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor([circuit_not_1d for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='minimum 3 qubits'): + # too few qubits. + circuit_small = cirq.Circuit(cirq.X(qubits[0]), cirq.X(qubits[1]), + cirq.X(qubits[2])) + small_pauli = cirq.Z(qubits[0]) + + simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor([circuit_small for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[small_pauli] for _ in pauli_sums]), + num_samples) + + def test_simulate_sampled_mps_1d_expectation_simple(self): + """Makes sure that the op shows the same result with Cirq.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch = [ + cirq.Circuit( + cirq.X(qubits[0])**sympy.Symbol(symbol_names[0]), + cirq.Z(qubits[1]), + cirq.CNOT(qubits[2], qubits[3]), + cirq.Y(qubits[4])**sympy.Symbol(symbol_names[0]), + ) for _ in range(batch_size) + ] + resolver_batch = [{symbol_names[0]: 0.123} for _ in range(batch_size)] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = [ + cirq.Z(qubits[0]) * cirq.X(qubits[4]) for _ in range(batch_size) + ] + + num_samples = np.ones(shape=(len(pauli_sums), 1)) * 10000 + + cirq_result = [ + cirq.Simulator().simulate_expectation_values(c, p, r) + for c, p, r in zip(circuit_batch, pauli_sums, resolver_batch) + ] + # Default bond_dim=4 + mps_result = simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + # Expected value of 0.349... + self.assertAllClose(mps_result, cirq_result, atol=5e-2) + + def test_complex_equality(self): + """Check moderate sized 1d random circuits.""" + batch_size = 10 + qubits = cirq.GridQubit.rect(1, 8) + circuit_batch = [_make_1d_circuit(qubits, 3) for _ in range(batch_size)] + + pauli_sums = [[ + cirq.Z(qubits[0]), + cirq.Z(qubits[-1]), + cirq.Z(qubits[0]) * cirq.Z(qubits[-1]), + cirq.Z(qubits[0]) + cirq.Z(qubits[-1]) + ] for _ in range(batch_size)] + symbol_names = [] + resolver_batch = [{} for _ in range(batch_size)] + # Because `pauli_sums` has inhomogeneous shape due to the different + # number of terms, `np.ones_like` failed with `pauli_sums`. + puali_sums_len = [[len(x) for x in y] for y in pauli_sums] + num_samples = np.ones_like(puali_sums_len, dtype=int) * 1000 + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + cirq_result = [ + cirq.Simulator().simulate_expectation_values(c, p, r) + for c, p, r in zip(circuit_batch, pauli_sums, resolver_batch) + ] + mps_result = simulate_mps.mps_1d_sampled_expectation( + util.convert_to_tensor(circuit_batch), + symbol_names, + symbol_values_array, + util.convert_to_tensor(pauli_sums), + num_samples, + bond_dim=32) + self.assertAllClose(mps_result, cirq_result, atol=2e-1) + + def test_correctness_empty(self): + """Tests the mps op with empty circuits.""" + + empty_circuit = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_symbols = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + empty_paulis = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + num_samples = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.int32) + + out = simulate_mps.mps_1d_sampled_expectation(empty_circuit, + empty_symbols, + empty_values, + empty_paulis, num_samples, + 32) + + self.assertShapeEqual(np.zeros((0, 0)), out) + + +class InputTypesTest(tf.test.TestCase, parameterized.TestCase): + """Tests that different inputs types work for all of the ops. """ + + @parameterized.parameters([ + { + 'symbol_type': tf.float32 + }, + { + 'symbol_type': tf.float64 + }, + { + 'symbol_type': tf.int32 + }, + { + 'symbol_type': tf.int64 + }, + { + 'symbol_type': tf.complex64 + }, + ]) + def test_symbol_values_type(self, symbol_type): + """Tests all three ops for the different types. """ + qubits = cirq.GridQubit.rect(1, 5) + circuits = util.convert_to_tensor( + [cirq.Circuit(cirq.H.on_each(*qubits))]) + symbol_names = ['symbol'] + symbol_values = tf.convert_to_tensor([[1]], dtype=symbol_type) + pauli_sums = util.random_pauli_sums(qubits, 3, 1) + pauli_sums = util.convert_to_tensor([[x] for x in pauli_sums]) + + result = simulate_mps.mps_1d_expectation(circuits, symbol_names, + symbol_values, pauli_sums) + self.assertDTypeEqual(result, np.float32) + + result = simulate_mps.mps_1d_sample(circuits, symbol_names, + symbol_values, [100]) + self.assertDTypeEqual(result.numpy(), np.int8) + + result = simulate_mps.mps_1d_sampled_expectation( + circuits, symbol_names, symbol_values, pauli_sums, [[100]]) + self.assertDTypeEqual(result, np.float32) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc b/tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc index cf6fe9c32..374aa5b55 100644 --- a/tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc +++ b/tensorflow_quantum/core/ops/math_ops/tfq_inner_product.cc @@ -21,21 +21,22 @@ 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" #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/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 QsimGate; typedef qsim::Circuit QsimCircuit; @@ -86,17 +87,21 @@ class TfqInnerProductOp : public tensorflow::OpKernel { std::vector fused_circuits(programs.size(), QsimFusedCircuit({})); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); auto construct_f = [&](int start, int end) { for (int i = start; i < end; i++) { - OP_REQUIRES_OK(context, QsimCircuitFromProgram( - programs[i], maps[i], num_qubits[i], - &qsim_circuits[i], &fused_circuits[i])); + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); } }; const int num_cycles = 1000; context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( output_dim_batch_size, num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); // Construct qsim circuits for other_programs. std::vector> other_qsim_circuits( @@ -114,16 +119,19 @@ class TfqInnerProductOp : public tensorflow::OpKernel { Status status = QsimCircuitFromProgram( other_programs[ii][jj], {}, num_qubits[ii], &other_qsim_circuits[ii][jj], &other_fused_circuits[ii][jj]); - OP_REQUIRES(context, status.ok(), - tensorflow::errors::InvalidArgument(absl::StrCat( - "Found symbols in other_programs.", - "No symbols are allowed in these circuits."))); + NESTED_FN_STATUS_SYNC(parse_status, status, p_lock); } }; context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( output_dim_batch_size * output_dim_internal_size, num_cycles, construct_f2); + if (!parse_status.ok()) { + OP_REQUIRES_OK(context, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Found symbols in other_programs.", + "No symbols are allowed in these circuits."))); + } int max_num_qubits = 0; for (const int num : num_qubits) { @@ -166,7 +174,7 @@ class TfqInnerProductOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { // need to switch to larger statespace. @@ -178,10 +186,10 @@ class TfqInnerProductOp : public tensorflow::OpKernel { // the state if there is a possibility that circuit[i] and // circuit[i + 1] produce the same state. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } - for (int j = 0; j < other_fused_circuits[i].size(); j++) { + for (size_t j = 0; j < other_fused_circuits[i].size(); j++) { // (#679) Just ignore empty program if (fused_circuits[i].size() == 0) { (*output_tensor)(i, j) = std::complex(1, 0); @@ -189,7 +197,7 @@ class TfqInnerProductOp : public tensorflow::OpKernel { } ss.SetStateZero(scratch); - for (int k = 0; k < other_fused_circuits[i][j].size(); k++) { + for (size_t k = 0; k < other_fused_circuits[i][j].size(); k++) { qsim::ApplyFusedGate(sim, other_fused_circuits[i][j][k], scratch); } @@ -247,13 +255,13 @@ class TfqInnerProductOp : public tensorflow::OpKernel { // no need to update scratch_state since ComputeExpectation // will take care of things for us. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[cur_batch_index].size(); j++) { + for (size_t j = 0; j < fused_circuits[cur_batch_index].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[cur_batch_index][j], sv); } } ss.SetStateZero(scratch); - for (int k = 0; + for (size_t k = 0; k < other_fused_circuits[cur_batch_index][cur_internal_index].size(); k++) { @@ -306,7 +314,7 @@ REGISTER_OP("TfqInnerProduct") c->Dim(other_programs_shape, 1); c->set_output(0, c->Matrix(output_rows, output_cols)); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/math_ops/tfq_inner_product_grad.cc b/tensorflow_quantum/core/ops/math_ops/tfq_inner_product_grad.cc new file mode 100644 index 000000000..534d7fef9 --- /dev/null +++ b/tensorflow_quantum/core/ops/math_ops/tfq_inner_product_grad.cc @@ -0,0 +1,496 @@ +/* Copyright 2021 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#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 ::tensorflow::Status; +using ::tfq::proto::PauliSum; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; +typedef std::vector> QsimFusedCircuit; + +class TfqInnerProductGradOp : public tensorflow::OpKernel { + public: + explicit TfqInnerProductGradOp(tensorflow::OpKernelConstruction* context) + : OpKernel(context) {} + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + const int num_inputs = context->num_inputs(); + OP_REQUIRES(context, num_inputs == 5, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Expected 5 inputs, got ", num_inputs, " inputs."))); + + // Create the output Tensor. + const int output_dim_batch_size = context->input(0).dim_size(0); + const int output_dim_internal_size = context->input(3).dim_size(1); + const int output_dim_symbol_size = context->input(1).dim_size(0); + OP_REQUIRES(context, output_dim_symbol_size > 0, + tensorflow::errors::InvalidArgument(absl::StrCat( + "The number of symbols must be a positive integer, got ", + output_dim_symbol_size, " symbols."))); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_batch_size); + output_shape.AddDim(output_dim_symbol_size); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->matrix>(); + + // Parse program protos. + std::vector programs; + std::vector num_qubits; + std::vector> other_programs; + OP_REQUIRES_OK(context, + GetProgramsAndNumQubits(context, &programs, &num_qubits, + &other_programs)); + + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + + OP_REQUIRES(context, programs.size() == maps.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and symbol_values do not match. Got ", + programs.size(), " circuits and ", maps.size(), + " symbol values."))); + OP_REQUIRES(context, output_dim_symbol_size == maps[0].size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of symbols and symbol maps do not match. Got ", + output_dim_symbol_size, " symbols and ", maps[0].size(), + " symbol values."))); + + // Construct qsim circuits for programs. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector fused_circuits(programs.size(), + QsimFusedCircuit({})); + + // track metadata. + std::vector> gate_meta( + programs.size(), std::vector({})); + + // Construct qsim circuits. + std::vector>>> + partial_fused_circuits( + programs.size(), + std::vector>>({})); + + // track gradients + std::vector> gradient_gates( + programs.size(), std::vector({})); + + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = QsimCircuitFromProgram( + programs[i], maps[i], num_qubits[i], &qsim_circuits[i], + &fused_circuits[i], &gate_meta[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + + CreateGradientCircuit(qsim_circuits[i], gate_meta[i], + &partial_fused_circuits[i], &gradient_gates[i]); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + output_dim_batch_size, num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + // Construct qsim circuits for other_programs. + std::vector> other_qsim_circuits( + output_dim_batch_size, + std::vector(output_dim_internal_size, QsimCircuit())); + std::vector> other_fused_circuits( + output_dim_batch_size, + std::vector(output_dim_internal_size, + QsimFusedCircuit({}))); + + auto construct_f2 = [&](int start, int end) { + for (int i = start; i < end; i++) { + int ii = i / output_dim_internal_size; + int jj = i % output_dim_internal_size; + Status status = QsimCircuitFromProgram( + other_programs[ii][jj], {}, num_qubits[ii], + &other_qsim_circuits[ii][jj], &other_fused_circuits[ii][jj]); + NESTED_FN_STATUS_SYNC(parse_status, status, p_lock); + } + }; + + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + output_dim_batch_size * output_dim_internal_size, num_cycles, + construct_f2); + if (!parse_status.ok()) { + OP_REQUIRES_OK(context, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Found symbols in other_programs.", + "No symbols are allowed in these circuits."))); + } + + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + // Get downstream gradients. + std::vector> downstream_grads; + OP_REQUIRES_OK(context, GetPrevGrads(context, &downstream_grads)); + + OP_REQUIRES(context, downstream_grads.size() == programs.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of gradients and circuits do not match. Got ", + downstream_grads.size(), " gradients and ", programs.size(), + " circuits."))); + + OP_REQUIRES(context, downstream_grads[0].size() == output_dim_internal_size, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of gradients and other_programs do not match. Got ", + downstream_grads[0].size(), " gradient entries and ", + output_dim_internal_size, " other programs."))); + + output_tensor.setZero(); + + // Cross reference with standard google cloud compute instances + // Memory ~= 2 * num_threads * (2 * 64 * 2 ** num_qubits in circuits) + // e2s2 = 2 CPU, 8GB -> Can safely do 23 since Memory = 4GB + // e2s4 = 4 CPU, 16GB -> Can safely do 23 since Memory = 8GB + // ... + if (max_num_qubits >= 24 || output_dim_batch_size == 1) { + ComputeLarge(num_qubits, maps, qsim_circuits, fused_circuits, + partial_fused_circuits, gradient_gates, other_fused_circuits, + downstream_grads, context, &output_tensor); + } else { + ComputeSmall(num_qubits, max_num_qubits, maps, qsim_circuits, + fused_circuits, partial_fused_circuits, gradient_gates, + other_fused_circuits, downstream_grads, context, + &output_tensor); + } + } + + private: + void ComputeLarge( + const std::vector& num_qubits, const std::vector& maps, + const std::vector& qsim_circuits, + const std::vector& fused_circuits, + const std::vector>>>& + partial_fused_circuits, + const std::vector>& gradient_gates, + const std::vector>& other_fused_circuits, + const std::vector>& downstream_grads, + tensorflow::OpKernelContext* context, + tensorflow::TTypes>::Matrix* output_tensor) { + // Instantiate qsim objects. + const auto tfq_for = tfq::QsimFor(context); + using Simulator = qsim::Simulator; + using StateSpace = Simulator::StateSpace; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(tfq_for); + StateSpace ss = StateSpace(tfq_for); + auto sv = ss.Create(largest_nq); + auto scratch = ss.Create(largest_nq); + auto scratch2 = ss.Create(largest_nq); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as necessary. + for (std::vector>>::size_type i = 0; + i < fused_circuits.size(); i++) { + int nq = num_qubits[i]; + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + scratch2 = ss.Create(largest_nq); + } + ss.SetStateZero(sv); + for (std::vector>::size_type j = 0; + j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + + auto status = + AccumulateFusedCircuits(downstream_grads[i], other_fused_circuits[i], + sim, ss, scratch2, scratch); + + // now sv is |psi> + // scratch contains sum_j downstream_grads[i][j]*|phi[i][j]> + // Start adjoint differentiation. + for (int l = partial_fused_circuits[i].size() - 1; l >= 0; l--) { + for (int k = partial_fused_circuits[i][l].size() - 1; k >= 0; k--) { + ApplyFusedGateDagger(sim, partial_fused_circuits[i][l][k], sv); + ApplyFusedGateDagger(sim, partial_fused_circuits[i][l][k], scratch); + } + if (l == 0) { + // last layer will have no parametrized gates so can break. + break; + } + + // Hit a parameterized gate. + // todo fix this copy. + auto cur_gate = qsim_circuits[i].gates[gradient_gates[i][l - 1].index]; + ApplyGateDagger(sim, cur_gate, sv); + + // if applicable compute control qubit mask and control value bits. + uint64_t mask = 0; + uint64_t cbits = 0; + for (std::vector::size_type k = 0; + k < cur_gate.controlled_by.size(); k++) { + uint64_t control_loc = cur_gate.controlled_by[k]; + mask |= uint64_t{1} << control_loc; + cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; + } + + for (std::vector::size_type k = 0; + k < gradient_gates[i][l - 1].grad_gates.size(); k++) { + // Copy sv onto scratch2 in anticipation of non-unitary "gradient + // gate". + ss.Copy(sv, scratch2); + if (!cur_gate.controlled_by.empty()) { + // Gradient of controlled gates puts zeros on diagonal which is + // the same as collapsing the state and then applying the + // non-controlled version of the gradient gate. + ss.BulkSetAmpl(scratch2, mask, cbits, 0, 0, true); + } + qsim::ApplyGate(sim, gradient_gates[i][l - 1].grad_gates[k], + scratch2); + + // don't need not-found check since this is done upstream already. + const auto it = maps[i].find(gradient_gates[i][l - 1].params[k]); + const int loc = it->second.first; + // Apply finite differencing for adjoint gradients. + // Finite differencing enables applying multiple `gradient_gate` + // of a symbol at the same circuit. For analytic methods like + // parameter-shift we need to apply a single `gradient_gate` + // per a symbol. + std::complex result = ss.InnerProduct(scratch2, scratch); + (*output_tensor)(i, loc) += + std::complex(static_cast(result.real()), + static_cast(result.imag())); + } + ApplyGateDagger(sim, cur_gate, scratch); + } + } + } + + void ComputeSmall( + const std::vector& num_qubits, const int max_num_qubits, + const std::vector& maps, + const std::vector& qsim_circuits, + const std::vector& fused_circuits, + const std::vector>>>& + partial_fused_circuits, + const std::vector>& gradient_gates, + const std::vector>& other_fused_circuits, + const std::vector>& downstream_grads, + tensorflow::OpKernelContext* context, + tensorflow::TTypes>::Matrix* output_tensor) { + const auto tfq_for = qsim::SequentialFor(1); + using Simulator = qsim::Simulator; + using StateSpace = Simulator::StateSpace; + + const int output_dim_internal_size = other_fused_circuits[0].size(); + + auto DoWork = [&](int start, int end) { + int old_batch_index = -2; + int cur_batch_index = -1; + int largest_nq = 1; + int cur_internal_index; + + Simulator sim = Simulator(tfq_for); + StateSpace ss = StateSpace(tfq_for); + auto sv = ss.Create(largest_nq); + auto sv_adj = ss.Create(largest_nq); + auto scratch = ss.Create(largest_nq); + auto scratch2 = ss.Create(largest_nq); + for (int i = start; i < end; i++) { + cur_batch_index = i / output_dim_internal_size; + cur_internal_index = i % output_dim_internal_size; + + const int nq = num_qubits[cur_batch_index]; + + if (cur_batch_index != old_batch_index) { + // We've run into a new state vector we must compute. + // Only compute a new state vector when we have to. + if (nq > largest_nq) { + largest_nq = nq; + sv = ss.Create(largest_nq); + sv_adj = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + scratch2 = ss.Create(largest_nq); + } + ss.SetStateZero(sv); + for (std::vector>::size_type j = 0; + j < fused_circuits[cur_batch_index].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[cur_batch_index][j], sv); + } + } + + ss.SetStateZero(scratch); + for (std::vector>::size_type k = 0; + k < + other_fused_circuits[cur_batch_index][cur_internal_index].size(); + k++) { + qsim::ApplyFusedGate( + sim, other_fused_circuits[cur_batch_index][cur_internal_index][k], + scratch); + } + // now sv is |psi>, scratch is |phi> + // Start adjoint differentiation. + ss.Copy(sv, sv_adj); + for (int l = partial_fused_circuits[cur_batch_index].size() - 1; l >= 0; + l--) { + for (int k = partial_fused_circuits[cur_batch_index][l].size() - 1; + k >= 0; k--) { + ApplyFusedGateDagger( + sim, partial_fused_circuits[cur_batch_index][l][k], sv_adj); + ApplyFusedGateDagger( + sim, partial_fused_circuits[cur_batch_index][l][k], scratch); + } + if (l == 0) { + // last layer will have no parametrized gates so can break. + break; + } + + // Hit a parameterized gate. + // todo fix this copy. + auto cur_gate = + qsim_circuits[cur_batch_index] + .gates[gradient_gates[cur_batch_index][l - 1].index]; + ApplyGateDagger(sim, cur_gate, sv_adj); + + // if applicable compute control qubit mask and control value bits. + uint64_t mask = 0; + uint64_t cbits = 0; + for (size_t k = 0; k < cur_gate.controlled_by.size(); k++) { + uint64_t control_loc = cur_gate.controlled_by[k]; + mask |= uint64_t{1} << control_loc; + cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; + } + + for (size_t k = 0; + k < gradient_gates[cur_batch_index][l - 1].grad_gates.size(); + k++) { + // Copy sv_adj onto scratch2 in anticipation of non-unitary + // "gradient gate". + ss.Copy(sv_adj, scratch2); + if (!cur_gate.controlled_by.empty()) { + // Gradient of controlled gates puts zeros on diagonal which is + // the same as collapsing the state and then applying the + // non-controlled version of the gradient gate. + ss.BulkSetAmpl(scratch2, mask, cbits, 0, 0, true); + } + qsim::ApplyGate( + sim, gradient_gates[cur_batch_index][l - 1].grad_gates[k], + scratch2); + + // don't need not-found check since this is done upstream already. + const auto it = maps[cur_batch_index].find( + gradient_gates[cur_batch_index][l - 1].params[k]); + const int loc = it->second.first; + // Apply finite differencing for adjoint gradients. + // Finite differencing enables applying multiple `gradient_gate` + // of a symbol at the same circuit. For analytic methods like + // parameter-shift we need to apply a single `gradient_gate` + // per a symbol. + std::complex result = ss.InnerProduct(scratch2, scratch); + (*output_tensor)(cur_batch_index, loc) += + (downstream_grads[cur_batch_index][cur_internal_index] * + std::complex(static_cast(result.real()), + static_cast(result.imag()))); + } + ApplyGateDagger(sim, cur_gate, scratch); + } + old_batch_index = cur_batch_index; + } + }; + + const int64_t num_cycles = + 200 * (int64_t(1) << static_cast(max_num_qubits)); + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + fused_circuits.size() * output_dim_internal_size, num_cycles, DoWork); + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqInnerProductGrad").Device(tensorflow::DEVICE_CPU), + TfqInnerProductGradOp); + +REGISTER_OP("TfqInnerProductGrad") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("other_programs: string") + .Input("downstream_grads: float") + .Output("inner_products_grad: complex64") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle other_programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 2, &other_programs_shape)); + + tensorflow::shape_inference::ShapeHandle downstream_grads_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(4), 2, &downstream_grads_shape)); + + tensorflow::shape_inference::DimensionHandle output_rows = + c->Dim(programs_shape, 0); + + // Use kUnknownDim instead to prevent shape inference from breaking + // @tf.custom_gradient code in fidelity_op.py. The grad function has + // an implicit data dependency on `sybmol_names` that shape infrence + // can't (and shouldn't) see. Not specifying shape prevents this break. + // std::vector dims = { + // output_rows, + // tensorflow::shape_inference::InferenceContext::kUnknownDim}; + c->set_output( + 0, c->MakeShape( + {output_rows, + tensorflow::shape_inference::InferenceContext::kUnknownDim})); + + return ::tensorflow::Status(); + }); + +} // namespace tfq diff --git a/tensorflow_quantum/core/ops/math_ops/tfq_simulate_1d_expectation.cc b/tensorflow_quantum/core/ops/math_ops/tfq_simulate_1d_expectation.cc new file mode 100644 index 000000000..c00b43a9b --- /dev/null +++ b/tensorflow_quantum/core/ops/math_ops/tfq_simulate_1d_expectation.cc @@ -0,0 +1,253 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/formux.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/mps_simulator.h" +#include "../qsim/lib/mps_statespace.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#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/pauli_sum.pb.h" +#include "tensorflow_quantum/core/proto/program.pb.h" +#include "tensorflow_quantum/core/src/program_resolution.h" +#include "tensorflow_quantum/core/src/util_qsim.h" + +namespace tfq { + +using ::tensorflow::Status; +using ::tfq::proto::PauliSum; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateMPS1DExpectationOp : public tensorflow::OpKernel { + public: + explicit TfqSimulateMPS1DExpectationOp( + tensorflow::OpKernelConstruction* context) + : OpKernel(context) { + // Get the bond dimension of MPS + // Checked that bond_dim is a positive integer >= 2 by QSim definition. + OP_REQUIRES_OK(context, context->GetAttr("bond_dim", &bond_dim_)); + } + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + const int num_inputs = context->num_inputs(); + OP_REQUIRES(context, num_inputs == 4, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Expected 4 inputs, got ", num_inputs, " inputs."))); + + // Create the output Tensor. + const int output_dim_batch_size = context->input(0).dim_size(0); + const int output_dim_op_size = context->input(3).dim_size(1); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_batch_size); + output_shape.AddDim(output_dim_op_size); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->matrix(); + + // Parse program protos. + std::vector programs; + std::vector num_qubits; + std::vector> pauli_sums; + + // TODO: remove endianness workaround introduced here: + // https://github.com/tensorflow/quantum/pull/610 + // once https://github.com/quantumlib/qsim/issues/492 + // is resolved. + OP_REQUIRES_OK(context, + GetProgramsAndNumQubits(context, &programs, &num_qubits, + &pauli_sums, true)); + + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + + OP_REQUIRES(context, programs.size() == maps.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and symbol_values do not match. Got ", + programs.size(), " circuits and ", maps.size(), + " symbol values."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector fused_circuits(programs.size(), + QsimFusedCircuit({})); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + // If parsing works, check MPS constraints. + if (local.ok()) { + local = CheckMPSSupported(programs[i]); + } + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + output_dim_batch_size, num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + // Find largest circuit for tensor size padding and allocate + // the output tensor. + int max_num_qubits = 0; + int min_num_qubits = 1 << 30; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + min_num_qubits = std::min(min_num_qubits, num); + } + + OP_REQUIRES(context, min_num_qubits > 3, + tensorflow::errors::InvalidArgument( + "All input circuits require minimum 3 qubits.")); + + // Since MPS simulations have much smaller memory footprint, + // we do not need a ComputeLarge like we do for state vector simulation. + ComputeSmall(num_qubits, max_num_qubits, qsim_circuits, pauli_sums, context, + &output_tensor); + } + + private: + int bond_dim_; + + void ComputeSmall(const std::vector& num_qubits, + const int max_num_qubits, + const std::vector& unfused_circuits, + const std::vector>& pauli_sums, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + using Simulator = qsim::mps::MPSSimulator; + using StateSpace = Simulator::MPSStateSpace_; + + const int output_dim_op_size = output_tensor->dimension(1); + + Status compute_status = ::tensorflow::Status(); + auto c_lock = tensorflow::mutex(); + auto DoWork = [&](int start, int end) { + int old_batch_index = -2; + int cur_batch_index = -1; + int largest_nq = 1; + int cur_op_index; + + // Note: ForArgs in MPSSimulator and MPSStateState are currently unused. + // So, this 1 is a dummy for qsim::For. + Simulator sim = Simulator(1); + StateSpace ss = StateSpace(1); + auto sv = ss.Create(largest_nq, bond_dim_); + auto scratch = ss.Create(largest_nq, bond_dim_); + for (int i = start; i < end; i++) { + cur_batch_index = i / output_dim_op_size; + cur_op_index = i % output_dim_op_size; + + const int nq = num_qubits[cur_batch_index]; + + // (#679) Just ignore empty program + auto unfused_gates = unfused_circuits[cur_batch_index].gates; + if (unfused_gates.size() == 0) { + (*output_tensor)(cur_batch_index, cur_op_index) = -2.0; + continue; + } + + if (cur_batch_index != old_batch_index) { + // We've run into a new state vector we must compute. + // Only compute a new state vector when we have to. + if (nq > largest_nq) { + largest_nq = nq; + sv = ss.Create(largest_nq, bond_dim_); + scratch = ss.Create(largest_nq, bond_dim_); + } + // no need to update scratch_state since ComputeExpectationMPSQsim + // will take care of things for us. + ss.SetStateZero(sv); + for (auto gate : unfused_gates) { + // Can't fuse, since this might break nearest neighbor constraints. + qsim::ApplyGate(sim, gate, sv); + } + } + + // Compute expectation values without fusing gates. + float exp_v = 0.0; + NESTED_FN_STATUS_SYNC( + compute_status, + ComputeExpectationQsim(pauli_sums[cur_batch_index][cur_op_index], + sim, ss, sv, scratch, &exp_v, false), + c_lock); + (*output_tensor)(cur_batch_index, cur_op_index) = exp_v; + old_batch_index = cur_batch_index; + } + }; + + const int64_t num_cycles = + 200 * (int64_t(1) << static_cast(max_num_qubits)); + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + unfused_circuits.size() * output_dim_op_size, num_cycles, DoWork); + OP_REQUIRES_OK(context, compute_status); + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqSimulateMPS1DExpectation").Device(tensorflow::DEVICE_CPU), + TfqSimulateMPS1DExpectationOp); + +REGISTER_OP("TfqSimulateMPS1DExpectation") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("pauli_sums: string") + .Output("expectations: float") + .Attr("bond_dim: int >= 4 = 4") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle pauli_sums_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 2, &pauli_sums_shape)); + + tensorflow::shape_inference::DimensionHandle output_rows = + c->Dim(programs_shape, 0); + tensorflow::shape_inference::DimensionHandle output_cols = + c->Dim(pauli_sums_shape, 1); + c->set_output(0, c->Matrix(output_rows, output_cols)); + + return ::tensorflow::Status(); + }); + +} // namespace tfq diff --git a/tensorflow_quantum/core/ops/math_ops/tfq_simulate_1d_sampled_expectation.cc b/tensorflow_quantum/core/ops/math_ops/tfq_simulate_1d_sampled_expectation.cc new file mode 100644 index 000000000..ba94e8c72 --- /dev/null +++ b/tensorflow_quantum/core/ops/math_ops/tfq_simulate_1d_sampled_expectation.cc @@ -0,0 +1,297 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/formux.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/mps_simulator.h" +#include "../qsim/lib/mps_statespace.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/platform/mutex.h" +#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/program_resolution.h" +#include "tensorflow_quantum/core/src/util_qsim.h" + +namespace tfq { + +using ::tensorflow::Status; +using ::tfq::proto::PauliSum; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateMPS1DSampledExpectationOp : public tensorflow::OpKernel { + public: + explicit TfqSimulateMPS1DSampledExpectationOp( + tensorflow::OpKernelConstruction* context) + : OpKernel(context) { + // Get the bond dimension of MPS + OP_REQUIRES_OK(context, context->GetAttr("bond_dim", &bond_dim_)); + } + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + const int num_inputs = context->num_inputs(); + OP_REQUIRES(context, num_inputs == 5, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Expected 5 inputs, got ", num_inputs, " inputs."))); + + // Create the output Tensor. + const int output_dim_batch_size = context->input(0).dim_size(0); + const int output_dim_op_size = context->input(3).dim_size(1); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_batch_size); + output_shape.AddDim(output_dim_op_size); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->matrix(); + + std::vector programs; + std::vector num_qubits; + std::vector> pauli_sums; + OP_REQUIRES_OK(context, + GetProgramsAndNumQubits(context, &programs, &num_qubits, + &pauli_sums, true)); + + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + + OP_REQUIRES(context, programs.size() == maps.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and symbol_values do not match. Got ", + programs.size(), " circuits and ", maps.size(), + " symbol values."))); + + std::vector> num_samples; + OP_REQUIRES_OK(context, GetNumSamples(context, &num_samples)); + + OP_REQUIRES(context, num_samples.size() == pauli_sums.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Dimension 0 of num_samples and pauli_sums do not match.", + "Got ", num_samples.size(), " lists of sample sizes and ", + pauli_sums.size(), " lists of pauli sums."))); + + OP_REQUIRES( + context, context->input(4).dim_size(1) == context->input(3).dim_size(1), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Dimension 1 of num_samples and pauli_sums do not match.", "Got ", + context->input(4).dim_size(1), " lists of sample sizes and ", + context->input(3).dim_size(1), " lists of pauli sums."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> fused_circuits( + programs.size(), std::vector>({})); + + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + // If parsing works, check MPS constraints. + if (local.ok()) { + local = CheckMPSSupported(programs[i]); + } + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + // Find largest circuit for tensor size padding and allocate + // the output tensor. + int max_num_qubits = 0; + int min_num_qubits = 1 << 30; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + min_num_qubits = std::min(min_num_qubits, num); + } + + OP_REQUIRES(context, min_num_qubits > 3, + tensorflow::errors::InvalidArgument( + "All input circuits require minimum 3 qubits.")); + + // Since MPS simulations have much smaller memory footprint, + // we do not need a ComputeLarge like we do for state vector simulation. + ComputeSmall(num_qubits, max_num_qubits, qsim_circuits, pauli_sums, + num_samples, context, &output_tensor); + } + + private: + int bond_dim_; + void ComputeSmall(const std::vector& num_qubits, + const int max_num_qubits, + const std::vector& unfused_circuits, + const std::vector>& pauli_sums, + const std::vector>& num_samples, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::mps::MPSSimulator; + using StateSpace = Simulator::MPSStateSpace_; + + const int output_dim_op_size = output_tensor->dimension(1); + + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + int largest_sum = -1; + for (const auto& sums : pauli_sums) { + for (const auto& sum : sums) { + largest_sum = std::max(largest_sum, sum.terms().size()); + } + } + const int num_threads = context->device() + ->tensorflow_cpu_worker_threads() + ->workers->NumThreads(); + + Status compute_status = ::tensorflow::Status(); + auto c_lock = tensorflow::mutex(); + auto DoWork = [&](int start, int end) { + int old_batch_index = -2; + int cur_batch_index = -1; + int largest_nq = 1; + int cur_op_index; + + // Note: ForArgs in MPSSimulator and MPSStateState are currently unused. + // So, this 1 is a dummy for qsim::For. + Simulator sim = Simulator(1); + StateSpace ss = StateSpace(1); + auto sv = ss.Create(largest_nq, bond_dim_); + auto scratch = ss.Create(largest_nq, bond_dim_); + auto scratch2 = ss.Create(largest_nq, bond_dim_); + auto scratch3 = ss.Create(largest_nq, bond_dim_); + + int n_random = largest_sum * output_dim_op_size * unfused_circuits.size(); + n_random /= num_threads; + n_random += 1; + auto local_gen = random_gen.ReserveSamples32(n_random); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + for (int i = start; i < end; i++) { + cur_batch_index = i / output_dim_op_size; + cur_op_index = i % output_dim_op_size; + + const int nq = num_qubits[cur_batch_index]; + + // (#679) Just ignore empty program + auto unfused_gates = unfused_circuits[cur_batch_index].gates; + // (#679) Just ignore empty program + if (unfused_gates.size() == 0) { + (*output_tensor)(cur_batch_index, cur_op_index) = -2.0; + continue; + } + + if (cur_batch_index != old_batch_index) { + // We've run into a new state vector we must compute. + // Only compute a new state vector when we have to. + if (nq > largest_nq) { + largest_nq = nq; + sv = ss.Create(largest_nq, bond_dim_); + scratch = ss.Create(largest_nq, bond_dim_); + scratch2 = ss.Create(largest_nq, bond_dim_); + scratch3 = ss.Create(largest_nq, bond_dim_); + } + // no need to update scratch_state since ComputeExpectation + // will take care of things for us. + ss.SetStateZero(sv); + for (auto gate : unfused_gates) { + // Can't fuse, since this might break nearest neighbor constraints. + qsim::ApplyGate(sim, gate, sv); + } + } + + float exp_v = 0.0; + NESTED_FN_STATUS_SYNC( + compute_status, + ComputeMPSSampledExpectationQsim( + pauli_sums[cur_batch_index][cur_op_index], sim, ss, sv, scratch, + scratch2, scratch3, num_samples[cur_batch_index][cur_op_index], + rand_source, &exp_v), + c_lock); + + (*output_tensor)(cur_batch_index, cur_op_index) = exp_v; + old_batch_index = cur_batch_index; + } + }; + + const int64_t num_cycles = + 200 * (int64_t(1) << static_cast(max_num_qubits)); + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + unfused_circuits.size() * output_dim_op_size, num_cycles, DoWork); + OP_REQUIRES_OK(context, compute_status); + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqSimulateMPS1DSampledExpectation").Device(tensorflow::DEVICE_CPU), + TfqSimulateMPS1DSampledExpectationOp); + +REGISTER_OP("TfqSimulateMPS1DSampledExpectation") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("pauli_sums: string") + .Input("num_samples: int32") + .Output("expectations: float") + .Attr("bond_dim: int >= 4 = 4") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle pauli_sums_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 2, &pauli_sums_shape)); + + tensorflow::shape_inference::ShapeHandle num_samples_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(4), 2, &num_samples_shape)); + + tensorflow::shape_inference::DimensionHandle output_rows = + c->Dim(programs_shape, 0); + tensorflow::shape_inference::DimensionHandle output_cols = + c->Dim(pauli_sums_shape, 1); + c->set_output(0, c->Matrix(output_rows, output_cols)); + + return ::tensorflow::Status(); + }); + +} // namespace tfq diff --git a/tensorflow_quantum/core/ops/math_ops/tfq_simulate_1d_samples.cc b/tensorflow_quantum/core/ops/math_ops/tfq_simulate_1d_samples.cc new file mode 100644 index 000000000..608f94689 --- /dev/null +++ b/tensorflow_quantum/core/ops/math_ops/tfq_simulate_1d_samples.cc @@ -0,0 +1,248 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/formux.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/mps_simulator.h" +#include "../qsim/lib/mps_statespace.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/platform/mutex.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/program_resolution.h" +#include "tensorflow_quantum/core/src/util_qsim.h" + +namespace tfq { + +using ::tensorflow::Status; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateMPS1DSamplesOp : public tensorflow::OpKernel { + public: + explicit TfqSimulateMPS1DSamplesOp(tensorflow::OpKernelConstruction* context) + : OpKernel(context) { + // Get the bond dimension of MPS + OP_REQUIRES_OK(context, context->GetAttr("bond_dim", &bond_dim_)); + } + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + DCHECK_EQ(4, context->num_inputs()); + + // Parse to Program Proto and num_qubits. + std::vector programs; + std::vector num_qubits; + OP_REQUIRES_OK(context, + GetProgramsAndNumQubits(context, &programs, &num_qubits, + nullptr, true)); + + // Parse symbol maps for parameter resolution in the circuits. + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + OP_REQUIRES( + context, maps.size() == programs.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and values do not match. Got ", programs.size(), + " circuits and ", maps.size(), " values."))); + + int num_samples = 0; + OP_REQUIRES_OK(context, GetIndividualSample(context, &num_samples)); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> fused_circuits( + programs.size(), std::vector>({})); + + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + // If parsing works, check MPS constraints. + if (local.ok()) { + local = CheckMPSSupported(programs[i]); + } + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + // Find largest circuit for tensor size padding and allocate + // the output tensor. + int max_num_qubits = 0; + int min_num_qubits = 1 << 30; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + min_num_qubits = std::min(min_num_qubits, num); + } + + OP_REQUIRES(context, min_num_qubits > 3, + tensorflow::errors::InvalidArgument( + "All input circuits require minimum 3 qubits.")); + + const int output_dim_size = maps.size(); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_size); + output_shape.AddDim(num_samples); + output_shape.AddDim(max_num_qubits); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->tensor(); + + if (num_samples == 0) { + return; // bug in qsim dependency we can't control. + } + + // Since MPS simulations have much smaller memory footprint, + // we do not need a ComputeLarge like we do for state vector simulation. + ComputeSmall(num_qubits, max_num_qubits, num_samples, qsim_circuits, + context, &output_tensor); + } + + private: + int bond_dim_; + + void ComputeSmall(const std::vector& num_qubits, + const int max_num_qubits, const int num_samples, + const std::vector& unfused_circuits, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Tensor* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::mps::MPSSimulator; + using StateSpace = Simulator::MPSStateSpace_; + + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + + auto DoWork = [&](int start, int end) { + int largest_nq = 1; + // Note: ForArgs in MPSSimulator and MPSStateState are currently unused. + // So, this 1 is a dummy for qsim::For. + Simulator sim = Simulator(1); + StateSpace ss = StateSpace(1); + auto sv = ss.Create(largest_nq, bond_dim_); + auto scratch = ss.Create(largest_nq, bond_dim_); + auto scratch2 = ss.Create(largest_nq, bond_dim_); + + auto local_gen = random_gen.ReserveSamples32(unfused_circuits.size() + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + for (int i = start; i < end; i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq, bond_dim_); + scratch = ss.Create(largest_nq, bond_dim_); + scratch2 = ss.Create(largest_nq, bond_dim_); + } + ss.SetStateZero(sv); + auto unfused_gates = unfused_circuits[i].gates; + for (auto gate : unfused_gates) { + // Can't fuse, since this might break nearest neighbor constraints. + qsim::ApplyGate(sim, gate, sv); + } + + std::vector> results(num_samples, + std::vector({})); + + ss.Sample(sv, scratch, scratch2, num_samples, rand_source.Rand32(), + &results); + + for (int j = 0; j < num_samples; j++) { + int64_t q_ind = 0; + while (q_ind < max_num_qubits - nq) { + (*output_tensor)(i, j, static_cast(q_ind)) = -2; + q_ind++; + } + while (q_ind < max_num_qubits) { + (*output_tensor)(i, j, static_cast(q_ind)) = + results[j][q_ind - max_num_qubits + nq]; + q_ind++; + } + } + } + }; + + const int64_t num_cycles = + 200 * (int64_t(1) << static_cast(max_num_qubits)); + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + unfused_circuits.size(), num_cycles, DoWork); + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqSimulateMPS1DSamples").Device(tensorflow::DEVICE_CPU), + TfqSimulateMPS1DSamplesOp); + +REGISTER_OP("TfqSimulateMPS1DSamples") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("num_samples: int32") + .Output("samples: int8") + .Attr("bond_dim: int >= 4 = 4") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle num_samples_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 1, &num_samples_shape)); + + // [batch_size, n_samples, largest_n_qubits] + c->set_output( + 0, c->MakeShape( + {c->Dim(programs_shape, 0), + tensorflow::shape_inference::InferenceContext::kUnknownDim, + tensorflow::shape_inference::InferenceContext::kUnknownDim})); + + return ::tensorflow::Status(); + }); + +} // namespace tfq diff --git a/tensorflow_quantum/core/ops/noise/BUILD b/tensorflow_quantum/core/ops/noise/BUILD new file mode 100644 index 000000000..3758037e5 --- /dev/null +++ b/tensorflow_quantum/core/ops/noise/BUILD @@ -0,0 +1,135 @@ +# load op_wrapper + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +# Export for the PIP package. +exports_files(["__init__.py"]) + +config_setting( + name = "windows", + constraint_values = ["@bazel_tools//platforms:windows"], +) + +cc_binary( + name = "_tfq_noise_ops.so", + srcs = [ + "tfq_noisy_expectation.cc", + "tfq_noisy_sampled_expectation.cc", + "tfq_noisy_samples.cc" + ], + copts = select({ + ":windows": [ + "/D__CLANG_SUPPORT_DYN_ANNOTATION__", + "/D_USE_MATH_DEFINES", + "/DEIGEN_MPL2_ONLY", + "/DEIGEN_MAX_ALIGN_BYTES=64", + "/DEIGEN_HAS_TYPE_TRAITS=0", + "/DTF_USE_SNAPPY", + "/showIncludes", + "/MD", + "/O2", + "/DNDEBUG", + "/w", + "-DWIN32_LEAN_AND_MEAN", + "-DNOGDI", + "/d2ReducedOptimizeHugeFunctions", + "/arch:AVX", + "/std:c++17", + "-DTENSORFLOW_MONOLITHIC_BUILD", + "/DPLATFORM_WINDOWS", + "/DEIGEN_HAS_C99_MATH", + "/DTENSORFLOW_USE_EIGEN_THREADPOOL", + "/DEIGEN_AVOID_STL_ARRAY", + "/Iexternal/gemmlowp", + "/wd4018", + "/wd4577", + "/DNOGDI", + "/UTF_COMPILE_LIBRARY", + ], + "//conditions:default": [ + "-pthread", + "-std=c++17", + "-D_GLIBCXX_USE_CXX11_ABI=1", + ], + }), + features = select({ + ":windows": ["windows_export_all_symbols"], + "//conditions:default": [], + }), + linkshared = 1, + deps = [ + # cirq cc proto + "//tensorflow_quantum/core/ops:parse_context", + "//tensorflow_quantum/core/ops:tfq_simulate_utils", + "//tensorflow_quantum/core/src:circuit_parser_qsim", + "//tensorflow_quantum/core/src:util_qsim", + "@qsim//lib:qsim_lib", + # tensorflow core framework + # tensorflow core lib + # tensorflow core protos + ], +) + +py_library( + name = "noisy_expectation_op_py", + srcs = ["noisy_expectation_op.py"], + data = [":_tfq_noise_ops.so"], + deps = [ + "//tensorflow_quantum/core/ops:load_module", + ], +) + +py_test( + name = "noisy_expectation_op_test", + srcs = ["noisy_expectation_op_test.py"], + python_version = "PY3", + deps = [ + ":noisy_expectation_op_py", + "//tensorflow_quantum/core/ops:batch_util", + "//tensorflow_quantum/python:util", + ], +) + +py_library( + name = "noisy_sampled_expectation_op_py", + srcs = ["noisy_sampled_expectation_op.py"], + data = [":_tfq_noise_ops.so"], + deps = [ + "//tensorflow_quantum/core/ops:load_module", + ], +) + +py_test( + name = "noisy_sampled_expectation_op_test", + srcs = ["noisy_sampled_expectation_op_test.py"], + python_version = "PY3", + deps = [ + ":noisy_sampled_expectation_op_py", + "//tensorflow_quantum/core/ops:batch_util", + "//tensorflow_quantum/python:util", + ], +) + +py_library( + name = "noisy_samples_op_py", + srcs = ["noisy_samples_op.py"], + data = [":_tfq_noise_ops.so"], + deps = [ + "//tensorflow_quantum/core/ops:load_module", + "//tensorflow_quantum/core/ops:tfq_utility_ops_py", + ], +) + +py_test( + name = "noisy_samples_op_test", + srcs = ["noisy_samples_op_test.py"], + python_version = "PY3", + deps = [ + ":noisy_samples_op_py", + "//tensorflow_quantum/core/ops:batch_util", + "//tensorflow_quantum/python:util", + ], +) + diff --git a/tensorflow_quantum/core/ops/noise/__init__.py b/tensorflow_quantum/core/ops/noise/__init__.py new file mode 100644 index 000000000..d7969cec5 --- /dev/null +++ b/tensorflow_quantum/core/ops/noise/__init__.py @@ -0,0 +1,20 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Module for tfq.core.ops.noise.*""" + +from tensorflow_quantum.core.ops.noise.noisy_expectation_op import expectation +from tensorflow_quantum.core.ops.noise.noisy_sampled_expectation_op import \ +sampled_expectation +from tensorflow_quantum.core.ops.noise.noisy_samples_op import samples diff --git a/tensorflow_quantum/core/ops/noise/noisy_expectation_op.py b/tensorflow_quantum/core/ops/noise/noisy_expectation_op.py new file mode 100644 index 000000000..7f801e686 --- /dev/null +++ b/tensorflow_quantum/core/ops/noise/noisy_expectation_op.py @@ -0,0 +1,98 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Module for high performance noisy circuit simulation ops.""" +import os +import tensorflow as tf +from tensorflow_quantum.core.ops.load_module import load_module + +NOISY_OP_MODULE = load_module(os.path.join("noise", "_tfq_noise_ops.so")) + + +def expectation(programs, symbol_names, symbol_values, pauli_sums, num_samples): + """Calculate the analytic expectation values using monte-carlo trajectories. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + Channels in this simulation will be "tossed" to a certain realization + during simulation. This simulation is repeated `num_samples` times and + analytic expectation calculations with the given `pauli_sums` are calculated + after each run. Once all the runs are finished, these quantities are + averaged together. This process can be thought of as analyical expectation + calculation done using monte carlo state vector simulation to account + for noisy operations in the given circuits. + + + >>> # Prepare some inputs. + >>> qubit = cirq.GridQubit(0, 0) + >>> my_symbol = sympy.Symbol('alpha') + >>> my_circuit_tensor = tfq.convert_to_tensor([ + ... cirq.Circuit( + ... cirq.H(qubit) ** my_symbol, + ... cirq.depolarize(0.01)(qubit) + ... ) + ... ]) + >>> my_values = np.array([[0.123]]) + >>> my_paulis = tfq.convert_to_tensor([[ + ... 3.5 * cirq.X(qubit) - 2.2 * cirq.Y(qubit) + ... ]]) + >>> my_num_samples = np.array([[100]]) + >>> # This op can now be run with: + >>> output = tfq.noise.expectation( + ... my_circuit_tensor, ['alpha'], my_values, my_paulis, my_num_samples) + >>> output + tf.Tensor([[0.71530885]], shape=(1, 1), dtype=float32) + + + In order to make the op differentiable, a `tfq.differentiator` object is + needed. see `tfq.differentiators` for more details. Below is a simple + example of how to make the from the above code block differentiable: + + + >>> diff = tfq.differentiators.ForwardDifference() + >>> my_differentiable_op = diff.generate_differentiable_op( + ... sampled_op=tfq.noise.expectation + ... ) + + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] + containing the string representation of the operators that will + be used on all of the circuits in the expectation calculations. + num_samples: `tf.Tensor` with `num_samples[i][j]` is equal to the + number of times `programs[i]` will be simulated to estimate + `pauli_sums[i][j]`. Therefore, `num_samples` must have the same + shape as `pauli_sums`. Note: internally this quantity can get + rounded up to the nearest multiple of the number of available + threads to TensorFlow. For best performance ensure that the + quantities in `num_samples` are a multiple of the number of + available threads. + Returns: + `tf.Tensor` with shape [batch_size, n_ops] that holds the + expectation value for each circuit with each op applied to it + (after resolving the corresponding parameters in). + """ + return NOISY_OP_MODULE.tfq_noisy_expectation( + programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums, + tf.cast(num_samples, dtype=tf.int32)) diff --git a/tensorflow_quantum/core/ops/noise/noisy_expectation_op_test.py b/tensorflow_quantum/core/ops/noise/noisy_expectation_op_test.py new file mode 100644 index 000000000..5c87bdbfc --- /dev/null +++ b/tensorflow_quantum/core/ops/noise/noisy_expectation_op_test.py @@ -0,0 +1,345 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Tests that specifically target noisy expectation calculation.""" +# 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 + +import numpy as np +from absl.testing import parameterized +import tensorflow as tf +import cirq + +from tensorflow_quantum.core.ops import batch_util +from tensorflow_quantum.core.ops.noise import noisy_expectation_op +from tensorflow_quantum.python import util + + +class NoisyExpectationCalculationTest(tf.test.TestCase, parameterized.TestCase): + """Tests tfq.noise.expectation.""" + + def test_noisy_expectation_inputs(self): + """Make sure noisy expectation op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, include_channels=True) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + num_samples = [[10]] * batch_size + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # Circuit tensor has too many dimensions. + noisy_expectation_op.expectation( + util.convert_to_tensor([circuit_batch]), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1.'): + # symbol_names tensor has too many dimensions. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too many dimensions. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array]), + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too few dimensions. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[0], + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too few dimensions. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + util.convert_to_tensor(list(pauli_sums)), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too many dimensions. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + [util.convert_to_tensor([[x] for x in pauli_sums])], + num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'num_samples must be rank 2'): + # num_samples tensor has the wrong shape. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'num_samples must be rank 2'): + # num_samples tensor has the wrong shape. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + num_samples[0]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # circuit tensor has the right type but invalid values. + noisy_expectation_op.expectation( + ['junk'] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type but invalid values. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), ['junk'], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'qubits not found in circuit'): + # pauli_sums tensor has the right type but invalid values. + new_qubits = [cirq.GridQubit(5, 5), cirq.GridQubit(9, 9)] + new_pauli_sums = util.random_pauli_sums(new_qubits, 2, batch_size) + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in new_pauli_sums]), + num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # pauli_sums tensor has the right type but invalid values 2. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [['junk']] * batch_size, num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # circuits tensor has the wrong type. + noisy_expectation_op.expectation( + [1.0] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), [0.1234], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # pauli_sums tensor has the wrong type. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [[1.0]] * batch_size, num_samples) + + with self.assertRaisesRegex(TypeError, 'missing'): + # we are missing an argument. + # pylint: disable=no-value-for-parameter + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, num_samples) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(TypeError, 'positional arguments'): + # pylint: disable=too-many-function-args + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), [], + num_samples) + # pylint: enable=too-many-function-args + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong op size. + noisy_expectation_op.expectation( + util.convert_to_tensor([cirq.Circuit()]), symbol_names, + symbol_values_array.astype(np.float64), + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'greater than 0'): + # pylint: disable=too-many-function-args + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + [[-1]] * batch_size) + # pylint: enable=too-many-function-args + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)], + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + @parameterized.parameters([ + { + 'n_qubits': 13, + 'batch_size': 1, + 'noisy': False + }, # ComputeLarge. + { + 'n_qubits': 6, + 'batch_size': 25, + 'noisy': False + }, # ComputeSmall. + { + 'n_qubits': 6, + 'batch_size': 10, + 'noisy': True + }, # ComputeSmall. + { + 'n_qubits': 8, + 'batch_size': 1, + 'noisy': True + } # ComputeLarge. + ]) + def test_simulate_consistency(self, batch_size, n_qubits, noisy): + """Test consistency with batch_util.py simulation.""" + symbol_names = ['alpha', 'beta'] + qubits = cirq.GridQubit.rect(1, n_qubits) + + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, include_channels=noisy) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums1 = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums2 = util.random_pauli_sums(qubits, 3, batch_size) + batch_pauli_sums = [[x, y] for x, y in zip(pauli_sums1, pauli_sums2)] + num_samples = [[10000 if noisy else 3] * 2] * batch_size + + op_exps = noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + util.convert_to_tensor(batch_pauli_sums), num_samples) + + cirq_exps = batch_util.batch_calculate_expectation( + circuit_batch, resolver_batch, batch_pauli_sums, + cirq.DensityMatrixSimulator() if noisy else cirq.Simulator()) + tol = 5e-2 if noisy else 5e-4 + self.assertAllClose(cirq_exps, op_exps, atol=tol, rtol=tol) + + @parameterized.parameters([{ + 'channel': x + } for x in util.get_supported_channels()]) + def test_single_channel(self, channel): + """Individually test adding just a single channel type to circuits.""" + symbol_names = [] + batch_size = 5 + n_qubits = 6 + qubits = cirq.LineQubit.range(n_qubits) + + circuit_batch, resolver_batch = \ + util.random_circuit_resolver_batch( + qubits, batch_size, include_channels=False) + + for i in range(batch_size): + circuit_batch[i] = circuit_batch[i] + channel.on_each(*qubits) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums1 = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums2 = util.random_pauli_sums(qubits, 3, batch_size) + batch_pauli_sums = [[x, y] for x, y in zip(pauli_sums1, pauli_sums2)] + num_samples = [[10000] * 2] * batch_size + + op_exps = noisy_expectation_op.expectation( + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + util.convert_to_tensor(batch_pauli_sums), num_samples) + + cirq_exps = batch_util.batch_calculate_expectation( + circuit_batch, resolver_batch, batch_pauli_sums, + cirq.DensityMatrixSimulator()) + + self.assertAllClose(cirq_exps, op_exps, atol=5e-2, rtol=5e-2) + + def test_correctness_empty(self): + """Test the expectation for empty circuits.""" + empty_circuit = util.convert_to_tensor([cirq.Circuit()]) + empty_symbols = tf.convert_to_tensor([], dtype=tf.dtypes.string) + empty_values = tf.convert_to_tensor([[]]) + empty_paulis = tf.convert_to_tensor([[]], dtype=tf.dtypes.string) + empty_n_samples = tf.convert_to_tensor([[]], dtype=tf.int32) + + out = noisy_expectation_op.expectation(empty_circuit, empty_symbols, + empty_values, empty_paulis, + empty_n_samples) + + expected = np.array([[]], dtype=np.complex64) + self.assertAllClose(out, expected) + + def test_correctness_no_circuit(self): + """Test the correctness with the empty tensor.""" + empty_circuit = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_symbols = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + empty_paulis = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + empty_n_samples = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.int32) + + out = noisy_expectation_op.expectation(empty_circuit, empty_symbols, + empty_values, empty_paulis, + empty_n_samples) + + self.assertShapeEqual(np.zeros((0, 0)), out) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op.py b/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op.py new file mode 100644 index 000000000..2cc84fd47 --- /dev/null +++ b/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op.py @@ -0,0 +1,97 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Module for high performance noisy circuit sampled epxectation ops.""" +import os +import tensorflow as tf +from tensorflow_quantum.core.ops.load_module import load_module + +NOISY_OP_MODULE = load_module(os.path.join("noise", "_tfq_noise_ops.so")) + + +def sampled_expectation(programs, symbol_names, symbol_values, pauli_sums, + num_samples): + """Estimates (via sampling) expectation values using monte-carlo simulation. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + Channels in this simulation will be "tossed" to a certain realization + during simulation. This simulation is repeated `num_samples` times and + bitstring based expectation calculations with the given `pauli_sums` are + calculated after each run. Once all the runs are finished, these quantities + are averaged together. + + + >>> # Prepare some inputs. + >>> qubit = cirq.GridQubit(0, 0) + >>> my_symbol = sympy.Symbol('alpha') + >>> my_circuit_tensor = tfq.convert_to_tensor([ + ... cirq.Circuit( + ... cirq.H(qubit) ** my_symbol, + ... cirq.depolarize(0.01)(qubit) + ... ) + ... ]) + >>> my_values = np.array([[0.123]]) + >>> my_paulis = tfq.convert_to_tensor([[ + ... 3.5 * cirq.X(qubit) - 2.2 * cirq.Y(qubit) + ... ]]) + >>> my_num_samples = np.array([[100]]) + >>> # This op can now be run with: + >>> output = tfq.noise.sampled_expectation( + ... my_circuit_tensor, ['alpha'], my_values, my_paulis, my_num_samples) + >>> output + tf.Tensor([[0.71530885]], shape=(1, 1), dtype=float32) + + + In order to make the op differentiable, a `tfq.differentiator` object is + needed. see `tfq.differentiators` for more details. Below is a simple + example of how to make the from the above code block differentiable: + + + >>> diff = tfq.differentiators.ForwardDifference() + >>> my_differentiable_op = diff.generate_differentiable_op( + ... sampled_op=tfq.noise.sampled_expectation + ... ) + + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] + containing the string representation of the operators that will + be used on all of the circuits in the expectation calculations. + num_samples: `tf.Tensor` with `num_samples[i][j]` is equal to the + number of times `programs[i]` will be simulated to estimate + `pauli_sums[i][j]`. Therefore, `num_samples` must have the same + shape as `pauli_sums`. Note: internally this quantity can get + rounded up to the nearest multiple of the number of available + threads to TensorFlow. For best performance ensure that the + quantities in `num_samples` are a multiple of the number of + available threads. + Returns: + `tf.Tensor` with shape [batch_size, n_ops] that holds the + expectation value for each circuit with each op applied to it + (after resolving the corresponding parameters in). + """ + return NOISY_OP_MODULE.tfq_noisy_sampled_expectation( + programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums, + tf.cast(num_samples, dtype=tf.int32)) diff --git a/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op_test.py b/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op_test.py new file mode 100644 index 000000000..ea967c93b --- /dev/null +++ b/tensorflow_quantum/core/ops/noise/noisy_sampled_expectation_op_test.py @@ -0,0 +1,345 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Tests that specifically target noisy expectation calculation.""" +# 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 + +import numpy as np +from absl.testing import parameterized +import tensorflow as tf +import cirq + +from tensorflow_quantum.core.ops import batch_util +from tensorflow_quantum.core.ops.noise import noisy_sampled_expectation_op +from tensorflow_quantum.python import util + + +class NoisyExpectationCalculationTest(tf.test.TestCase, parameterized.TestCase): + """Tests tfq.noise.expectation.""" + + def test_noisy_expectation_inputs(self): + """Make sure noisy expectation op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, include_channels=True) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + num_samples = [[10]] * batch_size + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # Circuit tensor has too many dimensions. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor([circuit_batch]), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1.'): + # symbol_names tensor has too many dimensions. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too many dimensions. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array]), + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too few dimensions. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[0], + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too few dimensions. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + util.convert_to_tensor(list(pauli_sums)), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too many dimensions. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + [util.convert_to_tensor([[x] for x in pauli_sums])], + num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'num_samples must be rank 2'): + # num_samples tensor has the wrong shape. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'num_samples must be rank 2'): + # num_samples tensor has the wrong shape. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + num_samples[0]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # circuit tensor has the right type but invalid values. + noisy_sampled_expectation_op.sampled_expectation( + ['junk'] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type but invalid values. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), ['junk'], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'qubits not found in circuit'): + # pauli_sums tensor has the right type but invalid values. + new_qubits = [cirq.GridQubit(5, 5), cirq.GridQubit(9, 9)] + new_pauli_sums = util.random_pauli_sums(new_qubits, 2, batch_size) + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in new_pauli_sums]), + num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # pauli_sums tensor has the right type but invalid values 2. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [['junk']] * batch_size, num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # circuits tensor has the wrong type. + noisy_sampled_expectation_op.sampled_expectation( + [1.0] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), [0.1234], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # pauli_sums tensor has the wrong type. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [[1.0]] * batch_size, num_samples) + + with self.assertRaisesRegex(TypeError, 'missing'): + # we are missing an argument. + # pylint: disable=no-value-for-parameter + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, num_samples) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(TypeError, 'positional arguments'): + # pylint: disable=too-many-function-args + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), [], + num_samples) + # pylint: enable=too-many-function-args + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong op size. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor([cirq.Circuit()]), symbol_names, + symbol_values_array.astype(np.float64), + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'greater than 0'): + # pylint: disable=too-many-function-args + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + [[-1]] * batch_size) + # pylint: enable=too-many-function-args + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)], + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + @parameterized.parameters([ + { + 'n_qubits': 13, + 'batch_size': 1, + 'noisy': False + }, # ComputeLarge. + { + 'n_qubits': 6, + 'batch_size': 25, + 'noisy': False + }, # ComputeSmall. + { + 'n_qubits': 6, + 'batch_size': 10, + 'noisy': True + }, # ComputeSmall. + { + 'n_qubits': 8, + 'batch_size': 1, + 'noisy': True + } # ComputeLarge. + ]) + def test_simulate_consistency(self, batch_size, n_qubits, noisy): + """Test consistency with batch_util.py simulation.""" + symbol_names = ['alpha', 'beta'] + qubits = cirq.GridQubit.rect(1, n_qubits) + + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, include_channels=noisy) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums1 = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums2 = util.random_pauli_sums(qubits, 3, batch_size) + batch_pauli_sums = [[x, y] for x, y in zip(pauli_sums1, pauli_sums2)] + num_samples = [[10000] * 2] * batch_size + + op_exps = noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + util.convert_to_tensor(batch_pauli_sums), num_samples) + + cirq_exps = batch_util.batch_calculate_expectation( + circuit_batch, resolver_batch, batch_pauli_sums, + cirq.DensityMatrixSimulator() if noisy else cirq.Simulator()) + tol = 0.5 + self.assertAllClose(cirq_exps, op_exps, atol=tol, rtol=tol) + + @parameterized.parameters([{ + 'channel': x + } for x in util.get_supported_channels()]) + def test_single_channel(self, channel): + """Individually test adding just a single channel type to circuits.""" + symbol_names = [] + batch_size = 5 + n_qubits = 6 + qubits = cirq.LineQubit.range(n_qubits) + + circuit_batch, resolver_batch = \ + util.random_circuit_resolver_batch( + qubits, batch_size, include_channels=False) + + for i in range(batch_size): + circuit_batch[i] = circuit_batch[i] + channel.on_each(*qubits) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums1 = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums2 = util.random_pauli_sums(qubits, 3, batch_size) + batch_pauli_sums = [[x, y] for x, y in zip(pauli_sums1, pauli_sums2)] + num_samples = [[20000] * 2] * batch_size + + op_exps = noisy_sampled_expectation_op.sampled_expectation( + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + util.convert_to_tensor(batch_pauli_sums), num_samples) + + cirq_exps = batch_util.batch_calculate_expectation( + circuit_batch, resolver_batch, batch_pauli_sums, + cirq.DensityMatrixSimulator()) + + self.assertAllClose(cirq_exps, op_exps, atol=0.35, rtol=0.35) + + def test_correctness_empty(self): + """Test the expectation for empty circuits.""" + empty_circuit = util.convert_to_tensor([cirq.Circuit()]) + empty_symbols = tf.convert_to_tensor([], dtype=tf.dtypes.string) + empty_values = tf.convert_to_tensor([[]]) + empty_paulis = tf.convert_to_tensor([[]], dtype=tf.dtypes.string) + empty_n_samples = tf.convert_to_tensor([[]], dtype=tf.int32) + + out = noisy_sampled_expectation_op.sampled_expectation( + empty_circuit, empty_symbols, empty_values, empty_paulis, + empty_n_samples) + + expected = np.array([[]], dtype=np.complex64) + self.assertAllClose(out, expected) + + def test_correctness_no_circuit(self): + """Test the correctness with the empty tensor.""" + empty_circuit = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_symbols = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + empty_paulis = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + empty_n_samples = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.int32) + + out = noisy_sampled_expectation_op.sampled_expectation( + empty_circuit, empty_symbols, empty_values, empty_paulis, + empty_n_samples) + + self.assertShapeEqual(np.zeros((0, 0)), out) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/ops/noise/noisy_samples_op.py b/tensorflow_quantum/core/ops/noise/noisy_samples_op.py new file mode 100644 index 000000000..1e19b19ae --- /dev/null +++ b/tensorflow_quantum/core/ops/noise/noisy_samples_op.py @@ -0,0 +1,71 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Module for high performance noisy circuit sampling ops""" +import os +import tensorflow as tf +from tensorflow_quantum.core.ops import tfq_utility_ops +from tensorflow_quantum.core.ops.load_module import load_module + +NOISY_OP_MODULE = load_module(os.path.join("noise", "_tfq_noise_ops.so")) + + +def samples(programs, symbol_names, symbol_values, num_samples): + """Generate samples using the C++ noisy trajectory simulator. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + Channels in this simulation will be "tossed" to a certain realization + during simulation. After each simulation is a run a single bitstring + will be drawn. These simulations are repeated `num_samples` times. + + + >>> # Sample a noisy circuit with C++. + >>> qubit = cirq.GridQubit(0, 0) + >>> my_symbol = sympy.Symbol('alpha') + >>> my_circuit_tensor = tfq.convert_to_tensor([ + ... cirq.Circuit( + ... cirq.X(qubit) ** my_symbol, + ... cirq.depolarize(0.01)(qubit) + ... ) + ... ]) + >>> my_values = np.array([[0.123]]) + >>> my_num_samples = np.array([100]) + >>> # This op can now be run with: + >>> output = tfq.noise.samples( + ... my_circuit_tensor, ['alpha'], my_values, my_num_samples) + >>> output + + + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specified by programs, following the ordering + dictated by `symbol_names`. + num_samples: `tf.Tensor` with one element indicating the number of + samples to draw for all circuits in the batch. + Returns: + A `tf.Tensor` containing the samples taken from each circuit in + `programs`. + """ + padded_samples = NOISY_OP_MODULE.tfq_noisy_samples( + programs, symbol_names, tf.cast(symbol_values, tf.float32), num_samples) + return tfq_utility_ops.padded_to_ragged(padded_samples) \ No newline at end of file diff --git a/tensorflow_quantum/core/ops/noise/noisy_samples_op_test.py b/tensorflow_quantum/core/ops/noise/noisy_samples_op_test.py new file mode 100644 index 000000000..88b221941 --- /dev/null +++ b/tensorflow_quantum/core/ops/noise/noisy_samples_op_test.py @@ -0,0 +1,300 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Tests that specifically target noisy sampling.""" +# 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 + +import numpy as np +from scipy import stats +from absl.testing import parameterized +import tensorflow as tf +import cirq + +from tensorflow_quantum.core.ops import batch_util +from tensorflow_quantum.core.ops.noise import noisy_samples_op +from tensorflow_quantum.python import util + + +class NoisySamplingTest(tf.test.TestCase, parameterized.TestCase): + """Tests tfq.noise.expectation.""" + + def _compute_hists(self, x, n_qubits): + """Compute the batchwise histograms of a sample tensor.""" + x = np.asarray(x) + return [ + np.histogram( + sample.dot(1 << np.arange(sample.shape[-1] - 1, -1, -1)), + range=(0, 2**n_qubits), + bins=2**n_qubits)[0] for sample in x + ] + + def test_simulate_samples_inputs(self): + """Make sure the sample op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + num_samples = 10 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 1. Got rank 2'): + # programs tensor has the wrong shape. + noisy_samples_op.samples(util.convert_to_tensor([circuit_batch]), + symbol_names, symbol_values_array, + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 1. Got rank 2'): + # symbol_names tensor has the wrong shape. + noisy_samples_op.samples(util.convert_to_tensor(circuit_batch), + np.array([symbol_names]), + symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 2. Got rank 3'): + # symbol_values tensor has the wrong shape. + noisy_samples_op.samples(util.convert_to_tensor(circuit_batch), + symbol_names, + np.array([symbol_values_array]), + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 2. Got rank 1'): + # symbol_values tensor has the wrong shape 2. + noisy_samples_op.samples(util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array[0], + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 1. Got rank 2'): + # num_samples tensor has the wrong shape. + noisy_samples_op.samples(util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + [[num_samples]]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # programs tensor has the right type, but invalid value. + noisy_samples_op.samples(['junk'] * batch_size, symbol_names, + symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type, but invalid value. + noisy_samples_op.samples(util.convert_to_tensor(circuit_batch), + ['junk'], symbol_values_array, + [num_samples]) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # programs tensor has the wrong type. + noisy_samples_op.samples([1] * batch_size, symbol_names, + symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # programs tensor has the wrong type. + noisy_samples_op.samples(util.convert_to_tensor(circuit_batch), [1], + symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, + 'Cast string to float is not supported'): + # programs tensor has the wrong type. + noisy_samples_op.samples(util.convert_to_tensor(circuit_batch), + symbol_names, [['junk']] * batch_size, + [num_samples]) + + with self.assertRaisesRegex(Exception, 'junk'): + # num_samples tensor has the wrong type. + noisy_samples_op.samples(util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + ['junk']) + + with self.assertRaisesRegex(TypeError, 'missing'): + # too few tensors. + # pylint: disable=no-value-for-parameter + noisy_samples_op.samples(util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + noisy_samples_op.samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)], num_samples) + + @parameterized.parameters([ + { + 'n_qubits': 13, + 'batch_size': 1, + 'noisy': False + }, # ComputeLarge. + { + 'n_qubits': 6, + 'batch_size': 25, + 'noisy': False + }, # ComputeSmall. + { + 'n_qubits': 6, + 'batch_size': 10, + 'noisy': True + }, # ComputeSmall. + { + 'n_qubits': 8, + 'batch_size': 1, + 'noisy': True + } # ComputeLarge. + ]) + def test_simulate_consistency(self, batch_size, n_qubits, noisy): + """Test consistency with batch_util.py simulation.""" + symbol_names = ['alpha', 'beta'] + qubits = cirq.LineQubit.range(n_qubits) + + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size, include_channels=noisy) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + n_samples = 10000 + op_samples = noisy_samples_op.samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [n_samples]).to_list() + + op_hists = self._compute_hists(op_samples, n_qubits) + + cirq_samples = batch_util.batch_sample( + circuit_batch, resolver_batch, n_samples, + cirq.DensityMatrixSimulator() if noisy else cirq.Simulator()) + + cirq_hists = self._compute_hists(cirq_samples, n_qubits) + tol = 1.5 if noisy else 1.0 + for a, b in zip(op_hists, cirq_hists): + self.assertLess(stats.entropy(a + 1e-8, b + 1e-8), tol) + + @parameterized.parameters([{ + 'channel': x + } for x in util.get_supported_channels()]) + def test_single_channel(self, channel): + """Individually test adding just a single channel type to circuits.""" + symbol_names = [] + batch_size = 3 + n_qubits = 5 + qubits = cirq.GridQubit.rect(1, n_qubits) + + circuit_batch, resolver_batch = \ + util.random_circuit_resolver_batch( + qubits, batch_size, include_channels=False) + + for i in range(batch_size): + circuit_batch[i] = circuit_batch[i] + channel.on_each(*qubits) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + n_samples = (2**n_qubits) * 1000 + + op_samples = noisy_samples_op.samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [n_samples]).to_list() + op_hists = self._compute_hists(op_samples, n_qubits) + + cirq_samples = batch_util.batch_sample(circuit_batch, resolver_batch, + n_samples, + cirq.DensityMatrixSimulator()) + cirq_hists = self._compute_hists(cirq_samples, n_qubits) + + for a, b in zip(op_hists, cirq_hists): + self.assertLess(stats.entropy(a + 1e-8, b + 1e-8), 0.15) + + def test_correct_padding(self): + """Test the variable sized circuits are properly padded.""" + symbol_names = [] + batch_size = 2 + n_qubits = 5 + qubits1 = cirq.GridQubit.rect(1, n_qubits) + qubits2 = cirq.GridQubit.rect(1, n_qubits + 1) + + circuit_batch1, resolver_batch1 = \ + util.random_circuit_resolver_batch( + qubits1, batch_size, include_channels=True) + + circuit_batch2, resolver_batch2 = \ + util.random_circuit_resolver_batch( + qubits2, batch_size, include_channels=True) + + p1 = [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch1] + p2 = [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch2] + symbol_values_array = np.array(p1 + p2) + + n_samples = 10 + + op_samples = noisy_samples_op.samples( + util.convert_to_tensor(circuit_batch1 + circuit_batch2), + symbol_names, symbol_values_array, [n_samples]).to_list() + a_reps = np.asarray(op_samples[:2]) + b_reps = np.asarray(op_samples[2:]) + self.assertEqual(a_reps.shape, (2, 10, 5)) + self.assertEqual(b_reps.shape, (2, 10, 6)) + + def test_correctness_empty(self): + """Test the expectation for empty circuits.""" + empty_circuit = util.convert_to_tensor([cirq.Circuit()]) + empty_symbols = tf.convert_to_tensor([], dtype=tf.dtypes.string) + empty_values = tf.convert_to_tensor([[]]) + empty_n_samples = tf.convert_to_tensor([1], dtype=tf.int32) + + out = noisy_samples_op.samples(empty_circuit, empty_symbols, + empty_values, empty_n_samples) + + expected = np.array([[[]]], dtype=np.int8) + self.assertAllClose(out.to_tensor(), expected) + + def test_correctness_no_circuit(self): + """Test the correctness with the empty tensor.""" + empty_circuit = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_symbols = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + empty_n_samples = tf.convert_to_tensor([1], dtype=tf.int32) + + out = noisy_samples_op.samples(empty_circuit, empty_symbols, + empty_values, empty_n_samples) + + self.assertShapeEqual(np.zeros((0, 0, 0)), out.to_tensor()) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/ops/noise/tfq_noisy_expectation.cc b/tensorflow_quantum/core/ops/noise/tfq_noisy_expectation.cc new file mode 100644 index 000000000..6f09da68f --- /dev/null +++ b/tensorflow_quantum/core/ops/noise/tfq_noisy_expectation.cc @@ -0,0 +1,424 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include +#include + +#include "../qsim/lib/channel.h" +#include "../qsim/lib/channels_cirq.h" +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/circuit_noisy.h" +#include "../qsim/lib/fuser_mqubit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/io.h" +#include "../qsim/lib/qtrajectory.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/platform/mutex.h" +#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 ::tensorflow::Status; +using ::tfq::proto::PauliSum; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; +typedef qsim::NoisyCircuit NoisyQsimCircuit; + +class TfqNoisyExpectationOp : public tensorflow::OpKernel { + public: + explicit TfqNoisyExpectationOp(tensorflow::OpKernelConstruction* context) + : OpKernel(context) {} + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + const int num_inputs = context->num_inputs(); + OP_REQUIRES(context, num_inputs == 5, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Expected 5 inputs, got ", num_inputs, " inputs."))); + + // Create the output Tensor. + const int output_dim_batch_size = context->input(0).dim_size(0); + const int output_dim_op_size = context->input(3).dim_size(1); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_batch_size); + output_shape.AddDim(output_dim_op_size); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->matrix(); + + std::vector programs; + std::vector num_qubits; + std::vector> pauli_sums; + OP_REQUIRES_OK(context, GetProgramsAndNumQubits(context, &programs, + &num_qubits, &pauli_sums)); + + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + + OP_REQUIRES(context, programs.size() == maps.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and symbol_values do not match. Got ", + programs.size(), " circuits and ", maps.size(), + " symbol values."))); + + std::vector> num_samples; + OP_REQUIRES_OK(context, GetNumSamples(context, &num_samples)); + + OP_REQUIRES(context, num_samples.size() == pauli_sums.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Dimension 0 of num_samples and pauli_sums do not match.", + "Got ", num_samples.size(), " lists of sample sizes and ", + pauli_sums.size(), " lists of pauli sums."))); + + OP_REQUIRES( + context, context->input(4).dim_size(1) == context->input(3).dim_size(1), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Dimension 1 of num_samples and pauli_sums do not match.", "Got ", + context->input(4).dim_size(1), " lists of sample sizes and ", + context->input(3).dim_size(1), " lists of pauli sums."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), + NoisyQsimCircuit()); + + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = NoisyQsimCircuitFromProgram( + programs[i], maps[i], num_qubits[i], false, &qsim_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + // Cross reference with standard google cloud compute instances + // Memory ~= 2 * num_threads * (2 * 64 * 2 ** num_qubits in circuits) + // e2s2 = 2 CPU, 8GB -> Can safely do 25 since Memory = 4GB + // e2s4 = 4 CPU, 16GB -> Can safely do 25 since Memory = 8GB + // ... + if (max_num_qubits >= 26) { + // If the number of qubits is lager than 24, we switch to an + // alternate parallelization scheme with runtime: + // O(n_circuits * max_j(num_samples[i])) with parallelization being + // multiple threads per wavefunction. + ComputeLarge(num_qubits, qsim_circuits, pauli_sums, num_samples, context, + &output_tensor); + } else { + // Runtime: O(n_circuits * max_j(num_samples[i])) with parallelization + // being done over number of trials. + ComputeSmall(num_qubits, max_num_qubits, qsim_circuits, pauli_sums, + num_samples, context, &output_tensor); + } + } + + private: + void ComputeLarge(const std::vector& num_qubits, + const std::vector& ncircuits, + const std::vector>& pauli_sums, + const std::vector>& num_samples, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + // Instantiate qsim objects. + const auto tfq_for = tfq::QsimFor(context); + using Simulator = qsim::Simulator; + using StateSpace = Simulator::StateSpace; + using QTSimulator = + qsim::QuantumTrajectorySimulator; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(tfq_for); + StateSpace ss = StateSpace(tfq_for); + auto sv = ss.Create(largest_nq); + auto scratch = ss.Create(largest_nq); + + tensorflow::GuardedPhiloxRandom random_gen; + int max_n_shots = 1; + for (size_t i = 0; i < num_samples.size(); i++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { + max_n_shots = std::max(max_n_shots, num_samples[i][j]); + } + } + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + auto local_gen = + random_gen.ReserveSamples128(ncircuits.size() * max_n_shots + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as necessary. + for (size_t i = 0; i < ncircuits.size(); i++) { + int nq = num_qubits[i]; + + // (#679) Just ignore empty program + if (ncircuits[i].channels.size() == 0) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { + (*output_tensor)(i, j) = -2.0; + } + continue; + } + + if (nq > largest_nq) { + largest_nq = nq; + sv = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + } + QTSimulator::Parameter param; + param.collect_kop_stat = false; + param.collect_mea_stat = false; + param.normalize_before_mea_gates = true; + QTSimulator::Stat unused_stats; + // Track op-wise stats. + std::vector run_samples(num_samples[i].size(), 0); + std::vector rolling_sums(num_samples[i].size(), 0.0); + + while (1) { + ss.SetStateZero(sv); + + QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss, sim, + sv, unused_stats); + + // Use this trajectory as a source for all expectation calculations. + for (size_t j = 0; j < pauli_sums[i].size(); j++) { + if (run_samples[j] >= num_samples[i][j]) { + continue; + } + float exp_v = 0.0; + OP_REQUIRES_OK(context, + ComputeExpectationQsim(pauli_sums[i][j], sim, ss, sv, + scratch, &exp_v)); + rolling_sums[j] += static_cast(exp_v); + run_samples[j]++; + } + bool break_loop = true; + for (size_t j = 0; j < num_samples[i].size(); j++) { + if (run_samples[j] < num_samples[i][j]) { + break_loop = false; + break; + } + } + if (break_loop) { + for (size_t j = 0; j < num_samples[i].size(); j++) { + rolling_sums[j] /= num_samples[i][j]; + (*output_tensor)(i, j) = static_cast(rolling_sums[j]); + } + break; + } + } + } + } + + void ComputeSmall(const std::vector& num_qubits, + const int max_num_qubits, + const std::vector& ncircuits, + const std::vector>& pauli_sums, + const std::vector>& num_samples, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + using Simulator = qsim::Simulator; + using StateSpace = Simulator::StateSpace; + using QTSimulator = + qsim::QuantumTrajectorySimulator; + + const int output_dim_batch_size = output_tensor->dimension(0); + std::vector batch_locks(output_dim_batch_size, + tensorflow::mutex()); + + const int num_threads = context->device() + ->tensorflow_cpu_worker_threads() + ->workers->NumThreads(); + + // [num_threads, batch_size]. + std::vector> rep_offsets( + num_threads, std::vector(output_dim_batch_size, 0)); + + BalanceTrajectory(num_samples, num_threads, &rep_offsets); + + output_tensor->setZero(); + + tensorflow::GuardedPhiloxRandom random_gen; + int max_n_shots = 1; + for (size_t i = 0; i < num_samples.size(); i++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { + max_n_shots = std::max(max_n_shots, num_samples[i][j]); + } + } + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + + Status compute_status = ::tensorflow::Status(); + auto c_lock = tensorflow::mutex(); + auto DoWork = [&](int start, int end) { + // Begin simulation. + const auto tfq_for = qsim::SequentialFor(1); + int largest_nq = 1; + Simulator sim = Simulator(tfq_for); + StateSpace ss = StateSpace(tfq_for); + auto sv = ss.Create(largest_nq); + auto scratch = ss.Create(largest_nq); + + int n_rand = ncircuits.size() * max_n_shots + 1; + n_rand = (n_rand + num_threads) / num_threads; + auto local_gen = + random_gen.ReserveSamples128(ncircuits.size() * max_n_shots + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + for (size_t i = 0; i < ncircuits.size(); i++) { + int nq = num_qubits[i]; + int rep_offset = rep_offsets[start][i]; + + // (#679) Just ignore empty program + if (ncircuits[i].channels.size() == 0) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { + (*output_tensor)(i, j) = -2.0; + } + continue; + } + + if (nq > largest_nq) { + largest_nq = nq; + sv = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + } + QTSimulator::Parameter param; + param.collect_kop_stat = false; + param.collect_mea_stat = false; + param.normalize_before_mea_gates = true; + QTSimulator::Stat unused_stats; + // Track op-wise stats. + std::vector run_samples(num_samples[i].size(), 0); + std::vector rolling_sums(num_samples[i].size(), 0.0); + + while (1) { + ss.SetStateZero(sv); + + QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss, + sim, sv, unused_stats); + + // Compute expectations across all ops using this trajectory. + for (size_t j = 0; j < pauli_sums[i].size(); j++) { + int p_reps = (num_samples[i][j] + num_threads - 1) / num_threads; + if (run_samples[j] >= p_reps + rep_offset) { + continue; + } + float exp_v = 0.0; + NESTED_FN_STATUS_SYNC( + compute_status, + ComputeExpectationQsim(pauli_sums[i][j], sim, ss, sv, scratch, + &exp_v), + c_lock); + rolling_sums[j] += static_cast(exp_v); + run_samples[j]++; + } + + // Check if we have run enough trajectories for all ops. + bool break_loop = true; + for (size_t j = 0; j < num_samples[i].size(); j++) { + int p_reps = (num_samples[i][j] + num_threads - 1) / num_threads; + if (run_samples[j] < p_reps + rep_offset) { + break_loop = false; + break; + } + } + if (break_loop) { + // Lock writing to this batch index in output_tensor. + batch_locks[i].lock(); + for (size_t j = 0; j < num_samples[i].size(); j++) { + rolling_sums[j] /= num_samples[i][j]; + (*output_tensor)(i, j) += static_cast(rolling_sums[j]); + } + batch_locks[i].unlock(); + break; + } + } + } + }; + + // block_size = 1. + tensorflow::thread::ThreadPool::SchedulingParams scheduling_params( + tensorflow::thread::ThreadPool::SchedulingStrategy::kFixedBlockSize, + absl::nullopt, 1); + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + num_threads, scheduling_params, DoWork); + OP_REQUIRES_OK(context, compute_status); + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqNoisyExpectation").Device(tensorflow::DEVICE_CPU), + TfqNoisyExpectationOp); + +REGISTER_OP("TfqNoisyExpectation") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("pauli_sums: string") + .Input("num_samples: int32") + .Output("expectations: float") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle pauli_sums_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 2, &pauli_sums_shape)); + + tensorflow::shape_inference::ShapeHandle num_samples_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(4), 2, &num_samples_shape)); + + tensorflow::shape_inference::DimensionHandle output_rows = + c->Dim(programs_shape, 0); + tensorflow::shape_inference::DimensionHandle output_cols = + c->Dim(pauli_sums_shape, 1); + c->set_output(0, c->Matrix(output_rows, output_cols)); + + return ::tensorflow::Status(); + }); + +} // namespace tfq diff --git a/tensorflow_quantum/core/ops/noise/tfq_noisy_sampled_expectation.cc b/tensorflow_quantum/core/ops/noise/tfq_noisy_sampled_expectation.cc new file mode 100644 index 000000000..7e1993a7e --- /dev/null +++ b/tensorflow_quantum/core/ops/noise/tfq_noisy_sampled_expectation.cc @@ -0,0 +1,430 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include +#include + +#include "../qsim/lib/channel.h" +#include "../qsim/lib/channels_cirq.h" +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/circuit_noisy.h" +#include "../qsim/lib/fuser_mqubit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/io.h" +#include "../qsim/lib/qtrajectory.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/platform/mutex.h" +#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 ::tensorflow::Status; +using ::tfq::proto::PauliSum; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; +typedef qsim::NoisyCircuit NoisyQsimCircuit; + +class TfqNoisySampledExpectationOp : public tensorflow::OpKernel { + public: + explicit TfqNoisySampledExpectationOp( + tensorflow::OpKernelConstruction* context) + : OpKernel(context) {} + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + const int num_inputs = context->num_inputs(); + OP_REQUIRES(context, num_inputs == 5, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Expected 5 inputs, got ", num_inputs, " inputs."))); + + // Create the output Tensor. + const int output_dim_batch_size = context->input(0).dim_size(0); + const int output_dim_op_size = context->input(3).dim_size(1); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_batch_size); + output_shape.AddDim(output_dim_op_size); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->matrix(); + + std::vector programs; + std::vector num_qubits; + std::vector> pauli_sums; + OP_REQUIRES_OK(context, GetProgramsAndNumQubits(context, &programs, + &num_qubits, &pauli_sums)); + + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + + OP_REQUIRES(context, programs.size() == maps.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and symbol_values do not match. Got ", + programs.size(), " circuits and ", maps.size(), + " symbol values."))); + + std::vector> num_samples; + OP_REQUIRES_OK(context, GetNumSamples(context, &num_samples)); + + OP_REQUIRES(context, num_samples.size() == pauli_sums.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Dimension 0 of num_samples and pauli_sums do not match.", + "Got ", num_samples.size(), " lists of sample sizes and ", + pauli_sums.size(), " lists of pauli sums."))); + + OP_REQUIRES( + context, context->input(4).dim_size(1) == context->input(3).dim_size(1), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Dimension 1 of num_samples and pauli_sums do not match.", "Got ", + context->input(4).dim_size(1), " lists of sample sizes and ", + context->input(3).dim_size(1), " lists of pauli sums."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), + NoisyQsimCircuit()); + + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = NoisyQsimCircuitFromProgram( + programs[i], maps[i], num_qubits[i], false, &qsim_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + // Cross reference with standard google cloud compute instances + // Memory ~= 2 * num_threads * (2 * 64 * 2 ** num_qubits in circuits) + // e2s2 = 2 CPU, 8GB -> Can safely do 25 since Memory = 4GB + // e2s4 = 4 CPU, 16GB -> Can safely do 25 since Memory = 8GB + // ... + if (max_num_qubits >= 26) { + // If the number of qubits is lager than 25, we switch to an + // alternate parallelization scheme with runtime: + // O(n_circuits * max_j(num_samples[i])) with parallelization being + // multiple threads per wavefunction. + ComputeLarge(num_qubits, qsim_circuits, pauli_sums, num_samples, context, + &output_tensor); + } else { + // Runtime: O(n_circuits * max_j(num_samples[i])) with parallelization + // being done over number of trials. + ComputeSmall(num_qubits, max_num_qubits, qsim_circuits, pauli_sums, + num_samples, context, &output_tensor); + } + } + + private: + void ComputeLarge(const std::vector& num_qubits, + const std::vector& ncircuits, + const std::vector>& pauli_sums, + const std::vector>& num_samples, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + // Instantiate qsim objects. + const auto tfq_for = tfq::QsimFor(context); + using Simulator = qsim::Simulator; + using StateSpace = Simulator::StateSpace; + using QTSimulator = + qsim::QuantumTrajectorySimulator; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(tfq_for); + StateSpace ss = StateSpace(tfq_for); + auto sv = ss.Create(largest_nq); + auto scratch = ss.Create(largest_nq); + + tensorflow::GuardedPhiloxRandom random_gen; + int max_psum_length = 1; + int max_n_shots = 1; + for (size_t i = 0; i < pauli_sums.size(); i++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { + max_psum_length = + std::max(max_psum_length, pauli_sums[i][j].terms().size()); + max_n_shots = std::max(max_n_shots, num_samples[i][j]); + } + } + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + auto local_gen = random_gen.ReserveSamples128( + ncircuits.size() * (1 + max_psum_length) * max_n_shots); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as necessary. + for (size_t i = 0; i < ncircuits.size(); i++) { + int nq = num_qubits[i]; + + // (#679) Just ignore empty program + if (ncircuits[i].channels.empty()) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { + (*output_tensor)(i, j) = -2.0; + } + continue; + } + + if (nq > largest_nq) { + largest_nq = nq; + sv = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + } + QTSimulator::Parameter param; + param.collect_kop_stat = false; + param.collect_mea_stat = false; + param.normalize_before_mea_gates = true; + QTSimulator::Stat unused_stats; + // Track op-wise stats. + std::vector run_samples(num_samples[i].size(), 0); + std::vector rolling_sums(num_samples[i].size(), 0.0); + + while (1) { + ss.SetStateZero(sv); + + QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss, sim, + sv, unused_stats); + + // Use this trajectory as a source for all expectation calculations. + for (size_t j = 0; j < pauli_sums[i].size(); j++) { + if (run_samples[j] >= num_samples[i][j]) { + continue; + } + float exp_v = 0.0; + OP_REQUIRES_OK(context, ComputeSampledExpectationQsim( + pauli_sums[i][j], sim, ss, sv, scratch, 1, + rand_source, &exp_v)); + rolling_sums[j] += static_cast(exp_v); + run_samples[j]++; + } + bool break_loop = true; + for (size_t j = 0; j < num_samples[i].size(); j++) { + if (run_samples[j] < num_samples[i][j]) { + break_loop = false; + break; + } + } + if (break_loop) { + for (size_t j = 0; j < num_samples[i].size(); j++) { + rolling_sums[j] /= num_samples[i][j]; + (*output_tensor)(i, j) = static_cast(rolling_sums[j]); + } + break; + } + } + } + } + + void ComputeSmall(const std::vector& num_qubits, + const int max_num_qubits, + const std::vector& ncircuits, + const std::vector>& pauli_sums, + const std::vector>& num_samples, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + using Simulator = qsim::Simulator; + using StateSpace = Simulator::StateSpace; + using QTSimulator = + qsim::QuantumTrajectorySimulator; + + const int output_dim_batch_size = output_tensor->dimension(0); + std::vector batch_locks(output_dim_batch_size, + tensorflow::mutex()); + + const int num_threads = context->device() + ->tensorflow_cpu_worker_threads() + ->workers->NumThreads(); + + // [num_threads, batch_size]. + std::vector> rep_offsets( + num_threads, std::vector(output_dim_batch_size, 0)); + + BalanceTrajectory(num_samples, num_threads, &rep_offsets); + + output_tensor->setZero(); + + tensorflow::GuardedPhiloxRandom random_gen; + int max_psum_length = 1; + int max_n_shots = 1; + for (size_t i = 0; i < pauli_sums.size(); i++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { + max_psum_length = + std::max(max_psum_length, pauli_sums[i][j].terms().size()); + max_n_shots = std::max(max_n_shots, num_samples[i][j]); + } + } + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + + Status compute_status = ::tensorflow::Status(); + auto c_lock = tensorflow::mutex(); + auto DoWork = [&](int start, int end) { + // Begin simulation. + const auto tfq_for = qsim::SequentialFor(1); + int largest_nq = 1; + Simulator sim = Simulator(tfq_for); + StateSpace ss = StateSpace(tfq_for); + auto sv = ss.Create(largest_nq); + auto scratch = ss.Create(largest_nq); + + int num_rand = ncircuits.size() * (1 + max_psum_length) * max_n_shots; + num_rand = (num_rand + num_threads) / num_threads + 1; + auto local_gen = random_gen.ReserveSamples128(num_rand); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + for (size_t i = 0; i < ncircuits.size(); i++) { + int nq = num_qubits[i]; + int rep_offset = rep_offsets[start][i]; + + // (#679) Just ignore empty program + if (ncircuits[i].channels.empty()) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { + (*output_tensor)(i, j) = -2.0; + } + continue; + } + + if (nq > largest_nq) { + largest_nq = nq; + sv = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + } + QTSimulator::Parameter param; + param.collect_kop_stat = false; + param.collect_mea_stat = false; + param.normalize_before_mea_gates = true; + QTSimulator::Stat unused_stats; + // Track op-wise stats. + std::vector run_samples(num_samples[i].size(), 0); + std::vector rolling_sums(num_samples[i].size(), 0.0); + + while (1) { + ss.SetStateZero(sv); + + QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss, + sim, sv, unused_stats); + + // Compute expectations across all ops using this trajectory. + for (size_t j = 0; j < pauli_sums[i].size(); j++) { + int p_reps = (num_samples[i][j] + num_threads - 1) / num_threads; + if (run_samples[j] >= p_reps + rep_offset) { + continue; + } + float exp_v = 0.0; + NESTED_FN_STATUS_SYNC( + compute_status, + ComputeSampledExpectationQsim(pauli_sums[i][j], sim, ss, sv, + scratch, 1, rand_source, &exp_v), + c_lock); + rolling_sums[j] += static_cast(exp_v); + run_samples[j]++; + } + + // Check if we have run enough trajectories for all ops. + bool break_loop = true; + for (size_t j = 0; j < num_samples[i].size(); j++) { + int p_reps = (num_samples[i][j] + num_threads - 1) / num_threads; + if (run_samples[j] < p_reps + rep_offset) { + break_loop = false; + break; + } + } + if (break_loop) { + // Lock writing to this batch index in output_tensor. + batch_locks[i].lock(); + for (size_t j = 0; j < num_samples[i].size(); j++) { + rolling_sums[j] /= num_samples[i][j]; + (*output_tensor)(i, j) += static_cast(rolling_sums[j]); + } + batch_locks[i].unlock(); + break; + } + } + } + }; + + // block_size = 1. + tensorflow::thread::ThreadPool::SchedulingParams scheduling_params( + tensorflow::thread::ThreadPool::SchedulingStrategy::kFixedBlockSize, + absl::nullopt, 1); + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + num_threads, scheduling_params, DoWork); + OP_REQUIRES_OK(context, compute_status); + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqNoisySampledExpectation").Device(tensorflow::DEVICE_CPU), + TfqNoisySampledExpectationOp); + +REGISTER_OP("TfqNoisySampledExpectation") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("pauli_sums: string") + .Input("num_samples: int32") + .Output("expectations: float") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle pauli_sums_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 2, &pauli_sums_shape)); + + tensorflow::shape_inference::ShapeHandle num_samples_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(4), 2, &num_samples_shape)); + + tensorflow::shape_inference::DimensionHandle output_rows = + c->Dim(programs_shape, 0); + tensorflow::shape_inference::DimensionHandle output_cols = + c->Dim(pauli_sums_shape, 1); + c->set_output(0, c->Matrix(output_rows, output_cols)); + + return ::tensorflow::Status(); + }); + +} // namespace tfq diff --git a/tensorflow_quantum/core/ops/noise/tfq_noisy_samples.cc b/tensorflow_quantum/core/ops/noise/tfq_noisy_samples.cc new file mode 100644 index 000000000..1af738323 --- /dev/null +++ b/tensorflow_quantum/core/ops/noise/tfq_noisy_samples.cc @@ -0,0 +1,349 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include + +#include "../qsim/lib/channel.h" +#include "../qsim/lib/channels_cirq.h" +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/circuit_noisy.h" +#include "../qsim/lib/fuser_mqubit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/io.h" +#include "../qsim/lib/qtrajectory.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/random/random.h" +#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 ::tensorflow::Status; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; +typedef qsim::NoisyCircuit NoisyQsimCircuit; + +class TfqNoisySamplesOp : public tensorflow::OpKernel { + public: + explicit TfqNoisySamplesOp(tensorflow::OpKernelConstruction* context) + : OpKernel(context) {} + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + DCHECK_EQ(4, context->num_inputs()); + + // Parse to Program Proto and num_qubits. + std::vector programs; + std::vector num_qubits; + OP_REQUIRES_OK(context, + GetProgramsAndNumQubits(context, &programs, &num_qubits)); + + // Parse symbol maps for parameter resolution in the circuits. + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + OP_REQUIRES( + context, maps.size() == programs.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and values do not match. Got ", programs.size(), + " circuits and ", maps.size(), " values."))); + + int num_samples = 0; + OP_REQUIRES_OK(context, GetIndividualSample(context, &num_samples)); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), + NoisyQsimCircuit()); + + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + auto r = NoisyQsimCircuitFromProgram( + programs[i], maps[i], num_qubits[i], true, &qsim_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, r, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + const int output_dim_size = maps.size(); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_size); + output_shape.AddDim(num_samples); + output_shape.AddDim(max_num_qubits); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->tensor(); + + if (num_samples == 0 || output_dim_size == 0 || max_num_qubits == 0) { + return; // bug in qsim dependency we can't control. + } + + // Cross reference with standard google cloud compute instances + // Memory ~= 2 * num_threads * (2 * 64 * 2 ** num_qubits in circuits) + // e2s2 = 2 CPU, 8GB -> Can safely do 25 since Memory = 4GB + // e2s4 = 4 CPU, 16GB -> Can safely do 25 since Memory = 8GB + // ... + if (max_num_qubits >= 26) { + ComputeLarge(num_qubits, max_num_qubits, num_samples, qsim_circuits, + context, &output_tensor); + } else { + ComputeSmall(num_qubits, max_num_qubits, num_samples, qsim_circuits, + context, &output_tensor); + } + } + + private: + void ComputeLarge(const std::vector& num_qubits, + const int max_num_qubits, const int num_samples, + const std::vector& ncircuits, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Tensor* output_tensor) { + // Instantiate qsim objects. + const auto tfq_for = tfq::QsimFor(context); + using Simulator = qsim::Simulator; + using StateSpace = Simulator::StateSpace; + using QTSimulator = + qsim::QuantumTrajectorySimulator; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(tfq_for); + StateSpace ss = StateSpace(tfq_for); + auto sv = ss.Create(largest_nq); + + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + auto local_gen = + random_gen.ReserveSamples32(2 * num_samples * ncircuits.size() + 2); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as nescessary. + for (size_t i = 0; i < ncircuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + } + + QTSimulator::Parameter param; + param.collect_kop_stat = false; + param.collect_mea_stat = true; + param.normalize_before_mea_gates = true; + + // Track op-wise stats. + QTSimulator::Stat gathered_samples; + + for (int j = 0; j < num_samples; j++) { + ss.SetStateZero(sv); + + QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss, sim, + sv, gathered_samples); + uint64_t q_ind = 0; + uint64_t mask = 1; + bool val = 0; + while (q_ind < nq) { + val = gathered_samples.samples[0] & mask; + (*output_tensor)( + i, j, static_cast(max_num_qubits - q_ind - 1)) = val; + q_ind++; + mask <<= 1; + } + while (q_ind < max_num_qubits) { + (*output_tensor)( + i, j, static_cast(max_num_qubits - q_ind - 1)) = -2; + q_ind++; + } + } + } + } + + void ComputeSmall(const std::vector& num_qubits, + const int max_num_qubits, const int num_samples, + const std::vector& ncircuits, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Tensor* output_tensor) { + using Simulator = qsim::Simulator; + using StateSpace = Simulator::StateSpace; + using QTSimulator = + qsim::QuantumTrajectorySimulator; + + const int output_dim_batch_size = output_tensor->dimension(0); + const int num_threads = context->device() + ->tensorflow_cpu_worker_threads() + ->workers->NumThreads(); + + // [num_threads, batch_size]. + std::vector> rep_offsets( + num_threads, std::vector(output_dim_batch_size, 0)); + BalanceTrajectory(num_samples, num_threads, &rep_offsets); + + // [num_threads, batch_size] stores the number of + // samples written by thread range [0, i]. + std::vector> offset_prefix_sum( + num_threads, std::vector(output_dim_batch_size, 0)); + + for (int i = 0; i < output_dim_batch_size; i++) { + int p_reps = (num_samples + num_threads - 1) / num_threads; + offset_prefix_sum[0][i] = rep_offsets[0][i] + p_reps; + for (int j = 1; j < num_threads; j++) { + offset_prefix_sum[j][i] += offset_prefix_sum[j - 1][i]; + offset_prefix_sum[j][i] += rep_offsets[j][i] + p_reps; + } + } + + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + + auto DoWork = [&](int start, int end) { + // Begin simulation. + const auto tfq_for = qsim::SequentialFor(1); + int largest_nq = 1; + Simulator sim = Simulator(tfq_for); + StateSpace ss = StateSpace(tfq_for); + auto sv = ss.Create(largest_nq); + + int needed_random = + 4 * (num_samples * ncircuits.size() + num_threads) / num_threads; + needed_random += 4; + auto local_gen = random_gen.ReserveSamples32(needed_random); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + for (size_t i = 0; i < ncircuits.size(); i++) { + int nq = num_qubits[i]; + int j = start > 0 ? offset_prefix_sum[start - 1][i] : 0; + int needed_samples = offset_prefix_sum[start][i] - j; + if (needed_samples <= 0) { + continue; + } + + if (nq > largest_nq) { + largest_nq = nq; + sv = ss.Create(largest_nq); + } + QTSimulator::Parameter param; + param.collect_kop_stat = false; + param.collect_mea_stat = true; + param.normalize_before_mea_gates = true; + + // Track op-wise stats. + QTSimulator::Stat gathered_samples; + int run_samples = 0; + + while (1) { + ss.SetStateZero(sv); + QTSimulator::RunOnce(param, ncircuits[i], rand_source.Rand64(), ss, + sim, sv, gathered_samples); + + uint64_t q_ind = 0; + uint64_t mask = 1; + bool val = 0; + while (q_ind < nq) { + val = gathered_samples.samples[0] & mask; + (*output_tensor)( + i, j, static_cast(max_num_qubits - q_ind - 1)) = val; + q_ind++; + mask <<= 1; + } + while (q_ind < max_num_qubits) { + (*output_tensor)( + i, j, static_cast(max_num_qubits - q_ind - 1)) = -2; + q_ind++; + } + + j++; + run_samples++; + + // Check if we have gathered enough samples. + if (run_samples >= needed_samples) { + break; + } + } + } + }; + + // block_size = 1. + tensorflow::thread::ThreadPool::SchedulingParams scheduling_params( + tensorflow::thread::ThreadPool::SchedulingStrategy::kFixedBlockSize, + absl::nullopt, 1); + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + num_threads, scheduling_params, DoWork); + } +}; + +REGISTER_KERNEL_BUILDER(Name("TfqNoisySamples").Device(tensorflow::DEVICE_CPU), + TfqNoisySamplesOp); + +REGISTER_OP("TfqNoisySamples") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("num_samples: int32") + .Output("samples: int8") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle num_samples_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 1, &num_samples_shape)); + + // [batch_size, n_samples, largest_n_qubits] + c->set_output( + 0, c->MakeShape( + {c->Dim(programs_shape, 0), + tensorflow::shape_inference::InferenceContext::kUnknownDim, + tensorflow::shape_inference::InferenceContext::kUnknownDim})); + + return ::tensorflow::Status(); + }); + +} // namespace tfq diff --git a/tensorflow_quantum/core/ops/parse_context.cc b/tensorflow_quantum/core/ops/parse_context.cc index 2d8f5b573..026c57321 100644 --- a/tensorflow_quantum/core/ops/parse_context.cc +++ b/tensorflow_quantum/core/ops/parse_context.cc @@ -20,38 +20,40 @@ limitations under the License. #include #include -#include "cirq/google/api/v2/program.pb.h" +#include "absl/status/status.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 Status ParseProto(const std::string& text, T* proto) { // First attempt to parse from the binary representation. if (proto->ParseFromString(text)) { - return Status::OK(); + return ::tensorflow::Status(); } // If that fails, then try to parse from the human readable representation. if (google::protobuf::TextFormat::ParseFromString(text, proto)) { - return Status::OK(); + return ::tensorflow::Status(); } - return Status(tensorflow::error::INVALID_ARGUMENT, - "Unparseable proto: " + text); + return Status( + static_cast(absl::StatusCode::kInvalidArgument), + "Unparseable proto: " + text); } } // namespace @@ -67,7 +69,8 @@ Status ParsePrograms(OpKernelContext* context, const std::string& input_name, if (input->dims() != 1) { // Never parse anything other than a 1d list of circuits. return Status( - tensorflow::error::INVALID_ARGUMENT, + static_cast( + absl::StatusCode::kInvalidArgument), absl::StrCat("programs must be rank 1. Got rank ", input->dims(), ".")); } @@ -75,9 +78,13 @@ Status ParsePrograms(OpKernelContext* context, const std::string& input_name, const int num_programs = program_strings.dimension(0); programs->assign(num_programs, Program()); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto DoWork = [&](int start, int end) { for (int i = start; i < end; i++) { - OP_REQUIRES_OK(context, ParseProto(program_strings(i), &programs->at(i))); + Status local = ParseProto(program_strings(i), &programs->at(i)); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); } }; @@ -86,7 +93,7 @@ Status ParsePrograms(OpKernelContext* context, const std::string& input_name, context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( num_programs, cycle_estimate, DoWork); - return Status::OK(); + return parse_status; } Status ParsePrograms2D(OpKernelContext* context, const std::string& input_name, @@ -99,7 +106,8 @@ Status ParsePrograms2D(OpKernelContext* context, const std::string& input_name, if (input->dims() != 2) { // Never parse anything other than a 1d list of circuits. - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), absl::StrCat("other_programs must be rank 2. Got rank ", input->dims(), ".")); } @@ -109,12 +117,14 @@ Status ParsePrograms2D(OpKernelContext* context, const std::string& input_name, const int num_entries = program_strings.dimension(1); programs->assign(num_programs, std::vector(num_entries, Program())); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); auto DoWork = [&](int start, int end) { for (int i = start; i < end; i++) { - OP_REQUIRES_OK( - context, + Status local = ParseProto(program_strings(i / num_entries, i % num_entries), - &programs->at(i / num_entries).at(i % num_entries))); + &programs->at(i / num_entries).at(i % num_entries)); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); } }; @@ -123,7 +133,7 @@ Status ParsePrograms2D(OpKernelContext* context, const std::string& input_name, context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( num_programs * num_entries, cycle_estimate, DoWork); - return Status::OK(); + return parse_status; } Status GetProgramsAndProgramsToAppend( @@ -140,17 +150,19 @@ Status GetProgramsAndProgramsToAppend( } if (programs->size() != programs_to_append->size()) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), "programs and programs_to_append must have matching sizes."); } - return Status::OK(); + return ::tensorflow::Status(); } Status GetProgramsAndNumQubits( OpKernelContext* context, std::vector* programs, std::vector* num_qubits, - std::vector>* p_sums /*=nullptr*/) { + std::vector>* p_sums /*=nullptr*/, + bool swap_endianness /*=false*/) { // 1. Parse input programs // 2. (Optional) Parse input PauliSums // 3. Convert GridQubit locations to integers. @@ -166,7 +178,8 @@ Status GetProgramsAndNumQubits( } if (programs->size() != p_sums->size()) { return Status( - tensorflow::error::INVALID_ARGUMENT, + static_cast( + absl::StatusCode::kInvalidArgument), absl::StrCat("Number of circuits and PauliSums do not match. Got ", programs->size(), " circuits and ", p_sums->size(), " paulisums.")); @@ -174,17 +187,22 @@ Status GetProgramsAndNumQubits( } // Resolve qubit ID's in parallel. + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); num_qubits->assign(programs->size(), -1); auto DoWork = [&](int start, int end) { for (int i = start; i < end; i++) { Program& program = (*programs)[i]; unsigned int this_num_qubits; + Status local; if (p_sums) { - OP_REQUIRES_OK(context, ResolveQubitIds(&program, &this_num_qubits, - &(p_sums->at(i)))); + local = ResolveQubitIds(&program, &this_num_qubits, &(p_sums->at(i)), + swap_endianness); } else { - OP_REQUIRES_OK(context, ResolveQubitIds(&program, &this_num_qubits)); + local = ResolveQubitIds(&program, &this_num_qubits, nullptr, + swap_endianness); } + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); (*num_qubits)[i] = this_num_qubits; } }; @@ -194,7 +212,7 @@ Status GetProgramsAndNumQubits( context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( num_qubits->size(), cycle_estimate, DoWork); - return Status::OK(); + return parse_status; } tensorflow::Status GetProgramsAndNumQubits( @@ -215,30 +233,34 @@ tensorflow::Status GetProgramsAndNumQubits( } if (programs->size() != other_programs->size()) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), absl::StrCat("programs and other_programs batch dimension", " do not match. Foud: ", programs->size(), " and ", other_programs->size())); } // Resolve qubit ID's in parallel. + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); num_qubits->assign(programs->size(), -1); auto DoWork = [&](int start, int end) { for (int i = start; i < end; i++) { Program& program = (*programs)[i]; unsigned int this_num_qubits; - OP_REQUIRES_OK(context, ResolveQubitIds(&program, &this_num_qubits, - &(*other_programs)[i])); + Status local = + ResolveQubitIds(&program, &this_num_qubits, &(*other_programs)[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); (*num_qubits)[i] = this_num_qubits; } }; // TODO(mbbrough): Determine if this is a good cycle estimate. - const int cycle_estimate = 1000 * (*other_programs)[0].size(); + const int cycle_estimate = 1000; context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( num_qubits->size(), cycle_estimate, DoWork); - return Status::OK(); + return parse_status; } Status GetPauliSums(OpKernelContext* context, @@ -251,7 +273,8 @@ Status GetPauliSums(OpKernelContext* context, } if (input->dims() != 2) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), absl::StrCat("pauli_sums must be rank 2. Got rank ", input->dims(), ".")); } @@ -260,12 +283,18 @@ Status GetPauliSums(OpKernelContext* context, p_sums->assign(sum_specs.dimension(0), std::vector(sum_specs.dimension(1), PauliSum())); const int op_dim = sum_specs.dimension(1); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); auto DoWork = [&](int start, int end) { for (int ii = start; ii < end; ii++) { const int i = ii / op_dim; const int j = ii % op_dim; PauliSum p; - OP_REQUIRES_OK(context, ParseProto(sum_specs(i, j), &p)); + // We should not stop the whole program, because TFQ cuQuantum ops + // requires running destructors to return cuQuantum handlers, + // and not to fall into segfault. + Status local = ParseProto(sum_specs(i, j), &p); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); (*p_sums)[i][j] = p; } }; @@ -275,7 +304,7 @@ Status GetPauliSums(OpKernelContext* context, context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( sum_specs.dimension(0) * sum_specs.dimension(1), cycle_estimate, DoWork); - return Status::OK(); + return parse_status; } Status GetSymbolMaps(OpKernelContext* context, std::vector* maps) { @@ -287,7 +316,8 @@ Status GetSymbolMaps(OpKernelContext* context, std::vector* maps) { } if (input_names->dims() != 1) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), absl::StrCat("symbol_names must be rank 1. Got rank ", input_names->dims(), ".")); } @@ -299,7 +329,8 @@ Status GetSymbolMaps(OpKernelContext* context, std::vector* maps) { } if (input_values->dims() != 2) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), absl::StrCat("symbol_values must be rank 2. Got rank ", input_values->dims(), ".")); } @@ -308,7 +339,8 @@ Status GetSymbolMaps(OpKernelContext* context, std::vector* maps) { const auto symbol_values = input_values->matrix(); if (symbol_names.dimension(0) != symbol_values.dimension(1)) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), "Input symbol names and value sizes do not match."); } @@ -330,7 +362,7 @@ Status GetSymbolMaps(OpKernelContext* context, std::vector* maps) { context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( symbol_values.dimension(0), cycle_estimate, DoWork); - return Status::OK(); + return ::tensorflow::Status(); } tensorflow::Status GetNumSamples( @@ -343,7 +375,8 @@ tensorflow::Status GetNumSamples( } if (input_num_samples->dims() != 2) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), absl::StrCat("num_samples must be rank 2. Got rank ", input_num_samples->dims(), ".")); } @@ -356,7 +389,8 @@ tensorflow::Status GetNumSamples( for (unsigned int j = 0; j < matrix_num_samples.dimension(1); j++) { const int num_samples = matrix_num_samples(i, j); if (num_samples < 1) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), "Each element of num_samples must be greater than 0."); } sub_parsed_num_samples.push_back(num_samples); @@ -364,7 +398,7 @@ tensorflow::Status GetNumSamples( parsed_num_samples->push_back(sub_parsed_num_samples); } - return Status::OK(); + return ::tensorflow::Status(); } // used by tfq_simulate_samples. @@ -377,7 +411,8 @@ Status GetIndividualSample(tensorflow::OpKernelContext* context, } if (input_num_samples->dims() != 1) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), absl::StrCat("num_samples must be rank 1. Got rank ", input_num_samples->dims(), ".")); } @@ -385,13 +420,14 @@ Status GetIndividualSample(tensorflow::OpKernelContext* context, const auto vector_num_samples = input_num_samples->vec(); if (vector_num_samples.dimension(0) != 1) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), absl::StrCat("num_samples must contain 1 element. Got ", vector_num_samples.dimension(0), ".")); } (*n_samples) = vector_num_samples(0); - return Status::OK(); + return ::tensorflow::Status(); } // used by adj_grad_op. @@ -405,7 +441,8 @@ tensorflow::Status GetPrevGrads( } if (input_grads->dims() != 2) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), absl::StrCat("downstream_grads must be rank 2. Got rank ", input_grads->dims(), ".")); } @@ -422,7 +459,7 @@ tensorflow::Status GetPrevGrads( parsed_prev_grads->push_back(sub_parsed_grads); } - return Status::OK(); + return ::tensorflow::Status(); } } // namespace tfq diff --git a/tensorflow_quantum/core/ops/parse_context.h b/tensorflow_quantum/core/ops/parse_context.h index 510598755..c811b68c5 100644 --- a/tensorflow_quantum/core/ops/parse_context.h +++ b/tensorflow_quantum/core/ops/parse_context.h @@ -16,32 +16,41 @@ limitations under the License. #ifndef TFQ_CORE_OPS_PARSE_CONTEXT #define TFQ_CORE_OPS_PARSE_CONTEXT +// Syncs a threads work status with some global status. +#define NESTED_FN_STATUS_SYNC(global_status, local_status, global_lock) \ + if (TF_PREDICT_FALSE(!local_status.ok())) { \ + global_lock.lock(); \ + global_status = local_status; \ + global_lock.unlock(); \ + return; \ + } + #include #include #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* programs); +tensorflow::Status ParsePrograms(tensorflow::OpKernelContext* context, + const std::string& input_name, + std::vector* programs); // Simplest Program proto parsing in 2D. tensorflow::Status ParsePrograms2D( tensorflow::OpKernelContext* context, const std::string& input_name, - std::vector>* programs); + std::vector>* programs); // Parses a vector of programs along with another vector of programs to append tensorflow::Status GetProgramsAndProgramsToAppend( tensorflow::OpKernelContext* context, - std::vector* programs, - std::vector* programs_to_append); + std::vector* programs, + std::vector* 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 @@ -54,9 +63,9 @@ typedef absl::flat_hash_map> SymbolMap; // and correct with the original programs. tensorflow::Status GetProgramsAndNumQubits( tensorflow::OpKernelContext* context, - std::vector* programs, - std::vector* num_qubits, - std::vector>* p_sums = nullptr); + std::vector* programs, std::vector* num_qubits, + std::vector>* p_sums = nullptr, + bool swap_endianness = false); // Parses Cirq Program protos out of the 'circuit_specs' input Tensor. Also // resolves the QubitIds inside of the Program. This override also parses and @@ -64,9 +73,8 @@ tensorflow::Status GetProgramsAndNumQubits( // found in all programs[i][j] for all j. tensorflow::Status GetProgramsAndNumQubits( tensorflow::OpKernelContext* context, - std::vector* programs, - std::vector* num_qubits, - std::vector>* other_programs); + std::vector* programs, std::vector* num_qubits, + std::vector>* 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 diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc index bc4c74972..fe88a5817 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op.cc @@ -21,23 +21,24 @@ 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" #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/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 QsimGate; typedef qsim::Circuit QsimCircuit; @@ -98,12 +99,14 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { std::vector> gradient_gates( programs.size(), std::vector({})); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); auto construct_f = [&](int start, int end) { for (int i = start; i < end; i++) { - OP_REQUIRES_OK( - context, QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], - &qsim_circuits[i], &full_fuse[i], - &gate_meta[i])); + Status local = QsimCircuitFromProgram(programs[i], maps[i], + num_qubits[i], &qsim_circuits[i], + &full_fuse[i], &gate_meta[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); CreateGradientCircuit(qsim_circuits[i], gate_meta[i], &partial_fused_circuits[i], &gradient_gates[i]); } @@ -112,6 +115,7 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { const int num_cycles = 1000; context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); // Get downstream gradients. std::vector> downstream_grads; @@ -124,11 +128,11 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { " circuits."))); OP_REQUIRES( - context, downstream_grads[0].size() == pauli_sums[0].size(), + context, context->input(4).dim_size(1) == context->input(3).dim_size(1), tensorflow::errors::InvalidArgument(absl::StrCat( "Number of gradients and pauli sum dimension do not match. Got ", - downstream_grads[0].size(), " gradient entries and ", - pauli_sums[0].size(), " paulis per circuit."))); + context->input(4).dim_size(1), " gradient entries and ", + context->input(3).dim_size(1), " paulis per circuit."))); int max_num_qubits = 0; for (const int num : num_qubits) { @@ -198,15 +202,15 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { } ss.SetStateZero(sv); - for (int j = 0; j < full_fuse[i].size(); j++) { + for (size_t j = 0; j < full_fuse[i].size(); j++) { qsim::ApplyFusedGate(sim, full_fuse[i][j], sv); } // sv now contains psi // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> // scratch2 now contains psi as well. - AccumulateOperators(pauli_sums[i], downstream_grads[i], sim, ss, sv, - scratch2, scratch); + [[maybe_unused]] Status unused = AccumulateOperators( + pauli_sums[i], downstream_grads[i], sim, ss, sv, scratch2, scratch); for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { for (int k = partial_fused_circuits[i][j].size() - 1; k >= 0; k--) { @@ -219,12 +223,31 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { } // Hit a parameterized gate. - ApplyGateDagger( - sim, qsim_circuits[i].gates[gradient_gates[i][j - 1].index], sv); - for (int k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); k++) { + auto cur_gate = + qsim_circuits[i].gates[gradient_gates[i][j - 1].index]; + + ApplyGateDagger(sim, cur_gate, sv); + + // if applicable compute control qubit mask and control value bits. + uint64_t mask = 0; + uint64_t cbits = 0; + for (size_t k = 0; k < cur_gate.controlled_by.size(); k++) { + uint64_t control_loc = cur_gate.controlled_by[k]; + mask |= uint64_t{1} << control_loc; + cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; + } + + for (size_t k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); + k++) { // Copy sv onto scratch2 in anticipation of non-unitary "gradient // gate". ss.Copy(sv, scratch2); + if (!cur_gate.controlled_by.empty()) { + // Gradient of controlled gates puts zeros on diagonal which is + // the same as collapsing the state and then applying the + // non-controlled version of the gradient gate. + ss.BulkSetAmpl(scratch2, mask, cbits, 0, 0, true); + } qsim::ApplyGate(sim, gradient_gates[i][j - 1].grad_gates[k], scratch2); @@ -239,9 +262,7 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { (*output_tensor)(i, loc) += ss.RealInnerProduct(scratch2, scratch) + ss.RealInnerProduct(scratch, scratch2); } - ApplyGateDagger( - sim, qsim_circuits[i].gates[gradient_gates[i][j - 1].index], - scratch); + ApplyGateDagger(sim, cur_gate, scratch); } } }; @@ -277,7 +298,7 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { auto scratch = ss.Create(largest_nq); auto scratch2 = ss.Create(largest_nq); - for (int i = 0; i < partial_fused_circuits.size(); i++) { + for (size_t i = 0; i < partial_fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -294,15 +315,15 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { } ss.SetStateZero(sv); - for (int j = 0; j < full_fuse[i].size(); j++) { + for (size_t j = 0; j < full_fuse[i].size(); j++) { qsim::ApplyFusedGate(sim, full_fuse[i][j], sv); } // sv now contains psi // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> // scratch2 now contains psi as well. - AccumulateOperators(pauli_sums[i], downstream_grads[i], sim, ss, sv, - scratch2, scratch); + [[maybe_unused]] Status unused = AccumulateOperators( + pauli_sums[i], downstream_grads[i], sim, ss, sv, scratch2, scratch); for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { for (int k = partial_fused_circuits[i][j].size() - 1; k >= 0; k--) { @@ -315,12 +336,30 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { } // Hit a parameterized gate. - ApplyGateDagger( - sim, qsim_circuits[i].gates[gradient_gates[i][j - 1].index], sv); - for (int k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); k++) { + // todo fix this copy. + auto cur_gate = qsim_circuits[i].gates[gradient_gates[i][j - 1].index]; + ApplyGateDagger(sim, cur_gate, sv); + + // if applicable compute control qubit mask and control value bits. + uint64_t mask = 0; + uint64_t cbits = 0; + for (size_t k = 0; k < cur_gate.controlled_by.size(); k++) { + uint64_t control_loc = cur_gate.controlled_by[k]; + mask |= uint64_t{1} << control_loc; + cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; + } + + for (size_t k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); + k++) { // Copy sv onto scratch2 in anticipation of non-unitary "gradient // gate". ss.Copy(sv, scratch2); + if (!cur_gate.controlled_by.empty()) { + // Gradient of controlled gates puts zeros on diagonal which is + // the same as collapsing the state and then applying the + // non-controlled version of the gradient gate. + ss.BulkSetAmpl(scratch2, mask, cbits, 0, 0, true); + } qsim::ApplyGate(sim, gradient_gates[i][j - 1].grad_gates[k], scratch2); @@ -335,9 +374,7 @@ class TfqAdjointGradientOp : public tensorflow::OpKernel { (*output_tensor)(i, loc) += ss.RealInnerProduct(scratch2, scratch) + ss.RealInnerProduct(scratch, scratch2); } - ApplyGateDagger(sim, - qsim_circuits[i].gates[gradient_gates[i][j - 1].index], - scratch); + ApplyGateDagger(sim, cur_gate, scratch); } } } @@ -376,7 +413,7 @@ REGISTER_OP("TfqAdjointGradient") c->Dim(symbol_names_shape, 0); c->set_output(0, c->Matrix(output_rows, output_cols)); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op.py index 04b8ff0fb..ead1e34d6 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op.py +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to register python op gradient.""" import tensorflow as tf from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc new file mode 100644 index 000000000..55213c78b --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.cu.cc @@ -0,0 +1,342 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/seqfor.h" +#include "../qsim/lib/simmux_gpu.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#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/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 { + +namespace { +// TODO(jaeyoo): Temorary hack for BulkSetAmpl with cuda ops. +// Updates qsim custatevec side BulkSetAmple ops, and remove these utilities. +template +__global__ void BulkSetAmplKernel(uint64_t mask, uint64_t bits, FP re, FP im, + bool exclude, FP* state) { + uint64_t k1 = uint64_t{blockIdx.x} * blockDim.x + threadIdx.x; + + bool set = ((k1 & mask) == bits) ^ exclude; + + if (set) { + state[2 * k1] = re; + state[2 * k1 + 1] = im; + } +} + +// Sets state[i] = complex(re, im) where (i & mask) == bits. +// if `exclude` is true then the criteria becomes (i & mask) != bits. +template +void BulkSetAmpl(qsim::SimulatorCuStateVec::StateSpace::State& state, + uint64_t mask, uint64_t bits, fp_type re, fp_type im, + bool exclude = false) { + uint64_t size = uint64_t{1} << state.num_qubits(); + + unsigned threads = std::min(size, uint64_t{512}); + unsigned blocks = size / threads; + + BulkSetAmplKernel<<>>(mask, bits, re, im, exclude, + state.get()); + cudaPeekAtLastError(); + cudaDeviceSynchronize(); +} +} // namespace + +using ::tensorflow::Status; +using ::tfq::proto::PauliSum; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqAdjointGradientCuquantumOp : public tensorflow::OpKernel { + public: + explicit TfqAdjointGradientCuquantumOp( + tensorflow::OpKernelConstruction* context) + : OpKernel(context) { + // create handles for simulator + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } + + ~TfqAdjointGradientCuquantumOp() { + // destroy handles in sync with simulator lifetime + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + const int num_inputs = context->num_inputs(); + OP_REQUIRES(context, num_inputs == 5, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Expected 5 inputs, got ", num_inputs, " inputs."))); + + // Create the output Tensor. + const int output_dim_batch_size = context->input(0).dim_size(0); + const int output_dim_param_size = context->input(2).dim_size(1); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_batch_size); + output_shape.AddDim(output_dim_param_size); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->matrix(); + + // Parse program protos. + std::vector programs; + std::vector num_qubits; + std::vector> pauli_sums; + OP_REQUIRES_OK(context, GetProgramsAndNumQubits(context, &programs, + &num_qubits, &pauli_sums)); + + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + + OP_REQUIRES(context, programs.size() == maps.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and symbol_values do not match. Got ", + programs.size(), " circuits and ", maps.size(), + " symbol values."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> full_fuse( + programs.size(), std::vector>({})); + std::vector>>> + partial_fused_circuits( + programs.size(), + std::vector>>({})); + + // track metadata. + std::vector> gate_meta( + programs.size(), std::vector({})); + + // track gradients + std::vector> gradient_gates( + programs.size(), std::vector({})); + + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = QsimCircuitFromProgram(programs[i], maps[i], + num_qubits[i], &qsim_circuits[i], + &full_fuse[i], &gate_meta[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + CreateGradientCircuit(qsim_circuits[i], gate_meta[i], + &partial_fused_circuits[i], &gradient_gates[i]); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + // Get downstream gradients. + std::vector> downstream_grads; + OP_REQUIRES_OK(context, GetPrevGrads(context, &downstream_grads)); + + OP_REQUIRES(context, downstream_grads.size() == programs.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of gradients and circuits do not match. Got ", + downstream_grads.size(), " gradients and ", programs.size(), + " circuits."))); + + OP_REQUIRES( + context, context->input(4).dim_size(1) == context->input(3).dim_size(1), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of gradients and pauli sum dimension do not match. Got ", + context->input(4).dim_size(1), " gradient entries and ", + context->input(3).dim_size(1), " paulis per circuit."))); + + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + output_tensor.setZero(); + + ComputeLarge(num_qubits, qsim_circuits, maps, full_fuse, + partial_fused_circuits, pauli_sums, gradient_gates, + downstream_grads, context, &output_tensor); + } + + private: + cublasHandle_t cublas_handle_; + custatevecHandle_t custatevec_handle_; + + void ComputeLarge( + const std::vector& num_qubits, + const std::vector& qsim_circuits, + const std::vector& maps, + const std::vector>>& full_fuse, + const std::vector>>>& + partial_fused_circuits, + const std::vector>& pauli_sums, + const std::vector>& gradient_gates, + const std::vector>& downstream_grads, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + auto scratch = ss.Create(largest_nq); + auto scratch2 = ss.Create(largest_nq); + + for (size_t i = 0; i < partial_fused_circuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + scratch2 = ss.Create(largest_nq); + } + + // (#679) Just ignore empty program + if (qsim_circuits[i].gates.size() == 0) { + continue; + } + + ss.SetStateZero(sv); + for (size_t j = 0; j < full_fuse[i].size(); j++) { + qsim::ApplyFusedGate(sim, full_fuse[i][j], sv); + } + + // sv now contains psi + // scratch contains (sum_j paulis_sums[i][j] * downstream_grads[j])|psi> + // scratch2 now contains psi as well. + [[maybe_unused]] Status unused = AccumulateOperators( + pauli_sums[i], downstream_grads[i], sim, ss, sv, scratch2, scratch); + + for (int j = partial_fused_circuits[i].size() - 1; j >= 0; j--) { + for (int k = partial_fused_circuits[i][j].size() - 1; k >= 0; k--) { + ApplyFusedGateDagger(sim, partial_fused_circuits[i][j][k], sv); + ApplyFusedGateDagger(sim, partial_fused_circuits[i][j][k], scratch); + } + if (j == 0) { + // last layer will have no parametrized gates so can break. + break; + } + + // Hit a parameterized gate. + // todo fix this copy. + auto cur_gate = qsim_circuits[i].gates[gradient_gates[i][j - 1].index]; + ApplyGateDagger(sim, cur_gate, sv); + + // if applicable compute control qubit mask and control value bits. + uint64_t mask = 0; + uint64_t cbits = 0; + for (size_t k = 0; k < cur_gate.controlled_by.size(); k++) { + uint64_t control_loc = cur_gate.controlled_by[k]; + mask |= uint64_t{1} << control_loc; + cbits |= ((cur_gate.cmask >> k) & 1) << control_loc; + } + + for (size_t k = 0; k < gradient_gates[i][j - 1].grad_gates.size(); + k++) { + // Copy sv onto scratch2 in anticipation of non-unitary "gradient + // gate". + ss.Copy(sv, scratch2); + if (!cur_gate.controlled_by.empty()) { + // Gradient of controlled gates puts zeros on diagonal which is + // the same as collapsing the state and then applying the + // non-controlled version of the gradient gate. + BulkSetAmpl(scratch2, mask, cbits, 0, 0, true); + } + qsim::ApplyGate(sim, gradient_gates[i][j - 1].grad_gates[k], + scratch2); + + // don't need not-found check since this is done upstream already. + const auto it = maps[i].find(gradient_gates[i][j - 1].params[k]); + const int loc = it->second.first; + // Apply finite differencing for adjoint gradients. + // Finite differencing enables applying multiple `gradient_gate` + // of a symbol at the same circuit. For analytic methods like + // parameter-shift we need to apply a single `gradient_gate` + // per a symbol. + (*output_tensor)(i, loc) += ss.RealInnerProduct(scratch2, scratch) + + ss.RealInnerProduct(scratch, scratch2); + } + ApplyGateDagger(sim, cur_gate, scratch); + } + } + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqAdjointGradientCuquantum").Device(tensorflow::DEVICE_CPU), + TfqAdjointGradientCuquantumOp); + +REGISTER_OP("TfqAdjointGradientCuquantum") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("pauli_sums: string") + .Input("downstream_grads: float") + .Output("grads: float") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle pauli_sums_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 2, &pauli_sums_shape)); + + tensorflow::shape_inference::ShapeHandle downstream_grads_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(4), 2, &downstream_grads_shape)); + + tensorflow::shape_inference::DimensionHandle output_rows = + c->Dim(programs_shape, 0); + tensorflow::shape_inference::DimensionHandle output_cols = + c->Dim(symbol_names_shape, 0); + c->set_output(0, c->Matrix(output_rows, output_cols)); + + return ::tensorflow::Status(); + }); + +} // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.py new file mode 100644 index 000000000..e73775a45 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum.py @@ -0,0 +1,48 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Module to register python op gradient.""" +import tensorflow as tf +from tensorflow_quantum.core.ops.load_module import load_module + +SIM_OP_MODULE = load_module("_tfq_adj_grad_cuquantum.so") + + +def tfq_adj_grad(programs, symbol_names, symbol_values, pauli_sums, prev_grad): + """Calculate gradient of expectation value of circuits wrt some operator(s). + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] + containing the string representation of the operators that will + be used on all of the circuits in the expectation calculations. + prev_grad: `tf.Tensor` of real numbers with shape [batch_size, n_ops] + backprop of values from downstream in the compute graph. + Returns: + `tf.Tensor` with shape [batch_size, n_params] that holds the gradient of + expectation value for each circuit with each op applied to it + (after resolving the corresponding parameters in). + """ + return SIM_OP_MODULE.tfq_adjoint_gradient_cuquantum( + programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums, + tf.cast(prev_grad, tf.float32)) diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py new file mode 100644 index 000000000..262f81728 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_cuquantum_test.py @@ -0,0 +1,490 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Tests that specifically target tfq_unitary_op.""" +# 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 + +import time +import numpy as np +from absl.testing import parameterized +import tensorflow as tf +import cirq +import sympy + +from tensorflow_quantum.python import util +from tensorflow_quantum.core.ops import tfq_adj_grad_op +from tensorflow_quantum.core.ops import tfq_adj_grad_op_cuquantum + + +def measure_average_runtime( + fn, + tag, + num_samples=10, + result_avg=False, +): + """Measures average runtime for given function. + + Args: + fn: function. + tag: The message title. + num_samples: The number of measurements. + result_avg: True if the results are all averaged. + + Returns: + The average time and the (averaged) result. + """ + avg_time = [] + avg_res = [] + for _ in range(num_samples): + begin_time = time.time() + result = fn() + duration = time.time() - begin_time + avg_time.append(duration) + if result_avg: + avg_res.append(result) + avg_time = sum(avg_time) / float(num_samples) + print(f"\n\t{tag} time: {avg_time}\n") + if result_avg: + result = np.average(avg_res, axis=0) + return avg_time, result + + +class ADJGradTest(tf.test.TestCase, parameterized.TestCase): + """Tests tfq_calculate_unitary.""" + + def test_calculate_adj_grad_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + prev_grads = tf.ones([batch_size, len(symbol_names)]) + + cpu_avg_time, res_cpu = measure_average_runtime( + lambda: tfq_adj_grad_op.tfq_adj_grad( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor, + prev_grads), + "Adjoint CPU", + num_samples=10, + result_avg=True, + ) + + cuquantum_avg_time, res_cuquantum = measure_average_runtime( + lambda: tfq_adj_grad_op_cuquantum.tfq_adj_grad( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor, + prev_grads), + "Adjoint cuQuantum", + num_samples=10, + result_avg=True, + ) + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuquantum_avg_time) + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, + res_cuquantum, + atol=1e-4, + err_msg=""" + # If failed, the GPU architecture in this system may be unsupported. + # Please refer to the supported architectures here. + # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec + """) + + def test_adj_grad_inputs(self): + """Make sure that the expectation op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + upstream_grads = np.ones((batch_size, len(symbol_names))) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # Circuit tensor has too many dimensions. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor([circuit_batch]), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1.'): + # symbol_names tensor has too many dimensions. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too many dimensions. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(np.array([symbol_values_array])), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too few dimensions. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array[0]), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too few dimensions. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor(list(pauli_sums)), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too many dimensions. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[[x]] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # circuit tensor has the right type but invalid values. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + ['junk'] * batch_size, symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type but invalid values. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), ['junk'], + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'qubits not found in circuit'): + # pauli_sums tensor has the right type but invalid values. + new_qubits = [cirq.GridQubit(5, 5), cirq.GridQubit(9, 9)] + new_pauli_sums = util.random_pauli_sums(new_qubits, 2, batch_size) + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in new_pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # pauli_sums tensor has the right type but invalid values 2. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + [['junk']] * batch_size, tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # circuits tensor has the wrong type. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + [1.0] * batch_size, symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), [0.1234], + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size, + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # pauli_sums tensor has the wrong type. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), [[1.0]] * batch_size, + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(TypeError, 'missing'): + # we are missing an argument. + # pylint: disable=no-value-for-parameter + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + tf.convert_to_tensor(upstream_grads)) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(TypeError, 'positional arguments'): + # pylint: disable=too-many-function-args + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads), []) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong op size. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor([cirq.Circuit()]), symbol_names, + symbol_values_array.astype(np.float64), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='rank 2'): + # wrong grad shape. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor([upstream_grads])) + + with self.assertRaisesRegex( + tf.errors.InvalidArgumentError, + expected_regex='gradients and circuits do not match'): + # wrong grad batch size. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor([[0 for i in range(len(symbol_names))]])) + + with self.assertRaisesRegex( + tf.errors.InvalidArgumentError, + expected_regex='gradients and pauli sum dimension do not match' + ): + # wrong grad inner size. + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), symbol_names, + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor([[0, 0] for _ in range(len(circuit_batch)) + ])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor([noisy_circuit for _ in circuit_batch]), + symbol_names, tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + + def test_calculate_adj_grad_empty(self): + """Verify that the empty case is handled gracefully.""" + out = tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor([cirq.Circuit()]), + tf.convert_to_tensor([], dtype=tf.dtypes.string), + tf.convert_to_tensor([[]]), + tf.convert_to_tensor([[]], dtype=tf.dtypes.string), + tf.convert_to_tensor([[]])) + self.assertShapeEqual(np.zeros((1, 0)), out) + + def test_calculate_adj_grad_no_circuit(self): + """Verify that the no circuit case is handled gracefully.""" + out = tfq_adj_grad_op_cuquantum.tfq_adj_grad( + tf.raw_ops.Empty(shape=(0,), dtype=tf.string), + tf.raw_ops.Empty(shape=(0,), dtype=tf.string), + tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32), + tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string), + tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32), + ) + self.assertShapeEqual(np.zeros((0, 0)), out) + + def test_calculate_adj_grad_simple_case(self): + """Make sure that adjoint gradient works on simple input case.""" + n_qubits = 2 + batch_size = 1 + symbol_names = ['alpha', 'beta'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + [cirq.Circuit(cirq.X(qubits[0]) ** sympy.Symbol('alpha'), + cirq.Y(qubits[1]) ** sympy.Symbol('beta'), + cirq.CNOT(qubits[0], qubits[1]))], [{'alpha': 0.123, 'beta': 0.456}] + + op_batch = [ + [cirq.Z(qubits[0]), cirq.X(qubits[1])] for _ in range(batch_size) + ] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + prev_grads = tf.ones([batch_size, len(symbol_names)]) + + out = tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), + tf.convert_to_tensor(symbol_names), + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor(op_batch), prev_grads) + + self.assertAllClose(out, np.array([[-1.18392, 0.43281]]), atol=1e-3) + + def test_calculate_adj_grad_simple_case2(self): + """Make sure the adjoint gradient works on another simple input case.""" + n_qubits = 2 + batch_size = 1 + symbol_names = ['alpha', 'beta', 'gamma'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + [cirq.Circuit(cirq.X(qubits[0]) ** sympy.Symbol('alpha'), + cirq.Y(qubits[1]) ** sympy.Symbol('beta'), + cirq.CNOT(qubits[0], qubits[1]), + cirq.FSimGate(sympy.Symbol('gamma'), 0.5)(qubits[0], qubits[1])) + ], [{'alpha': 0.123, 'beta': 0.456, 'gamma': 0.789}] + + op_batch = [ + [cirq.Z(qubits[0]), cirq.X(qubits[1])] for _ in range(batch_size) + ] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + prev_grads = tf.ones([batch_size, len(op_batch[0])]) + + out = tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), + tf.convert_to_tensor(symbol_names), + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor(op_batch), prev_grads) + + self.assertAllClose(out, + np.array([[-2.100, -1.7412, -1.5120]]), + atol=1e-3) + + def test_calculate_adj_grad_simple_case_shared(self): + """Make sure the adjoint gradient works on a shared symbol gate.""" + n_qubits = 2 + batch_size = 1 + symbol_names = ['alpha', 'beta', 'gamma'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + [cirq.Circuit(cirq.X(qubits[0]) ** sympy.Symbol('alpha'), + cirq.Y(qubits[1]) ** sympy.Symbol('beta'), + cirq.CNOT(qubits[0], qubits[1]), + cirq.FSimGate( + sympy.Symbol('gamma'), + sympy.Symbol('gamma'))(qubits[0], qubits[1])) + ], [{'alpha': 0.123, 'beta': 0.456, 'gamma': 0.789}] + + op_batch = [ + [cirq.Z(qubits[0]), cirq.X(qubits[1])] for _ in range(batch_size) + ] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + prev_grads = tf.ones([batch_size, len(op_batch[0])]) + + out = tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), + tf.convert_to_tensor(symbol_names), + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor(op_batch), prev_grads) + + self.assertAllClose(out, + np.array([[-2.3484, -1.7532, -1.64264]]), + atol=1e-3) + + def test_calculate_adj_grad_simple_case_single(self): + """Make sure the adjoint gradient works on a one symbol for all gate.""" + n_qubits = 2 + batch_size = 1 + symbol_names = ['alpha', 'beta', 'gamma'] + qubits = cirq.LineQubit.range(n_qubits) + circuit_batch, resolver_batch = \ + [cirq.Circuit(cirq.X(qubits[0]) ** sympy.Symbol('alpha'), + cirq.Y(qubits[1]) ** sympy.Symbol('alpha'), + cirq.CNOT(qubits[0], qubits[1]), + cirq.FSimGate( + -0.56, + sympy.Symbol('alpha'))(qubits[0], qubits[1])) + ], [{'alpha': 0.123, 'beta': 0.456, 'gamma': 0.789}] + + op_batch = [ + [cirq.Z(qubits[0]), cirq.X(qubits[1])] for _ in range(batch_size) + ] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + prev_grads = tf.ones([batch_size, len(op_batch[0])]) + + out = tfq_adj_grad_op_cuquantum.tfq_adj_grad( + util.convert_to_tensor(circuit_batch), + tf.convert_to_tensor(symbol_names), + tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor(op_batch), prev_grads) + + self.assertAllClose(out, np.array([[1.2993, 0, 0]]), atol=1e-3) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.py b/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.py index 277996ffe..3acb662c4 100644 --- a/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.py +++ b/tensorflow_quantum/core/ops/tfq_adj_grad_op_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target tfq_unitary_op.""" +# 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 + import numpy as np from absl.testing import parameterized import tensorflow as tf @@ -86,7 +94,7 @@ def test_adj_grad_inputs(self): tfq_adj_grad_op.tfq_adj_grad( util.convert_to_tensor(circuit_batch), symbol_names, tf.convert_to_tensor(symbol_values_array), - util.convert_to_tensor([x for x in pauli_sums]), + util.convert_to_tensor(list(pauli_sums)), tf.convert_to_tensor(upstream_grads)) with self.assertRaisesRegex(tf.errors.InvalidArgumentError, @@ -223,6 +231,16 @@ def test_adj_grad_inputs(self): tf.convert_to_tensor([[0, 0] for _ in range(len(circuit_batch)) ])) + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_adj_grad_op.tfq_adj_grad( + util.convert_to_tensor([noisy_circuit for _ in circuit_batch]), + symbol_names, tf.convert_to_tensor(symbol_values_array), + util.convert_to_tensor([[x] for x in pauli_sums]), + tf.convert_to_tensor(upstream_grads)) + def test_calculate_adj_grad_empty(self): """Verify that the empty case is handled gracefully.""" out = tfq_adj_grad_op.tfq_adj_grad( @@ -233,6 +251,17 @@ def test_calculate_adj_grad_empty(self): tf.convert_to_tensor([[]])) self.assertShapeEqual(np.zeros((1, 0)), out) + def test_calculate_adj_grad_no_circuit(self): + """Verify that the no circuit case is handled gracefully.""" + out = tfq_adj_grad_op.tfq_adj_grad( + tf.raw_ops.Empty(shape=(0,), dtype=tf.string), + tf.raw_ops.Empty(shape=(0,), dtype=tf.string), + tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32), + tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string), + tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32), + ) + self.assertShapeEqual(np.zeros((0, 0)), out) + def test_calculate_adj_grad_simple_case(self): """Make sure that adjoint gradient works on simple input case.""" n_qubits = 2 @@ -338,7 +367,7 @@ def test_calculate_adj_grad_simple_case_single(self): n_qubits = 2 batch_size = 1 symbol_names = ['alpha', 'beta', 'gamma'] - qubits = cirq.GridQubit.rect(1, n_qubits) + qubits = cirq.LineQubit.range(n_qubits) circuit_batch, resolver_batch = \ [cirq.Circuit(cirq.X(qubits[0]) ** sympy.Symbol('alpha'), cirq.Y(qubits[1]) ** sympy.Symbol('alpha'), diff --git a/tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc b/tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc index 6d444a829..4f1f662ca 100644 --- a/tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc +++ b/tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc @@ -19,21 +19,22 @@ 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" #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/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 QsimGate; typedef qsim::Circuit QsimCircuit; @@ -67,17 +68,21 @@ class TfqCalculateUnitaryOp : public tensorflow::OpKernel { std::vector>> fused_circuits( programs.size(), std::vector>({})); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); auto construct_f = [&](int start, int end) { for (int i = start; i < end; i++) { - OP_REQUIRES_OK(context, QsimCircuitFromProgram( - programs[i], maps[i], num_qubits[i], - &qsim_circuits[i], &fused_circuits[i])); + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); } }; const int num_cycles = 1000; context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); // Find largest circuit for tensor size padding and allocate // the output tensor. @@ -106,22 +111,22 @@ class TfqCalculateUnitaryOp : public tensorflow::OpKernel { // Begin simulation. int largest_nq = 1; - Unitary u = UnitarySpace(largest_nq, tfq_for).CreateUnitary(); + Unitary u = UnitarySpace(tfq_for).CreateUnitary(largest_nq); // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the unitary as nescessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; - UCalculator sim = UCalculator(nq, tfq_for); - UnitarySpace us = UnitarySpace(nq, tfq_for); + UCalculator sim = UCalculator(tfq_for); + UnitarySpace us = UnitarySpace(tfq_for); if (nq > largest_nq) { // need to switch to larger unitaryspace. largest_nq = nq; - u = us.CreateUnitary(); + u = us.CreateUnitary(nq); } us.SetIdentity(u); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], u); } @@ -136,7 +141,7 @@ class TfqCalculateUnitaryOp : public tensorflow::OpKernel { uint64_t k = l % (1 << max_num_qubits); if (k < crossover && j < crossover) { output_tensor(static_cast(i), static_cast(j), - static_cast(k)) = us.GetEntry(u, j, k); + static_cast(k)) = us.GetEntry(u, k, j); } else { output_tensor(static_cast(i), static_cast(j), static_cast(k)) = @@ -177,7 +182,7 @@ REGISTER_OP("TfqCalculateUnitary") tensorflow::shape_inference::InferenceContext::kUnknownDim, tensorflow::shape_inference::InferenceContext::kUnknownDim})); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc b/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc index 5eb37ffcf..582bd1681 100644 --- a/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc +++ b/tensorflow_quantum/core/ops/tfq_circuit_append_op.cc @@ -15,7 +15,6 @@ limitations under the License. #include -#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" @@ -23,11 +22,12 @@ limitations under the License. #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: @@ -90,7 +90,7 @@ REGISTER_OP("TfqAppendCircuit") c->set_output(0, c->input(0)); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc b/tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc index 89fca8ff3..5c20e546e 100644 --- a/tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc +++ b/tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc @@ -16,7 +16,6 @@ limitations under the License. #include #include -#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" @@ -24,16 +23,17 @@ limitations under the License. #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: @@ -55,7 +55,7 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel { 0, context->input(0).shape(), &output)); auto output_tensor = output->flat(); - const int max_buffer_moments = 3; + const int max_buffer_moments = 5; auto DoWork = [&](int start, int end) { for (int i = start; i < end; i++) { @@ -65,11 +65,11 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel { new_program.mutable_language()->set_gate_set("tfq_gate_set"); new_program.mutable_circuit()->set_scheduling_strategy( Circuit::MOMENT_BY_MOMENT); - for (int j = 0; j < cur_program.circuit().moments().size(); j++) { + for (size_t j = 0; j < cur_program.circuit().moments().size(); j++) { Moment cur_moment(cur_program.circuit().moments().at(j)); std::vector temp_moment_list(max_buffer_moments, Moment()); int num_extra_moments = 0; - for (int k = 0; k < cur_moment.operations().size(); k++) { + for (size_t k = 0; k < cur_moment.operations().size(); k++) { Operation cur_op = cur_moment.operations().at(k); auto &cur_op_map = *cur_op.mutable_args(); if (cur_op.gate().id() == "PISP") { @@ -79,21 +79,21 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel { phase_exponent.arg_case() == Arg::ArgCase::kSymbol) { // Decompose cirq.PhasedISwapPowGate only if it is // parameterized. - num_extra_moments = 3; + num_extra_moments = 5; Operation new_op; new_op = getOpForPISP(cur_op, 0, 0); cur_moment.mutable_operations()->at(k) = new_op; new_op = getOpForPISP(cur_op, 1, 1); - *cur_moment.add_operations() = new_op; - new_op = getOpForISP(cur_op, "XXP", exponent.symbol()); *temp_moment_list[0].add_operations() = new_op; - new_op = getOpForISP(cur_op, "YYP", exponent.symbol()); + new_op = getOpForISP(cur_op, "XXP", exponent.symbol()); *temp_moment_list[1].add_operations() = new_op; - new_op = getOpForPISP(cur_op, 1, 0); + new_op = getOpForISP(cur_op, "YYP", exponent.symbol()); *temp_moment_list[2].add_operations() = new_op; + new_op = getOpForPISP(cur_op, 1, 0); + *temp_moment_list[3].add_operations() = new_op; new_op = getOpForPISP(cur_op, 0, 1); - *temp_moment_list[2].add_operations() = new_op; + *temp_moment_list[4].add_operations() = new_op; } } else if (cur_op.gate().id() == "ISP") { auto exponent = cur_op_map.at("exponent"); @@ -176,6 +176,11 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel { new_op_map["exponent_scalar"].mutable_arg_value()->set_float_value( cur_exponent_scalar * -0.5); new_op_map["exponent"].set_symbol(symbol); + // Copy over control metadata. + new_op_map["control_qubits"].mutable_arg_value()->set_string_value( + cur_op_map["control_qubits"].arg_value().string_value()); + new_op_map["control_values"].mutable_arg_value()->set_string_value( + cur_op_map["control_values"].arg_value().string_value()); // Step 4. add qubits. *new_op.mutable_qubits() = {cur_op_qubits.begin(), cur_op_qubits.end()}; return new_op; @@ -215,6 +220,11 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel { } // Step 4. add qubits. *new_op.mutable_qubits() = {cur_op_qubits.begin(), cur_op_qubits.end()}; + // Copy over control metadata. + new_op_map["control_qubits"].mutable_arg_value()->set_string_value( + cur_op_map["control_qubits"].arg_value().string_value()); + new_op_map["control_values"].mutable_arg_value()->set_string_value( + cur_op_map["control_values"].arg_value().string_value()); return new_op; } @@ -251,6 +261,11 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel { } *new_op.mutable_qubits() = {cur_op_qubits.begin() + use_target, cur_op_qubits.end() - !use_target}; + // Copy over control metadata. + new_op_map["control_qubits"].mutable_arg_value()->set_string_value( + cur_op_map["control_qubits"].arg_value().string_value()); + new_op_map["control_values"].mutable_arg_value()->set_string_value( + cur_op_map["control_values"].arg_value().string_value()); return new_op; } @@ -290,6 +305,11 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel { } // Step 4. add qubits. *new_op.mutable_qubits() = {cur_op_qubits.begin(), cur_op_qubits.end()}; + // Copy over control metadata. + new_op_map["control_qubits"].mutable_arg_value()->set_string_value( + cur_op_map["control_qubits"].arg_value().string_value()); + new_op_map["control_values"].mutable_arg_value()->set_string_value( + cur_op_map["control_values"].arg_value().string_value()); return new_op; } }; @@ -306,7 +326,7 @@ REGISTER_OP("TfqPsDecompose") c->set_output(0, c->input(0)); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc b/tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc index 8117f3be1..6a38be061 100644 --- a/tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc +++ b/tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc @@ -15,7 +15,6 @@ limitations under the License. #include -#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" @@ -23,13 +22,14 @@ limitations under the License. #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; @@ -89,9 +89,9 @@ class TfqPsSymbolReplaceOp : public tensorflow::OpKernel { std::string symbol_to_replace = symbols(sidx); std::string temp_symbol_holder; Program cur_program = programs.at(pidx); - for (int j = 0; j < cur_program.circuit().moments().size(); j++) { + for (size_t j = 0; j < cur_program.circuit().moments().size(); j++) { Moment cur_moment = cur_program.circuit().moments().at(j); - for (int k = 0; k < cur_moment.operations().size(); k++) { + for (size_t k = 0; k < cur_moment.operations().size(); k++) { Operation cur_op = cur_moment.operations().at(k); for (auto l = cur_op.args().begin(); l != cur_op.args().end(); l++) { @@ -163,12 +163,12 @@ class TfqPsSymbolReplaceOp : public tensorflow::OpKernel { for (int i = start; i < end; i++) { int sidx = i % n_symbols; int pidx = i / n_symbols; - for (int j = 0; j < output_programs.at(pidx).at(sidx).size(); j++) { + for (size_t j = 0; j < output_programs.at(pidx).at(sidx).size(); j++) { output_tensor(pidx, sidx, j) = output_programs.at(pidx).at(sidx).at(j); } - for (int j = output_programs.at(pidx).at(sidx).size(); j < biggest_pad; - j++) { + for (size_t j = output_programs.at(pidx).at(sidx).size(); + j < biggest_pad; j++) { output_tensor(pidx, sidx, j) = empty_program; } } @@ -206,7 +206,7 @@ REGISTER_OP("TfqPsSymbolReplace") tensorflow::shape_inference::InferenceContext::kUnknownDim, tensorflow::shape_inference::InferenceContext::kUnknownDim})); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_ps_util_ops.py b/tensorflow_quantum/core/ops/tfq_ps_util_ops.py index ad746d045..5a90eb0b3 100644 --- a/tensorflow_quantum/core/ops/tfq_ps_util_ops.py +++ b/tensorflow_quantum/core/ops/tfq_ps_util_ops.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Expose bindings for ParameterShift C++ ops.""" from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_ps_util_ops_test.py b/tensorflow_quantum/core/ops/tfq_ps_util_ops_test.py index c87838f44..3ee1b3f61 100644 --- a/tensorflow_quantum/core/ops/tfq_ps_util_ops_test.py +++ b/tensorflow_quantum/core/ops/tfq_ps_util_ops_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test for ParameterShift specific C++ ops.""" +# 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 + import numpy as np import tensorflow as tf import sympy @@ -123,96 +131,99 @@ def test_decompose_with_complex_circuit(self): # Be careful, they are not decomposed if not parameterized. circuit_batch = [ cirq.Circuit([ - cirq.Moment(operations=[ - cirq.FSimGate(theta=0.10338130973488413 * - sympy.Symbol('CLAE'), - phi=0.10338130973488413 * - sympy.Symbol('IRKB')). - on(cirq.GridQubit(0, 2), cirq.GridQubit(0, 3)), + cirq.Moment([ + cirq.FSimGate( + theta=0.10338130973488413 * sympy.Symbol('CLAE'), + phi=0.10338130973488413 * sympy.Symbol('IRKB')).on( + cirq.GridQubit(0, 2), cirq.GridQubit(0, 3)), cirq.PhasedXPowGate(phase_exponent=1.0, exponent=0.86426029696045281 * sympy.Symbol('HRYV')).on( cirq.GridQubit(0, 1)), ]), - cirq.Moment(operations=[ + cirq.Moment([ cirq.Y.on(cirq.GridQubit(0, 3)), cirq.Z.on(cirq.GridQubit(0, 0)), cirq.FSimGate(theta=1, phi=1).on(cirq.GridQubit(0, 1), cirq.GridQubit(0, 2)), ]), - cirq.Moment(operations=[ - (cirq.CNOT**(0.92874230274398684 * sympy.Symbol('IRKB')) - ).on(cirq.GridQubit(0, 1), cirq.GridQubit(0, 2)), + cirq.Moment([ + (cirq.CNOT**(0.92874230274398684 * + sympy.Symbol('IRKB'))).on( + cirq.GridQubit(0, 1), cirq.GridQubit(0, + 2)), ]), - cirq.Moment(operations=[ + cirq.Moment([ cirq.PhasedXPowGate(phase_exponent=sympy.Symbol('PJOU'), exponent=0.2081415255258906 * sympy.Symbol('LKRV')).on( cirq.GridQubit(0, 2)), - (cirq.ISWAP**(0.32860954996781722 * sympy.Symbol('PJOU')) - ).on(cirq.GridQubit(0, 1), cirq.GridQubit(0, 3)), + (cirq.ISWAP**(0.32860954996781722 * + sympy.Symbol('PJOU'))).on( + cirq.GridQubit(0, 1), + cirq.GridQubit(0, 3)), ]), - cirq.Moment(operations=[ + cirq.Moment([ cirq.PhasedXPowGate(phase_exponent=sympy.Symbol('CJKX')).on( cirq.GridQubit(0, 1)), cirq.ZZ.on(cirq.GridQubit(0, 0), cirq.GridQubit(0, 3)), - (cirq.X**(0.6826594585474709 * - sympy.Symbol('HRYV'))).on(cirq.GridQubit(0, 2)), + (cirq.X**(0.6826594585474709 * sympy.Symbol('HRYV'))).on( + cirq.GridQubit(0, 2)), ]), - cirq.Moment(operations=[ - (cirq.ZZ**(0.18781276022427218 * sympy.Symbol('PJOU')) - ).on(cirq.GridQubit(0, 0), cirq.GridQubit(0, 3)), + cirq.Moment([ + (cirq.ZZ**(0.18781276022427218 * sympy.Symbol('PJOU'))).on( + cirq.GridQubit(0, 0), cirq.GridQubit(0, 3)), ]), - cirq.Moment(operations=[ + cirq.Moment([ cirq.Y.on(cirq.GridQubit(0, 0)), ]), - cirq.Moment(operations=[ - cirq.FSimGate(theta=0.13793763138552417 * - sympy.Symbol('CJKX'), - phi=0.13793763138552417 * - sympy.Symbol('PJOU')). - on(cirq.GridQubit(0, 2), cirq.GridQubit(0, 3)), - (cirq.ISWAP**(0.028165738453673095 * sympy.Symbol('NASW')) - ).on(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)), + cirq.Moment([ + cirq.FSimGate( + theta=0.13793763138552417 * sympy.Symbol('CJKX'), + phi=0.13793763138552417 * sympy.Symbol('PJOU')).on( + cirq.GridQubit(0, 2), cirq.GridQubit(0, 3)), + (cirq.ISWAP**(0.028165738453673095 * + sympy.Symbol('NASW'))).on( + cirq.GridQubit(0, 0), + cirq.GridQubit(0, 1)), ]), - cirq.Moment(operations=[ - cirq.FSimGate(theta=0.74356520426349459 * - sympy.Symbol('CJKX'), - phi=0.74356520426349459 * - sympy.Symbol('NASW')). - on(cirq.GridQubit(0, 3), cirq.GridQubit(0, 0)), + cirq.Moment([ + cirq.FSimGate( + theta=0.74356520426349459 * sympy.Symbol('CJKX'), + phi=0.74356520426349459 * sympy.Symbol('NASW')).on( + cirq.GridQubit(0, 3), cirq.GridQubit(0, 0)), ]), - cirq.Moment(operations=[ + cirq.Moment([ cirq.CNOT.on(cirq.GridQubit(0, 0), cirq.GridQubit(0, 2)), cirq.SWAP.on(cirq.GridQubit(0, 3), cirq.GridQubit(0, 1)), ]), - cirq.Moment(operations=[ + cirq.Moment([ cirq.H.on(cirq.GridQubit(0, 3)), cirq.H.on(cirq.GridQubit(0, 2)), cirq.CNOT.on(cirq.GridQubit(0, 1), cirq.GridQubit(0, 0)), ]), - cirq.Moment(operations=[ + cirq.Moment([ cirq.CNOT.on(cirq.GridQubit(0, 0), cirq.GridQubit(0, 1)), cirq.YY.on(cirq.GridQubit(0, 2), cirq.GridQubit(0, 3)), ]), - cirq.Moment(operations=[ + cirq.Moment([ cirq.CZ.on(cirq.GridQubit(0, 1), cirq.GridQubit(0, 0)), cirq.CNOT.on(cirq.GridQubit(0, 2), cirq.GridQubit(0, 3)), ]), - cirq.Moment(operations=[ + cirq.Moment([ cirq.FSimGate(theta=1, phi=1).on(cirq.GridQubit(0, 0), cirq.GridQubit(0, 2)), cirq.CNOT.on(cirq.GridQubit(0, 3), cirq.GridQubit(0, 1)), ]), - cirq.Moment(operations=[ + cirq.Moment([ cirq.FSimGate(theta=1, phi=1).on(cirq.GridQubit(0, 0), cirq.GridQubit(0, 3)), cirq.SWAP.on(cirq.GridQubit(0, 2), cirq.GridQubit(0, 1)), ]), - cirq.Moment(operations=[ + cirq.Moment([ cirq.Y.on(cirq.GridQubit(0, 0)), - cirq.PhasedXPowGate( - phase_exponent=1.0).on(cirq.GridQubit(0, 2)), + cirq.PhasedXPowGate(phase_exponent=1.0).on( + cirq.GridQubit(0, 2)), cirq.FSimGate(theta=1, phi=1).on(cirq.GridQubit(0, 1), cirq.GridQubit(0, 3)), ]), @@ -256,7 +267,7 @@ def test_moment_preservation(self): """Test Moment-structure preservation.""" t = sympy.Symbol('t') r = sympy.Symbol('r') - qubits = cirq.GridQubit.rect(1, 6) + qubits = cirq.LineQubit.range(6) circuit_batch = [ cirq.Circuit( cirq.Moment([cirq.H(q) for q in qubits]), @@ -468,7 +479,7 @@ def test_weight_coefficient(self): def test_simple_pad(self): """Test simple padding.""" - bit = cirq.GridQubit(0, 0) + bit = cirq.LineQubit(1) circuit = cirq.Circuit( cirq.X(bit)**sympy.Symbol('alpha'), cirq.Y(bit)**sympy.Symbol('alpha'), @@ -717,7 +728,7 @@ def test_error(self): def test_many_values(self): """Ensure that padding with few symbols and many values works.""" - bit = cirq.GridQubit(0, 0) + bit = cirq.LineQubit(1) circuits = [ cirq.Circuit( cirq.X(bit)**(sympy.Symbol('alpha') * 2.0), diff --git a/tensorflow_quantum/core/ops/tfq_ps_weights_from_symbols_op.cc b/tensorflow_quantum/core/ops/tfq_ps_weights_from_symbols_op.cc index cfbeb34ce..65c03a77c 100644 --- a/tensorflow_quantum/core/ops/tfq_ps_weights_from_symbols_op.cc +++ b/tensorflow_quantum/core/ops/tfq_ps_weights_from_symbols_op.cc @@ -18,7 +18,6 @@ limitations under the License. #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" #include "absl/strings/numbers.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" @@ -26,14 +25,15 @@ limitations under the License. #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 ::tensorflow::Tensor; +using ::tfq::proto::Arg; +using ::tfq::proto::Moment; +using ::tfq::proto::Operation; +using ::tfq::proto::Program; class TfqPsWeightsFromSymbolOp : public tensorflow::OpKernel { public: @@ -71,7 +71,9 @@ class TfqPsWeightsFromSymbolOp : public tensorflow::OpKernel { for (int i = 0; i < n_symbols; i++) { symbols_map[symbols(i)] = i; } - std::vector ignore_list = {"I", "ISP", "PXP", "FSIM", "PISP"}; + std::vector ignore_list = {"I", "ISP", "PXP", "FSIM", "PISP", + "AD", "ADP", "DP", "GAD", "BF", + "PF", "PD", "RST"}; absl::flat_hash_set ignored_symbol_set(ignore_list.begin(), ignore_list.end()); @@ -80,9 +82,9 @@ class TfqPsWeightsFromSymbolOp : public tensorflow::OpKernel { auto DoWork = [&](int start, int end) { for (int i = start; i < end; i++) { Program cur_program = programs.at(i); - for (int j = 0; j < cur_program.circuit().moments().size(); j++) { + for (size_t j = 0; j < cur_program.circuit().moments().size(); j++) { Moment cur_moment = cur_program.circuit().moments().at(j); - for (int k = 0; k < cur_moment.operations().size(); k++) { + for (size_t k = 0; k < cur_moment.operations().size(); k++) { Operation cur_op = cur_moment.operations().at(k); if (ignored_symbol_set.contains(cur_op.gate().id())) continue; @@ -144,10 +146,10 @@ class TfqPsWeightsFromSymbolOp : public tensorflow::OpKernel { auto DoWork2 = [&](int start, int end) { for (int i = start; i < end; i++) { for (int j = 0; j < n_symbols; j++) { - for (int k = 0; k < output_results.at(i).at(j).size(); k++) { + for (size_t k = 0; k < output_results.at(i).at(j).size(); k++) { output_tensor(i, j, k) = output_results.at(i).at(j).at(k); } - for (int k = output_results.at(i).at(j).size(); + for (size_t k = output_results.at(i).at(j).size(); k < largest_single_symbol; k++) { output_tensor(i, j, k) = 0.0f; } @@ -182,7 +184,7 @@ REGISTER_OP("TfqPsWeightsFromSymbols") tensorflow::shape_inference::InferenceContext::kUnknownDim, tensorflow::shape_inference::InferenceContext::kUnknownDim})); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_resolve_parameters_op.cc b/tensorflow_quantum/core/ops/tfq_resolve_parameters_op.cc index a2078516b..8d7ce06cf 100644 --- a/tensorflow_quantum/core/ops/tfq_resolve_parameters_op.cc +++ b/tensorflow_quantum/core/ops/tfq_resolve_parameters_op.cc @@ -15,21 +15,22 @@ limitations under the License. #include -#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/error_codes.pb.h" #include "tensorflow/core/lib/core/status.h" #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/ops/tfq_simulate_utils.h" +#include "tensorflow_quantum/core/proto/program.pb.h" #include "tensorflow_quantum/core/src/program_resolution.h" namespace tfq { -using ::cirq::google::api::v2::Program; using ::tensorflow::Status; +using ::tfq::proto::Program; class TfqResolveParametersOp : public tensorflow::OpKernel { public: @@ -58,11 +59,14 @@ class TfqResolveParametersOp : public tensorflow::OpKernel { "Number of circuits and values do not match. Got ", programs.size(), " circuits and ", maps.size(), " values."))); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); auto DoWork = [&](int start, int end) { std::string temp; for (int i = start; i < end; i++) { Program program = programs[i]; - OP_REQUIRES_OK(context, ResolveSymbols(maps[i], &program, false)); + Status local = ResolveSymbols(maps[i], &program, false); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); program.SerializeToString(&temp); output_tensor(i) = temp; } @@ -71,6 +75,7 @@ class TfqResolveParametersOp : public tensorflow::OpKernel { const int num_cycles = 1000; context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( programs.size(), num_cycles, DoWork); + OP_REQUIRES_OK(context, parse_status); } }; @@ -95,7 +100,7 @@ REGISTER_OP("TfqResolveParameters") c->set_output(0, c->input(0)); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc index ea7c61b7e..210e9e93f 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op.cc @@ -21,22 +21,23 @@ 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" #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/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/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 QsimGate; typedef qsim::Circuit QsimCircuit; @@ -85,17 +86,21 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel { std::vector>> fused_circuits( programs.size(), std::vector>({})); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); auto construct_f = [&](int start, int end) { for (int i = start; i < end; i++) { - OP_REQUIRES_OK(context, QsimCircuitFromProgram( - programs[i], maps[i], num_qubits[i], - &qsim_circuits[i], &fused_circuits[i])); + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); } }; const int num_cycles = 1000; context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); int max_num_qubits = 0; for (const int num : num_qubits) { @@ -138,7 +143,7 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -151,10 +156,10 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel { // the state if there is a possibility that circuit[i] and // circuit[i + 1] produce the same state. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { // (#679) Just ignore empty program if (fused_circuits[i].size() == 0) { (*output_tensor)(i, j) = -2.0; @@ -181,6 +186,8 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel { const int output_dim_op_size = output_tensor->dimension(1); + Status compute_status = ::tensorflow::Status(); + auto c_lock = tensorflow::mutex(); auto DoWork = [&](int start, int end) { int old_batch_index = -2; int cur_batch_index = -1; @@ -214,15 +221,17 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel { // no need to update scratch_state since ComputeExpectation // will take care of things for us. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[cur_batch_index].size(); j++) { + for (size_t j = 0; j < fused_circuits[cur_batch_index].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[cur_batch_index][j], sv); } } float exp_v = 0.0; - OP_REQUIRES_OK(context, ComputeExpectationQsim( - pauli_sums[cur_batch_index][cur_op_index], - sim, ss, sv, scratch, &exp_v)); + NESTED_FN_STATUS_SYNC( + compute_status, + ComputeExpectationQsim(pauli_sums[cur_batch_index][cur_op_index], + sim, ss, sv, scratch, &exp_v), + c_lock); (*output_tensor)(cur_batch_index, cur_op_index) = exp_v; old_batch_index = cur_batch_index; } @@ -232,6 +241,7 @@ class TfqSimulateExpectationOp : public tensorflow::OpKernel { 200 * (int64_t(1) << static_cast(max_num_qubits)); context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( fused_circuits.size() * output_dim_op_size, num_cycles, DoWork); + OP_REQUIRES_OK(context, compute_status); } }; @@ -264,7 +274,7 @@ REGISTER_OP("TfqSimulateExpectation") c->Dim(pauli_sums_shape, 1); c->set_output(0, c->Matrix(output_rows, output_cols)); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc new file mode 100644 index 000000000..28fe5ee65 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_expectation_op_cuquantum.cu.cc @@ -0,0 +1,220 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include +#include +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/gates_qsim.h" +#include "../qsim/lib/simmux_gpu.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#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/pauli_sum.pb.h" +#include "tensorflow_quantum/core/proto/program.pb.h" +#include "tensorflow_quantum/core/src/util_qsim.h" + +namespace tfq { + +using ::tensorflow::Status; +using ::tfq::proto::PauliSum; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateExpectationOpCuQuantum : public tensorflow::OpKernel { + public: + explicit TfqSimulateExpectationOpCuQuantum( + tensorflow::OpKernelConstruction* context) + : OpKernel(context) { + // Allocates handlers for initialization. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } + + ~TfqSimulateExpectationOpCuQuantum() { + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + const int num_inputs = context->num_inputs(); + OP_REQUIRES(context, num_inputs == 4, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Expected 4 inputs, got ", num_inputs, " inputs."))); + + // Create the output Tensor. + const int output_dim_batch_size = context->input(0).dim_size(0); + const int output_dim_op_size = context->input(3).dim_size(1); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_batch_size); + output_shape.AddDim(output_dim_op_size); + + tensorflow::Tensor* output = nullptr; + tensorflow::AllocatorAttributes alloc_attr; + alloc_attr.set_on_host(true); // why?? + alloc_attr.set_gpu_compatible(true); + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output, + alloc_attr)); + auto output_tensor = output->matrix(); + // Parse program protos. + std::vector programs; + std::vector num_qubits; + std::vector> + pauli_sums; // why is this a vector of vectors?? + OP_REQUIRES_OK(context, GetProgramsAndNumQubits(context, &programs, + &num_qubits, &pauli_sums)); + + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + + OP_REQUIRES(context, programs.size() == maps.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and symbol_values do not match. Got ", + programs.size(), " circuits and ", maps.size(), + " symbol values."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> fused_circuits( + programs.size(), std::vector>({})); + + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + ComputeLarge(num_qubits, fused_circuits, pauli_sums, context, + &output_tensor); + } + + private: + cublasHandle_t cublas_handle_; + custatevecHandle_t custatevec_handle_; + + // Define the GPU implementation that launches the CUDA kernel. + void ComputeLarge( + const std::vector& num_qubits, + const std::vector>>& fused_circuits, + const std::vector>& pauli_sums, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + // Launch the cuda kernel. + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + ss.SetStateZero(sv); + auto scratch = ss.Create(largest_nq); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as necessary. + for (size_t i = 0; i < fused_circuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + } + // TODO: add heuristic here so that we do not always recompute + // the state if there is a possibility that circuit[i] and + // circuit[i + 1] produce the same state. + ss.SetStateZero(sv); + for (size_t j = 0; j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + for (size_t j = 0; j < pauli_sums[i].size(); j++) { + // (#679) Just ignore empty program + if (fused_circuits[i].size() == 0) { + (*output_tensor)(i, j) = -2.0; + continue; + } + float exp_v = 0.0; + OP_REQUIRES_OK(context, + ComputeExpectationQsim(pauli_sums[i][j], sim, ss, sv, + scratch, &exp_v)); + (*output_tensor)(i, j) = exp_v; + } + } + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqSimulateExpectationCuquantum").Device(tensorflow::DEVICE_CPU), + TfqSimulateExpectationOpCuQuantum); + +REGISTER_OP("TfqSimulateExpectationCuquantum") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("pauli_sums: string") + .Output("expectations: float") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle pauli_sums_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 2, &pauli_sums_shape)); + + tensorflow::shape_inference::DimensionHandle output_rows = + c->Dim(programs_shape, 0); + tensorflow::shape_inference::DimensionHandle output_cols = + c->Dim(pauli_sums_shape, 1); + c->set_output(0, c->Matrix(output_rows, output_cols)); + + return ::tensorflow::Status(); + }); + +} // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops.py b/tensorflow_quantum/core/ops/tfq_simulate_ops.py index 17f1fd6bd..a68116c3e 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to register python op gradient.""" import tensorflow as tf from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py new file mode 100644 index 000000000..27165e4d6 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum.py @@ -0,0 +1,134 @@ +# Copyright 2023 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Module to register cuQuantum simulation python op.""" +import tensorflow as tf +from tensorflow_quantum.core.ops.load_module import load_module + +SIM_OP_MODULE = load_module("_tfq_simulate_ops_cuquantum.so") + + +def tfq_simulate_expectation(programs, symbol_names, symbol_values, pauli_sums): + """Calculates the expectation value of circuits wrt some operator(s). + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] + containing the string representation of the operators that will + be used on all of the circuits in the expectation calculations. + Returns: + `tf.Tensor` with shape [batch_size, n_ops] that holds the + expectation value for each circuit with each op applied to it + (after resolving the corresponding parameters in). + """ + return SIM_OP_MODULE.tfq_simulate_expectation_cuquantum( + programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums) + + +def tfq_simulate_state(programs, symbol_names, symbol_values): + """Returns the state of the programs using the C++ state vector simulator. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + Returns: + A `tf.Tensor` containing the final state of each circuit in `programs`. + """ + return SIM_OP_MODULE.tfq_simulate_state_cuquantum( + programs, symbol_names, tf.cast(symbol_values, tf.float32)) + + +def tfq_simulate_samples(programs, symbol_names, symbol_values, num_samples): + """Generate samples using the C++ state vector simulator. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + From there we will then sample from the final state using native tensorflow + operations. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specified by programs, following the ordering + dictated by `symbol_names`. + num_samples: `tf.Tensor` with one element indicating the number of + samples to draw. + Returns: + A `tf.Tensor` containing the samples taken from each circuit in + `programs`. + """ + return SIM_OP_MODULE.tfq_simulate_samples_cuquantum( + programs, symbol_names, tf.cast(symbol_values, tf.float32), num_samples) + + +def tfq_simulate_sampled_expectation(programs, symbol_names, symbol_values, + pauli_sums, num_samples): + """Calculate the expectation value of circuits using samples. + + Simulate the final state of `programs` given `symbol_values` are placed + inside of the symbols with the name in `symbol_names` in each circuit. + Them, sample the resulting state `num_samples` times and use these samples + to compute expectation values of the given `pauli_sums`. + + Args: + programs: `tf.Tensor` of strings with shape [batch_size] containing + the string representations of the circuits to be executed. + symbol_names: `tf.Tensor` of strings with shape [n_params], which + is used to specify the order in which the values in + `symbol_values` should be placed inside of the circuits in + `programs`. + symbol_values: `tf.Tensor` of real numbers with shape + [batch_size, n_params] specifying parameter values to resolve + into the circuits specificed by programs, following the ordering + dictated by `symbol_names`. + pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] + containing the string representation of the operators that will + be used on all of the circuits in the expectation calculations. + num_samples: `tf.Tensor` with `num_samples[i][j]` is equal to the + number of samples to draw in each term of `pauli_sums[i][j]` + when estimating the expectation. Therefore, `num_samples` must + have the same shape as `pauli_sums`. + Returns: + `tf.Tensor` with shape [batch_size, n_ops] that holds the + expectation value for each circuit with each op applied to it + (after resolving the corresponding parameters in). + """ + return SIM_OP_MODULE.tfq_simulate_sampled_expectation_cuquantum( + programs, symbol_names, tf.cast(symbol_values, tf.float32), pauli_sums, + tf.cast(num_samples, dtype=tf.int32)) diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py new file mode 100644 index 000000000..f3854a3c8 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_cuquantum_test.py @@ -0,0 +1,918 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Tests that specifically target tfq_simulate_ops_cu*.""" +import time +import numpy as np +from absl.testing import parameterized +import tensorflow as tf +import cirq + +from tensorflow_quantum.core.ops import tfq_simulate_ops +from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum +from tensorflow_quantum.python import util + + +def measure_average_runtime( + fn, + tag, + num_samples=10, + result_avg=False, +): + """Measures average runtime for given function. + + Args: + fn: function. + tag: The message title. + num_samples: The number of measurements. + result_avg: True if the results are all averaged. + + Returns: + The average time and the (averaged) result. + """ + avg_time = [] + avg_res = [] + for _ in range(num_samples): + begin_time = time.time() + result = fn() + duration = time.time() - begin_time + avg_time.append(duration) + if result_avg: + avg_res.append(result) + avg_time = sum(avg_time) / float(num_samples) + print(f"\n\t{tag} time: {avg_time}\n") + if result_avg: + result = np.average(avg_res, axis=0) + return avg_time, result + + +class SimulateExpectationCuquantumTest(tf.test.TestCase): + """Tests tfq_simulate_expectation.""" + + def test_simulate_expectation_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + _, res_cpu = measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), + "Expectation CPU", + num_samples=100, + ) + + _, res_cuquantum = measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), + "Expectation cuQuantum", + num_samples=100, + ) + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, + res_cuquantum, + atol=1e-4, + err_msg=""" + # If failed, the GPU architecture in this system may be unsupported. + # Please refer to the supported architectures here. + # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec + """) + + def test_simulate_expectation_inputs(self): + """Make sure that the expectation op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # Circuit tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor([circuit_batch]), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1.'): + # symbol_names tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array]), + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too few dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[0], + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too few dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, util.convert_to_tensor(list(pauli_sums))) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[[x]] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # circuit tensor has the right type but invalid values. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + ['junk'] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type but invalid values. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), ['junk'], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'qubits not found in circuit'): + # pauli_sums tensor has the right type but invalid values. + new_qubits = [cirq.GridQubit(5, 5), cirq.GridQubit(9, 9)] + new_pauli_sums = util.random_pauli_sums(new_qubits, 2, batch_size) + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in new_pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # pauli_sums tensor has the right type but invalid values 2. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [['junk']] * batch_size) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # circuits tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + [1.0] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), [0.1234], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size, + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # pauli_sums tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [[1.0]] * batch_size) + + with self.assertRaisesRegex(TypeError, 'missing'): + # we are missing an argument. + # pylint: disable=no-value-for-parameter + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(TypeError, 'positional arguments'): + # pylint: disable=too-many-function-args + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), []) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong op size. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums + ][:int(batch_size * 0.5)])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)], + util.convert_to_tensor([[x] for x in pauli_sums])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor([noisy_circuit for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + + res = tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + util.convert_to_tensor([cirq.Circuit() for _ in pauli_sums]), + symbol_names, symbol_values_array.astype(np.float64), + util.convert_to_tensor([[x] for x in pauli_sums])) + self.assertDTypeEqual(res, np.float32) + + +class SimulateSampledExpectationCuquantumTest(tf.test.TestCase): + """Tests tfq_simulate_sampled_expectation.""" + + def test_simulate_sampled_expectation_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + n_samples = [[10000]] * batch_size + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + _, res_cpu = measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_sampled_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor, + n_samples), + "SampledExpectation CPU", + num_samples=10, + result_avg=False, + ) + + _, res_cuquantum = measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor, + n_samples), + "SampledExpectation cuQuantum", + num_samples=10, + result_avg=False, + ) + + # cuQuantum op should be faster than CPU op. + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, + res_cuquantum, + atol=0.07, + err_msg=""" + # If failed, the GPU architecture in this system may be unsupported. + # Please refer to the supported architectures here. + # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec + """) + + def test_simulate_sampled_expectation_inputs(self): + """Make sure sampled expectation op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + num_samples = [[10]] * batch_size + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # Circuit tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor([circuit_batch]), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1.'): + # symbol_names tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array]), + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2.'): + # symbol_values_array tensor has too few dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[0], + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too few dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + util.convert_to_tensor(list(pauli_sums)), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'pauli_sums must be rank 2.'): + # pauli_sums tensor has too many dimensions. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + [util.convert_to_tensor([[x] for x in pauli_sums])], + num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'num_samples must be rank 2'): + # num_samples tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'num_samples must be rank 2'): + # num_samples tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + num_samples[0]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # circuit tensor has the right type but invalid values. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + ['junk'] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type but invalid values. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), ['junk'], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'qubits not found in circuit'): + # pauli_sums tensor has the right type but invalid values. + new_qubits = [cirq.GridQubit(5, 5), cirq.GridQubit(9, 9)] + new_pauli_sums = util.random_pauli_sums(new_qubits, 2, batch_size) + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in new_pauli_sums]), + num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # pauli_sums tensor has the right type but invalid values 2. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [['junk']] * batch_size, num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # circuits tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + [1.0] * batch_size, symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), [0.1234], + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # pauli_sums tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [[1.0]] * batch_size, num_samples) + + with self.assertRaisesRegex(TypeError, 'missing'): + # we are missing an argument. + # pylint: disable=no-value-for-parameter + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, num_samples) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(TypeError, 'positional arguments'): + # pylint: disable=too-many-function-args + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), [], + num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong op size. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor([cirq.Circuit()]), symbol_names, + symbol_values_array.astype(np.float64), + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'greater than 0'): + # pylint: disable=too-many-function-args + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), + [[-1]] * batch_size) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)], + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_simulate_ops_cuquantum.tfq_simulate_sampled_expectation( + util.convert_to_tensor([noisy_circuit for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + + +class SimulateSamplesCuquantumTest(tf.test.TestCase, parameterized.TestCase): + """Tests tfq_simulate_samples.""" + + def test_simulate_samples_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + n_samples = [100] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + _, res_cpu = measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_samples( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), n_samples), + "Samples CPU", + num_samples=10, + result_avg=False, + ) + + _, res_cuquantum = measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_samples( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), n_samples), + "Samples cuQuantum", + num_samples=10, + result_avg=False, + ) + + # cuQuantum op should be faster than CPU op. + + res_cpu = np.average(res_cpu, axis=1) + res_cuquantum = np.average(res_cuquantum, axis=1) + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, + res_cuquantum, + atol=0.3, + err_msg=""" + # If failed, the GPU architecture in this system may be unsupported. + # Please refer to the supported architectures here. + # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec + """) + + def test_simulate_samples_inputs(self): + """Make sure the sample op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + num_samples = 10 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 1. Got rank 2'): + # programs tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor([circuit_batch]), symbol_names, + symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 1. Got rank 2'): + # symbol_names tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 2. Got rank 3'): + # symbol_values tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array]), [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 2. Got rank 1'): + # symbol_values tensor has the wrong shape 2. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[0], [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'rank 1. Got rank 2'): + # num_samples tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, [[num_samples]]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # programs tensor has the right type, but invalid value. + tfq_simulate_ops_cuquantum.tfq_simulate_samples(\ + ['junk'] * batch_size, + symbol_names, + symbol_values_array, + [num_samples]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type, but invalid value. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), ['junk'], + symbol_values_array, [num_samples]) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # programs tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_samples([1] * batch_size, + symbol_names, + symbol_values_array, + [num_samples]) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # programs tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), [1], symbol_values_array, + [num_samples]) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, + 'Cast string to float is not supported'): + # programs tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size, [num_samples]) + + with self.assertRaisesRegex(Exception, 'junk'): + # num_samples tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, ['junk']) + + with self.assertRaisesRegex(TypeError, 'missing'): + # too few tensors. + # pylint: disable=no-value-for-parameter + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array) + # pylint: enable=no-value-for-parameter + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)], num_samples) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_simulate_ops_cuquantum.tfq_simulate_samples( + util.convert_to_tensor([noisy_circuit for _ in circuit_batch]), + symbol_names, symbol_values_array, [num_samples]) + + @parameterized.parameters([ + { + 'all_n_qubits': [2, 3], + 'n_samples': 10 + }, + { + 'all_n_qubits': [1, 5, 8], + 'n_samples': 10 + }, + ]) + def test_sampling_output_padding(self, all_n_qubits, n_samples): + """Check that the sampling ops pad outputs correctly""" + op = tfq_simulate_ops_cuquantum.tfq_simulate_samples + circuits = [] + expected_outputs = [] + for n_qubits in all_n_qubits: + this_expected_output = np.zeros((n_samples, max(all_n_qubits))) + this_expected_output[:, max(all_n_qubits) - n_qubits:] = 1 + this_expected_output[:, :max(all_n_qubits) - n_qubits] = -2 + expected_outputs.append(this_expected_output) + circuits.append( + cirq.Circuit(*cirq.X.on_each( + *cirq.GridQubit.rect(1, n_qubits)))) + results = op(util.convert_to_tensor(circuits), [], [[]] * len(circuits), + [n_samples]).numpy() + self.assertAllClose(expected_outputs, results) + + +class SimulateStateCuquantumTest(tf.test.TestCase, parameterized.TestCase): + """Tests tfq_simulate_samples.""" + + def test_simulate_state_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + _, res_cpu = measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_state( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64)), + "State CPU", + num_samples=10, + ) + + _, res_cuquantum = measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_state( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64)), + "State cuQuantum", + num_samples=10, + ) + + # cuQuantum op should be faster than CPU op. + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, + res_cuquantum, + atol=1e-4, + err_msg=""" + # If failed, the GPU architecture in this system may be unsupported. + # Please refer to the supported architectures here. + # https://docs.nvidia.com/cuda/cuquantum/getting_started.html#custatevec + """) + + def test_simulate_state_inputs(self): + """Make sure the state op fails gracefully on bad inputs.""" + n_qubits = 5 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'programs must be rank 1'): + # programs tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor([circuit_batch]), symbol_names, + symbol_values_array) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_names must be rank 1'): + # symbol_names tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), np.array([symbol_names]), + symbol_values_array) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2'): + # symbol_values tensor has the wrong shape. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), symbol_names, + np.array([symbol_values_array])) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'symbol_values must be rank 2'): + # symbol_values tensor has the wrong shape 2. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[0]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Unparseable proto'): + # programs tensor has the right type, but invalid value. + tfq_simulate_ops_cuquantum.tfq_simulate_state(['junk'] * batch_size, + symbol_names, + symbol_values_array) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + 'Could not find symbol in parameter map'): + # symbol_names tensor has the right type, but invalid value. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), ['junk'], + symbol_values_array) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # programs tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_state([1] * batch_size, + symbol_names, + symbol_values_array) + + with self.assertRaisesRegex(TypeError, 'Cannot convert'): + # symbol_names tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), [1], symbol_values_array) + + with self.assertRaisesRegex(tf.errors.UnimplementedError, ''): + # symbol_values tensor has the wrong type. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), symbol_names, + [['junk']] * batch_size) + + with self.assertRaisesRegex(TypeError, 'missing'): + # too few tensors. + # pylint: disable=no-value-for-parameter + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), symbol_names) + # pylint: enable=no-value-for-parameter + + # TODO (mbbrough): determine if we should allow extra arguments ? + with self.assertRaisesRegex(TypeError, 'positional arguments'): + # pylint: disable=too-many-function-args + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array, []) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='do not match'): + # wrong symbol_values size. + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), symbol_names, + symbol_values_array[:int(batch_size * 0.5)]) + + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor([noisy_circuit for _ in circuit_batch]), + symbol_names, symbol_values_array) + + @parameterized.parameters([ + { + 'all_n_qubits': [2, 3] + }, + { + 'all_n_qubits': [1, 5, 8] + }, + ]) + def test_simulate_state_output_padding(self, all_n_qubits): + """If a tfq_simulate op is asked to simulate states given circuits + acting on different numbers of qubits, the op should return a tensor + padded with zeros up to the size of the largest circuit. The padding + should be physically correct, such that samples taken from the padded + states still match samples taken from the original circuit. """ + circuit_batch = [] + for n_qubits in all_n_qubits: + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch += util.random_circuit_resolver_batch(qubits, 1)[0] + + tfq_results = tfq_simulate_ops_cuquantum.tfq_simulate_state( + util.convert_to_tensor(circuit_batch), [], + [[]] * len(circuit_batch)) + + # Don't use batch_util here to enforce consistent padding everywhere + # without extra tests. + sim = cirq.Simulator() + manual_padded_results = [] + for circuit in circuit_batch: + result = sim.simulate(circuit) + wf = result.final_state_vector + blank_state = np.ones( + (2**max(all_n_qubits)), dtype=np.complex64) * -2 + blank_state[:wf.shape[0]] = wf + manual_padded_results.append(blank_state) + + self.assertAllClose(tfq_results, manual_padded_results, atol=1e-5) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py new file mode 100644 index 000000000..eb1bc02f6 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_gpu_test.py @@ -0,0 +1,139 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Tests that specifically target tfq_simulate_ops_cu*.""" +import time +import numpy as np +import tensorflow as tf +import cirq + +from tensorflow_quantum.core.ops import tfq_simulate_ops +from tensorflow_quantum.core.ops import tfq_simulate_ops_cuda +from tensorflow_quantum.core.ops import tfq_simulate_ops_cuquantum +from tensorflow_quantum.python import util + + +def measure_average_runtime(fn, tag, num_samples=10): + """ + Measure the average runtime of a function. + + Args: + fn: A function to measure. + tag: A string to print. + num_samples: Number of samples to measure. + + Returns: + A tuple of (average runtime, function result). + """ + avg_time = [] + for _ in range(num_samples): + begin_time = time.time() + result = fn() + duration = time.time() - begin_time + avg_time.append(duration) + avg_time = sum(avg_time) / float(num_samples) + print(f"\n\t{tag} time: {avg_time}\n") + return avg_time, result + + +class SimulateExpectationGpuTest(tf.test.TestCase): + """Tests tfq_simulate_expectation.""" + + def test_simulate_expectation_cpu_vs_cuda(self): + """Make sure that cpu & gpu(cuda) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + cpu_avg_time, res_cpu = measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), + "CPU", + num_samples=100, + ) + + cuda_avg_time, res_cuda = measure_average_runtime( + lambda: tfq_simulate_ops_cuda.tfq_simulate_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), + "CUDA", + num_samples=100, + ) + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, res_cuda, atol=1e-4) + + # CUDA op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuda_avg_time) + + def test_simulate_expectation_cpu_vs_cuquantum(self): + """Make sure that cpu & gpu(cuquantum) ops have the same results.""" + n_qubits = 20 + batch_size = 5 + symbol_names = ['alpha'] + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + qubits, symbol_names, batch_size) + + circuit_batch_tensor = util.convert_to_tensor(circuit_batch) + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch]) + + pauli_sums = util.random_pauli_sums(qubits, 3, batch_size) + pauli_sums_tensor = util.convert_to_tensor([[x] for x in pauli_sums]) + + cpu_avg_time, res_cpu = measure_average_runtime( + lambda: tfq_simulate_ops.tfq_simulate_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), + "CPU", + num_samples=100, + ) + + cuda_avg_time, res_cuda = measure_average_runtime( + lambda: tfq_simulate_ops_cuquantum.tfq_simulate_expectation( + circuit_batch_tensor, symbol_names, + symbol_values_array.astype(np.float64), pauli_sums_tensor), + "cuQuantum", + num_samples=100, + ) + + # The result should be the similar within a tolerance. + np.testing.assert_allclose(res_cpu, res_cuda, atol=1e-4) + + # cuQuantum op should be faster than CPU op. + self.assertGreater(cpu_avg_time, cuda_avg_time) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/ops/tfq_simulate_ops_test.py b/tensorflow_quantum/core/ops/tfq_simulate_ops_test.py index 8cf79bc6a..cb1d05f10 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_ops_test.py +++ b/tensorflow_quantum/core/ops/tfq_simulate_ops_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target tfq_simulate_ops.""" +# 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 + import numpy as np from absl.testing import parameterized import tensorflow as tf @@ -79,8 +87,7 @@ def test_simulate_expectation_inputs(self): # pauli_sums tensor has too few dimensions. tfq_simulate_ops.tfq_simulate_expectation( util.convert_to_tensor(circuit_batch), symbol_names, - symbol_values_array, - util.convert_to_tensor([x for x in pauli_sums])) + symbol_values_array, util.convert_to_tensor(list(pauli_sums))) with self.assertRaisesRegex(tf.errors.InvalidArgumentError, 'pauli_sums must be rank 2.'): @@ -180,6 +187,15 @@ def test_simulate_expectation_inputs(self): symbol_values_array[:int(batch_size * 0.5)], util.convert_to_tensor([[x] for x in pauli_sums])) + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_simulate_ops.tfq_simulate_expectation( + util.convert_to_tensor([noisy_circuit for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums])) + res = tfq_simulate_ops.tfq_simulate_expectation( util.convert_to_tensor([cirq.Circuit() for _ in pauli_sums]), symbol_names, symbol_values_array.astype(np.float64), @@ -284,6 +300,14 @@ def test_simulate_state_inputs(self): util.convert_to_tensor(circuit_batch), symbol_names, symbol_values_array[:int(batch_size * 0.5)]) + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_simulate_ops.tfq_simulate_state( + util.convert_to_tensor([noisy_circuit for _ in circuit_batch]), + symbol_names, symbol_values_array) + @parameterized.parameters([ { 'all_n_qubits': [2, 3] @@ -319,7 +343,7 @@ def test_simulate_state_output_padding(self, all_n_qubits): blank_state[:wf.shape[0]] = wf manual_padded_results.append(blank_state) - self.assertAllClose(tfq_results, manual_padded_results) + self.assertAllClose(tfq_results, manual_padded_results, atol=1e-5) class SimulateSamplesTest(tf.test.TestCase, parameterized.TestCase): @@ -432,6 +456,14 @@ def test_simulate_samples_inputs(self): util.convert_to_tensor(circuit_batch), symbol_names, symbol_values_array[:int(batch_size * 0.5)], num_samples) + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_simulate_ops.tfq_simulate_samples( + util.convert_to_tensor([noisy_circuit for _ in circuit_batch]), + symbol_names, symbol_values_array, [num_samples]) + @parameterized.parameters([ { 'all_n_qubits': [2, 3], @@ -453,8 +485,8 @@ def test_sampling_output_padding(self, all_n_qubits, n_samples): this_expected_output[:, :max(all_n_qubits) - n_qubits] = -2 expected_outputs.append(this_expected_output) circuits.append( - cirq.Circuit( - *cirq.X.on_each(*cirq.GridQubit.rect(1, n_qubits)))) + cirq.Circuit(*cirq.X.on_each( + *cirq.GridQubit.rect(1, n_qubits)))) results = op(util.convert_to_tensor(circuits), [], [[]] * len(circuits), [n_samples]).numpy() self.assertAllClose(expected_outputs, results) @@ -517,9 +549,9 @@ def test_simulate_sampled_expectation_inputs(self): 'pauli_sums must be rank 2.'): # pauli_sums tensor has too few dimensions. tfq_simulate_ops.tfq_simulate_sampled_expectation( - util.convert_to_tensor(circuit_batch), symbol_names, - symbol_values_array, - util.convert_to_tensor([x for x in pauli_sums]), num_samples) + util.convert_to_tensor(circuit_batch), + symbol_names, symbol_values_array, + util.convert_to_tensor(list(pauli_sums)), num_samples) with self.assertRaisesRegex(tf.errors.InvalidArgumentError, 'pauli_sums must be rank 2.'): @@ -648,6 +680,15 @@ def test_simulate_sampled_expectation_inputs(self): symbol_values_array[:int(batch_size * 0.5)], util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + tfq_simulate_ops.tfq_simulate_sampled_expectation( + util.convert_to_tensor([noisy_circuit for _ in pauli_sums]), + symbol_names, symbol_values_array, + util.convert_to_tensor([[x] for x in pauli_sums]), num_samples) + class InputTypesTest(tf.test.TestCase, parameterized.TestCase): """Tests that different inputs types work for all of the ops. """ diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc index 2e1973213..82abb74b9 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op.cc @@ -21,22 +21,26 @@ 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" #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/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/platform/mutex.h" +#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 QsimGate; typedef qsim::Circuit QsimCircuit; @@ -45,7 +49,9 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { public: explicit TfqSimulateSampledExpectationOp( tensorflow::OpKernelConstruction* context) - : OpKernel(context) {} + : OpKernel(context) { + OP_REQUIRES_OK(context, random_gen_.Init(context)); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. @@ -90,28 +96,32 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { pauli_sums.size(), " lists of pauli sums."))); OP_REQUIRES( - context, num_samples[0].size() == pauli_sums[0].size(), + context, context->input(4).dim_size(1) == context->input(3).dim_size(1), tensorflow::errors::InvalidArgument(absl::StrCat( "Dimension 1 of num_samples and pauli_sums do not match.", "Got ", - num_samples[0].size(), " lists of sample sizes and ", - pauli_sums[0].size(), " lists of pauli sums."))); + context->input(4).dim_size(1), " lists of sample sizes and ", + context->input(3).dim_size(1), " lists of pauli sums."))); // Construct qsim circuits. std::vector qsim_circuits(programs.size(), QsimCircuit()); std::vector>> fused_circuits( programs.size(), std::vector>({})); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); auto construct_f = [&](int start, int end) { for (int i = start; i < end; i++) { - OP_REQUIRES_OK(context, QsimCircuitFromProgram( - programs[i], maps[i], num_qubits[i], - &qsim_circuits[i], &fused_circuits[i])); + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); } }; const int num_cycles = 1000; context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); int max_num_qubits = 0; for (const int num : num_qubits) { @@ -133,6 +143,8 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { } private: + tensorflow::GuardedPhiloxRandom random_gen_; + void ComputeLarge( const std::vector& num_qubits, const std::vector>>& fused_circuits, @@ -152,10 +164,20 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { auto sv = ss.Create(largest_nq); auto scratch = ss.Create(largest_nq); + int largest_sum = -1; + for (const auto& sums : pauli_sums) { + for (const auto& sum : sums) { + largest_sum = std::max(largest_sum, sum.terms().size()); + } + } + auto local_gen = random_gen_.ReserveSamples32( + largest_sum * pauli_sums[0].size() * fused_circuits.size() + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as necessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -168,10 +190,10 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { // the state if there is a possibility that circuit[i] and // circuit[i + 1] produce the same state. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } - for (int j = 0; j < pauli_sums[i].size(); j++) { + for (size_t j = 0; j < pauli_sums[i].size(); j++) { // (#679) Just ignore empty program if (fused_circuits[i].size() == 0) { (*output_tensor)(i, j) = -2.0; @@ -180,7 +202,7 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { float exp_v = 0.0; OP_REQUIRES_OK(context, ComputeSampledExpectationQsim( pauli_sums[i][j], sim, ss, sv, scratch, - num_samples[i][j], &exp_v)); + num_samples[i][j], rand_source, &exp_v)); (*output_tensor)(i, j) = exp_v; } } @@ -199,6 +221,18 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { const int output_dim_op_size = output_tensor->dimension(1); + int largest_sum = -1; + for (const auto& sums : pauli_sums) { + for (const auto& sum : sums) { + largest_sum = std::max(largest_sum, sum.terms().size()); + } + } + const int num_threads = context->device() + ->tensorflow_cpu_worker_threads() + ->workers->NumThreads(); + + Status compute_status = ::tensorflow::Status(); + auto c_lock = tensorflow::mutex(); auto DoWork = [&](int start, int end) { int old_batch_index = -2; int cur_batch_index = -1; @@ -209,6 +243,13 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { StateSpace ss = StateSpace(tfq_for); auto sv = ss.Create(largest_nq); auto scratch = ss.Create(largest_nq); + + int n_random = largest_sum * output_dim_op_size * fused_circuits.size(); + n_random /= num_threads; + n_random += 1; + auto local_gen = random_gen_.ReserveSamples32(n_random); + tensorflow::random::SimplePhilox rand_source(&local_gen); + for (int i = start; i < end; i++) { cur_batch_index = i / output_dim_op_size; cur_op_index = i % output_dim_op_size; @@ -232,17 +273,20 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { // no need to update scratch_state since ComputeExpectation // will take care of things for us. ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[cur_batch_index].size(); j++) { + for (size_t j = 0; j < fused_circuits[cur_batch_index].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[cur_batch_index][j], sv); } } float exp_v = 0.0; - OP_REQUIRES_OK( - context, + NESTED_FN_STATUS_SYNC( + compute_status, ComputeSampledExpectationQsim( pauli_sums[cur_batch_index][cur_op_index], sim, ss, sv, scratch, - num_samples[cur_batch_index][cur_op_index], &exp_v)); + num_samples[cur_batch_index][cur_op_index], rand_source, + &exp_v), + c_lock); + (*output_tensor)(cur_batch_index, cur_op_index) = exp_v; old_batch_index = cur_batch_index; } @@ -252,6 +296,7 @@ class TfqSimulateSampledExpectationOp : public tensorflow::OpKernel { 200 * (int64_t(1) << static_cast(max_num_qubits)); context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( fused_circuits.size() * output_dim_op_size, num_cycles, DoWork); + OP_REQUIRES_OK(context, compute_status); } }; @@ -265,7 +310,10 @@ REGISTER_OP("TfqSimulateSampledExpectation") .Input("symbol_values: float") .Input("pauli_sums: string") .Input("num_samples: int32") + .SetIsStateful() .Output("expectations: float") + .Attr("seed: int = 0") + .Attr("seed2: int = 0") .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { tensorflow::shape_inference::ShapeHandle programs_shape; TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); @@ -288,7 +336,7 @@ REGISTER_OP("TfqSimulateSampledExpectation") c->Dim(pauli_sums_shape, 1); c->set_output(0, c->Matrix(output_rows, output_cols)); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc new file mode 100644 index 000000000..5d4300fc5 --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_sampled_expectation_op_cuquantum.cu.cc @@ -0,0 +1,256 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include +#include +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/simmux_gpu.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/platform/mutex.h" +#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 ::tensorflow::Status; +using ::tfq::proto::PauliSum; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateSampledExpectationOpCuQuantum : public tensorflow::OpKernel { + public: + explicit TfqSimulateSampledExpectationOpCuQuantum( + tensorflow::OpKernelConstruction* context) + : OpKernel(context) { + OP_REQUIRES_OK(context, random_gen_.Init(context)); + // Allocates handlers for initialization. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } + + ~TfqSimulateSampledExpectationOpCuQuantum() { + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + const int num_inputs = context->num_inputs(); + OP_REQUIRES(context, num_inputs == 5, + tensorflow::errors::InvalidArgument(absl::StrCat( + "Expected 5 inputs, got ", num_inputs, " inputs."))); + + // Create the output Tensor. + const int output_dim_batch_size = context->input(0).dim_size(0); + const int output_dim_op_size = context->input(3).dim_size(1); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_batch_size); + output_shape.AddDim(output_dim_op_size); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->matrix(); + + std::vector programs; + std::vector num_qubits; + std::vector> pauli_sums; + OP_REQUIRES_OK(context, GetProgramsAndNumQubits(context, &programs, + &num_qubits, &pauli_sums)); + + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + + OP_REQUIRES(context, programs.size() == maps.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and symbol_values do not match. Got ", + programs.size(), " circuits and ", maps.size(), + " symbol values."))); + + std::vector> num_samples; + OP_REQUIRES_OK(context, GetNumSamples(context, &num_samples)); + + OP_REQUIRES(context, num_samples.size() == pauli_sums.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Dimension 0 of num_samples and pauli_sums do not match.", + "Got ", num_samples.size(), " lists of sample sizes and ", + pauli_sums.size(), " lists of pauli sums."))); + + OP_REQUIRES( + context, context->input(4).dim_size(1) == context->input(3).dim_size(1), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Dimension 1 of num_samples and pauli_sums do not match.", "Got ", + context->input(4).dim_size(1), " lists of sample sizes and ", + context->input(3).dim_size(1), " lists of pauli sums."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> fused_circuits( + programs.size(), std::vector>({})); + + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + ComputeLarge(num_qubits, fused_circuits, pauli_sums, num_samples, context, + &output_tensor); + } + + private: + cublasHandle_t cublas_handle_; + custatevecHandle_t custatevec_handle_; + tensorflow::GuardedPhiloxRandom random_gen_; + + void ComputeLarge( + const std::vector& num_qubits, + const std::vector>>& fused_circuits, + const std::vector>& pauli_sums, + const std::vector>& num_samples, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Matrix* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + auto scratch = ss.Create(largest_nq); + + int largest_sum = 0; + for (const auto& sums : pauli_sums) { + for (const auto& sum : sums) { + largest_sum = std::max(largest_sum, sum.terms().size()); + } + } + // If empty tensor is fed, just return. + if (fused_circuits.size() == 0) return; + + auto local_gen = random_gen_.ReserveSamples32( + largest_sum * pauli_sums[0].size() * fused_circuits.size() + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as necessary. + for (size_t i = 0; i < fused_circuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + scratch = ss.Create(largest_nq); + } + // TODO: add heuristic here so that we do not always recompute + // the state if there is a possibility that circuit[i] and + // circuit[i + 1] produce the same state. + ss.SetStateZero(sv); + for (size_t j = 0; j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + for (size_t j = 0; j < pauli_sums[i].size(); j++) { + // (#679) Just ignore empty program + if (fused_circuits[i].size() == 0) { + (*output_tensor)(i, j) = -2.0; + continue; + } + float exp_v = 0.0; + OP_REQUIRES_OK(context, ComputeSampledExpectationQsim( + pauli_sums[i][j], sim, ss, sv, scratch, + num_samples[i][j], rand_source, &exp_v)); + (*output_tensor)(i, j) = exp_v; + } + } + } +}; + +REGISTER_KERNEL_BUILDER(Name("TfqSimulateSampledExpectationCuquantum") + .Device(tensorflow::DEVICE_CPU), + TfqSimulateSampledExpectationOpCuQuantum); + +REGISTER_OP("TfqSimulateSampledExpectationCuquantum") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("pauli_sums: string") + .Input("num_samples: int32") + .SetIsStateful() + .Output("expectations: float") + .Attr("seed: int = 0") + .Attr("seed2: int = 0") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle pauli_sums_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 2, &pauli_sums_shape)); + + tensorflow::shape_inference::ShapeHandle num_samples_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(4), 2, &num_samples_shape)); + + tensorflow::shape_inference::DimensionHandle output_rows = + c->Dim(programs_shape, 0); + tensorflow::shape_inference::DimensionHandle output_cols = + c->Dim(pauli_sums_shape, 1); + c->set_output(0, c->Matrix(output_rows, output_cols)); + + return ::tensorflow::Status(); + }); + +} // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc index 325dda8d1..a5918ba27 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op.cc @@ -22,21 +22,25 @@ 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" #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/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/platform/mutex.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 QsimGate; typedef qsim::Circuit QsimCircuit; @@ -44,7 +48,9 @@ typedef qsim::Circuit QsimCircuit; class TfqSimulateSamplesOp : public tensorflow::OpKernel { public: explicit TfqSimulateSamplesOp(tensorflow::OpKernelConstruction* context) - : OpKernel(context) {} + : OpKernel(context) { + OP_REQUIRES_OK(context, random_gen_.Init(context)); + } void Compute(tensorflow::OpKernelContext* context) override { // TODO (mbbrough): add more dimension checks for other inputs here. @@ -73,17 +79,21 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { std::vector>> fused_circuits( programs.size(), std::vector>({})); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); auto construct_f = [&](int start, int end) { for (int i = start; i < end; i++) { - OP_REQUIRES_OK(context, QsimCircuitFromProgram( - programs[i], maps[i], num_qubits[i], - &qsim_circuits[i], &fused_circuits[i])); + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); } }; const int num_cycles = 1000; context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); // Find largest circuit for tensor size padding and allocate // the output tensor. @@ -102,6 +112,10 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); auto output_tensor = output->tensor(); + if (num_samples == 0) { + return; // bug in qsim dependency we can't control. + } + // Cross reference with standard google cloud compute instances // Memory ~= 2 * num_threads * (2 * 64 * 2 ** num_qubits in circuits) // e2s2 = 2 CPU, 8GB -> Can safely do 25 since Memory = 4GB @@ -117,6 +131,8 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { } private: + tensorflow::GuardedPhiloxRandom random_gen_; + void ComputeLarge( const std::vector& num_qubits, const int max_num_qubits, const int num_samples, @@ -134,10 +150,13 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { StateSpace ss = StateSpace(tfq_for); auto sv = ss.Create(largest_nq); + auto local_gen = random_gen_.ReserveSamples32(fused_circuits.size() + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a // a larger circuit we will grow the Statevector as nescessary. - for (int i = 0; i < fused_circuits.size(); i++) { + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -146,11 +165,11 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { sv = ss.Create(largest_nq); } ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } - auto samples = ss.Sample(sv, num_samples, rand() % 123456); + auto samples = ss.Sample(sv, num_samples, rand_source.Rand32()); for (int j = 0; j < num_samples; j++) { uint64_t q_ind = 0; uint64_t mask = 1; @@ -186,6 +205,10 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { Simulator sim = Simulator(tfq_for); StateSpace ss = StateSpace(tfq_for); auto sv = ss.Create(largest_nq); + + auto local_gen = random_gen_.ReserveSamples32(fused_circuits.size() + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + for (int i = start; i < end; i++) { int nq = num_qubits[i]; @@ -195,11 +218,11 @@ class TfqSimulateSamplesOp : public tensorflow::OpKernel { sv = ss.Create(largest_nq); } ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } - auto samples = ss.Sample(sv, num_samples, rand() % 123456); + auto samples = ss.Sample(sv, num_samples, rand_source.Rand32()); for (int j = 0; j < num_samples; j++) { uint64_t q_ind = 0; uint64_t mask = 1; @@ -236,7 +259,10 @@ REGISTER_OP("TfqSimulateSamples") .Input("symbol_names: string") .Input("symbol_values: float") .Input("num_samples: int32") + .SetIsStateful() .Output("samples: int8") + .Attr("seed: int = 0") + .Attr("seed2: int = 0") .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { tensorflow::shape_inference::ShapeHandle programs_shape; TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); @@ -257,7 +283,7 @@ REGISTER_OP("TfqSimulateSamples") tensorflow::shape_inference::InferenceContext::kUnknownDim, tensorflow::shape_inference::InferenceContext::kUnknownDim})); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc new file mode 100644 index 000000000..3c4d8666c --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_samples_op_cuquantum.cu.cc @@ -0,0 +1,232 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include +#include + +#include +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/simmux_gpu.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/core/threadpool.h" +#include "tensorflow/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/platform/mutex.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 ::tensorflow::Status; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateSamplesOpCuQuantum : public tensorflow::OpKernel { + public: + explicit TfqSimulateSamplesOpCuQuantum( + tensorflow::OpKernelConstruction* context) + : OpKernel(context) { + OP_REQUIRES_OK(context, random_gen_.Init(context)); + // Allocates handlers for initialization. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } + + ~TfqSimulateSamplesOpCuQuantum() { + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + DCHECK_EQ(4, context->num_inputs()); + + // Parse to Program Proto and num_qubits. + std::vector programs; + std::vector num_qubits; + OP_REQUIRES_OK(context, + GetProgramsAndNumQubits(context, &programs, &num_qubits)); + + // Parse symbol maps for parameter resolution in the circuits. + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + OP_REQUIRES( + context, maps.size() == programs.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and values do not match. Got ", programs.size(), + " circuits and ", maps.size(), " values."))); + + int num_samples = 0; + OP_REQUIRES_OK(context, GetIndividualSample(context, &num_samples)); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> fused_circuits( + programs.size(), std::vector>({})); + + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + // Find largest circuit for tensor size padding and allocate + // the output tensor. + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + const int output_dim_size = maps.size(); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_size); + output_shape.AddDim(num_samples); + output_shape.AddDim(max_num_qubits); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + auto output_tensor = output->tensor(); + + if (num_samples == 0) { + return; // bug in qsim dependency we can't control. + } + + ComputeLarge(num_qubits, max_num_qubits, num_samples, fused_circuits, + context, &output_tensor); + } + + private: + cublasHandle_t cublas_handle_; + custatevecHandle_t custatevec_handle_; + tensorflow::GuardedPhiloxRandom random_gen_; + + void ComputeLarge( + const std::vector& num_qubits, const int max_num_qubits, + const int num_samples, + const std::vector>>& fused_circuits, + tensorflow::OpKernelContext* context, + tensorflow::TTypes::Tensor* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + // Begin simulation. + int largest_nq = 1; + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + auto sv = ss.Create(largest_nq); + + auto local_gen = random_gen_.ReserveSamples32(fused_circuits.size() + 1); + tensorflow::random::SimplePhilox rand_source(&local_gen); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as nescessary. + for (size_t i = 0; i < fused_circuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + } + ss.SetStateZero(sv); + for (size_t j = 0; j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + + auto samples = ss.Sample(sv, num_samples, rand_source.Rand32()); + for (int j = 0; j < num_samples; j++) { + uint64_t q_ind = 0; + uint64_t mask = 1; + bool val = 0; + while (q_ind < nq) { + val = samples[j] & mask; + (*output_tensor)( + i, j, static_cast(max_num_qubits - q_ind - 1)) = val; + q_ind++; + mask <<= 1; + } + while (q_ind < max_num_qubits) { + (*output_tensor)( + i, j, static_cast(max_num_qubits - q_ind - 1)) = -2; + q_ind++; + } + } + } + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqSimulateSamplesCuquantum").Device(tensorflow::DEVICE_CPU), + TfqSimulateSamplesOpCuQuantum); + +REGISTER_OP("TfqSimulateSamplesCuquantum") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Input("num_samples: int32") + .SetIsStateful() + .Output("samples: int8") + .Attr("seed: int = 0") + .Attr("seed2: int = 0") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + tensorflow::shape_inference::ShapeHandle num_samples_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(3), 1, &num_samples_shape)); + + // [batch_size, n_samples, largest_n_qubits] + c->set_output( + 0, c->MakeShape( + {c->Dim(programs_shape, 0), + tensorflow::shape_inference::InferenceContext::kUnknownDim, + tensorflow::shape_inference::InferenceContext::kUnknownDim})); + + return ::tensorflow::Status(); + }); + +} // namespace tfq \ No newline at end of file diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc index da4fddb03..833deb965 100644 --- a/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op.cc @@ -20,21 +20,22 @@ 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" #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/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 QsimGate; typedef qsim::Circuit QsimCircuit; @@ -68,17 +69,21 @@ class TfqSimulateStateOp : public tensorflow::OpKernel { std::vector>> fused_circuits( programs.size(), std::vector>({})); + Status parse_status = ::tensorflow::Status(); + auto p_lock = tensorflow::mutex(); auto construct_f = [&](int start, int end) { for (int i = start; i < end; i++) { - OP_REQUIRES_OK(context, QsimCircuitFromProgram( - programs[i], maps[i], num_qubits[i], - &qsim_circuits[i], &fused_circuits[i])); + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); } }; const int num_cycles = 1000; context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); // Find largest circuit for tensor size padding and allocate // the output tensor. @@ -130,8 +135,8 @@ class TfqSimulateStateOp : public tensorflow::OpKernel { // Simulate programs one by one. Parallelizing over state vectors // we no longer parallelize over circuits. Each time we encounter a - // a larger circuit we will grow the Statevector as nescessary. - for (int i = 0; i < fused_circuits.size(); i++) { + // a larger circuit we will grow the Statevector as necessary. + for (size_t i = 0; i < fused_circuits.size(); i++) { int nq = num_qubits[i]; if (nq > largest_nq) { @@ -140,7 +145,7 @@ class TfqSimulateStateOp : public tensorflow::OpKernel { sv = ss.Create(largest_nq); } ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } @@ -189,7 +194,7 @@ class TfqSimulateStateOp : public tensorflow::OpKernel { sv = ss.Create(largest_nq); } ss.SetStateZero(sv); - for (int j = 0; j < fused_circuits[i].size(); j++) { + for (size_t j = 0; j < fused_circuits[i].size(); j++) { qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); } @@ -233,7 +238,7 @@ REGISTER_OP("TfqSimulateState") {c->Dim(programs_shape, 0), tensorflow::shape_inference::InferenceContext::kUnknownDim})); - return tensorflow::Status::OK(); + return ::tensorflow::Status(); }); } // namespace tfq diff --git a/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc new file mode 100644 index 000000000..0ad5feb2d --- /dev/null +++ b/tensorflow_quantum/core/ops/tfq_simulate_state_op_cuquantum.cu.cc @@ -0,0 +1,217 @@ +/* Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include + +#include +#include +#include + +#include "../qsim/lib/circuit.h" +#include "../qsim/lib/gate_appl.h" +#include "../qsim/lib/gates_cirq.h" +#include "../qsim/lib/simmux_gpu.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/error_codes.pb.h" +#include "tensorflow/core/lib/core/status.h" +#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 ::tensorflow::Status; +using ::tfq::proto::Program; + +typedef qsim::Cirq::GateCirq QsimGate; +typedef qsim::Circuit QsimCircuit; + +class TfqSimulateStateOpCuQuantum : public tensorflow::OpKernel { + public: + explicit TfqSimulateStateOpCuQuantum( + tensorflow::OpKernelConstruction* context) + : OpKernel(context) { + // Allocates handlers for initialization. + cublasCreate(&cublas_handle_); + custatevecCreate(&custatevec_handle_); + } + + ~TfqSimulateStateOpCuQuantum() { + // Destroys handlers in sync with simulator lifetime. + cublasDestroy(cublas_handle_); + custatevecDestroy(custatevec_handle_); + } + + void Compute(tensorflow::OpKernelContext* context) override { + // TODO (mbbrough): add more dimension checks for other inputs here. + DCHECK_EQ(3, context->num_inputs()); + + // Parse to Program Proto and num_qubits. + std::vector programs; + std::vector num_qubits; + OP_REQUIRES_OK(context, + GetProgramsAndNumQubits(context, &programs, &num_qubits)); + + // Parse symbol maps for parameter resolution in the circuits. + std::vector maps; + OP_REQUIRES_OK(context, GetSymbolMaps(context, &maps)); + OP_REQUIRES( + context, maps.size() == programs.size(), + tensorflow::errors::InvalidArgument(absl::StrCat( + "Number of circuits and values do not match. Got ", programs.size(), + " circuits and ", maps.size(), " values."))); + + // Construct qsim circuits. + std::vector qsim_circuits(programs.size(), QsimCircuit()); + std::vector>> fused_circuits( + programs.size(), std::vector>({})); + + Status parse_status = Status::OK(); + auto p_lock = tensorflow::mutex(); + auto construct_f = [&](int start, int end) { + for (int i = start; i < end; i++) { + Status local = + QsimCircuitFromProgram(programs[i], maps[i], num_qubits[i], + &qsim_circuits[i], &fused_circuits[i]); + NESTED_FN_STATUS_SYNC(parse_status, local, p_lock); + } + }; + + const int num_cycles = 1000; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + programs.size(), num_cycles, construct_f); + OP_REQUIRES_OK(context, parse_status); + + // Find largest circuit for tensor size padding and allocate + // the output tensor. + int max_num_qubits = 0; + for (const int num : num_qubits) { + max_num_qubits = std::max(max_num_qubits, num); + } + + const int output_dim_size = maps.size(); + tensorflow::TensorShape output_shape; + output_shape.AddDim(output_dim_size); + output_shape.AddDim(1 << max_num_qubits); + + tensorflow::Tensor* output = nullptr; + OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); + tensorflow::TTypes, 1>::Matrix output_tensor = + output->matrix>(); + + ComputeLarge(num_qubits, max_num_qubits, fused_circuits, context, + &output_tensor); + } + + private: + cublasHandle_t cublas_handle_; + custatevecHandle_t custatevec_handle_; + + void ComputeLarge( + const std::vector& num_qubits, const int max_num_qubits, + const std::vector>>& fused_circuits, + tensorflow::OpKernelContext* context, + tensorflow::TTypes, 1>::Matrix* output_tensor) { + // Instantiate qsim objects. + using Simulator = qsim::SimulatorCuStateVec; + using StateSpace = Simulator::StateSpace; + + // Begin simulation. + Simulator sim = Simulator(cublas_handle_, custatevec_handle_); + StateSpace ss = StateSpace(cublas_handle_, custatevec_handle_); + // Begin simulation. + int largest_nq = 1; + auto sv = ss.Create(largest_nq); + std::vector sv_host; + sv_host.resize(2 * (uint64_t(1) << largest_nq)); + + // Simulate programs one by one. Parallelizing over state vectors + // we no longer parallelize over circuits. Each time we encounter a + // a larger circuit we will grow the Statevector as necessary. + for (size_t i = 0; i < fused_circuits.size(); i++) { + int nq = num_qubits[i]; + + if (nq > largest_nq) { + // need to switch to larger statespace. + largest_nq = nq; + sv = ss.Create(largest_nq); + sv_host.resize(2 * (uint64_t(1) << largest_nq)); + } + ss.SetStateZero(sv); + for (size_t j = 0; j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], sv); + } + + // Copy the whole GPU data to CPU memory once. + // Please don't use ss.GetAmpl(), because it copies amplitude + // one-by-one, which makes huge speed slowdown, even slower than CPU op. + ss.Copy(sv, sv_host.data()); + // Parallel copy state vector information from qsim into tensorflow + // tensors. We need type conversions from 2 floats to std::complex. + auto copy_f = [i, nq, max_num_qubits, &output_tensor, &sv_host]( + uint64_t start, uint64_t end) { + uint64_t crossover = uint64_t(1) << nq; + uint64_t upper = std::min(end, crossover); + + if (start < crossover) { + for (uint64_t j = 0; j < upper; j++) { + (*output_tensor)(i, j) = + std::complex(sv_host[2 * j], sv_host[2 * j + 1]); + } + } + for (uint64_t j = upper; j < end; j++) { + (*output_tensor)(i, j) = std::complex(-2, 0); + } + }; + const int num_cycles_copy = 50; + context->device()->tensorflow_cpu_worker_threads()->workers->ParallelFor( + uint64_t(1) << max_num_qubits, num_cycles_copy, copy_f); + } + } +}; + +REGISTER_KERNEL_BUILDER( + Name("TfqSimulateStateCuquantum").Device(tensorflow::DEVICE_CPU), + TfqSimulateStateOpCuQuantum); + +REGISTER_OP("TfqSimulateStateCuquantum") + .Input("programs: string") + .Input("symbol_names: string") + .Input("symbol_values: float") + .Output("state_vector: complex64") + .SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) { + tensorflow::shape_inference::ShapeHandle programs_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_names_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(1), 1, &symbol_names_shape)); + + tensorflow::shape_inference::ShapeHandle symbol_values_shape; + TF_RETURN_IF_ERROR(c->WithRank(c->input(2), 2, &symbol_values_shape)); + + c->set_output( + 0, c->MakeShape( + {c->Dim(programs_shape, 0), + tensorflow::shape_inference::InferenceContext::kUnknownDim})); + + return ::tensorflow::Status(); + }); + +} // namespace tfq \ No newline at end of file diff --git a/tensorflow_quantum/core/ops/tfq_unitary_op.py b/tensorflow_quantum/core/ops/tfq_unitary_op.py index 5db7005db..775516896 100644 --- a/tensorflow_quantum/core/ops/tfq_unitary_op.py +++ b/tensorflow_quantum/core/ops/tfq_unitary_op.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to register python op gradient.""" import tensorflow as tf from tensorflow_quantum.core.ops import tfq_utility_ops diff --git a/tensorflow_quantum/core/ops/tfq_unitary_op_test.py b/tensorflow_quantum/core/ops/tfq_unitary_op_test.py index 615068285..04f8c576a 100644 --- a/tensorflow_quantum/core/ops/tfq_unitary_op_test.py +++ b/tensorflow_quantum/core/ops/tfq_unitary_op_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests that specifically target tfq_unitary_op.""" +# 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 + import numpy as np from absl.testing import parameterized import tensorflow as tf @@ -102,6 +110,14 @@ def test_calculate_unitary_inputs(self): unitary_op(util.convert_to_tensor(circuit_batch), symbol_names, symbol_values_array, []) + with self.assertRaisesRegex(tf.errors.InvalidArgumentError, + expected_regex='cirq.Channel'): + # attempting to use noisy circuit. + noisy_circuit = cirq.Circuit(cirq.depolarize(0.3).on_each(*qubits)) + unitary_op( + util.convert_to_tensor([noisy_circuit for _ in circuit_batch]), + symbol_names, symbol_values_array) + @parameterized.parameters([ { 'all_n_qubits': [2, 3] @@ -136,6 +152,15 @@ def test_calculate_unitary_empty(self): self.assertAllClose(tfq_empty_u, [empty_u], atol=1e-5) # wrap in batch. + def test_calculate_unitary_no_circuit(self): + """Ensure calculate_unitary is consistent with no circuits.""" + unitary_op = tfq_unitary_op.get_unitary_op() + no_circuit = tf.raw_ops.Empty(shape=(0,), dtype=tf.string) + empty_values = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + tfq_empty_u = unitary_op(no_circuit, [], empty_values) + expected_shape = tf.TensorShape([0, None, None]) + self.assertEqual(tfq_empty_u.shape.as_list(), expected_shape.as_list()) + @parameterized.parameters([{ 'n_qubits': 6, 'unitary_op': tfq_unitary_op.get_unitary_op(True) @@ -153,7 +178,7 @@ def test_calculate_unitary_consistency_symbol_free(self, n_qubits, unitary_op): """Test calculate_unitary works without symbols.""" unitary_op = tfq_unitary_op.get_unitary_op() - qubits = cirq.GridQubit.rect(1, n_qubits) + qubits = cirq.LineQubit.range(n_qubits) circuit_batch, _ = util.random_circuit_resolver_batch(qubits, 25) tfq_results = unitary_op(util.convert_to_tensor(circuit_batch), [], diff --git a/tensorflow_quantum/core/ops/tfq_utility_ops.py b/tensorflow_quantum/core/ops/tfq_utility_ops.py index e560f579c..2d0d45def 100644 --- a/tensorflow_quantum/core/ops/tfq_utility_ops.py +++ b/tensorflow_quantum/core/ops/tfq_utility_ops.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Expose bindings for tfq utility ops.""" import tensorflow as tf from tensorflow_quantum.core.ops.load_module import load_module diff --git a/tensorflow_quantum/core/ops/tfq_utility_ops_test.py b/tensorflow_quantum/core/ops/tfq_utility_ops_test.py index bc743ae14..806437176 100644 --- a/tensorflow_quantum/core/ops/tfq_utility_ops_test.py +++ b/tensorflow_quantum/core/ops/tfq_utility_ops_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for tfq utility ops.""" +# 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 + import numpy as np import sympy import tensorflow as tf @@ -75,7 +83,7 @@ def test_append_input_checking(self): # These tests really just makes sure we can cast output res = tfq_utility_ops.append_circuit([], []) - self.assertDTypeEqual(res.numpy().astype(np.str), np.dtype(' args = 2; + + // Which qubits the operation acts on. + repeated Qubit qubits = 3; +} + +// The instruction identifying the action taken on the quantum computer. +message Gate { + // Name for the Gate. + // + // These names must match those specified in the gate set. This is found + // in cirq/google/gate_sets.py. + string id = 1; +} + +// An identifier for a qubit. +message Qubit { + // Id of the qubit. These depend on the device being scheduled upon. + // + // Typically ids for qubits on a line are simple string versions of integers, + // while for qubits on a square grid these are integers separated by a + // underscore, i.e. '0_1', '1_2', etc. + string id = 2; +} + +// Arguments needed to specify a gate. +message Arg { + // Arguments are either a number, a symbol, or an argument function + // (which recursively depends on Arg). + // + // ArgValue is used to specify an argument that does not vary + // depending on RunContext. + // + // Symbol is used when an argument will be resolved (supplied a value) + // by a Run Context. + // + // Functions are used to define a simple s-expression tree describing + // how to combine numbers and symbols mathematically. + oneof arg { + ArgValue arg_value = 1; + string symbol = 2; + ArgFunction func = 3; + } +} + +// Value that can be passed as an argument to a gate. +message ArgValue { + oneof arg_value { + float float_value = 1; + RepeatedBoolean bool_values = 2; + string string_value = 3; + double double_value = 4; + } +} + +// A repeated boolean value. +message RepeatedBoolean { + repeated bool values = 1; +} + +// A function of arguments. This is an s-expression tree representing +// mathematically the function being evaluated. +// +// What language is supported is specified by the arg_function_language +// in the language message. +message ArgFunction { + // The name of the function. I.e. if the function is the sum of two symbols, + // this could be '+', and the args would be two string symbol values. + // + // Valid values for the type are given in cirq/google/arg_func_langs.py + // and must be consistent with the arg_function_language specified in the + // language field of the program. + string type = 1; + + // The arguments to the function. + repeated Arg args = 2; +} \ No newline at end of file diff --git a/tensorflow_quantum/core/proto/projector_sum.proto b/tensorflow_quantum/core/proto/projector_sum.proto new file mode 100644 index 000000000..d51df1467 --- /dev/null +++ b/tensorflow_quantum/core/proto/projector_sum.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +package tfq.proto; + +// Store the sum of simpler terms. +message ProjectorSum { + repeated ProjectorTerm terms = 1; +} + +// Store a term which is a coefficient and the qubits of the projection. +message ProjectorTerm { + float coefficient_real = 1; + float coefficient_imag = 2; + repeated ProjectorDictEntry projector_dict = 3; +} + +// Store a single projection. +message ProjectorDictEntry { + string qubit_id = 1; + // False means |0> and true means |1>. + bool basis_state = 2; +} + diff --git a/tensorflow_quantum/core/serialize/BUILD b/tensorflow_quantum/core/serialize/BUILD index 7c12ed7ff..fa28d20e6 100644 --- a/tensorflow_quantum/core/serialize/BUILD +++ b/tensorflow_quantum/core/serialize/BUILD @@ -5,11 +5,84 @@ licenses(["notice"]) # Export for the PIP package. exports_files(["__init__.py"]) +py_library( + name = "serialize", + srcs = ["__init__.py"], + srcs_version = "PY3", + deps = [":serializer"], +) + +py_library( + name = "op_serializer", + srcs = ["op_serializer.py"], + srcs_version = "PY3", + deps = [ + "//tensorflow_quantum/core/proto:program_py_proto" + ], +) + +py_test( + name = "op_serializer_test", + srcs = ["op_serializer_test.py"], + srcs_version = "PY3", + deps = [ + ":op_serializer", + "//tensorflow_quantum/core/proto:program_py_proto", + ], +) + +py_library( + name = "op_deserializer", + srcs = ["op_deserializer.py"], + srcs_version = "PY3", + deps = [ + "//tensorflow_quantum/core/proto:program_py_proto" + ], +) + +py_test( + name = "op_deserializer_test", + srcs = ["op_deserializer_test.py"], + srcs_version = "PY3", + deps = [ + ":op_deserializer", + "//tensorflow_quantum/core/proto:program_py_proto" + ], +) + +py_library( + name = "serializable_gate_set", + srcs = ["serializable_gate_set.py"], + srcs_version = "PY3", + deps = [ + "//tensorflow_quantum/core/proto:program_py_proto" + ], +) + +py_test( + name = "serializable_gate_set_test", + srcs = ["serializable_gate_set_test.py"], + srcs_version = "PY3", + deps = [ + ":op_serializer", + ":op_deserializer", + ":serializable_gate_set", + "//tensorflow_quantum/core/proto:program_py_proto" + ], +) + py_library( name = "serializer", srcs = ["serializer.py"], + srcs_version = "PY3", deps = [ + # cirq proto + ":op_serializer", + ":op_deserializer", + ":serializable_gate_set", "//tensorflow_quantum/core/proto:pauli_sum_py_proto", + "//tensorflow_quantum/core/proto:program_py_proto", + "//tensorflow_quantum/core/proto:projector_sum_py_proto", ], ) @@ -19,5 +92,8 @@ py_test( python_version = "PY3", deps = [ ":serializer", + # cirq proto + "//tensorflow_quantum/core/proto:pauli_sum_py_proto", + "//tensorflow_quantum/core/proto:projector_sum_py_proto", ], ) diff --git a/tensorflow_quantum/core/serialize/__init__.py b/tensorflow_quantum/core/serialize/__init__.py index 6ee678723..eebbe0156 100644 --- a/tensorflow_quantum/core/serialize/__init__.py +++ b/tensorflow_quantum/core/serialize/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.core.serialize.*""" from tensorflow_quantum.core.serialize.serializer import (serialize_circuit, deserialize_circuit, diff --git a/tensorflow_quantum/core/serialize/op_deserializer.py b/tensorflow_quantum/core/serialize/op_deserializer.py new file mode 100644 index 000000000..667ee0ef0 --- /dev/null +++ b/tensorflow_quantum/core/serialize/op_deserializer.py @@ -0,0 +1,243 @@ +# Copyright 2019 The Cirq Developers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Adaption of op_deserializer.py from Cirq 0.9.0.""" + +import re +import math +import sympy +import cirq + +GRID_QUBIT_ID_PATTERN = r'^q?(-?\d+)_(-?\d+)$' +LINE_QUBIT_ID_PATTERN = r'^q?(-?\d+)$' +SUPPORTED_FUNCTIONS_FOR_LANGUAGE = { + '': frozenset(), + 'linear': frozenset({'add', 'mul'}), + 'exp': frozenset({'add', 'mul', 'pow'}), + # None means any. Is used when inferring the language during serialization. + None: frozenset({'add', 'mul', 'pow'}), +} + + +def qubit_from_proto(proto_id): + """Parse a proto id to a `cirq.GridQubit`. + Proto ids for grid qubits are of the form `{row}_{col}` where `{row}` is + the integer row of the grid qubit, and `{col}` is the integer column of + the qubit. + Args: + proto_id: The id to convert. + Returns: + A `cirq.GridQubit` corresponding to the proto id. + Raises: + ValueError: If the string not of the correct format. + """ + + match = re.match(GRID_QUBIT_ID_PATTERN, proto_id) + if match is not None: + row, col = match.groups() + return cirq.GridQubit(row=int(row), col=int(col)) + + match = re.match(LINE_QUBIT_ID_PATTERN, proto_id) + if match is not None: + x, = match.groups() + return cirq.LineQubit(int(x)) + + raise ValueError('Expected GridQubit proto w/ form [q]_,' + f' or LineQubit w/ form [q] got {proto_id}') + + +def _arg_from_proto( + arg_proto, + *, + arg_function_language, + required_arg_name=None, +): + """Extracts a python value from an argument value proto. + Args: + arg_proto: The proto containing a serialized value. + arg_function_language: The `arg_function_language` field from + `Program.Language`. + required_arg_name: If set to `None`, the method will return `None` when + given an unset proto value. If set to a string, the method will + instead raise an error complaining that the value is missing in that + situation. + Returns: + The deserialized value, or else None if there was no set value and + `required_arg_name` was set to `None`. + """ + supported = SUPPORTED_FUNCTIONS_FOR_LANGUAGE.get(arg_function_language) + if supported is None: + raise ValueError(f'Unrecognized arg_function_language: ' + f'{arg_function_language!r}') + + which = arg_proto.WhichOneof('arg') + if which == 'arg_value': + arg_value = arg_proto.arg_value + which_val = arg_value.WhichOneof('arg_value') + if which_val == 'float_value' or which_val == 'double_value': + if which_val == 'double_value': + result = float(arg_value.double_value) + else: + result = float(arg_value.float_value) + if math.ceil(result) == math.floor(result): + result = int(result) + return result + if which_val == 'bool_values': + return list(arg_value.bool_values.values) + if which_val == 'string_value': + return str(arg_value.string_value) + raise ValueError(f'Unrecognized value type: {which_val!r}') + + if which == 'symbol': + return sympy.Symbol(arg_proto.symbol) + + if which == 'func': + func = arg_proto.func + + if func.type not in supported: + raise ValueError( + f'Unrecognized function type {func.type!r} ' + f'for arg_function_language={arg_function_language!r}') + + if func.type == 'add': + return sympy.Add(*[ + _arg_from_proto(a, + arg_function_language=arg_function_language, + required_arg_name='An addition argument') + for a in func.args + ]) + + if func.type == 'mul': + return sympy.Mul(*[ + _arg_from_proto(a, + arg_function_language=arg_function_language, + required_arg_name='A multiplication argument') + for a in func.args + ]) + + if func.type == 'pow': + return sympy.Pow(*[ + _arg_from_proto(a, + arg_function_language=arg_function_language, + required_arg_name='A power argument') + for a in func.args + ]) + + if required_arg_name is not None: + raise ValueError( + f'{required_arg_name} is missing or has an unrecognized ' + f'argument type (WhichOneof("arg")={which!r}).') + + return None + + +class DeserializingArg: + """Specification of the arguments to deserialize an argument to a gate. + + Args: + serialized_name: The serialized name of the gate that is being + deserialized. + constructor_arg_name: The name of the argument in the constructor of + the gate corresponding to this serialized argument. + value_func: Sometimes a value from the serialized proto needs to + converted to an appropriate type or form. This function takes the + serialized value and returns the appropriate type. Defaults to + None. + required: Whether a value must be specified when constructing the + deserialized gate. Defaults to True. + default: default value to set if the value is not present in the + arg. If set, required is ignored. + """ + + def __init__(self, + serialized_name, + constructor_arg_name, + value_func=None, + required=True, + default=None): + self.serialized_name = serialized_name + self.constructor_arg_name = constructor_arg_name + self.value_func = value_func + self.required = required + self.default = default + + +class GateOpDeserializer: + """Describes how to deserialize a proto to a given Gate type. + + Attributes: + serialized_gate_id: The id used when serializing the gate. + """ + + def __init__(self, + serialized_gate_id, + gate_constructor, + args, + num_qubits_param=None, + op_wrapper=lambda x, y: x): + """Constructs a deserializer. + + Args: + serialized_gate_id: The serialized id of the gate that is being + deserialized. + gate_constructor: A function that produces the deserialized gate + given arguments from args. + args: A list of the arguments to be read from the serialized + gate and the information required to use this to construct + the gate using the gate_constructor above. + num_qubits_param: Some gate constructors require that the number + of qubits be passed to their constructor. This is the name + of the parameter in the constructor for this value. If None, + no number of qubits is passed to the constructor. + op_wrapper: An optional Callable to modify the resulting + GateOperation, for instance, to add tags + """ + self.serialized_gate_id = serialized_gate_id + self.gate_constructor = gate_constructor + self.args = args + self.num_qubits_param = num_qubits_param + self.op_wrapper = op_wrapper + + def from_proto(self, proto, *, arg_function_language=''): + """Turns a cirq_google.api.v2.Operation proto into a GateOperation.""" + qubits = [qubit_from_proto(q.id) for q in proto.qubits] + args = self._args_from_proto( + proto, arg_function_language=arg_function_language) + if self.num_qubits_param is not None: + args[self.num_qubits_param] = len(qubits) + gate = self.gate_constructor(**args) + return self.op_wrapper(gate.on(*qubits), proto) + + def _args_from_proto(self, proto, *, arg_function_language): + return_args = {} + for arg in self.args: + if arg.serialized_name not in proto.args: + if arg.default: + return_args[arg.constructor_arg_name] = arg.default + continue + elif arg.required: + raise ValueError( + f'Argument {arg.serialized_name} ' + 'not in deserializing args, but is required.') + + value = _arg_from_proto(proto.args[arg.serialized_name], + arg_function_language=arg_function_language, + required_arg_name=None if not arg.required + else arg.serialized_name) + + if arg.value_func is not None: + value = arg.value_func(value) + + if value is not None: + return_args[arg.constructor_arg_name] = value + return return_args diff --git a/tensorflow_quantum/core/serialize/op_deserializer_test.py b/tensorflow_quantum/core/serialize/op_deserializer_test.py new file mode 100644 index 000000000..466e32200 --- /dev/null +++ b/tensorflow_quantum/core/serialize/op_deserializer_test.py @@ -0,0 +1,425 @@ +# Copyright 2019 The Cirq Developers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Test op deserialization correctness.""" +# 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 + +from typing import List +import tensorflow as tf + +import cirq +import sympy +from absl.testing import parameterized +from google.protobuf import json_format +from tensorflow_quantum.core.proto import program_pb2 +from tensorflow_quantum.core.serialize import op_deserializer + + +def op_proto(json_dict): + """Json to proto.""" + op = program_pb2.Operation() + json_format.ParseDict(json_dict, op) + return op + + +@cirq.value_equality +class GateWithAttribute(cirq.testing.SingleQubitGate): + """GateAttribute helper class.""" + + def __init__(self, val, not_req=None): + self.val = val + self.not_req = not_req + + def _value_equality_values_(self): + return (self.val,) + + +TEST_CASES = [ + (float, 1.0, { + 'arg_value': { + 'float_value': 1.0 + } + }), + (str, 'abc', { + 'arg_value': { + 'string_value': 'abc' + } + }), + (float, 1, { + 'arg_value': { + 'float_value': 1.0 + } + }), + (List[bool], [True, False], { + 'arg_value': { + 'bool_values': { + 'values': [True, False] + } + } + }), + (sympy.Symbol, sympy.Symbol('x'), { + 'symbol': 'x' + }), + (float, sympy.Symbol('x') - sympy.Symbol('y'), { + 'func': { + 'type': + 'add', + 'args': [{ + 'symbol': 'x' + }, { + 'func': { + 'type': + 'mul', + 'args': [{ + 'arg_value': { + 'float_value': -1.0 + } + }, { + 'symbol': 'y' + }] + } + }] + } + }), +] + + +class OpDeserializerTest(tf.test.TestCase, parameterized.TestCase): + """Test OpDeserializer functionality.""" + + @parameterized.parameters([ + CASE + (x,) + for CASE in TEST_CASES + for x in [cirq.GridQubit(1, 2), cirq.LineQubit(4)] + ]) + def test_from_proto(self, val_type, val, arg_value, q): + """Test from proto under many cases.""" + deserializer = op_deserializer.GateOpDeserializer( + serialized_gate_id='my_gate', + gate_constructor=GateWithAttribute, + args=[ + op_deserializer.DeserializingArg( + serialized_name='my_val', + constructor_arg_name='val', + ) + ]) + serialized = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'my_val': arg_value + }, + 'qubits': [{ + 'id': '1_2' if isinstance(q, cirq.GridQubit) else '4' + }] + }) + result = deserializer.from_proto(serialized, + arg_function_language='linear') + self.assertEqual(result, GateWithAttribute(val)(q)) + + def test_from_proto_required_missing(self): + """Test error raised when required is missing.""" + deserializer = op_deserializer.GateOpDeserializer( + serialized_gate_id='my_gate', + gate_constructor=GateWithAttribute, + args=[ + op_deserializer.DeserializingArg( + serialized_name='my_val', + constructor_arg_name='val', + ) + ]) + serialized = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'not_my_val': { + 'arg_value': { + 'float_value': 0.125 + } + } + }, + 'qubits': [{ + 'id': '1_2' + }] + }) + with self.assertRaisesRegex(Exception, expected_regex='my_val'): + deserializer.from_proto(serialized) + + def test_from_proto_unknown_function(self): + """Unknown function throws error when deserializing.""" + deserializer = op_deserializer.GateOpDeserializer( + serialized_gate_id='my_gate', + gate_constructor=GateWithAttribute, + args=[ + op_deserializer.DeserializingArg( + serialized_name='my_val', + constructor_arg_name='val', + ) + ]) + serialized = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'my_val': { + 'func': { + 'type': + 'UNKNOWN_OPERATION', + 'args': [ + { + 'symbol': 'x' + }, + { + 'arg_value': { + 'float_value': -1.0 + } + }, + ] + } + } + }, + 'qubits': [{ + 'id': '1_2' + }] + }) + with self.assertRaisesRegex( + ValueError, expected_regex='Unrecognized function type'): + _ = deserializer.from_proto(serialized) + + def test_from_proto_value_type_not_recognized(self): + """Ensure unrecognized value type errors.""" + deserializer = op_deserializer.GateOpDeserializer( + serialized_gate_id='my_gate', + gate_constructor=GateWithAttribute, + args=[ + op_deserializer.DeserializingArg( + serialized_name='my_val', + constructor_arg_name='val', + ) + ]) + serialized = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'my_val': { + 'arg_value': {}, + } + }, + 'qubits': [{ + 'id': '1_2' + }] + }) + with self.assertRaisesRegex(ValueError, + expected_regex='Unrecognized value type'): + _ = deserializer.from_proto(serialized) + + def test_from_proto_function_argument_not_set(self): + """Ensure unset function arguments error when deserializing.""" + deserializer = op_deserializer.GateOpDeserializer( + serialized_gate_id='my_gate', + gate_constructor=GateWithAttribute, + args=[ + op_deserializer.DeserializingArg( + serialized_name='my_val', + constructor_arg_name='val', + ) + ]) + serialized = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'my_val': { + 'func': { + 'type': 'mul', + 'args': [ + { + 'symbol': 'x' + }, + {}, + ] + } + } + }, + 'qubits': [{ + 'id': '1_2' + }] + }) + with self.assertRaisesRegex( + ValueError, + expected_regex='A multiplication argument is missing'): + _ = deserializer.from_proto(serialized, + arg_function_language='linear') + + @parameterized.parameters([cirq.GridQubit(1, 2), cirq.LineQubit(4)]) + def test_from_proto_value_func(self, q): + """Test value func deserialization in simple case.""" + deserializer = op_deserializer.GateOpDeserializer( + serialized_gate_id='my_gate', + gate_constructor=GateWithAttribute, + args=[ + op_deserializer.DeserializingArg(serialized_name='my_val', + constructor_arg_name='val', + value_func=lambda x: x + 1) + ]) + serialized = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'my_val': { + 'arg_value': { + 'float_value': 0.125 + } + } + }, + 'qubits': [{ + 'id': '1_2' if isinstance(q, cirq.GridQubit) else '4' + }] + }) + result = deserializer.from_proto(serialized) + self.assertEqual(result, GateWithAttribute(1.125)(q)) + + @parameterized.parameters([cirq.GridQubit(1, 2), cirq.LineQubit(4)]) + def test_from_proto_not_required_ok(self, q): + """Deserialization succeeds for missing not required fields.""" + deserializer = op_deserializer.GateOpDeserializer( + serialized_gate_id='my_gate', + gate_constructor=GateWithAttribute, + args=[ + op_deserializer.DeserializingArg( + serialized_name='my_val', + constructor_arg_name='val', + ), + op_deserializer.DeserializingArg(serialized_name='not_req', + constructor_arg_name='not_req', + required=False) + ]) + serialized = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'my_val': { + 'arg_value': { + 'float_value': 0.125 + } + } + }, + 'qubits': [{ + 'id': '1_2' if isinstance(q, cirq.GridQubit) else '4' + }] + }) + result = deserializer.from_proto(serialized) + self.assertEqual(result, GateWithAttribute(0.125)(q)) + + def test_from_proto_missing_required_arg(self): + """Error raised when required field is missing.""" + deserializer = op_deserializer.GateOpDeserializer( + serialized_gate_id='my_gate', + gate_constructor=GateWithAttribute, + args=[ + op_deserializer.DeserializingArg( + serialized_name='my_val', + constructor_arg_name='val', + ), + op_deserializer.DeserializingArg(serialized_name='not_req', + constructor_arg_name='not_req', + required=False) + ]) + serialized = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'not_req': { + 'arg_value': { + 'float_value': 0.125 + } + } + }, + 'qubits': [{ + 'id': '1_2' + }] + }) + with self.assertRaises(ValueError): + deserializer.from_proto(serialized) + + def test_from_proto_required_arg_not_assigned(self): + """Error if required arg isn't assigned.""" + deserializer = op_deserializer.GateOpDeserializer( + serialized_gate_id='my_gate', + gate_constructor=GateWithAttribute, + args=[ + op_deserializer.DeserializingArg( + serialized_name='my_val', + constructor_arg_name='val', + ), + op_deserializer.DeserializingArg(serialized_name='not_req', + constructor_arg_name='not_req', + required=False) + ]) + serialized = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'my_val': {} + }, + 'qubits': [{ + 'id': '1_2' + }] + }) + with self.assertRaises(ValueError): + deserializer.from_proto(serialized) + + @parameterized.parameters([cirq.GridQubit(1, 2), cirq.LineQubit(4)]) + def test_defaults(self, q): + """Ensure default values still deserialize.""" + deserializer = op_deserializer.GateOpDeserializer( + serialized_gate_id='my_gate', + gate_constructor=GateWithAttribute, + args=[ + op_deserializer.DeserializingArg(serialized_name='my_val', + constructor_arg_name='val', + default=1.0), + op_deserializer.DeserializingArg(serialized_name='not_req', + constructor_arg_name='not_req', + default='hello', + required=False) + ]) + serialized = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': {}, + 'qubits': [{ + 'id': '1_2' if isinstance(q, cirq.GridQubit) else '4' + }] + }) + g = GateWithAttribute(1.0) + g.not_req = 'hello' + self.assertEqual(deserializer.from_proto(serialized), g(q)) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/serialize/op_serializer.py b/tensorflow_quantum/core/serialize/op_serializer.py new file mode 100644 index 000000000..509216def --- /dev/null +++ b/tensorflow_quantum/core/serialize/op_serializer.py @@ -0,0 +1,250 @@ +# Copyright 2019 The Cirq Developers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""op_serializer.py adapated from Cirq release 0.9.0""" + +from typing import List +import cirq +import sympy +import numpy as np +from tensorflow_quantum.core.proto import program_pb2 + +SUPPORTED_SYMPY_OPS = (sympy.Symbol, sympy.Add, sympy.Mul, sympy.Pow) + +SUPPORTED_FUNCTIONS_FOR_LANGUAGE = { + '': frozenset(), + 'linear': frozenset({'add', 'mul'}), + 'exp': frozenset({'add', 'mul', 'pow'}), + # None means any. Is used when inferring the language during serialization. + None: frozenset({'add', 'mul', 'pow'}), +} + + +def qubit_to_proto(qubit): + """Return proto representation of a GridQubit.""" + if isinstance(qubit, cirq.GridQubit): + return '{}_{}'.format(qubit.row, qubit.col) + if isinstance(qubit, cirq.LineQubit): + return '{}'.format(qubit.x) + raise ValueError('Unsupported qubit type:' + str(type(qubit))) + + +def _arg_to_proto(value, *, arg_function_language, out=None): + """Writes an argument value into an Arg proto. + Args: + value: The value to encode. + arg_function_language: The language to use when encoding functions. If + this is set to None, it will be set to the minimal language + necessary to support the features that were actually used. + out: The proto to write the result into. Defaults to a new instance. + Returns: + The proto that was written into as well as the `arg_function_language` + that was used. + """ + + if arg_function_language not in SUPPORTED_FUNCTIONS_FOR_LANGUAGE: + raise ValueError(f'Unrecognized arg_function_language: ' + f'{arg_function_language!r}') + supported = SUPPORTED_FUNCTIONS_FOR_LANGUAGE[arg_function_language] + + msg = program_pb2.Arg() if out is None else out + + def check_support(func_type: str) -> str: + if func_type not in supported: + lang = (repr(arg_function_language) + if arg_function_language is not None else '[any]') + raise ValueError(f'Function type {func_type!r} not supported by ' + f'arg_function_language {lang}') + return func_type + + if isinstance(value, (float, int, sympy.Integer, sympy.Float, + sympy.Rational, sympy.NumberSymbol)): + msg.arg_value.float_value = float(value) + elif isinstance(value, str): + msg.arg_value.string_value = value + elif (isinstance(value, (list, tuple, np.ndarray)) and + all(isinstance(x, (bool, np.bool_)) for x in value)): + # Some protobuf / numpy combinations do not support bool_, so cast. + msg.arg_value.bool_values.values.extend([bool(x) for x in value]) + elif isinstance(value, sympy.Symbol): + msg.symbol = str(value.free_symbols.pop()) + elif isinstance(value, sympy.Add): + msg.func.type = check_support('add') + for arg in value.args: + _arg_to_proto(arg, + arg_function_language=arg_function_language, + out=msg.func.args.add()) + elif isinstance(value, sympy.Mul): + msg.func.type = check_support('mul') + for arg in value.args: + _arg_to_proto(arg, + arg_function_language=arg_function_language, + out=msg.func.args.add()) + elif isinstance(value, sympy.Pow): + msg.func.type = check_support('pow') + for arg in value.args: + _arg_to_proto(arg, + arg_function_language=arg_function_language, + out=msg.func.args.add()) + else: + raise ValueError(f'Unrecognized arg type: {type(value)}') + + return msg + + +class SerializingArg: + """Specification of the arguments for a Gate and its serialization. + + Args: + serialized_name: The name of the argument when it is serialized. + serialized_type: The type of the argument when it is serialized. + op_getter: The name of the property or attribute for getting the + value of this argument from a gate, or a function that takes a + operation and returns this value. The later can be used to supply + a value of the serialized arg by supplying a lambda that + returns this value (i.e. `lambda x: default_value`) + required: Whether this argument is a required argument for the + serialized form. + default: default value. avoid serializing if this is the value. + Note that the DeserializingArg must also have this as default. + """ + + def __init__(self, + serialized_name, + serialized_type, + op_getter, + required=True, + default=None): + self.serialized_name = serialized_name + self.serialized_type = serialized_type + self.op_getter = op_getter + self.required = required + self.default = default + + +class GateOpSerializer: + """Describes how to serialize a GateOperation for a given Gate type. + + Attributes: + gate_type: The type of the gate that can be serialized. + serialized_gate_id: The id used when serializing the gate. + """ + + def __init__(self, + *, + gate_type, + serialized_gate_id, + args, + can_serialize_predicate=lambda x: True): + """Construct the serializer. + + Args: + gate_type: The type of the gate that is being serialized. + serialized_gate_id: The string id of the gate when serialized. + can_serialize_predicate: Sometimes an Operation can only be + serialized for particular parameters. This predicate will be + checked before attempting to serialize the Operation. If the + predicate is False, serialization will result in a None value. + Default value is a lambda that always returns True. + args: A list of specification of the arguments to the gate when + serializing, including how to get this information from the + gate of the given gate type. + """ + self.gate_type = gate_type + self.serialized_gate_id = serialized_gate_id + self.args = args + self.can_serialize_predicate = can_serialize_predicate + + def can_serialize_operation(self, op): + """Whether the given operation can be serialized by this serializer. + + This checks that the gate is a subclass of the gate type for this + serializer, and that the gate returns true for + `can_serializer_predicate` called on the gate. + """ + supported_gate_type = self.gate_type in type(op.gate).mro() + return supported_gate_type and self.can_serialize_predicate(op) + + def to_proto( + self, + op, + msg=None, + *, + arg_function_language='', + ): + """Returns the cirq_google.api.v2.Operation message as a proto dict.""" + + gate = op.gate + if not isinstance(gate, self.gate_type): + raise ValueError( + 'Gate of type {} but serializer expected type {}'.format( + type(gate), self.gate_type)) + + if not self.can_serialize_predicate(op): + return None + + if msg is None: + msg = program_pb2.Operation() + + msg.gate.id = self.serialized_gate_id + for qubit in op.qubits: + msg.qubits.add().id = qubit_to_proto(qubit) + for arg in self.args: + value = self._value_from_gate(op, arg) + if value is not None and (not arg.default or value != arg.default): + _arg_to_proto(value, + out=msg.args[arg.serialized_name], + arg_function_language=arg_function_language) + return msg + + def _value_from_gate(self, op, arg): + value = None + op_getter = arg.op_getter + if isinstance(op_getter, str): + gate = op.gate + value = getattr(gate, op_getter, None) + if value is None and arg.required: + raise ValueError( + 'Gate {!r} does not have attribute or property {}'.format( + gate, op_getter)) + elif callable(op_getter): + value = op_getter(op) + + if arg.required and value is None: + raise ValueError( + 'Argument {} is required, but could not get from op {!r}'. + format(arg.serialized_name, op)) + + if isinstance(value, SUPPORTED_SYMPY_OPS): + return value + + if value is not None: + self._check_type(value, arg) + + return value + + def _check_type(self, value, arg): + if arg.serialized_type == float: + if not isinstance(value, (float, int)): + raise ValueError( + 'Expected type convertible to float but was {}'.format( + type(value))) + elif arg.serialized_type == List[bool]: + if (not isinstance(value, (list, tuple, np.ndarray)) or + not all(isinstance(x, (bool, np.bool_)) for x in value)): + raise ValueError('Expected type List[bool] but was {}'.format( + type(value))) + elif value is not None and not isinstance(value, arg.serialized_type): + raise ValueError( + 'Argument {} had type {} but gate returned type {}'.format( + arg.serialized_name, arg.serialized_type, type(value))) diff --git a/tensorflow_quantum/core/serialize/op_serializer_test.py b/tensorflow_quantum/core/serialize/op_serializer_test.py new file mode 100644 index 000000000..d0e4bc80b --- /dev/null +++ b/tensorflow_quantum/core/serialize/op_serializer_test.py @@ -0,0 +1,447 @@ +# Copyright 2019 The Cirq Developers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Adaption of op_serializer_test.py from Cirq 0.9.0.""" +# 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 + +from typing import List +import numpy as np +import tensorflow as tf + +import cirq +import sympy +from absl.testing import parameterized +from google.protobuf import json_format +from tensorflow_quantum.core.proto import program_pb2 +from tensorflow_quantum.core.serialize import op_serializer + + +def op_proto(json): + """Concert json to a proto.""" + op = program_pb2.Operation() + json_format.ParseDict(json, op) + return op + + +class GateWithAttribute(cirq.testing.SingleQubitGate): + """GateAttribute helper class.""" + + def __init__(self, val): + self.val = val + + +class GateWithProperty(cirq.testing.SingleQubitGate): + """GateProperty helper class.""" + + def __init__(self, val, not_req=None): + self._val = val + self._not_req = not_req + + @property + def val(self): + """get val.""" + return self._val + + +class GateWithMethod(cirq.testing.SingleQubitGate): + """GateMethod helper class.""" + + def __init__(self, val): + self._val = val + + def get_val(self): + """get val.""" + return self._val + + +class SubclassGate(GateWithAttribute): + """EmptyGate helper class.""" + + +def get_val(op): + """Get value of op.""" + return op.gate.get_val() + + +TEST_CASES = [ + (float, 1.0, { + 'arg_value': { + 'float_value': 1.0 + } + }), + (str, 'abc', { + 'arg_value': { + 'string_value': 'abc' + } + }), + (float, 1, { + 'arg_value': { + 'float_value': 1.0 + } + }), + (List[bool], [True, False], { + 'arg_value': { + 'bool_values': { + 'values': [True, False] + } + } + }), + (List[bool], (True, False), { + 'arg_value': { + 'bool_values': { + 'values': [True, False] + } + } + }), + (List[bool], np.array([True, False], dtype=np.bool_), { + 'arg_value': { + 'bool_values': { + 'values': [True, False] + } + } + }), + (sympy.Symbol, sympy.Symbol('x'), { + 'symbol': 'x' + }), + (float, sympy.Symbol('x'), { + 'symbol': 'x' + }), + (float, sympy.Symbol('x') - sympy.Symbol('y'), { + 'func': { + 'type': + 'add', + 'args': [{ + 'symbol': 'x' + }, { + 'func': { + 'type': + 'mul', + 'args': [{ + 'arg_value': { + 'float_value': -1.0 + } + }, { + 'symbol': 'y' + }] + } + }] + } + }), +] + + +class OpSerializerTest(tf.test.TestCase, parameterized.TestCase): + """Test OpSerializer functions correctly.""" + + @parameterized.parameters([ + CASE + (x,) + for CASE in TEST_CASES + for x in [cirq.GridQubit(1, 2), cirq.LineQubit(4)] + ]) + def test_to_proto_attribute(self, val_type, val, arg_value, q): + """Test proto attribute serialization works.""" + serializer = op_serializer.GateOpSerializer( + gate_type=GateWithAttribute, + serialized_gate_id='my_gate', + args=[ + op_serializer.SerializingArg(serialized_name='my_val', + serialized_type=val_type, + op_getter='val') + ]) + result = serializer.to_proto(GateWithAttribute(val)(q), + arg_function_language='linear') + expected = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'my_val': arg_value + }, + 'qubits': [{ + 'id': '1_2' if isinstance(q, cirq.GridQubit) else '4' + }] + }) + self.assertEqual(result, expected) + + @parameterized.parameters([ + CASE + (x,) + for CASE in TEST_CASES + for x in [cirq.GridQubit(1, 2), cirq.LineQubit(4)] + ]) + def test_to_proto_property(self, val_type, val, arg_value, q): + """Test proto property serialization works.""" + serializer = op_serializer.GateOpSerializer( + gate_type=GateWithProperty, + serialized_gate_id='my_gate', + args=[ + op_serializer.SerializingArg(serialized_name='my_val', + serialized_type=val_type, + op_getter='val') + ]) + result = serializer.to_proto(GateWithProperty(val)(q), + arg_function_language='linear') + expected = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'my_val': arg_value + }, + 'qubits': [{ + 'id': '1_2' if isinstance(q, cirq.GridQubit) else '4' + }] + }) + self.assertEqual(result, expected) + + @parameterized.parameters([ + CASE + (x,) + for CASE in TEST_CASES + for x in [cirq.GridQubit(1, 2), cirq.LineQubit(4)] + ]) + def test_to_proto_callable(self, val_type, val, arg_value, q): + """Test callable serialization works.""" + serializer = op_serializer.GateOpSerializer( + gate_type=GateWithMethod, + serialized_gate_id='my_gate', + args=[ + op_serializer.SerializingArg(serialized_name='my_val', + serialized_type=val_type, + op_getter=get_val) + ]) + result = serializer.to_proto(GateWithMethod(val)(q), + arg_function_language='linear') + expected = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'my_val': arg_value + }, + 'qubits': [{ + 'id': '1_2' if isinstance(q, cirq.GridQubit) else '4' + }] + }) + self.assertEqual(result, expected) + + @parameterized.parameters([cirq.GridQubit(1, 2), cirq.LineQubit(4)]) + def test_to_proto_gate_predicate(self, q): + """Test can_serialize works.""" + serializer = op_serializer.GateOpSerializer( + gate_type=GateWithAttribute, + serialized_gate_id='my_gate', + args=[ + op_serializer.SerializingArg(serialized_name='my_val', + serialized_type=float, + op_getter='val') + ], + can_serialize_predicate=lambda x: x.gate.val == 1) + self.assertIsNone(serializer.to_proto(GateWithAttribute(0)(q))) + self.assertIsNotNone(serializer.to_proto(GateWithAttribute(1)(q))) + self.assertFalse( + serializer.can_serialize_operation(GateWithAttribute(0)(q))) + self.assertTrue( + serializer.can_serialize_operation(GateWithAttribute(1)(q))) + + @parameterized.parameters([cirq.GridQubit(1, 2), cirq.LineQubit(4)]) + def test_to_proto_gate_mismatch(self, q): + """Test proto gate mismatch errors.""" + serializer = op_serializer.GateOpSerializer( + gate_type=GateWithProperty, + serialized_gate_id='my_gate', + args=[ + op_serializer.SerializingArg(serialized_name='my_val', + serialized_type=float, + op_getter='val') + ]) + with self.assertRaisesRegex( + ValueError, + expected_regex='GateWithAttribute.*GateWithProperty'): + serializer.to_proto(GateWithAttribute(1.0)(q)) + + @parameterized.parameters([cirq.GridQubit(1, 2), cirq.LineQubit(4)]) + def test_to_proto_unsupported_type(self, q): + """Test proto unsupported types errors.""" + serializer = op_serializer.GateOpSerializer( + gate_type=GateWithProperty, + serialized_gate_id='my_gate', + args=[ + op_serializer.SerializingArg(serialized_name='my_val', + serialized_type=bytes, + op_getter='val') + ]) + with self.assertRaisesRegex(ValueError, expected_regex='bytes'): + serializer.to_proto(GateWithProperty(b's')(q)) + + @parameterized.parameters([cirq.GridQubit(1, 2), cirq.LineQubit(4)]) + def test_to_proto_required_but_not_present(self, q): + """Test required and missing args errors.""" + serializer = op_serializer.GateOpSerializer( + gate_type=GateWithProperty, + serialized_gate_id='my_gate', + args=[ + op_serializer.SerializingArg(serialized_name='my_val', + serialized_type=float, + op_getter=lambda x: None) + ]) + with self.assertRaisesRegex(ValueError, expected_regex='required'): + serializer.to_proto(GateWithProperty(1.0)(q)) + + @parameterized.parameters([cirq.GridQubit(1, 2), cirq.LineQubit(4)]) + def test_to_proto_no_getattr(self, q): + """Test no op getter fails.""" + serializer = op_serializer.GateOpSerializer( + gate_type=GateWithProperty, + serialized_gate_id='my_gate', + args=[ + op_serializer.SerializingArg(serialized_name='my_val', + serialized_type=float, + op_getter='nope') + ]) + with self.assertRaisesRegex(ValueError, expected_regex='does not have'): + serializer.to_proto(GateWithProperty(1.0)(q)) + + @parameterized.parameters([cirq.GridQubit(1, 2), cirq.LineQubit(4)]) + def test_to_proto_not_required_ok(self, q): + """Test non require arg absense succeeds.""" + serializer = op_serializer.GateOpSerializer( + gate_type=GateWithProperty, + serialized_gate_id='my_gate', + args=[ + op_serializer.SerializingArg(serialized_name='my_val', + serialized_type=float, + op_getter='val'), + op_serializer.SerializingArg(serialized_name='not_req', + serialized_type=float, + op_getter='not_req', + required=False) + ]) + expected = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'my_val': { + 'arg_value': { + 'float_value': 0.125 + } + } + }, + 'qubits': [{ + 'id': '1_2' if isinstance(q, cirq.GridQubit) else '4' + }] + }) + + self.assertEqual(serializer.to_proto(GateWithProperty(0.125)(q)), + expected) + + @parameterized.parameters([{ + **x, + **{ + 'q': q + } + } for x in [{ + 'val_type': float, + 'val': 's' + }, { + 'val_type': str, + 'val': 1.0 + }, { + 'val_type': sympy.Symbol, + 'val': 1.0 + }, { + 'val_type': List[bool], + 'val': [1.0] + }, { + 'val_type': List[bool], + 'val': 'a' + }, { + 'val_type': List[bool], + 'val': (1.0,) + }] for q in [cirq.GridQubit(1, 2), cirq.LineQubit(4)]]) + def test_to_proto_type_mismatch(self, val_type, val, q): + """Test type mismatch fails.""" + serializer = op_serializer.GateOpSerializer( + gate_type=GateWithProperty, + serialized_gate_id='my_gate', + args=[ + op_serializer.SerializingArg(serialized_name='my_val', + serialized_type=val_type, + op_getter='val') + ]) + with self.assertRaisesRegex(ValueError, expected_regex=str(type(val))): + serializer.to_proto(GateWithProperty(val)(q)) + + @parameterized.parameters([cirq.GridQubit(1, 2), cirq.LineQubit(4)]) + def test_can_serialize_operation_subclass(self, q): + """Test can serialize subclass.""" + serializer = op_serializer.GateOpSerializer( + gate_type=GateWithAttribute, + serialized_gate_id='my_gate', + args=[ + op_serializer.SerializingArg(serialized_name='my_val', + serialized_type=float, + op_getter='val') + ], + can_serialize_predicate=lambda x: x.gate.val == 1) + self.assertTrue(serializer.can_serialize_operation(SubclassGate(1)(q))) + self.assertFalse(serializer.can_serialize_operation(SubclassGate(0)(q))) + + @parameterized.parameters([cirq.GridQubit(1, 2), cirq.LineQubit(4)]) + def test_defaults_not_serialized(self, q): + """Test defaults not serialized.""" + serializer = op_serializer.GateOpSerializer( + gate_type=GateWithAttribute, + serialized_gate_id='my_gate', + args=[ + op_serializer.SerializingArg(serialized_name='my_val', + serialized_type=float, + default=1.0, + op_getter='val') + ]) + no_default = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'args': { + 'my_val': { + 'arg_value': { + 'float_value': 0.125 + } + } + }, + 'qubits': [{ + 'id': '1_2' if isinstance(q, cirq.GridQubit) else '4' + }] + }) + self.assertEqual(no_default, + serializer.to_proto(GateWithAttribute(0.125)(q))) + with_default = op_proto({ + 'gate': { + 'id': 'my_gate' + }, + 'qubits': [{ + 'id': '1_2' if isinstance(q, cirq.GridQubit) else '4' + }] + }) + self.assertEqual(with_default, + serializer.to_proto(GateWithAttribute(1.0)(q))) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/serialize/serializable_gate_set.py b/tensorflow_quantum/core/serialize/serializable_gate_set.py new file mode 100644 index 000000000..977f05dfb --- /dev/null +++ b/tensorflow_quantum/core/serialize/serializable_gate_set.py @@ -0,0 +1,253 @@ +# Copyright 2019 The Cirq Developers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Support for serializing and deserializing cirq_google.api.v2 protos.""" + +import cirq +from tensorflow_quantum.core.proto import program_pb2 + +LANGUAGE_ORDER = [ + '', + 'linear', + 'exp', +] + + +def _max_lang(langs): + i = max((LANGUAGE_ORDER.index(e) for e in langs), default=0) + return LANGUAGE_ORDER[i] + + +def _infer_function_language_from_circuit(value): + return _max_lang({ + e for moment in value.moments for op in moment.operations + for e in _function_languages_from_operation(op) + }) + + +def _function_languages_from_operation(value): + for arg in value.args.values(): + yield from _function_languages_from_arg(arg) + + +def _function_languages_from_arg(arg_proto): + which = arg_proto.WhichOneof('arg') + if which == 'func': + if arg_proto.func.type in ['add', 'mul']: + yield 'linear' + for a in arg_proto.func.args: + yield from _function_languages_from_arg(a) + if arg_proto.func.type in ['pow']: + yield 'exp' + for a in arg_proto.func.args: + yield from _function_languages_from_arg(a) + + +class SerializableGateSet: + """A class for serializing and deserializing programs and operations. + + This class is for cirq_google.api.v2. protos. + """ + + def __init__(self, gate_set_name, serializers, deserializers): + """Construct the gate set. + + Args: + gate_set_name: The name used to identify the gate set. + serializers: The GateOpSerializers to use for serialization. + Multiple serializers for a given gate type are allowed and + will be checked for a given type in the order specified here. + This allows for a given gate type to be serialized into + different serialized form depending on the parameters of the + gate. + deserializers: The GateOpDeserializers to convert serialized + forms of gates to GateOperations. + """ + self.gate_set_name = gate_set_name + self.serializers = {} + for s in serializers: + self.serializers.setdefault(s.gate_type, []).append(s) + self.deserializers = {d.serialized_gate_id: d for d in deserializers} + + def with_added_gates( + self, + *, + gate_set_name=None, + serializers=(), + deserializers=(), + ): + """Creates a new gateset with additional (de)serializers. + + Args: + gate_set_name: Optional new name of the gateset. If not given, use + the same name as this gateset. + serializers: Serializers to add to those in this gateset. + deserializers: Deserializers to add to those in this gateset. + """ + # Iterate over all serializers in this gateset. + curr_serializers = (serializer + for serializers in self.serializers.values() + for serializer in serializers) + return SerializableGateSet( + gate_set_name or self.gate_set_name, + serializers=[*curr_serializers, *serializers], + deserializers=[*self.deserializers.values(), *deserializers]) + + def supported_gate_types(self): + """Tuple of support gate types.""" + return tuple(self.serializers.keys()) + + def is_supported_operation(self, op): + """Whether or not the given gate can be serialized by this gate set.""" + gate = op.gate + for gate_type_mro in type(gate).mro(): + if gate_type_mro in self.serializers: + for serializer in self.serializers[gate_type_mro]: + if serializer.can_serialize_operation(op): + return True + return False + + def serialize(self, program, msg=None, *, arg_function_language=None): + """Serialize a Circuit to cirq_google.api.v2.Program proto. + + Args: + program: The Circuit to serialize. + """ + if msg is None: + msg = program_pb2.Program() + msg.language.gate_set = self.gate_set_name + if isinstance(program, cirq.Circuit): + self._serialize_circuit(program, + msg.circuit, + arg_function_language=arg_function_language) + if arg_function_language is None: + arg_function_language = (_infer_function_language_from_circuit( + msg.circuit)) + else: + raise NotImplementedError( + f'Unrecognized program type: {type(program)}') + msg.language.arg_function_language = arg_function_language + return msg + + def serialize_op( + self, + op, + msg=None, + *, + arg_function_language='', + ): + """Serialize an Operation to cirq_google.api.v2.Operation proto. + + Args: + op: The operation to serialize. + + Returns: + A dictionary corresponds to the cirq_google.api.v2.Operation proto. + """ + gate_type = type(op.gate) + for gate_type_mro in gate_type.mro(): + # Check all super classes in method resolution order. + if gate_type_mro in self.serializers: + # Check each serializer in turn, if serializer proto returns + # None, then skip. + for serializer in self.serializers[gate_type_mro]: + proto_msg = serializer.to_proto( + op, msg, arg_function_language=arg_function_language) + if proto_msg is not None: + return proto_msg + raise ValueError('Cannot serialize op {!r} of type {}'.format( + op, gate_type)) + + def deserialize(self, proto, device=None): + """Deserialize a Circuit from a cirq_google.api.v2.Program. + + Args: + proto: A dictionary representing a cirq_google.api.v2.Program proto. + device: If the proto is for a schedule, a device is required + Otherwise optional. + + Returns: + The deserialized Circuit, with a device if device was + not None. + """ + if not proto.HasField('language') or not proto.language.gate_set: + raise ValueError('Missing gate set specification.') + if proto.language.gate_set != self.gate_set_name: + raise ValueError('Gate set in proto was {} but expected {}'.format( + proto.language.gate_set, self.gate_set_name)) + which = proto.WhichOneof('program') + if which == 'circuit': + circuit = self._deserialize_circuit( + proto.circuit, + arg_function_language=proto.language.arg_function_language) + return circuit if device is None else circuit.with_device(device) + + raise NotImplementedError('Program proto does not contain a circuit.') + + def deserialize_op( + self, + operation_proto, + *, + arg_function_language='', + ): + """Deserialize an Operation from a cirq_google.api.v2.Operation. + + Args: + operation_proto: A dictionary representing a + cirq_google.api.v2.Operation proto. + + Returns: + The deserialized Operation. + """ + if not operation_proto.gate.id: + raise ValueError('Operation proto does not have a gate.') + + gate_id = operation_proto.gate.id + if gate_id not in self.deserializers.keys(): + raise ValueError('Unsupported serialized gate with id "{}".' + '\n\noperation_proto:\n{}'.format( + gate_id, operation_proto)) + + return self.deserializers[gate_id].from_proto( + operation_proto, arg_function_language=arg_function_language) + + def _serialize_circuit(self, circuit, msg, *, arg_function_language): + msg.scheduling_strategy = program_pb2.Circuit.MOMENT_BY_MOMENT + for moment in circuit: + moment_proto = msg.moments.add() + for op in moment: + self.serialize_op(op, + moment_proto.operations.add(), + arg_function_language=arg_function_language) + + def _deserialize_circuit( + self, + circuit_proto, + *, + arg_function_language, + ): + moments = [] + for i, moment_proto in enumerate(circuit_proto.moments): + moment_ops = [] + for op in moment_proto.operations: + try: + moment_ops.append( + self.deserialize_op( + op, arg_function_language=arg_function_language)) + except ValueError as ex: + raise ValueError(f'Failed to deserialize circuit. ' + f'There was a problem in moment {i} ' + f'handling an operation with the ' + f'following proto:\n{op}') from ex + moments.append(cirq.Moment(moment_ops)) + return cirq.Circuit(moments) diff --git a/tensorflow_quantum/core/serialize/serializable_gate_set_test.py b/tensorflow_quantum/core/serialize/serializable_gate_set_test.py new file mode 100644 index 000000000..e8f94b1db --- /dev/null +++ b/tensorflow_quantum/core/serialize/serializable_gate_set_test.py @@ -0,0 +1,450 @@ +# Copyright 2019 The Cirq Developers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Test serializable_gat_set.py functionality.""" +# 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 + +import tensorflow as tf + +import cirq +from google.protobuf import json_format +from tensorflow_quantum.core.serialize import op_serializer, op_deserializer, \ + serializable_gate_set +from tensorflow_quantum.core.proto import program_pb2 + +X_SERIALIZER = op_serializer.GateOpSerializer( + gate_type=cirq.XPowGate, + serialized_gate_id='x_pow', + args=[ + op_serializer.SerializingArg( + serialized_name='half_turns', + serialized_type=float, + op_getter='exponent', + ) + ], +) + +X_DESERIALIZER = op_deserializer.GateOpDeserializer( + serialized_gate_id='x_pow', + gate_constructor=cirq.XPowGate, + args=[ + op_deserializer.DeserializingArg( + serialized_name='half_turns', + constructor_arg_name='exponent', + ) + ], +) + +Y_SERIALIZER = op_serializer.GateOpSerializer( + gate_type=cirq.YPowGate, + serialized_gate_id='y_pow', + args=[ + op_serializer.SerializingArg( + serialized_name='half_turns', + serialized_type=float, + op_getter='exponent', + ) + ], +) + +Y_DESERIALIZER = op_deserializer.GateOpDeserializer( + serialized_gate_id='y_pow', + gate_constructor=cirq.YPowGate, + args=[ + op_deserializer.DeserializingArg( + serialized_name='half_turns', + constructor_arg_name='exponent', + ) + ], +) + +MY_GATE_SET = serializable_gate_set.SerializableGateSet( + gate_set_name='my_gate_set', + serializers=[X_SERIALIZER], + deserializers=[X_DESERIALIZER], +) + + +def op_proto(json): + """Json to proto.""" + op = program_pb2.Operation() + json_format.ParseDict(json, op) + return op + + +class SerializableGateSetTest(tf.test.TestCase): + """Test SerializableGateSet and associated deserialize functionality.""" + + def test_supported_gate_types(self): + """Report correct gate types.""" + self.assertEqual(MY_GATE_SET.supported_gate_types(), (cirq.XPowGate,)) + + def test_is_supported_operation(self): + """Ensure supported operations are correct.""" + q = cirq.GridQubit(1, 1) + self.assertTrue(MY_GATE_SET.is_supported_operation(cirq.XPowGate()(q))) + self.assertTrue(MY_GATE_SET.is_supported_operation(cirq.X(q))) + self.assertFalse(MY_GATE_SET.is_supported_operation(cirq.ZPowGate()(q))) + + def test_is_supported_operation_can_serialize_predicate(self): + """Test can_serialize predicate for operations.""" + q = cirq.GridQubit(1, 2) + serializer = op_serializer.GateOpSerializer( + gate_type=cirq.XPowGate, + serialized_gate_id='x_pow', + args=[ + op_serializer.SerializingArg( + serialized_name='half_turns', + serialized_type=float, + op_getter='exponent', + ) + ], + can_serialize_predicate=lambda x: x.gate.exponent == 1.0) + gate_set = serializable_gate_set.SerializableGateSet( + gate_set_name='my_gate_set', + serializers=[serializer], + deserializers=[X_DESERIALIZER]) + self.assertTrue(gate_set.is_supported_operation(cirq.XPowGate()(q))) + self.assertFalse( + gate_set.is_supported_operation(cirq.XPowGate()(q)**0.5)) + self.assertTrue(gate_set.is_supported_operation(cirq.X(q))) + + def test_serialize_deserialize_circuit(self): + """Verify one to one serialize deserialize consistency.""" + q0 = cirq.GridQubit(1, 1) + q1 = cirq.GridQubit(1, 2) + circuit = cirq.Circuit(cirq.X(q0), cirq.X(q1), cirq.X(q0)) + + proto = program_pb2.Program( + language=program_pb2.Language(arg_function_language='', + gate_set='my_gate_set'), + circuit=program_pb2.Circuit( + scheduling_strategy=program_pb2.Circuit.MOMENT_BY_MOMENT, + moments=[ + program_pb2.Moment(operations=[ + X_SERIALIZER.to_proto(cirq.X(q0)), + X_SERIALIZER.to_proto(cirq.X(q1)) + ]), + program_pb2.Moment( + operations=[X_SERIALIZER.to_proto(cirq.X(q0))]), + ])) + self.assertEqual(proto, MY_GATE_SET.serialize(circuit)) + self.assertEqual(MY_GATE_SET.deserialize(proto), circuit) + + def test_deserialize_bad_operation_id(self): + """Ensure error is raised when deserializing bad operation.""" + proto = program_pb2.Program( + language=program_pb2.Language(arg_function_language='', + gate_set='my_gate_set'), + circuit=program_pb2.Circuit( + scheduling_strategy=program_pb2.Circuit.MOMENT_BY_MOMENT, + moments=[ + program_pb2.Moment(operations=[]), + program_pb2.Moment(operations=[ + program_pb2.Operation( + gate=program_pb2.Gate(id='UNKNOWN_GATE'), + args={ + 'half_turns': + program_pb2.Arg( + arg_value=program_pb2.ArgValue( + float_value=1.0)) + }, + qubits=[program_pb2.Qubit(id='1_1')]) + ]), + ])) + with self.assertRaisesRegex( + ValueError, + expected_regex='problem in moment 1 handling an ' + 'operation with the following'): + MY_GATE_SET.deserialize(proto) + + def test_serialize_deserialize_empty_circuit(self): + """Verify empty case serialize deserialize works.""" + circuit = cirq.Circuit() + + proto = program_pb2.Program( + language=program_pb2.Language(arg_function_language='', + gate_set='my_gate_set'), + circuit=program_pb2.Circuit( + scheduling_strategy=program_pb2.Circuit.MOMENT_BY_MOMENT, + moments=[])) + self.assertEqual(proto, MY_GATE_SET.serialize(circuit)) + self.assertEqual(MY_GATE_SET.deserialize(proto), circuit) + + def test_deserialize_empty_moment(self): + """Ensure deserialize empty moment works.""" + circuit = cirq.Circuit([cirq.Moment()]) + + proto = program_pb2.Program( + language=program_pb2.Language(arg_function_language='', + gate_set='my_gate_set'), + circuit=program_pb2.Circuit( + scheduling_strategy=program_pb2.Circuit.MOMENT_BY_MOMENT, + moments=[ + program_pb2.Moment(), + ])) + self.assertEqual(MY_GATE_SET.deserialize(proto), circuit) + + def test_serialize_unrecognized(self): + """Error on uncrecognized serialization.""" + with self.assertRaisesRegex(NotImplementedError, + expected_regex='program type'): + MY_GATE_SET.serialize("not quite right") + + def test_serialize_deserialize_op(self): + """Simple serialize and deserialize back test.""" + q0 = cirq.GridQubit(1, 1) + proto = op_proto({ + 'gate': { + 'id': 'x_pow' + }, + 'args': { + 'half_turns': { + 'arg_value': { + 'float_value': 0.125 + } + }, + }, + 'qubits': [{ + 'id': '1_1' + }] + }) + self.assertEqual( + proto, MY_GATE_SET.serialize_op(cirq.XPowGate(exponent=0.125)(q0))) + self.assertEqual(MY_GATE_SET.deserialize_op(proto), + cirq.XPowGate(exponent=0.125)(q0)) + + def test_serialize_deserialize_op_subclass(self): + """Verify subclasses can serialize and deserialize back.""" + q0 = cirq.GridQubit(1, 1) + proto = op_proto({ + 'gate': { + 'id': 'x_pow' + }, + 'args': { + 'half_turns': { + 'arg_value': { + 'float_value': 1.0 + } + }, + }, + 'qubits': [{ + 'id': '1_1' + }] + }) + # cirq.X is a subclass of XPowGate. + self.assertEqual(proto, MY_GATE_SET.serialize_op(cirq.X(q0))) + self.assertEqual(MY_GATE_SET.deserialize_op(proto), cirq.X(q0)) + + def test_multiple_serializers(self): + """Compound serialization.""" + serializer1 = op_serializer.GateOpSerializer( + gate_type=cirq.XPowGate, + serialized_gate_id='x_pow', + args=[ + op_serializer.SerializingArg(serialized_name='half_turns', + serialized_type=float, + op_getter='exponent') + ], + can_serialize_predicate=lambda x: x.gate.exponent != 1) + serializer2 = op_serializer.GateOpSerializer( + gate_type=cirq.XPowGate, + serialized_gate_id='x', + args=[ + op_serializer.SerializingArg(serialized_name='half_turns', + serialized_type=float, + op_getter='exponent') + ], + can_serialize_predicate=lambda x: x.gate.exponent == 1) + gate_set = serializable_gate_set.SerializableGateSet( + gate_set_name='my_gate_set', + serializers=[serializer1, serializer2], + deserializers=[]) + q0 = cirq.GridQubit(1, 1) + self.assertEqual(gate_set.serialize_op(cirq.X(q0)).gate.id, 'x') + self.assertEqual( + gate_set.serialize_op(cirq.X(q0)**0.5).gate.id, 'x_pow') + + def test_gateset_with_added_gates(self): + """Test adding new gates to gateset.""" + q = cirq.GridQubit(1, 1) + x_gateset = serializable_gate_set.SerializableGateSet( + gate_set_name='x', + serializers=[X_SERIALIZER], + deserializers=[X_DESERIALIZER], + ) + xy_gateset = x_gateset.with_added_gates( + gate_set_name='xy', + serializers=[Y_SERIALIZER], + deserializers=[Y_DESERIALIZER], + ) + self.assertEqual(x_gateset.gate_set_name, 'x') + self.assertTrue(x_gateset.is_supported_operation(cirq.X(q))) + self.assertFalse(x_gateset.is_supported_operation(cirq.Y(q))) + self.assertEqual(xy_gateset.gate_set_name, 'xy') + self.assertTrue(xy_gateset.is_supported_operation(cirq.X(q))) + self.assertTrue(xy_gateset.is_supported_operation(cirq.Y(q))) + + # test serialization and deserialization + proto = op_proto({ + 'gate': { + 'id': 'y_pow' + }, + 'args': { + 'half_turns': { + 'arg_value': { + 'float_value': 0.125 + } + }, + }, + 'qubits': [{ + 'id': '1_1' + }] + }) + + expected_gate = cirq.YPowGate(exponent=0.125)(cirq.GridQubit(1, 1)) + self.assertEqual(xy_gateset.serialize_op(expected_gate), proto) + self.assertEqual(xy_gateset.deserialize_op(proto), expected_gate) + + def test_gateset_with_added_gates_again(self): + """Verify that adding a serializer twice doesn't mess anything up.""" + q = cirq.GridQubit(2, 2) + x_gateset = serializable_gate_set.SerializableGateSet( + gate_set_name='x', + serializers=[X_SERIALIZER], + deserializers=[X_DESERIALIZER], + ) + xx_gateset = x_gateset.with_added_gates( + gate_set_name='xx', + serializers=[X_SERIALIZER], + deserializers=[X_DESERIALIZER], + ) + + self.assertEqual(xx_gateset.gate_set_name, 'xx') + self.assertTrue(xx_gateset.is_supported_operation(cirq.X(q))) + self.assertFalse(xx_gateset.is_supported_operation(cirq.Y(q))) + + # test serialization and deserialization + proto = op_proto({ + 'gate': { + 'id': 'x_pow' + }, + 'args': { + 'half_turns': { + 'arg_value': { + 'float_value': 0.125 + } + }, + }, + 'qubits': [{ + 'id': '1_1' + }] + }) + + expected_gate = cirq.XPowGate(exponent=0.125)(cirq.GridQubit(1, 1)) + self.assertEqual(xx_gateset.serialize_op(expected_gate), proto) + self.assertEqual(xx_gateset.deserialize_op(proto), expected_gate) + + def test_deserialize_op_invalid_gate(self): + """Ensure deserialize invalid gates errors.""" + proto = op_proto({ + 'gate': {}, + 'args': { + 'half_turns': { + 'arg_value': { + 'float_value': 0.125 + } + }, + }, + 'qubits': [{ + 'id': '1_1' + }] + }) + with self.assertRaisesRegex(ValueError, + expected_regex='does not have a gate'): + MY_GATE_SET.deserialize_op(proto) + + proto = op_proto({ + 'args': { + 'half_turns': { + 'arg_value': { + 'float_value': 0.125 + } + }, + }, + 'qubits': [{ + 'id': '1_1' + }] + }) + with self.assertRaisesRegex(ValueError, + expected_regex='does not have a gate'): + MY_GATE_SET.deserialize_op(proto) + + def test_deserialize_unsupported_gate_type(self): + """Ensure deserializing unsupported types errors.""" + proto = op_proto({ + 'gate': { + 'id': 'no_pow' + }, + 'args': { + 'half_turns': { + 'arg_value': { + 'float_value': 0.125 + } + }, + }, + 'qubits': [{ + 'id': '1_1' + }] + }) + with self.assertRaisesRegex(ValueError, expected_regex='no_pow'): + MY_GATE_SET.deserialize_op(proto) + + def test_serialize_op_unsupported_type(self): + """Serialize unsopported types should error.""" + q0 = cirq.GridQubit(1, 1) + with self.assertRaisesRegex(ValueError, expected_regex='YPowGate'): + MY_GATE_SET.serialize_op(cirq.YPowGate()(q0)) + + def test_deserialize_invalid_gate_set(self): + """Deserializing an invalid gate set should error if element not in.""" + proto = program_pb2.Program( + language=program_pb2.Language(gate_set='not_my_gate_set'), + circuit=program_pb2.Circuit( + scheduling_strategy=program_pb2.Circuit.MOMENT_BY_MOMENT, + moments=[])) + with self.assertRaisesRegex(ValueError, + expected_regex='not_my_gate_set'): + MY_GATE_SET.deserialize(proto) + + proto.language.gate_set = '' + with self.assertRaisesRegex(ValueError, + expected_regex='Missing gate set'): + MY_GATE_SET.deserialize(proto) + + proto = program_pb2.Program(circuit=program_pb2.Circuit( + scheduling_strategy=program_pb2.Circuit.MOMENT_BY_MOMENT, + moments=[])) + with self.assertRaisesRegex(ValueError, + expected_regex='Missing gate set'): + MY_GATE_SET.deserialize(proto) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/core/serialize/serializer.py b/tensorflow_quantum/core/serialize/serializer.py index 4b62db35f..80ddb6672 100644 --- a/tensorflow_quantum/core/serialize/serializer.py +++ b/tensorflow_quantum/core/serialize/serializer.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A basic serializer used to serialize/deserialize Cirq circuits for tfq.""" # TODO(pmassey / anyone): determine if this should be kept as globals. import copy @@ -20,8 +20,11 @@ import numpy as np import cirq -import cirq.google.api.v2 as v2 +from tensorflow_quantum.core.serialize import op_serializer, op_deserializer, \ + serializable_gate_set from tensorflow_quantum.core.proto import pauli_sum_pb2 +from tensorflow_quantum.core.proto import program_pb2 +from tensorflow_quantum.core.proto import projector_sum_pb2 # Needed to allow autograph to crawl AST without erroring. _CONSTANT_TRUE = lambda x: True @@ -60,16 +63,18 @@ def _scalar_extractor(x): return 1.0 expr = x.evalf() - if isinstance(expr, sympy.mul.Mul): + if isinstance(expr, sympy.core.Mul): lhs_eval, rhs_eval = _parse_mul(expr) if isinstance(lhs_eval, sympy.Symbol) and isinstance( - rhs_eval, (sympy.numbers.Float, sympy.numbers.Integer)): + rhs_eval, + (sympy.core.numbers.Float, sympy.core.numbers.Integer)): # lhs contains symbol rhs contains number. return _round(float(rhs_eval)) if isinstance(rhs_eval, sympy.Symbol) and isinstance( - lhs_eval, (sympy.numbers.Float, sympy.numbers.Integer)): + lhs_eval, + (sympy.core.numbers.Float, sympy.core.numbers.Integer)): # lhs contains number. return _round(float(lhs_eval)) @@ -90,16 +95,18 @@ def _symbol_extractor(x): return x expr = x.evalf() - if isinstance(expr, sympy.mul.Mul): + if isinstance(expr, sympy.core.Mul): lhs_eval, rhs_eval = _parse_mul(expr) if isinstance(lhs_eval, sympy.Symbol) and isinstance( - rhs_eval, (sympy.numbers.Float, sympy.numbers.Integer)): + rhs_eval, + (sympy.core.numbers.Float, sympy.core.numbers.Integer)): # lhs contains symbol rhs contains number. return lhs_eval if isinstance(rhs_eval, sympy.Symbol) and isinstance( - lhs_eval, (sympy.numbers.Float, sympy.numbers.Integer)): + lhs_eval, + (sympy.core.numbers.Float, sympy.core.numbers.Integer)): # lhs contains number. return rhs_eval @@ -109,33 +116,380 @@ def _symbol_extractor(x): "information.") +def _serialize_controls(gate): + """Helper to serialize control qubits if applicable.""" + if hasattr(gate, '_tfq_control_qubits'): + return ','.join( + op_serializer.qubit_to_proto(q) for q in gate._tfq_control_qubits) + return '' + + +def _serialize_control_vals(gate): + """Helper to serialize control values if applicable..""" + if hasattr(gate, '_tfq_control_values'): + return ','.join(str(v[0]) for v in gate._tfq_control_values) + return '' + + +class DelayedAssignmentGate(cirq.Gate): + """Class to do control qubit assignment before sub_gate qubit assignment.""" + + def __init__(self, gate_callable, control_qubits, control_values): + self._gate_callable = gate_callable + self._control_qubits = control_qubits + self._control_values = control_values + + def _qid_shape_(self): + raise ValueError("Called qid_shape on workaround class.") + + # pylint: disable=invalid-name + def on(self, *qubits): + """Returns gate_callable on qubits controlled by contol_qubits.""" + gate = self._gate_callable(*qubits) + # TODO(tonybruguier,#636): Here we call the parent's class controlled_by + # because Cirq's breaking change #4167 created 3-qubit gates that cannot + # be serialized yet. Instead, support 3-qubit gates and revert the + # work-around. + if len(self._control_qubits) == 0: + return gate + return cirq.ControlledOperation(self._control_qubits, + gate, + control_values=self._control_values) + + # pylint: enable=invalid-name + + +def _optional_control_promote(gate, qubits_message, values_message): + """Optionally promote to controlled gate based on serialized control msg.""" + if qubits_message == '' and values_message == '': + return gate + qbs = [ + op_deserializer.qubit_from_proto(qb) for qb in qubits_message.split(',') + ] + vals = [int(cv) for cv in values_message.split(',')] + + return DelayedAssignmentGate(gate, qbs, vals) + + +# Channels. +def _asymmetric_depolarize_serializer(): + """Make standard serializer for asymmetric depolarization channel.""" + args = [ + # cirq channels can't contain symbols. + op_serializer.SerializingArg(serialized_name="p_x", + serialized_type=float, + op_getter=lambda x: x.gate.p_x), + op_serializer.SerializingArg(serialized_name="p_y", + serialized_type=float, + op_getter=lambda x: x.gate.p_y), + op_serializer.SerializingArg(serialized_name="p_z", + serialized_type=float, + op_getter=lambda x: x.gate.p_z), + op_serializer.SerializingArg(serialized_name="control_qubits", + serialized_type=str, + op_getter=lambda x: ''), + op_serializer.SerializingArg(serialized_name="control_values", + serialized_type=str, + op_getter=lambda x: '') + ] + return op_serializer.GateOpSerializer( + gate_type=cirq.AsymmetricDepolarizingChannel, + serialized_gate_id="ADP", + args=args, + can_serialize_predicate=_CONSTANT_TRUE) + + +def _asymmetric_depolarize_deserializer(): + """Make standard deserializer for asymmetric depolarization channel.""" + args = [ + op_deserializer.DeserializingArg(serialized_name="p_x", + constructor_arg_name="p_x"), + op_deserializer.DeserializingArg(serialized_name="p_y", + constructor_arg_name="p_y"), + op_deserializer.DeserializingArg(serialized_name="p_z", + constructor_arg_name="p_z") + ] + return op_deserializer.GateOpDeserializer( + serialized_gate_id="ADP", + gate_constructor=cirq.AsymmetricDepolarizingChannel, + args=args) + + +def _depolarize_channel_serializer(): + """Make standard serializer for depolarization channel.""" + + args = [ + # cirq channels can't contain symbols. + op_serializer.SerializingArg(serialized_name="p", + serialized_type=float, + op_getter=lambda x: x.gate.p), + op_serializer.SerializingArg(serialized_name="control_qubits", + serialized_type=str, + op_getter=lambda x: ''), + op_serializer.SerializingArg(serialized_name="control_values", + serialized_type=str, + op_getter=lambda x: '') + ] + return op_serializer.GateOpSerializer( + gate_type=cirq.DepolarizingChannel, + serialized_gate_id="DP", + args=args, + can_serialize_predicate=_CONSTANT_TRUE) + + +def _depolarize_channel_deserializer(): + """Make standard deserializer for depolarization channel.""" + + args = [ + op_deserializer.DeserializingArg(serialized_name="p", + constructor_arg_name="p") + ] + return op_deserializer.GateOpDeserializer( + serialized_gate_id="DP", + gate_constructor=cirq.DepolarizingChannel, + args=args) + + +def _gad_channel_serializer(): + """Make standard serializer for GeneralizedAmplitudeDamping.""" + + args = [ + # cirq channels can't contain symbols. + op_serializer.SerializingArg(serialized_name="p", + serialized_type=float, + op_getter=lambda x: x.gate.p), + op_serializer.SerializingArg(serialized_name="gamma", + serialized_type=float, + op_getter=lambda x: x.gate.gamma), + op_serializer.SerializingArg(serialized_name="control_qubits", + serialized_type=str, + op_getter=lambda x: ''), + op_serializer.SerializingArg(serialized_name="control_values", + serialized_type=str, + op_getter=lambda x: '') + ] + return op_serializer.GateOpSerializer( + gate_type=cirq.GeneralizedAmplitudeDampingChannel, + serialized_gate_id="GAD", + args=args, + can_serialize_predicate=_CONSTANT_TRUE) + + +def _gad_channel_deserializer(): + """Make standard deserializer for GeneralizedAmplitudeDamping.""" + + args = [ + op_deserializer.DeserializingArg(serialized_name="p", + constructor_arg_name="p"), + op_deserializer.DeserializingArg(serialized_name="gamma", + constructor_arg_name="gamma") + ] + return op_deserializer.GateOpDeserializer( + serialized_gate_id="GAD", + gate_constructor=cirq.GeneralizedAmplitudeDampingChannel, + args=args) + + +def _amplitude_damp_channel_serializer(): + """Make standard serializer for AmplitudeDamp channel.""" + + args = [ + # cirq channels can't contain symbols. + op_serializer.SerializingArg(serialized_name="gamma", + serialized_type=float, + op_getter=lambda x: x.gate.gamma), + op_serializer.SerializingArg(serialized_name="control_qubits", + serialized_type=str, + op_getter=lambda x: ''), + op_serializer.SerializingArg(serialized_name="control_values", + serialized_type=str, + op_getter=lambda x: '') + ] + return op_serializer.GateOpSerializer( + gate_type=cirq.AmplitudeDampingChannel, + serialized_gate_id="AD", + args=args, + can_serialize_predicate=_CONSTANT_TRUE) + + +def _amplitude_damp_channel_deserializer(): + """Make standard deserializer for depolarization channel.""" + + args = [ + op_deserializer.DeserializingArg(serialized_name="gamma", + constructor_arg_name="gamma") + ] + return op_deserializer.GateOpDeserializer( + serialized_gate_id="AD", + gate_constructor=cirq.AmplitudeDampingChannel, + args=args) + + +def _reset_channel_serializer(): + """Make standard serializer for reset channel.""" + + args = [ + # cirq channels can't contain symbols. + op_serializer.SerializingArg(serialized_name="control_qubits", + serialized_type=str, + op_getter=lambda x: ''), + op_serializer.SerializingArg(serialized_name="control_values", + serialized_type=str, + op_getter=lambda x: '') + ] + return op_serializer.GateOpSerializer( + gate_type=cirq.ResetChannel, + serialized_gate_id="RST", + args=args, + can_serialize_predicate=_CONSTANT_TRUE) + + +def _reset_channel_deserializer(): + """Make standard deserializer for reset channel.""" + + args = [] + return op_deserializer.GateOpDeserializer( + serialized_gate_id="RST", gate_constructor=cirq.ResetChannel, args=args) + + +def _phase_damp_channel_serializer(): + """Make standard serializer for PhaseDamp channel.""" + args = [ + # cirq channels can't contain symbols. + op_serializer.SerializingArg(serialized_name="gamma", + serialized_type=float, + op_getter=lambda x: x.gate.gamma), + op_serializer.SerializingArg(serialized_name="control_qubits", + serialized_type=str, + op_getter=lambda x: ''), + op_serializer.SerializingArg(serialized_name="control_values", + serialized_type=str, + op_getter=lambda x: '') + ] + return op_serializer.GateOpSerializer( + gate_type=cirq.PhaseDampingChannel, + serialized_gate_id="PD", + args=args, + can_serialize_predicate=_CONSTANT_TRUE) + + +def _phase_damp_channel_deserializer(): + """Make standard deserializer for PhaseDamp channel.""" + args = [ + op_deserializer.DeserializingArg(serialized_name="gamma", + constructor_arg_name="gamma") + ] + return op_deserializer.GateOpDeserializer( + serialized_gate_id="PD", + gate_constructor=cirq.PhaseDampingChannel, + args=args) + + +def _phase_flip_channel_serializer(): + """Make standard serializer for PhaseFlip channel.""" + args = [ + # cirq channels can't contain symbols. + op_serializer.SerializingArg(serialized_name="p", + serialized_type=float, + op_getter=lambda x: x.gate.p), + op_serializer.SerializingArg(serialized_name="control_qubits", + serialized_type=str, + op_getter=lambda x: ''), + op_serializer.SerializingArg(serialized_name="control_values", + serialized_type=str, + op_getter=lambda x: '') + ] + return op_serializer.GateOpSerializer( + gate_type=cirq.PhaseFlipChannel, + serialized_gate_id="PF", + args=args, + can_serialize_predicate=_CONSTANT_TRUE) + + +def _phase_flip_channel_deserializer(): + """Make standard deserializer for PhaseFlip channel.""" + + args = [ + op_deserializer.DeserializingArg(serialized_name="p", + constructor_arg_name="p") + ] + return op_deserializer.GateOpDeserializer( + serialized_gate_id="PF", + gate_constructor=cirq.PhaseFlipChannel, + args=args) + + +def _bit_flip_channel_serializer(): + """Make standard serializer for BitFlip channel.""" + args = [ + # cirq channels can't contain symbols. + op_serializer.SerializingArg(serialized_name="p", + serialized_type=float, + op_getter=lambda x: x.gate.p), + op_serializer.SerializingArg(serialized_name="control_qubits", + serialized_type=str, + op_getter=lambda x: ''), + op_serializer.SerializingArg(serialized_name="control_values", + serialized_type=str, + op_getter=lambda x: '') + ] + return op_serializer.GateOpSerializer( + gate_type=cirq.BitFlipChannel, + serialized_gate_id="BF", + args=args, + can_serialize_predicate=_CONSTANT_TRUE) + + +def _bit_flip_channel_deserializer(): + """Make standard deserializer for BitFlip channel.""" + args = [ + op_deserializer.DeserializingArg(serialized_name="p", + constructor_arg_name="p") + ] + return op_deserializer.GateOpDeserializer( + serialized_gate_id="BF", + gate_constructor=cirq.BitFlipChannel, + args=args) + + +# Gates. def _eigen_gate_serializer(gate_type, serialized_id): """Make standard serializer for eigen gates.""" args = [ - cirq.google.SerializingArg( + op_serializer.SerializingArg( serialized_name="exponent", serialized_type=float, op_getter=lambda x: _symbol_extractor(x.gate.exponent)), - cirq.google.SerializingArg( + op_serializer.SerializingArg( serialized_name="exponent_scalar", serialized_type=float, op_getter=lambda x: _scalar_extractor(x.gate.exponent)), - cirq.google.SerializingArg( + op_serializer.SerializingArg( serialized_name="global_shift", serialized_type=float, - op_getter=lambda x: float(x.gate._global_shift)) + op_getter=lambda x: float(x.gate._global_shift)), + op_serializer.SerializingArg( + serialized_name="control_qubits", + serialized_type=str, + op_getter=lambda x: _serialize_controls(x)), + op_serializer.SerializingArg( + serialized_name="control_values", + serialized_type=str, + op_getter=lambda x: _serialize_control_vals(x)) ] - return cirq.google.GateOpSerializer(gate_type=gate_type, - serialized_gate_id=serialized_id, - args=args, - can_serialize_predicate=_CONSTANT_TRUE) + return op_serializer.GateOpSerializer( + gate_type=gate_type, + serialized_gate_id=serialized_id, + args=args, + can_serialize_predicate=_CONSTANT_TRUE) def _eigen_gate_deserializer(gate_type, serialized_id): """Make standard deserializer for eigen gates.""" - def _scalar_combiner(exponent, global_shift, exponent_scalar): + def _scalar_combiner(exponent, global_shift, exponent_scalar, + control_qubits, control_values): """This is a workaround to support symbol scalar multiplication. In the future we should likely get rid of this in favor of proper expression parsing once cirq supports it. See cirq.op_serializer @@ -143,74 +497,99 @@ def _scalar_combiner(exponent, global_shift, exponent_scalar): like cirq.rx('alpha'). """ if exponent_scalar == 1.0: - return gate_type(exponent=_round(exponent), - global_shift=_round(global_shift)) - return gate_type(exponent=_round(exponent) * _round(exponent_scalar), - global_shift=_round(global_shift)) + return _optional_control_promote( + gate_type(exponent=_round(exponent), + global_shift=_round(global_shift)), control_qubits, + control_values) + return _optional_control_promote( + gate_type(exponent=_round(exponent) * _round(exponent_scalar), + global_shift=_round(global_shift)), control_qubits, + control_values) args = [ - cirq.google.DeserializingArg(serialized_name="exponent", - constructor_arg_name="exponent"), - cirq.google.DeserializingArg(serialized_name="global_shift", - constructor_arg_name="global_shift"), - cirq.google.DeserializingArg(serialized_name="exponent_scalar", - constructor_arg_name="exponent_scalar") + op_deserializer.DeserializingArg(serialized_name="exponent", + constructor_arg_name="exponent"), + op_deserializer.DeserializingArg(serialized_name="global_shift", + constructor_arg_name="global_shift"), + op_deserializer.DeserializingArg( + serialized_name="exponent_scalar", + constructor_arg_name="exponent_scalar"), + op_deserializer.DeserializingArg(serialized_name="control_qubits", + constructor_arg_name="control_qubits"), + op_deserializer.DeserializingArg(serialized_name="control_values", + constructor_arg_name="control_values") ] - return cirq.google.GateOpDeserializer(serialized_gate_id=serialized_id, - gate_constructor=_scalar_combiner, - args=args) + return op_deserializer.GateOpDeserializer(serialized_gate_id=serialized_id, + gate_constructor=_scalar_combiner, + args=args) def _fsim_gate_serializer(): """Make standard serializer for fsim gate.""" args = [ - cirq.google.SerializingArg( + op_serializer.SerializingArg( serialized_name="theta", serialized_type=float, op_getter=lambda x: _symbol_extractor(x.gate.theta)), - cirq.google.SerializingArg( + op_serializer.SerializingArg( serialized_name="phi", serialized_type=float, op_getter=lambda x: _symbol_extractor(x.gate.phi)), - cirq.google.SerializingArg( + op_serializer.SerializingArg( serialized_name="theta_scalar", serialized_type=float, op_getter=lambda x: _scalar_extractor(x.gate.theta)), - cirq.google.SerializingArg( + op_serializer.SerializingArg( serialized_name="phi_scalar", serialized_type=float, op_getter=lambda x: _scalar_extractor(x.gate.phi)), + op_serializer.SerializingArg( + serialized_name="control_qubits", + serialized_type=str, + op_getter=lambda x: _serialize_controls(x)), + op_serializer.SerializingArg( + serialized_name="control_values", + serialized_type=str, + op_getter=lambda x: _serialize_control_vals(x)) ] - return cirq.google.GateOpSerializer(gate_type=cirq.FSimGate, - serialized_gate_id="FSIM", - args=args, - can_serialize_predicate=_CONSTANT_TRUE) + return op_serializer.GateOpSerializer( + gate_type=cirq.FSimGate, + serialized_gate_id="FSIM", + args=args, + can_serialize_predicate=_CONSTANT_TRUE) def _fsim_gate_deserializer(): """Make standard deserializer for fsim gate.""" - def _scalar_combiner(theta, theta_scalar, phi, phi_scalar): + def _scalar_combiner(theta, theta_scalar, phi, phi_scalar, control_qubits, + control_values): """This is a workaround to support symbol scalar multiplication. See `_eigen_gate_deserializer` for details. """ - return cirq.FSimGate(theta=_round(theta) * _round(theta_scalar), - phi=_round(phi) * _round(phi_scalar)) + return _optional_control_promote( + cirq.FSimGate(theta=_round(theta) * _round(theta_scalar), + phi=_round(phi) * _round(phi_scalar)), control_qubits, + control_values) args = [ - cirq.google.DeserializingArg(serialized_name="theta", - constructor_arg_name="theta"), - cirq.google.DeserializingArg(serialized_name="phi", - constructor_arg_name="phi"), - cirq.google.DeserializingArg(serialized_name="theta_scalar", - constructor_arg_name="theta_scalar"), - cirq.google.DeserializingArg(serialized_name="phi_scalar", - constructor_arg_name="phi_scalar"), + op_deserializer.DeserializingArg(serialized_name="theta", + constructor_arg_name="theta"), + op_deserializer.DeserializingArg(serialized_name="phi", + constructor_arg_name="phi"), + op_deserializer.DeserializingArg(serialized_name="theta_scalar", + constructor_arg_name="theta_scalar"), + op_deserializer.DeserializingArg(serialized_name="phi_scalar", + constructor_arg_name="phi_scalar"), + op_deserializer.DeserializingArg(serialized_name="control_qubits", + constructor_arg_name="control_qubits"), + op_deserializer.DeserializingArg(serialized_name="control_values", + constructor_arg_name="control_values") ] - return cirq.google.GateOpDeserializer(serialized_gate_id="FSIM", - gate_constructor=_scalar_combiner, - args=args) + return op_deserializer.GateOpDeserializer(serialized_gate_id="FSIM", + gate_constructor=_scalar_combiner, + args=args) def _identity_gate_serializer(): @@ -226,67 +605,89 @@ def _identity_check(x): # Here `args` is used for two reasons. 1. GateOpSerializer doesn't work well # with empty arg lists. 2. It is a nice way to check identity gate size. args = [ - cirq.google.SerializingArg(serialized_name="unused", - serialized_type=bool, - op_getter=_identity_check) + op_serializer.SerializingArg(serialized_name="unused", + serialized_type=bool, + op_getter=_identity_check), + op_serializer.SerializingArg( + serialized_name="control_qubits", + serialized_type=str, + op_getter=lambda x: _serialize_controls(x)), + op_serializer.SerializingArg( + serialized_name="control_values", + serialized_type=str, + op_getter=lambda x: _serialize_control_vals(x)) ] - return cirq.google.GateOpSerializer(gate_type=cirq.IdentityGate, - serialized_gate_id="I", - args=args, - can_serialize_predicate=_CONSTANT_TRUE) + return op_serializer.GateOpSerializer( + gate_type=cirq.IdentityGate, + serialized_gate_id="I", + args=args, + can_serialize_predicate=_CONSTANT_TRUE) def _identity_gate_deserializer(): """Make a standard deserializer for the single qubit identity.""" args = [ - cirq.google.DeserializingArg(serialized_name="unused", - constructor_arg_name="unused") + op_deserializer.DeserializingArg(serialized_name="unused", + constructor_arg_name="unused"), + op_deserializer.DeserializingArg(serialized_name="control_qubits", + constructor_arg_name="control_qubits"), + op_deserializer.DeserializingArg(serialized_name="control_values", + constructor_arg_name="control_values") ] - def _cirq_i_workaround(unused): - return cirq.I + def _cirq_i_workaround(unused, control_qubits, control_values): + return _optional_control_promote(cirq.I, control_qubits, control_values) - return cirq.google.GateOpDeserializer(serialized_gate_id="I", - gate_constructor=_cirq_i_workaround, - args=args) + return op_deserializer.GateOpDeserializer( + serialized_gate_id="I", gate_constructor=_cirq_i_workaround, args=args) def _phased_eigen_gate_serializer(gate_type, serialized_id): """Make a standard serializer for phased eigen gates.""" args = [ - cirq.google.SerializingArg( + op_serializer.SerializingArg( serialized_name="phase_exponent", serialized_type=float, op_getter=lambda x: _symbol_extractor(x.gate.phase_exponent)), - cirq.google.SerializingArg( + op_serializer.SerializingArg( serialized_name="phase_exponent_scalar", serialized_type=float, op_getter=lambda x: _scalar_extractor(x.gate.phase_exponent)), - cirq.google.SerializingArg( + op_serializer.SerializingArg( serialized_name="exponent", serialized_type=float, op_getter=lambda x: _symbol_extractor(x.gate.exponent)), - cirq.google.SerializingArg( + op_serializer.SerializingArg( serialized_name="exponent_scalar", serialized_type=float, op_getter=lambda x: _scalar_extractor(x.gate.exponent)), - cirq.google.SerializingArg( + op_serializer.SerializingArg( serialized_name="global_shift", serialized_type=float, - op_getter=lambda x: float(x.gate.global_shift)) + op_getter=lambda x: float(x.gate.global_shift)), + op_serializer.SerializingArg( + serialized_name="control_qubits", + serialized_type=str, + op_getter=lambda x: _serialize_controls(x)), + op_serializer.SerializingArg( + serialized_name="control_values", + serialized_type=str, + op_getter=lambda x: _serialize_control_vals(x)) ] - return cirq.google.GateOpSerializer(gate_type=gate_type, - serialized_gate_id=serialized_id, - args=args, - can_serialize_predicate=_CONSTANT_TRUE) + return op_serializer.GateOpSerializer( + gate_type=gate_type, + serialized_gate_id=serialized_id, + args=args, + can_serialize_predicate=_CONSTANT_TRUE) def _phased_eigen_gate_deserializer(gate_type, serialized_id): """Make a standard deserializer for phased eigen gates.""" def _scalar_combiner(exponent, global_shift, exponent_scalar, - phase_exponent, phase_exponent_scalar): + phase_exponent, phase_exponent_scalar, control_qubits, + control_values): """This is a workaround to support symbol scalar multiplication. In the future we should likely get rid of this in favor of proper expression parsing once cirq supports it. See cirq.op_serializer @@ -302,27 +703,36 @@ def _scalar_combiner(exponent, global_shift, exponent_scalar, if global_shift != 0: # needed in case this specific phasedeigengate doesn't # have a global_phase in constructor. - return gate_type(exponent=exponent, - global_shift=_round(global_shift), - phase_exponent=phase_exponent) - return gate_type(exponent=exponent, phase_exponent=phase_exponent) + return _optional_control_promote( + gate_type(exponent=exponent, + global_shift=_round(global_shift), + phase_exponent=phase_exponent), control_qubits, + control_values) + return _optional_control_promote( + gate_type(exponent=exponent, phase_exponent=phase_exponent), + control_qubits, control_values) args = [ - cirq.google.DeserializingArg(serialized_name="phase_exponent", - constructor_arg_name="phase_exponent"), - cirq.google.DeserializingArg( + op_deserializer.DeserializingArg(serialized_name="phase_exponent", + constructor_arg_name="phase_exponent"), + op_deserializer.DeserializingArg( serialized_name="phase_exponent_scalar", constructor_arg_name="phase_exponent_scalar"), - cirq.google.DeserializingArg(serialized_name="exponent", - constructor_arg_name="exponent"), - cirq.google.DeserializingArg(serialized_name="exponent_scalar", - constructor_arg_name="exponent_scalar"), - cirq.google.DeserializingArg(serialized_name="global_shift", - constructor_arg_name="global_shift"), + op_deserializer.DeserializingArg(serialized_name="exponent", + constructor_arg_name="exponent"), + op_deserializer.DeserializingArg( + serialized_name="exponent_scalar", + constructor_arg_name="exponent_scalar"), + op_deserializer.DeserializingArg(serialized_name="global_shift", + constructor_arg_name="global_shift"), + op_deserializer.DeserializingArg(serialized_name="control_qubits", + constructor_arg_name="control_qubits"), + op_deserializer.DeserializingArg(serialized_name="control_values", + constructor_arg_name="control_values") ] - return cirq.google.GateOpDeserializer(serialized_gate_id=serialized_id, - gate_constructor=_scalar_combiner, - args=args) + return op_deserializer.GateOpDeserializer(serialized_gate_id=serialized_id, + gate_constructor=_scalar_combiner, + args=args) EIGEN_GATES_DICT = { @@ -346,30 +756,45 @@ def _scalar_combiner(exponent, global_shift, exponent_scalar, SERIALIZERS = [ _eigen_gate_serializer(g, g_name) for g, g_name in EIGEN_GATES_DICT.items() -] + [ - _fsim_gate_serializer(), -] + [ - _identity_gate_serializer(), ] + [ _phased_eigen_gate_serializer(g, g_name) for g, g_name in PHASED_EIGEN_GATES_DICT.items() +] + [ + _amplitude_damp_channel_serializer(), + _asymmetric_depolarize_serializer(), + _bit_flip_channel_serializer(), + _depolarize_channel_serializer(), + _fsim_gate_serializer(), + _gad_channel_serializer(), + _identity_gate_serializer(), + _phase_damp_channel_serializer(), + _reset_channel_serializer(), + _phase_flip_channel_serializer() ] DESERIALIZERS = [ _eigen_gate_deserializer(g, g_name) for g, g_name in EIGEN_GATES_DICT.items() -] + [ - _fsim_gate_deserializer(), -] + [ - _identity_gate_deserializer(), ] + [ _phased_eigen_gate_deserializer(g, g_name) for g, g_name in PHASED_EIGEN_GATES_DICT.items() +] + [ + _amplitude_damp_channel_deserializer(), + _asymmetric_depolarize_deserializer(), + _bit_flip_channel_deserializer(), + _depolarize_channel_deserializer(), + _fsim_gate_deserializer(), + _gad_channel_deserializer(), + _identity_gate_deserializer(), + _phase_damp_channel_deserializer(), + _reset_channel_deserializer(), + _phase_flip_channel_deserializer() ] -SERIALIZER = cirq.google.SerializableGateSet(gate_set_name="tfq_gate_set", - serializers=SERIALIZERS, - deserializers=DESERIALIZERS) +SERIALIZER = serializable_gate_set.SerializableGateSet( + gate_set_name="tfq_gate_set", + serializers=SERIALIZERS, + deserializers=DESERIALIZERS) def serialize_circuit(circuit_inp): @@ -379,8 +804,8 @@ def serialize_circuit(circuit_inp): Currently we only support scalar multiplication of symbols and no other more complex arithmetic expressions. This means we can support things like X**(3*alpha), and Rx(alpha). Because - we use the `cirq.Program` proto, we only support `cirq.GridQubit` instances - during serialization of circuits. + we use the `cirq.Program` proto, we only support `cirq.GridQubit` + and `cirq.LineQubit` instances during serialization of circuits. Note: once serialized terminal measurements are removed. @@ -388,7 +813,7 @@ def serialize_circuit(circuit_inp): circuit_inp: A `cirq.Circuit`. Returns: - A `cirq.google.api.v2.Program` proto. + A `tfq.proto.Program` proto. """ circuit = copy.deepcopy(circuit_inp) if not isinstance(circuit, cirq.Circuit): @@ -407,10 +832,10 @@ def serialize_circuit(circuit_inp): measured_qubits = set() for op in moment: for qubit in op.qubits: - if not isinstance(qubit, cirq.GridQubit): + if not isinstance(qubit, (cirq.GridQubit, cirq.LineQubit)): raise ValueError( "Attempted to serialize circuit that don't use " - "only cirq.GridQubits.") + "only cirq.GridQubits or cirq.LineQubits.") if isinstance(op.gate, cirq.MeasurementGate): for qubit in op.qubits: @@ -434,6 +859,25 @@ def serialize_circuit(circuit_inp): old_moment.operations)) circuit[moment_ind] = new_moment + # Demote cirq.controlled_operations (controlled gates) to their sub_gate + # types with _tfq_control_qubits and _tfq_control_values fields so that + # the gates can still get picked up by the serializer. There would be no way + # to discern controlledgates from one another otherwise. This + # "momentary demotion" occurs with the help of the DelayedAssignmentGate. + for i, moment in enumerate(circuit): + controlled_ops = [ + op for op in moment if isinstance(op, cirq.ControlledOperation) + ] + new_ops = dict() + for op in controlled_ops: + tfq_compatible = op.sub_operation + tfq_compatible._tfq_control_qubits = op.controls + tfq_compatible._tfq_control_values = op.control_values + new_ops[op.qubits] = tfq_compatible + + circuit[i] = cirq.Moment( + new_ops[op.qubits] if op.qubits in new_ops else op for op in moment) + return SERIALIZER.serialize(circuit) @@ -443,14 +887,14 @@ def deserialize_circuit(proto): Note that the proto must use gates valid in the tfq_gate_set. Args: - proto: A `cirq.google.api.v2.Program` proto + proto: A `tfq.proto.Program` proto Returns: A `cirq.Circuit`. """ - if not isinstance(proto, cirq.google.api.v2.program_pb2.Program): + if not isinstance(proto, program_pb2.Program): raise TypeError("deserialize requires " - "cirq.google.api.v2.program_pb2.Program object." + "tfq.proto.Program object." " Given: " + str(type(proto))) return SERIALIZER.deserialize(proto) @@ -472,9 +916,10 @@ def serialize_paulisum(paulisum): raise TypeError("serialize requires a cirq.PauliSum object." " Given: " + str(type(paulisum))) - if any(not isinstance(qubit, cirq.GridQubit) for qubit in paulisum.qubits): + if any(not isinstance(qubit, (cirq.LineQubit, cirq.GridQubit)) + for qubit in paulisum.qubits): raise ValueError("Attempted to serialize a paulisum that doesn't use " - "only cirq.GridQubits.") + "only cirq.GridQubits or cirq.LineQubits.") paulisum_proto = pauli_sum_pb2.PauliSum() for term in paulisum: @@ -484,7 +929,7 @@ def serialize_paulisum(paulisum): pauliterm_proto.coefficient_imag = term.coefficient.imag for t in sorted(term.items()): # sort to keep qubits ordered. pauliterm_proto.paulis.add( - qubit_id=v2.qubit_to_proto_id(t[0]), + qubit_id=op_serializer.qubit_to_proto(t[0]), pauli_type=str(t[1]), ) paulisum_proto.terms.extend([pauliterm_proto]) @@ -512,7 +957,8 @@ def deserialize_paulisum(proto): term = coef * cirq.PauliString() for pauli_qubit_pair in term_proto.paulis: op = _process_pauli_type(pauli_qubit_pair.pauli_type) - term *= op(v2.grid_qubit_from_proto_id(pauli_qubit_pair.qubit_id)) + term *= op( + op_deserializer.qubit_from_proto(pauli_qubit_pair.qubit_id)) res += term return res @@ -526,3 +972,68 @@ def _process_pauli_type(char): if char == 'Y': return cirq.Y raise ValueError("Invalid pauli type.") + + +def serialize_projectorsum(projectorsum): + """Constructs a projector_sum proto from `cirq.ProjectorSum`. + + Args: + projectorsum: A `cirq.ProjectorSum` or `cirq.ProjectorString` object. + + Returns: + A projector_sum proto object. + """ + if isinstance(projectorsum, cirq.ProjectorString): + projectorsum = cirq.ProjectorSum.from_pauli_strings(projectorsum) + + if not isinstance(projectorsum, cirq.ProjectorSum): + raise TypeError("serialize requires a cirq.ProjectorSum object." + " Given: " + str(type(projectorsum))) + + if any(not isinstance(qubit, (cirq.GridQubit, cirq.LineQubit)) + for qubit in projectorsum.qubits): + raise ValueError("Attempted to serialize a paulisum that doesn't use " + "only cirq.GridQubit or cirq.LineQubit.") + + projectorsum_proto = projector_sum_pb2.ProjectorSum() + for term in projectorsum: + projectorterm_proto = projector_sum_pb2.ProjectorTerm() + + projectorterm_proto.coefficient_real = term.coefficient.real + projectorterm_proto.coefficient_imag = term.coefficient.imag + for qubit, basis_state in sorted( + term.projector_dict.items()): # sort to keep qubits ordered + projectorterm_proto.projector_dict.add( + qubit_id=op_serializer.qubit_to_proto(qubit), + basis_state=basis_state) + + projectorsum_proto.terms.extend([projectorterm_proto]) + + return projectorsum_proto + + +def deserialize_projectorsum(proto): + """Constructs a `cirq.ProjectorSum` from projector_sum proto. + + Args: + proto: A projector_sum proto object. + + Returns: + A `cirq.ProjectorSum` object. + """ + if not isinstance(proto, projector_sum_pb2.ProjectorSum): + raise TypeError("deserialize requires a projector_sum_pb2 object." + " Given: " + str(type(proto))) + + res = cirq.ProjectorSum() + for term_proto in proto.terms: + coef = float(_round(term_proto.coefficient_real)) + \ + 1.0j * float(_round(term_proto.coefficient_imag)) + projector_dict = {} + for projector_dict_entry in term_proto.projector_dict: + qubit = op_deserializer.qubit_from_proto( + projector_dict_entry.qubit_id) + projector_dict[qubit] = 1 if projector_dict_entry.basis_state else 0 + res += cirq.ProjectorString(projector_dict, coef) + + return res diff --git a/tensorflow_quantum/core/serialize/serializer_test.py b/tensorflow_quantum/core/serialize/serializer_test.py index 94fb1c1ea..d4e1667e6 100644 --- a/tensorflow_quantum/core/serialize/serializer_test.py +++ b/tensorflow_quantum/core/serialize/serializer_test.py @@ -11,26 +11,35 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module to test serialization core.""" +# 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 + import copy import numpy as np import sympy import tensorflow as tf import cirq -from cirq.google.api.v2 import program_pb2 from absl.testing import parameterized from tensorflow_quantum.core.proto import pauli_sum_pb2 +from tensorflow_quantum.core.proto import program_pb2 +from tensorflow_quantum.core.proto import projector_sum_pb2 from tensorflow_quantum.core.serialize import serializer -def _build_gate_proto(gate_id, arg_names, arg_vals, qubit_ids): +def _build_op_proto(gate_id, arg_names, arg_vals, qubit_ids): """Helper function to generate proto for a given circuit spec. Understand how it works from this example: - _build_gate_proto("HP", + _build_op_proto("HP", ['exponent', 'global_shift'], ['alpha', 0.0], ['0_0']) @@ -61,6 +70,18 @@ def _build_gate_proto(gate_id, arg_names, arg_vals, qubit_ids): symbol: "alpha" } } + args { + key: "control_qubits" + value { + arg_value: "" + } + } + args { + key: "control_values" + value { + arg_value: "" + } + } qubits { id: "0_0" } @@ -68,341 +89,446 @@ def _build_gate_proto(gate_id, arg_names, arg_vals, qubit_ids): } } """ - program_proto = program_pb2.Program() program_proto.language.gate_set = 'tfq_gate_set' circuit_proto = program_proto.circuit - circuit_proto.scheduling_strategy = circuit_proto.MOMENT_BY_MOMENT #'1'. + circuit_proto.scheduling_strategy = circuit_proto.MOMENT_BY_MOMENT circuit_proto.moments.add(operations=[program_pb2.Operation( gate = program_pb2.Gate(id=gate_id), args = {arg_names[i]: (program_pb2.Arg(symbol=arg_vals[i]) \ if isinstance(arg_vals[i], str) else \ program_pb2.Arg( - arg_value=cirq.google.api.v2.program_pb2.ArgValue( - float_value=np.round(float(arg_vals[i]), 6)))) \ + arg_value=program_pb2.ArgValue( + float_value=np.round(float(arg_vals[i]), 6)))) for i in range(len(arg_vals))}, qubits=[program_pb2.Qubit( id=q_id) for q_id in qubit_ids])]) + # Add in empty control information + t = program_proto.circuit.moments[0].operations[0] + t.args['control_qubits'].arg_value.string_value = '' + t.args['control_values'].arg_value.string_value = '' + return program_proto -def _get_valid_circuit_proto_pairs(): +def _make_controlled_gate_proto(program_proto, control_qubits, control_values): + """Turn a gate proto (from above) into a controlled gate proto. + + inserts control_qubits and control_values into gate args map. + """ + t = program_proto.circuit.moments[0].operations[0] + t.args['control_qubits'].arg_value.string_value = control_qubits + t.args['control_values'].arg_value.string_value = control_values + return program_proto + + +def _make_controlled_circuit(circuit, control_qubits, control_values): + new_circuit = cirq.Circuit() + for moment in circuit: + for op in moment: + new_op = op + for qb, v in zip(control_qubits[::-1], control_values[::-1]): + # TODO(tonybruguier,#636): Here we call the parent's class + # controlled_by because Cirq's breaking change #4167 created + # 3-qubit gates that cannot be serialized yet. Instead, support + # 3-qubit gates and revert the work-around. + new_op = cirq.ControlledOperation([qb], + new_op, + control_values=[v]) + new_circuit += new_op + return new_circuit + + +def _get_circuit_proto_pairs(qubit_type='grid'): q0 = cirq.GridQubit(0, 0) q1 = cirq.GridQubit(0, 1) + q0_str = '0_0' + q1_str = '0_1' + + if qubit_type == 'line': + q0 = cirq.LineQubit(0) + q1 = cirq.LineQubit(1) + q0_str = '0' + q1_str = '1' pairs = [ # HPOW and aliases. (cirq.Circuit(cirq.HPowGate(exponent=0.3)(q0)), - _build_gate_proto("HP", - ['exponent', 'exponent_scalar', 'global_shift'], - [0.3, 1.0, 0.0], ['0_0'])), + _build_op_proto("HP", ['exponent', 'exponent_scalar', 'global_shift'], + [0.3, 1.0, 0.0], [q0_str])), (cirq.Circuit(cirq.HPowGate(exponent=sympy.Symbol('alpha'))(q0)), - _build_gate_proto("HP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 1.0, 0.0], ['0_0'])), + _build_op_proto("HP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 1.0, 0.0], [q0_str])), (cirq.Circuit(cirq.HPowGate(exponent=3.1 * sympy.Symbol('alpha'))(q0)), - _build_gate_proto("HP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 3.1, 0.0], ['0_0'])), + _build_op_proto("HP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 3.1, 0.0], [q0_str])), (cirq.Circuit(cirq.H(q0)), - _build_gate_proto("HP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, 0.0], ['0_0'])), + _build_op_proto("HP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, 0.0], [q0_str])), # XPOW and aliases. (cirq.Circuit(cirq.XPowGate(exponent=0.3)(q0)), - _build_gate_proto("XP", - ['exponent', 'exponent_scalar', 'global_shift'], - [0.3, 1.0, 0.0], ['0_0'])), + _build_op_proto("XP", ['exponent', 'exponent_scalar', 'global_shift'], + [0.3, 1.0, 0.0], [q0_str])), (cirq.Circuit(cirq.XPowGate(exponent=sympy.Symbol('alpha'))(q0)), - _build_gate_proto("XP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 1.0, 0.0], ['0_0'])), + _build_op_proto("XP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 1.0, 0.0], [q0_str])), (cirq.Circuit(cirq.XPowGate(exponent=3.1 * sympy.Symbol('alpha'))(q0)), - _build_gate_proto("XP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 3.1, 0.0], ['0_0'])), + _build_op_proto("XP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 3.1, 0.0], [q0_str])), (cirq.Circuit(cirq.X(q0)), - _build_gate_proto("XP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, 0.0], ['0_0'])), + _build_op_proto("XP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, 0.0], [q0_str])), # YPOW and aliases (cirq.Circuit(cirq.YPowGate(exponent=0.3)(q0)), - _build_gate_proto("YP", - ['exponent', 'exponent_scalar', 'global_shift'], - [0.3, 1.0, 0.0], ['0_0'])), + _build_op_proto("YP", ['exponent', 'exponent_scalar', 'global_shift'], + [0.3, 1.0, 0.0], [q0_str])), (cirq.Circuit(cirq.YPowGate(exponent=sympy.Symbol('alpha'))(q0)), - _build_gate_proto("YP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 1.0, 0.0], ['0_0'])), + _build_op_proto("YP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 1.0, 0.0], [q0_str])), (cirq.Circuit(cirq.YPowGate(exponent=3.1 * sympy.Symbol('alpha'))(q0)), - _build_gate_proto("YP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 3.1, 0.0], ['0_0'])), + _build_op_proto("YP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 3.1, 0.0], [q0_str])), (cirq.Circuit(cirq.Y(q0)), - _build_gate_proto("YP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, 0.0], ['0_0'])), + _build_op_proto("YP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, 0.0], [q0_str])), # ZPOW and aliases. (cirq.Circuit(cirq.ZPowGate(exponent=0.3)(q0)), - _build_gate_proto("ZP", - ['exponent', 'exponent_scalar', 'global_shift'], - [0.3, 1.0, 0.0], ['0_0'])), + _build_op_proto("ZP", ['exponent', 'exponent_scalar', 'global_shift'], + [0.3, 1.0, 0.0], [q0_str])), (cirq.Circuit(cirq.ZPowGate(exponent=sympy.Symbol('alpha'))(q0)), - _build_gate_proto("ZP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 1.0, 0.0], ['0_0'])), + _build_op_proto("ZP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 1.0, 0.0], [q0_str])), (cirq.Circuit(cirq.ZPowGate(exponent=3.1 * sympy.Symbol('alpha'))(q0)), - _build_gate_proto("ZP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 3.1, 0.0], ['0_0'])), + _build_op_proto("ZP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 3.1, 0.0], [q0_str])), (cirq.Circuit(cirq.Z(q0)), - _build_gate_proto("ZP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, 0.0], ['0_0'])), + _build_op_proto("ZP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, 0.0], [q0_str])), # XXPow and aliases (cirq.Circuit(cirq.XXPowGate(exponent=0.3)(q0, q1)), - _build_gate_proto("XXP", - ['exponent', 'exponent_scalar', 'global_shift'], - [0.3, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("XXP", ['exponent', 'exponent_scalar', 'global_shift'], + [0.3, 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.XXPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("XXP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("XXP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit( cirq.XXPowGate(exponent=3.1 * sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("XXP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 3.1, 0.0], ['0_0', '0_1'])), + _build_op_proto("XXP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 3.1, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.XX(q0, q1)), - _build_gate_proto("XXP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("XXP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, 0.0], [q0_str, q1_str])), # YYPow and aliases (cirq.Circuit(cirq.YYPowGate(exponent=0.3)(q0, q1)), - _build_gate_proto("YYP", - ['exponent', 'exponent_scalar', 'global_shift'], - [0.3, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("YYP", ['exponent', 'exponent_scalar', 'global_shift'], + [0.3, 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.YYPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("YYP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("YYP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit( cirq.YYPowGate(exponent=3.1 * sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("YYP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 3.1, 0.0], ['0_0', '0_1'])), + _build_op_proto("YYP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 3.1, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.YY(q0, q1)), - _build_gate_proto("YYP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("YYP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, 0.0], [q0_str, q1_str])), # ZZPow and aliases (cirq.Circuit(cirq.ZZPowGate(exponent=0.3)(q0, q1)), - _build_gate_proto("ZZP", - ['exponent', 'exponent_scalar', 'global_shift'], - [0.3, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("ZZP", ['exponent', 'exponent_scalar', 'global_shift'], + [0.3, 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.ZZPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("ZZP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("ZZP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit( cirq.ZZPowGate(exponent=3.1 * sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("ZZP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 3.1, 0.0], ['0_0', '0_1'])), + _build_op_proto("ZZP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 3.1, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.ZZ(q0, q1)), - _build_gate_proto("ZZP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("ZZP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, 0.0], [q0_str, q1_str])), # CZPow and aliases (cirq.Circuit(cirq.CZPowGate(exponent=0.3)(q0, q1)), - _build_gate_proto("CZP", - ['exponent', 'exponent_scalar', 'global_shift'], - [0.3, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("CZP", ['exponent', 'exponent_scalar', 'global_shift'], + [0.3, 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.CZPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("CZP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("CZP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit( cirq.CZPowGate(exponent=3.1 * sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("CZP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 3.1, 0.0], ['0_0', '0_1'])), + _build_op_proto("CZP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 3.1, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.CZ(q0, q1)), - _build_gate_proto("CZP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("CZP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, 0.0], [q0_str, q1_str])), # CNOTPow and aliases (cirq.Circuit(cirq.CNotPowGate(exponent=0.3)(q0, q1)), - _build_gate_proto("CNP", - ['exponent', 'exponent_scalar', 'global_shift'], - [0.3, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("CNP", ['exponent', 'exponent_scalar', 'global_shift'], + [0.3, 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.CNotPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("CNP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("CNP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit( cirq.CNotPowGate(exponent=3.1 * sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("CNP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 3.1, 0.0], ['0_0', '0_1'])), + _build_op_proto("CNP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 3.1, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.CNOT(q0, q1)), - _build_gate_proto("CNP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("CNP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, 0.0], [q0_str, q1_str])), # SWAPPow and aliases (cirq.Circuit(cirq.SwapPowGate(exponent=0.3)(q0, q1)), - _build_gate_proto("SP", - ['exponent', 'exponent_scalar', 'global_shift'], - [0.3, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("SP", ['exponent', 'exponent_scalar', 'global_shift'], + [0.3, 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.SwapPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("SP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("SP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit( cirq.SwapPowGate(exponent=3.1 * sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("SP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 3.1, 0.0], ['0_0', '0_1'])), + _build_op_proto("SP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 3.1, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.SWAP(q0, q1)), - _build_gate_proto("SP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("SP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, 0.0], [q0_str, q1_str])), # ISWAPPow and aliases (cirq.Circuit(cirq.ISwapPowGate(exponent=0.3)(q0, q1)), - _build_gate_proto("ISP", - ['exponent', 'exponent_scalar', 'global_shift'], - [0.3, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("ISP", ['exponent', 'exponent_scalar', 'global_shift'], + [0.3, 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit( cirq.ISwapPowGate(exponent=sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("ISP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("ISP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 1.0, 0.0], [q0_str, q1_str])), (cirq.Circuit( cirq.ISwapPowGate(exponent=3.1 * sympy.Symbol('alpha'))(q0, q1)), - _build_gate_proto("ISP", - ['exponent', 'exponent_scalar', 'global_shift'], - ['alpha', 3.1, 0.0], ['0_0', '0_1'])), + _build_op_proto("ISP", ['exponent', 'exponent_scalar', 'global_shift'], + ['alpha', 3.1, 0.0], [q0_str, q1_str])), (cirq.Circuit(cirq.ISWAP(q0, q1)), - _build_gate_proto("ISP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, 0.0], ['0_0', '0_1'])), + _build_op_proto("ISP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, 0.0], [q0_str, q1_str])), # PhasedXPow and aliases (cirq.Circuit( cirq.PhasedXPowGate(phase_exponent=0.9, exponent=0.3, global_shift=0.2)(q0)), - _build_gate_proto("PXP", [ + _build_op_proto("PXP", [ 'phase_exponent', 'phase_exponent_scalar', 'exponent', 'exponent_scalar', 'global_shift' - ], [0.9, 1.0, 0.3, 1.0, 0.2], ['0_0'])), + ], [0.9, 1.0, 0.3, 1.0, 0.2], [q0_str])), (cirq.Circuit( cirq.PhasedXPowGate(phase_exponent=sympy.Symbol('alpha'), exponent=0.3)(q0)), - _build_gate_proto("PXP", [ + _build_op_proto("PXP", [ 'phase_exponent', 'phase_exponent_scalar', 'exponent', 'exponent_scalar', 'global_shift' - ], ['alpha', 1.0, 0.3, 1.0, 0.0], ['0_0'])), + ], ['alpha', 1.0, 0.3, 1.0, 0.0], [q0_str])), (cirq.Circuit( cirq.PhasedXPowGate(phase_exponent=3.1 * sympy.Symbol('alpha'), exponent=0.3)(q0)), - _build_gate_proto("PXP", [ + _build_op_proto("PXP", [ 'phase_exponent', 'phase_exponent_scalar', 'exponent', 'exponent_scalar', 'global_shift' - ], ['alpha', 3.1, 0.3, 1.0, 0.0], ['0_0'])), + ], ['alpha', 3.1, 0.3, 1.0, 0.0], [q0_str])), (cirq.Circuit( cirq.PhasedXPowGate(phase_exponent=0.9, exponent=sympy.Symbol('beta'))(q0)), - _build_gate_proto("PXP", [ + _build_op_proto("PXP", [ 'phase_exponent', 'phase_exponent_scalar', 'exponent', 'exponent_scalar', 'global_shift' - ], [0.9, 1.0, 'beta', 1.0, 0.0], ['0_0'])), + ], [0.9, 1.0, 'beta', 1.0, 0.0], [q0_str])), (cirq.Circuit( cirq.PhasedXPowGate(phase_exponent=0.9, exponent=5.1 * sympy.Symbol('beta'))(q0)), - _build_gate_proto("PXP", [ + _build_op_proto("PXP", [ 'phase_exponent', 'phase_exponent_scalar', 'exponent', 'exponent_scalar', 'global_shift' - ], [0.9, 1.0, 'beta', 5.1, 0.0], ['0_0'])), + ], [0.9, 1.0, 'beta', 5.1, 0.0], [q0_str])), (cirq.Circuit( cirq.PhasedXPowGate(phase_exponent=3.1 * sympy.Symbol('alpha'), exponent=5.1 * sympy.Symbol('beta'))(q0)), - _build_gate_proto("PXP", [ + _build_op_proto("PXP", [ 'phase_exponent', 'phase_exponent_scalar', 'exponent', 'exponent_scalar', 'global_shift' - ], ['alpha', 3.1, 'beta', 5.1, 0.0], ['0_0'])), + ], ['alpha', 3.1, 'beta', 5.1, 0.0], [q0_str])), # RX, RY, RZ with symbolization is tested in special cases as the # string comparison of the float converted sympy.pi does not happen # smoothly. See: test_serialize_deserialize_special_case_one_qubit (cirq.Circuit(cirq.rx(np.pi)(q0)), - _build_gate_proto("XP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, -0.5], ['0_0'])), + _build_op_proto("XP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, -0.5], [q0_str])), (cirq.Circuit(cirq.ry(np.pi)(q0)), - _build_gate_proto("YP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, -0.5], ['0_0'])), + _build_op_proto("YP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, -0.5], [q0_str])), (cirq.Circuit(cirq.rz(np.pi)(q0)), - _build_gate_proto("ZP", - ['exponent', 'exponent_scalar', 'global_shift'], - [1.0, 1.0, -0.5], ['0_0'])), + _build_op_proto("ZP", ['exponent', 'exponent_scalar', 'global_shift'], + [1.0, 1.0, -0.5], [q0_str])), # Identity (cirq.Circuit(cirq.I(q0)), - _build_gate_proto("I", ['unused'], [True], ['0_0'])), + _build_op_proto("I", ['unused'], [True], [q0_str])), # FSimGate (cirq.Circuit(cirq.FSimGate(theta=0.1, phi=0.2)(q0, q1)), - _build_gate_proto("FSIM", - ['theta', 'theta_scalar', 'phi', 'phi_scalar'], - [0.1, 1.0, 0.2, 1.0], ['0_0', '0_1'])), + _build_op_proto("FSIM", ['theta', 'theta_scalar', 'phi', 'phi_scalar'], + [0.1, 1.0, 0.2, 1.0], [q0_str, q1_str])), (cirq.Circuit( cirq.FSimGate(theta=2.1 * sympy.Symbol("alpha"), phi=1.3 * sympy.Symbol("beta"))(q0, q1)), - _build_gate_proto("FSIM", - ['theta', 'theta_scalar', 'phi', 'phi_scalar'], - ['alpha', 2.1, 'beta', 1.3], ['0_0', '0_1'])), + _build_op_proto("FSIM", ['theta', 'theta_scalar', 'phi', 'phi_scalar'], + ['alpha', 2.1, 'beta', 1.3], [q0_str, q1_str])), ] return pairs -def _get_valid_pauli_proto_pairs(): +def _get_controlled_circuit_proto_pairs(qubit_type='grid'): + + q0 = cirq.GridQubit(5, 6) + q1 = cirq.GridQubit(7, 8) + q2 = cirq.GridQubit(9, 10) + q0_str = '5_6' + q1_str = '7_8' + q2_str = '9_10' + + if qubit_type == 'line': + q0 = cirq.LineQubit(6) + q1 = cirq.LineQubit(7) + q2 = cirq.LineQubit(10) + q0_str = '6' + q1_str = '7' + q2_str = '10' + + return [(_make_controlled_circuit(a, [q0, q1, q2], [1, 1, 0]), + _make_controlled_gate_proto(b, ','.join([q0_str, q1_str, q2_str]), + '1,1,0')) + for a, b in _get_circuit_proto_pairs(qubit_type=qubit_type)] + + +def _get_valid_pauli_proto_pairs(qubit_type='grid'): """Generate valid paulisum proto pairs.""" q0 = cirq.GridQubit(0, 0) q1 = cirq.GridQubit(1, 0) + q0_str = '0_0' + q1_str = '1_0' + + if qubit_type == 'line': + q0 = cirq.LineQubit(0) + q1 = cirq.LineQubit(1) + q0_str = '0' + q1_str = '1' + pairs = [ (cirq.PauliSum.from_pauli_strings((2.1 + 0.2j) * cirq.Z(q0)), - _build_pauli_proto([2.1 + 0.2j], [['Z']], [['0_0']])), + _build_pauli_proto([2.1 + 0.2j], [['Z']], [[q0_str]])), (cirq.PauliSum.from_pauli_strings((1.0 + 0.0j) * cirq.X(q0)), - _build_pauli_proto([1.0 + 0.0j], [['X']], [['0_0']])), + _build_pauli_proto([1.0 + 0.0j], [['X']], [[q0_str]])), (cirq.PauliSum.from_pauli_strings((0.0 + 1.0j) * cirq.Y(q0)), - _build_pauli_proto([0.0 + 1.0j], [['Y']], [['0_0']])), + _build_pauli_proto([0.0 + 1.0j], [['Y']], [[q0_str]])), ((0.0 + 1.0j) * cirq.Y(q0) + 1.0 * cirq.Z(q1), _build_pauli_proto([0.0 + 1.0j, 1.0 + 0.0j], [['Y'], ['Z']], - [['0_0'], ['1_0']])), + [[q0_str], [q1_str]])), (2.0 * cirq.Y(q1) + 1.0 * cirq.Z(q0) + cirq.X(q0) * cirq.X(q1), _build_pauli_proto([2.0 + 0.0j, 1.0 + 0.0j, 1.0 + 0.0j], [['Y'], ['Z'], ['X', 'X']], - [['1_0'], ['0_0'], ['0_0', '1_0']])), + [[q1_str], [q0_str], [q0_str, q1_str]])), + ] + + return pairs + + +def _get_valid_projector_proto_pairs(qubit_type='grid'): + """Generate valid projectorsum proto pairs.""" + q0 = cirq.GridQubit(0, 0) + q1 = cirq.GridQubit(1, 0) + q0_str = '0_0' + q1_str = '1_0' + + if qubit_type == 'line': + q0 = cirq.LineQubit(0) + q1 = cirq.LineQubit(1) + q0_str = '0' + q1_str = '1' + + pairs = [ + (cirq.ProjectorSum.from_projector_strings( + cirq.ProjectorString(projector_dict={q0: 0})), + _build_projector_proto([1.0], [[0]], [[q0_str]])), + (cirq.ProjectorSum.from_projector_strings( + cirq.ProjectorString(projector_dict={q0: 0}, coefficient=0.125j)), + _build_projector_proto([0.125j], [[0]], [[q0_str]])), + (cirq.ProjectorSum.from_projector_strings([ + cirq.ProjectorString(projector_dict={ + q0: 0, + q1: 1 + }), + ]), _build_projector_proto([1.0], [[0, 1]], [[q0_str, q1_str]])), ] return pairs +def _get_noise_proto_pairs(qubit_type='grid'): + q0 = cirq.GridQubit(0, 0) + q0_str = '0_0' + + if qubit_type == 'line': + q0 = cirq.LineQubit(0) + q0_str = '0' + + # NOTE(tonybruguier): All the parameters are powers of 2. This is because + # Python only uses double, which means that Protobufs use double even if the + # field is a float. However, the serialization sometimes goes though C++ and + # thus would use float. Thus, we need to have numbers that are exactly + # representable on a float. Powers of 2 are a convenient subset. + pairs = [ + # Depolarization. + (cirq.Circuit(cirq.depolarize(p=0.5)(q0)), + _build_op_proto("DP", ['p'], [0.5], [q0_str])), + + # Asymmetric depolarization. + (cirq.Circuit( + cirq.asymmetric_depolarize(p_x=0.125, p_y=0.25, p_z=0.5)(q0)), + _build_op_proto("ADP", ['p_x', 'p_y', 'p_z'], [0.125, 0.25, 0.5], + [q0_str])), + + # Generalized Amplitude damp. + (cirq.Circuit(cirq.generalized_amplitude_damp(p=0.125, gamma=0.25)(q0)), + _build_op_proto("GAD", ['p', 'gamma'], [0.125, 0.25], [q0_str])), + + # Amplitude damp. + (cirq.Circuit(cirq.amplitude_damp(gamma=0.125)(q0)), + _build_op_proto("AD", ['gamma'], [0.125], [q0_str])), + + # Reset. + (cirq.Circuit(cirq.reset(q0)), _build_op_proto("RST", [], [], + [q0_str])), + + # Phase damp. + (cirq.Circuit(cirq.phase_damp(gamma=0.125)(q0)), + _build_op_proto("PD", ['gamma'], [0.125], [q0_str])), + + # Phase flip. + (cirq.Circuit(cirq.phase_flip(p=0.125)(q0)), + _build_op_proto("PF", ['p'], [0.125], [q0_str])), + + # Bit flip. + (cirq.Circuit(cirq.bit_flip(p=0.125)(q0)), + _build_op_proto("BF", ['p'], [0.125], [q0_str])) + ] + return pairs + + def _build_pauli_proto(coefs, ops, qubit_ids): """Construct pauli_sum proto explicitly.""" terms = [] @@ -420,20 +546,52 @@ def _build_pauli_proto(coefs, ops, qubit_ids): return a +def _build_projector_proto(coefs, basis_states, qubit_ids): + """Construct projector_sum proto explicitly.""" + terms = [] + for i in range(len(coefs)): + term = projector_sum_pb2.ProjectorTerm() + term.coefficient_real = coefs[i].real + term.coefficient_imag = coefs[i].imag + for j in range(len(qubit_ids[i])): + if basis_states[i][j] == 0: + term.projector_dict.add(qubit_id=qubit_ids[i][j]) + else: + term.projector_dict.add(qubit_id=qubit_ids[i][j], + basis_state=True) + terms.append(term) + + a = projector_sum_pb2.ProjectorSum() + a.terms.extend(terms) + return a + + class SerializerTest(tf.test.TestCase, parameterized.TestCase): """Tests basic serializer functionality""" - @parameterized.parameters([{ - 'circ_proto_pair': v - } for v in _get_valid_circuit_proto_pairs()]) + @parameterized.parameters( + [{ + 'circ_proto_pair': v + } for v in _get_controlled_circuit_proto_pairs(qubit_type='grid') + + _get_controlled_circuit_proto_pairs(qubit_type='line') + + _get_circuit_proto_pairs(qubit_type='grid') + + _get_circuit_proto_pairs(qubit_type='line') + + _get_noise_proto_pairs(qubit_type='grid') + + _get_noise_proto_pairs(qubit_type='line')]) def test_serialize_circuit_valid(self, circ_proto_pair): """Test conversion of cirq Circuits to tfq_gate_set proto.""" self.assertProtoEquals(serializer.serialize_circuit(circ_proto_pair[0]), circ_proto_pair[1]) - @parameterized.parameters([{ - 'circ_proto_pair': v - } for v in _get_valid_circuit_proto_pairs()]) + @parameterized.parameters( + [{ + 'circ_proto_pair': v + } for v in _get_controlled_circuit_proto_pairs(qubit_type='grid') + + _get_controlled_circuit_proto_pairs(qubit_type='line') + + _get_circuit_proto_pairs(qubit_type='grid') + + _get_circuit_proto_pairs(qubit_type='line') + + _get_noise_proto_pairs(qubit_type='grid') + + _get_noise_proto_pairs(qubit_type='line')]) def test_deserialize_circuit_valid(self, circ_proto_pair): """Test deserialization of protos in tfq_gate_set.""" @@ -443,9 +601,15 @@ def test_deserialize_circuit_valid(self, circ_proto_pair): self.assertEqual(circ_proto_pair[0], serializer.deserialize_circuit(circ_proto_pair[1])) - @parameterized.parameters([{ - 'circ_proto_pair': v - } for v in _get_valid_circuit_proto_pairs()]) + @parameterized.parameters( + [{ + 'circ_proto_pair': v + } for v in _get_controlled_circuit_proto_pairs(qubit_type='grid') + + _get_controlled_circuit_proto_pairs(qubit_type='line') + + _get_circuit_proto_pairs(qubit_type='grid') + + _get_circuit_proto_pairs(qubit_type='line') + + _get_noise_proto_pairs(qubit_type='grid') + + _get_noise_proto_pairs(qubit_type='line')]) def test_serialize_deserialize_circuit_consistency(self, circ_proto_pair): """Ensure that serializing followed by deserializing works.""" @@ -465,7 +629,7 @@ def test_serialize_circuit_unsupported_gate(self): """Ensure we error on unsupported gates.""" q0 = cirq.GridQubit(0, 0) q1 = cirq.GridQubit(0, 1) - unsupported_circuit = cirq.Circuit(cirq.QFT(q0, q1)) + unsupported_circuit = cirq.Circuit(cirq.qft(q0, q1)) with self.assertRaises(ValueError): serializer.serialize_circuit(unsupported_circuit) @@ -505,6 +669,9 @@ def test_serialize_circuit_with_large_identity(self): [0.35, float(0.35), 35e-2, np.float32(0.35), np.float64(0.35), 7] + for (q0, q1) in [( + cirq.GridQubit(0, 1), + cirq.GridQubit(0, 0)), (cirq.LineQubit(0), cirq.LineQubit(1))] ]) def test_serialize_circuit_valid_number_types(self, gate_with_param): """Tests number datatype support by our serializer.""" @@ -514,7 +681,7 @@ def test_serialize_circuit_valid_number_types(self, gate_with_param): serializer.serialize_circuit(gate_with_param)).unitary()) def test_serialize_circuit_unsupported_value(self): - """Ensure we error on unsupported arithmetic expressions.""" + """Ensure we error on unsupported arithmetic expressions and qubits.""" q0 = cirq.GridQubit(0, 0) unsupported_circuit = cirq.Circuit( cirq.HPowGate()(q0)**(sympy.Symbol('alpha') + 1)) @@ -528,6 +695,21 @@ def test_serialize_circuit_unsupported_value(self): with self.assertRaises(ValueError): serializer.serialize_circuit(unsupported_circuit2) + def test_serialize_controlled_circuit_unsupported_value(self): + """Ensure serializing invalid controlled gates fails gracefully.""" + qubits = cirq.GridQubit.rect(1, 2) + invalid_symbol = cirq.Circuit((cirq.HPowGate()( + qubits[0])**(sympy.Symbol('alpha') + 1)).controlled_by(qubits[1])) + with self.assertRaises(ValueError): + serializer.serialize_circuit(invalid_symbol) + + def test_serialize_noise_channel_unsupported_value(self): + """Ensure serializing invalid channels fails gracefully.""" + qubit = cirq.NamedQubit('wont work') + simple_circuit = cirq.Circuit(cirq.depolarize(0.3)(qubit)) + with self.assertRaises(ValueError): + serializer.serialize_circuit(simple_circuit) + @parameterized.parameters([{'inp': v} for v in ['wrong', 1.0, None, []]]) def test_serialize_circuit_wrong_type(self, inp): """Attempt to serialize invalid objects types.""" @@ -561,7 +743,8 @@ def test_serialize_paulisum_invalid(self): @parameterized.parameters([{ 'sum_proto_pair': v - } for v in _get_valid_pauli_proto_pairs()]) + } for v in _get_valid_pauli_proto_pairs(qubit_type='grid') + + _get_valid_pauli_proto_pairs(qubit_type='line')]) def test_serialize_paulisum_simple(self, sum_proto_pair): """Ensure serialization is correct.""" self.assertProtoEquals(sum_proto_pair[1], @@ -569,7 +752,8 @@ def test_serialize_paulisum_simple(self, sum_proto_pair): @parameterized.parameters([{ 'sum_proto_pair': v - } for v in _get_valid_pauli_proto_pairs()]) + } for v in _get_valid_pauli_proto_pairs(qubit_type='grid') + + _get_valid_pauli_proto_pairs(qubit_type='line')]) def test_deserialize_paulisum_simple(self, sum_proto_pair): """Ensure deserialization is correct.""" self.assertEqual(serializer.deserialize_paulisum(sum_proto_pair[1]), @@ -577,7 +761,8 @@ def test_deserialize_paulisum_simple(self, sum_proto_pair): @parameterized.parameters([{ 'sum_proto_pair': v - } for v in _get_valid_pauli_proto_pairs()]) + } for v in _get_valid_pauli_proto_pairs(qubit_type='grid') + + _get_valid_pauli_proto_pairs(qubit_type='line')]) def test_serialize_deserialize_paulisum_consistency(self, sum_proto_pair): """Serialize and deserialize and ensure nothing changed.""" self.assertEqual( @@ -590,6 +775,65 @@ def test_serialize_deserialize_paulisum_consistency(self, sum_proto_pair): serializer.serialize_paulisum(sum_proto_pair[0])), sum_proto_pair[0]) + @parameterized.parameters([{'inp': v} for v in ['wrong', 1.0, None, []]]) + def test_serialize_projectorsum_wrong_type(self, inp): + """Attempt to serialize invalid object types.""" + with self.assertRaises(TypeError): + serializer.serialize_projectorsum(inp) + + @parameterized.parameters([{'inp': v} for v in ['wrong', 1.0, None, []]]) + def test_deserialize_projectorsum_wrong_type(self, inp): + """Attempt to deserialize invalid object types.""" + with self.assertRaises(TypeError): + serializer.deserialize_projectorsum(inp) + + def test_serialize_projectorsum_invalid(self): + """Ensure we don't support anything but GridQubits.""" + q0 = cirq.NamedQubit('wont work') + a = cirq.ProjectorSum.from_projector_strings( + cirq.ProjectorString(projector_dict={q0: 0})) + with self.assertRaises(ValueError): + serializer.serialize_projectorsum(a) + + @parameterized.parameters( + [{ + 'sum_proto_pair': v + } for v in _get_valid_projector_proto_pairs(qubit_type='grid') + + _get_valid_projector_proto_pairs(qubit_type='line')]) + def test_serialize_projectorsum_simple(self, sum_proto_pair): + """Ensure serialization is correct.""" + self.assertProtoEquals( + sum_proto_pair[1], + serializer.serialize_projectorsum(sum_proto_pair[0])) + + @parameterized.parameters( + [{ + 'sum_proto_pair': v + } for v in _get_valid_projector_proto_pairs(qubit_type='grid') + + _get_valid_projector_proto_pairs(qubit_type='line')]) + def test_deserialize_projectorsum_simple(self, sum_proto_pair): + """Ensure deserialization is correct.""" + self.assertEqual(serializer.deserialize_projectorsum(sum_proto_pair[1]), + sum_proto_pair[0]) + + @parameterized.parameters( + [{ + 'sum_proto_pair': v + } for v in _get_valid_projector_proto_pairs(qubit_type='grid') + + _get_valid_projector_proto_pairs(qubit_type='line')]) + def test_serialize_deserialize_projectorsum_consistency( + self, sum_proto_pair): + """Serialize and deserialize and ensure nothing changed.""" + self.assertEqual( + serializer.serialize_projectorsum( + serializer.deserialize_projectorsum(sum_proto_pair[1])), + sum_proto_pair[1]) + + self.assertEqual( + serializer.deserialize_projectorsum( + serializer.serialize_projectorsum(sum_proto_pair[0])), + sum_proto_pair[0]) + @parameterized.parameters([ { 'gate': cirq.rx(3.0 * sympy.Symbol('alpha')) @@ -606,7 +850,7 @@ def test_serialize_deserialize_special_case_one_qubit(self, gate): q0 = cirq.GridQubit(0, 0) c = cirq.Circuit(gate(q0)) - c = c._resolve_parameters_(cirq.ParamResolver({"alpha": 0.1234567})) + c = cirq.resolve_parameters(c, cirq.ParamResolver({"alpha": 0.1234567})) before = c.unitary() c2 = serializer.deserialize_circuit(serializer.serialize_circuit(c)) after = c2.unitary() diff --git a/tensorflow_quantum/core/src/BUILD b/tensorflow_quantum/core/src/BUILD index 70c2fd4e4..5595a5ca2 100644 --- a/tensorflow_quantum/core/src/BUILD +++ b/tensorflow_quantum/core/src/BUILD @@ -5,19 +5,30 @@ licenses(["notice"]) # Export for the PIP package. exports_files(["__init__.py"]) +cc_library( + name = "src", + deps = [ + ":adj_util", + ":circuit_parser_qsim", + ":program_resolution", + ":util_qsim", + ], +) + cc_library( name = "adj_util", srcs = ["adj_util.cc"], hdrs = ["adj_util.h"], deps = [ + ":circuit_parser_qsim", + "@com_google_absl//absl/status", "@qsim//lib:circuit", - "@qsim//lib:gates_cirq", - "@qsim//lib:gate", "@qsim//lib:fuser", "@qsim//lib:fuser_basic", + "@qsim//lib:gate", + "@qsim//lib:gates_cirq", "@qsim//lib:io", "@qsim//lib:matrix", - ":circuit_parser_qsim", ], ) @@ -26,11 +37,13 @@ cc_test( srcs = ["adj_util_test.cc"], deps = [ ":adj_util", + ":circuit_parser_qsim", + "@com_google_googletest//:gtest_main", + "@com_google_absl//absl/status", + "@local_config_tf//:libtensorflow_framework", "@qsim//lib:gates_cirq", "@qsim//lib:matrix", - "@com_google_googletest//:gtest_main", - ":circuit_parser_qsim", - ] + ], ) cc_library( @@ -40,14 +53,40 @@ cc_library( deps = [ "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", "//tensorflow_quantum/core/proto:program_cc_proto", + "//tensorflow_quantum/core/proto:projector_sum_cc_proto", "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/status", "@local_config_tf//:libtensorflow_framework", "@local_config_tf//:tf_header_lib", + "@qsim//lib:channel", + "@qsim//lib:channels_cirq", "@qsim//lib:circuit", - "@qsim//lib:gates_cirq", + "@qsim//lib:circuit_noisy", "@qsim//lib:fuser", "@qsim//lib:fuser_basic", - "@qsim//lib:io" + "@qsim//lib:gates_cirq", + "@qsim//lib:io", + ], +) + +cc_test( + name = "circuit_parser_qsim_test", + size = "small", + srcs = ["circuit_parser_qsim_test.cc"], + linkstatic = 0, + deps = [ + ":circuit_parser_qsim", + "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", + "//tensorflow_quantum/core/proto:program_cc_proto", + "//tensorflow_quantum/core/proto:projector_sum_cc_proto", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/strings", + "@com_google_googletest//:gtest_main", + "@local_config_tf//:libtensorflow_framework", + "@local_config_tf//:tf_header_lib", + "@qsim//lib:circuit", + "@qsim//lib:fuser", + "@qsim//lib:gates_cirq", ], ) @@ -57,12 +96,13 @@ cc_library( hdrs = ["util_qsim.h"], deps = [ ":circuit_parser_qsim", + "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", + "//tensorflow_quantum/core/proto:projector_sum_cc_proto", + "@com_google_absl//absl/container:inlined_vector", # unclear why needed. "@local_config_tf//:libtensorflow_framework", "@local_config_tf//:tf_header_lib", - "@com_google_absl//absl/container:inlined_vector", # unclear why needed. - "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", "@qsim//lib:qsim_lib", - ] + ], ) cc_test( @@ -73,29 +113,10 @@ cc_test( deps = [ ":util_qsim", "@com_google_absl//absl/container:flat_hash_map", - "@qsim//lib:qsim_lib", - "@com_google_googletest//:gtest_main", - ] -) - -cc_test( - name = "circuit_parser_qsim_test", - size = "small", - srcs = ["circuit_parser_qsim_test.cc"], - linkstatic = 0, - deps = [ - ":circuit_parser_qsim", - "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", - "//tensorflow_quantum/core/proto:program_cc_proto", - "@com_google_absl//absl/container:flat_hash_map", - "@com_google_absl//absl/strings", "@com_google_googletest//:gtest_main", "@local_config_tf//:libtensorflow_framework", "@local_config_tf//:tf_header_lib", - "@qsim//lib:circuit", - "@qsim//lib:gates_cirq", - "@qsim//lib:fuser", - + "@qsim//lib:qsim_lib", ], ) @@ -106,9 +127,11 @@ cc_library( deps = [ "//tensorflow_quantum/core/proto:pauli_sum_cc_proto", "//tensorflow_quantum/core/proto:program_cc_proto", + "//tensorflow_quantum/core/proto:projector_sum_cc_proto", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/strings", + "@com_google_absl//absl/status", "@local_config_tf//:libtensorflow_framework", "@local_config_tf//:tf_header_lib", ], @@ -123,7 +146,9 @@ cc_test( ":program_resolution", "//tensorflow_quantum/core/proto:program_cc_proto", "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/status", "@com_google_googletest//:gtest_main", + "@local_config_tf//:libtensorflow_framework", "@local_config_tf//:tf_header_lib", ], ) diff --git a/tensorflow_quantum/core/src/adj_util.cc b/tensorflow_quantum/core/src/adj_util.cc index aee01a377..e15ff8a8c 100644 --- a/tensorflow_quantum/core/src/adj_util.cc +++ b/tensorflow_quantum/core/src/adj_util.cc @@ -38,8 +38,8 @@ void CreateGradientCircuit( const QsimCircuit& circuit, const std::vector& metadata, std::vector>>* partial_fuses, std::vector* grad_gates) { - for (int i = 0; i < metadata.size(); i++) { - if (metadata[i].symbol_values.size() == 0) { + for (size_t i = 0; i < metadata.size(); i++) { + if (metadata[i].symbol_values.empty()) { continue; } // found a gate that was constructed with symbols. @@ -78,7 +78,7 @@ void CreateGradientCircuit( // PhasedX else if (circuit.gates[i].kind == qsim::Cirq::GateKind::kPhasedXPowGate) { // Process potentially several symbols. - for (int j = 0; j < metadata[i].symbol_values.size(); j++) { + for (size_t j = 0; j < metadata[i].symbol_values.size(); j++) { if (metadata[i].placeholder_names[j] == GateParamNames::kPhaseExponent) { PopulateGradientPhasedXPhasedExponent( @@ -103,7 +103,7 @@ void CreateGradientCircuit( // Process potentially several symbols. bool swapq = circuit.gates[i].swapped; - for (int j = 0; j < metadata[i].symbol_values.size(); j++) { + for (size_t j = 0; j < metadata[i].symbol_values.size(); j++) { if (metadata[i].placeholder_names[j] == GateParamNames::kTheta) { PopulateGradientFsimTheta( metadata[i].symbol_values[j], i, @@ -128,7 +128,7 @@ void CreateGradientCircuit( qsim::Cirq::GateKind::kPhasedISwapPowGate) { // Process potentially several symbols. bool swapq = circuit.gates[i].swapped; - for (int j = 0; j < metadata[i].symbol_values.size(); j++) { + for (size_t j = 0; j < metadata[i].symbol_values.size(); j++) { if (metadata[i].placeholder_names[j] == GateParamNames::kPhaseExponent) { PopulateGradientPhasedISwapPhasedExponent( @@ -159,7 +159,7 @@ void CreateGradientCircuit( partial_fuses->assign(grad_gates->size() + 1, std::vector>({})); - for (int i = 0; i < grad_gates->size(); i++) { + for (size_t i = 0; i < grad_gates->size(); i++) { right = circuit.gates.begin() + (*grad_gates)[i].index; (*partial_fuses)[i] = fuser.FuseGates(qsim::BasicGateFuser::Parameter(), diff --git a/tensorflow_quantum/core/src/circuit_parser_qsim.cc b/tensorflow_quantum/core/src/circuit_parser_qsim.cc index 7fd66bf01..8b70ab041 100644 --- a/tensorflow_quantum/core/src/circuit_parser_qsim.cc +++ b/tensorflow_quantum/core/src/circuit_parser_qsim.cc @@ -18,31 +18,38 @@ limitations under the License. #include #include +#include "../qsim/lib/channel.h" +#include "../qsim/lib/channels_cirq.h" #include "../qsim/lib/circuit.h" +#include "../qsim/lib/circuit_noisy.h" #include "../qsim/lib/fuser.h" #include "../qsim/lib/fuser_basic.h" #include "../qsim/lib/gates_cirq.h" #include "../qsim/lib/io.h" #include "absl/container/flat_hash_map.h" +#include "absl/status/status.h" #include "absl/strings/numbers.h" +#include "absl/strings/str_split.h" +#include "absl/strings/string_view.h" #include "absl/types/optional.h" -#include "cirq/google/api/v2/program.pb.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 { -using ::cirq::google::api::v2::Moment; -using ::cirq::google::api::v2::Operation; -using ::cirq::google::api::v2::Program; using ::tensorflow::Status; +using ::tfq::proto::Moment; +using ::tfq::proto::Operation; using ::tfq::proto::PauliTerm; +using ::tfq::proto::Program; namespace { typedef absl::flat_hash_map> SymbolMap; typedef qsim::Cirq::GateCirq QsimGate; typedef qsim::Circuit QsimCircuit; +typedef qsim::NoisyCircuit NoisyQsimCircuit; inline Status ParseProtoArg( const Operation& op, const std::string& arg_name, @@ -52,11 +59,12 @@ inline Status ParseProtoArg( // iterator> const auto arg_v = op.args().find(arg_name); if (arg_v == op.args().end()) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), "Could not find arg: " + arg_name + " in op."); } // find proto arg field. - // ::cirq::google::api::v2::Arg + // ::tfq::proto::Arg const auto proto_arg = arg_v->second; *result = proto_arg.arg_value().float_value(); if (!proto_arg.symbol().empty()) { @@ -64,7 +72,8 @@ inline Status ParseProtoArg( const auto iter = param_map.find(proto_arg.symbol()); if (iter == param_map.end()) { return Status( - tensorflow::error::INVALID_ARGUMENT, + static_cast( + absl::StatusCode::kInvalidArgument), "Could not find symbol in parameter map: " + proto_arg.symbol()); } *result = iter->second.second; @@ -72,7 +81,73 @@ inline Status ParseProtoArg( symbol_used->emplace(iter->first); } } - return Status::OK(); + return ::tensorflow::Status(); +} + +inline Status ParseProtoControls(const Operation& op, + const unsigned int num_qubits, + std::vector* control_qubits, + std::vector* control_values) { + absl::string_view control_str = + op.args().at("control_qubits").arg_value().string_value(); + absl::string_view control_v_str = + op.args().at("control_values").arg_value().string_value(); + + if (control_str == "" && control_v_str == "") { + // empty default value set in serializer.py + return ::tensorflow::Status(); + } + + std::vector control_toks = + absl::StrSplit(control_str, ','); + std::vector control_v_toks = + absl::StrSplit(control_v_str, ','); + + if (control_toks.size() != control_v_toks.size()) { + return Status(static_cast( + absl::StatusCode::kInvalidArgument), + "Mistmatched number of control qubits and control values."); + } + if (control_toks.empty()) { + return ::tensorflow::Status(); + } + bool valid; + unsigned int tmp; + control_qubits->reserve(control_toks.size()); + for (auto tok : control_toks) { + // don't bother error checking since this is done earlier + // in program_resolution. + valid = absl::SimpleAtoi(tok, &tmp); + control_qubits->push_back(num_qubits - tmp - 1); + } + control_values->reserve(control_v_toks.size()); + for (auto tok : control_v_toks) { + valid = absl::SimpleAtoi(tok, &tmp); + if (!valid) { + return Status(static_cast( + absl::StatusCode::kInvalidArgument), + "Unparseable control value: " + std::string(tok)); + } + control_values->push_back(tmp); + } + return ::tensorflow::Status(); +} + +inline Status OptionalInsertControls(const Operation& op, + const unsigned int num_qubits, + QsimGate* gate) { + std::vector control_values; + std::vector control_qubits; + Status s; + s = ParseProtoControls(op, num_qubits, &control_qubits, &control_values); + if (!s.ok()) { + return s; + } + if (control_qubits.empty()) { + return ::tensorflow::Status(); + } + qsim::MakeControlledGate(control_qubits, control_values, *gate); + return ::tensorflow::Status(); } // series of fixed signature gate builders. @@ -87,8 +162,13 @@ inline Status SingleConstantGate( const unsigned int num_qubits, const unsigned int time, QsimCircuit* circuit, std::vector* metadata) { unsigned int q0; - bool unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); - circuit->gates.push_back(create_f(time, num_qubits - q0 - 1)); + (void)absl::SimpleAtoi(op.qubits(0).id(), &q0); + auto gate = create_f(time, num_qubits - q0 - 1); + Status s = OptionalInsertControls(op, num_qubits, &gate); + if (!s.ok()) { + return s; + } + circuit->gates.push_back(gate); // check for symbols and track metadata if needed. if (metadata != nullptr) { @@ -96,7 +176,7 @@ inline Status SingleConstantGate( info.index = circuit->gates.size() - 1; metadata->push_back(info); } - return Status::OK(); + return ::tensorflow::Status(); } // two qubit gate Create(time, q0, q1) @@ -107,10 +187,15 @@ inline Status TwoConstantGate( const unsigned int num_qubits, const unsigned int time, QsimCircuit* circuit, std::vector* metadata) { unsigned int q0, q1; - bool unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); unused = absl::SimpleAtoi(op.qubits(1).id(), &q1); - circuit->gates.push_back( - create_f(time, num_qubits - q0 - 1, num_qubits - q1 - 1)); + auto gate = create_f(time, num_qubits - q0 - 1, num_qubits - q1 - 1); + Status s = OptionalInsertControls(op, num_qubits, &gate); + if (!s.ok()) { + return s; + } + circuit->gates.push_back(gate); // check for symbols and track metadata if needed. if (metadata != nullptr) { @@ -118,7 +203,7 @@ inline Status TwoConstantGate( info.index = circuit->gates.size() - 1; metadata->push_back(info); } - return Status::OK(); + return ::tensorflow::Status(); } // single qubit eigen -> Create(time, q0, exponent, global_shift) @@ -129,9 +214,10 @@ inline Status SingleEigenGate( const unsigned int num_qubits, const unsigned int time, QsimCircuit* circuit, std::vector* metadata) { unsigned int q0; - bool unused; + float exp, exp_s, gs; Status u; + [[maybe_unused]] bool unused; unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); absl::optional exponent_symbol; @@ -148,8 +234,12 @@ inline Status SingleEigenGate( return u; } - circuit->gates.push_back( - create_f(time, num_qubits - q0 - 1, exp * exp_s, gs)); + auto gate = create_f(time, num_qubits - q0 - 1, exp * exp_s, gs); + Status s = OptionalInsertControls(op, num_qubits, &gate); + if (!s.ok()) { + return s; + } + circuit->gates.push_back(gate); // check for symbols and track metadata if needed. if (metadata != nullptr) { @@ -163,7 +253,7 @@ inline Status SingleEigenGate( } metadata->push_back(info); } - return Status::OK(); + return ::tensorflow::Status(); } // two qubit eigen -> Create(time, q0, q1, exp, gs) @@ -175,8 +265,9 @@ inline Status TwoEigenGate( QsimCircuit* circuit, std::vector* metadata) { unsigned int q0, q1; float exp, exp_s, gs; - bool unused; + Status u; + [[maybe_unused]] bool unused; unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); unused = absl::SimpleAtoi(op.qubits(1).id(), &q1); @@ -193,8 +284,14 @@ inline Status TwoEigenGate( if (!u.ok()) { return u; } - circuit->gates.push_back(create_f(time, num_qubits - q0 - 1, - num_qubits - q1 - 1, exp * exp_s, gs)); + auto gate = + create_f(time, num_qubits - q0 - 1, num_qubits - q1 - 1, exp * exp_s, gs); + + Status s = OptionalInsertControls(op, num_qubits, &gate); + if (!s.ok()) { + return s; + } + circuit->gates.push_back(gate); // check for symbols and track metadata if needed. if (metadata != nullptr) { @@ -208,7 +305,7 @@ inline Status TwoEigenGate( } metadata->push_back(info); } - return Status::OK(); + return ::tensorflow::Status(); } Status IGate(const Operation& op, const SymbolMap& param_map, @@ -308,9 +405,10 @@ inline Status PhasedXGate(const Operation& op, const SymbolMap& param_map, const unsigned int time, QsimCircuit* circuit, std::vector* metadata) { int q0; - bool unused; + float pexp, pexp_s, exp, exp_s, gs; Status u; + [[maybe_unused]] bool unused; unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); absl::optional exponent_symbol; @@ -336,8 +434,13 @@ inline Status PhasedXGate(const Operation& op, const SymbolMap& param_map, if (!u.ok()) { return u; } - circuit->gates.push_back(qsim::Cirq::PhasedXPowGate::Create( - time, num_qubits - q0 - 1, pexp * pexp_s, exp * exp_s, gs)); + auto gate = qsim::Cirq::PhasedXPowGate::Create( + time, num_qubits - q0 - 1, pexp * pexp_s, exp * exp_s, gs); + Status s = OptionalInsertControls(op, num_qubits, &gate); + if (!s.ok()) { + return s; + } + circuit->gates.push_back(gate); // check for symbols and track metadata if needed. if (metadata != nullptr) { @@ -354,7 +457,7 @@ inline Status PhasedXGate(const Operation& op, const SymbolMap& param_map, } metadata->push_back(info); } - return Status::OK(); + return ::tensorflow::Status(); } // two qubit fsim -> Create(time, q0, q1, theta, phi) @@ -363,9 +466,10 @@ inline Status FsimGate(const Operation& op, const SymbolMap& param_map, QsimCircuit* circuit, std::vector* metadata) { int q0, q1; - bool unused; + float theta, theta_s, phi, phi_s; Status u; + [[maybe_unused]] bool unused; unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); unused = absl::SimpleAtoi(op.qubits(1).id(), &q1); @@ -387,9 +491,14 @@ inline Status FsimGate(const Operation& op, const SymbolMap& param_map, if (!u.ok()) { return u; } - circuit->gates.push_back(qsim::Cirq::FSimGate::Create( - time, num_qubits - q0 - 1, num_qubits - q1 - 1, theta * theta_s, - phi * phi_s)); + auto gate = qsim::Cirq::FSimGate::Create(time, num_qubits - q0 - 1, + num_qubits - q1 - 1, + theta * theta_s, phi * phi_s); + Status s = OptionalInsertControls(op, num_qubits, &gate); + if (!s.ok()) { + return s; + } + circuit->gates.push_back(gate); // check for symbols and track metadata if needed. if (metadata != nullptr) { @@ -406,7 +515,7 @@ inline Status FsimGate(const Operation& op, const SymbolMap& param_map, } metadata->push_back(info); } - return Status::OK(); + return ::tensorflow::Status(); } // two qubit phase iswap -> Create(time, q0, q1, pexp, exp) @@ -415,9 +524,10 @@ inline Status PhasedISwapGate(const Operation& op, const SymbolMap& param_map, const unsigned int time, QsimCircuit* circuit, std::vector* metadata) { int q0, q1; - bool unused; + float pexp, pexp_s, exp, exp_s; Status u; + [[maybe_unused]] bool unused; unused = absl::SimpleAtoi(op.qubits(0).id(), &q0); unused = absl::SimpleAtoi(op.qubits(1).id(), &q1); @@ -440,9 +550,14 @@ inline Status PhasedISwapGate(const Operation& op, const SymbolMap& param_map, if (!u.ok()) { return u; } - circuit->gates.push_back(qsim::Cirq::PhasedISwapPowGate::Create( + auto gate = qsim::Cirq::PhasedISwapPowGate::Create( time, num_qubits - q0 - 1, num_qubits - q1 - 1, pexp * pexp_s, - exp * exp_s)); + exp * exp_s); + Status s = OptionalInsertControls(op, num_qubits, &gate); + if (!s.ok()) { + return s; + } + circuit->gates.push_back(gate); // check for symbols and track metadata if needed. if (metadata != nullptr) { @@ -459,7 +574,7 @@ inline Status PhasedISwapGate(const Operation& op, const SymbolMap& param_map, } metadata->push_back(info); } - return Status::OK(); + return ::tensorflow::Status(); } tensorflow::Status ParseAppendGate(const Operation& op, @@ -467,7 +582,8 @@ tensorflow::Status ParseAppendGate(const Operation& op, const unsigned int num_qubits, const unsigned int time, QsimCircuit* circuit, - std::vector* metadata) { + std::vector* metadata, + bool* lookup_succeeded) { // map gate name -> callable to build that qsim gate from operation proto. static const absl::flat_hash_map< std::string, @@ -485,14 +601,264 @@ tensorflow::Status ParseAppendGate(const Operation& op, auto build_f = func_map.find(op.gate().id()); if (build_f == func_map.end()) { - return Status(tensorflow::error::INVALID_ARGUMENT, - "Could not parse gate id: " + op.gate().id()); - } + *lookup_succeeded = false; + return Status(static_cast( + absl::StatusCode::kInvalidArgument), + absl::StrCat("Could not parse gate id: ", op.gate().id(), + ". This is likely because a cirq.Channel was " + "used in an op that does not support them.")); + } + *lookup_succeeded = true; return build_f->second(op, param_map, num_qubits, time, circuit, metadata); } +inline Status AsymmetricDepolarizingChannel(const Operation& op, + const unsigned int num_qubits, + const unsigned int time, + NoisyQsimCircuit* ncircuit) { + int q; + + float p_x, p_y, p_z; + Status u; + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + + u = ParseProtoArg(op, "p_x", {}, &p_x); + u = ParseProtoArg(op, "p_y", {}, &p_y); + u = ParseProtoArg(op, "p_z", {}, &p_z); + if (!u.ok()) { + return u; + } + auto chan = qsim::Cirq::AsymmetricDepolarizingChannel::Create( + time, num_qubits - q - 1, p_x, p_y, p_z); + ncircuit->channels.push_back(chan); + return ::tensorflow::Status(); +} + +inline Status DepolarizingChannel(const Operation& op, + const unsigned int num_qubits, + const unsigned int time, + NoisyQsimCircuit* ncircuit) { + int q; + + float p; + Status u; + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + + u = ParseProtoArg(op, "p", {}, &p); + if (!u.ok()) { + return u; + } + auto chan = qsim::Cirq::DepolarizingChannel::Create( + time, num_qubits - q - 1, p); + ncircuit->channels.push_back(chan); + return ::tensorflow::Status(); +} + +inline Status GADChannel(const Operation& op, const unsigned int num_qubits, + const unsigned int time, NoisyQsimCircuit* ncircuit) { + int q; + + float p, gamma; + Status u; + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + + u = ParseProtoArg(op, "p", {}, &p); + if (!u.ok()) { + return u; + } + u = ParseProtoArg(op, "gamma", {}, &gamma); + if (!u.ok()) { + return u; + } + + auto chan = qsim::Cirq::GeneralizedAmplitudeDampingChannel::Create( + time, num_qubits - q - 1, p, gamma); + ncircuit->channels.push_back(chan); + return ::tensorflow::Status(); +} + +inline Status ResetChannel(const Operation& op, const unsigned int num_qubits, + const unsigned int time, + NoisyQsimCircuit* ncircuit) { + int q; + + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + + auto chan = qsim::Cirq::ResetChannel::Create(time, num_qubits - q - 1); + ncircuit->channels.push_back(chan); + return ::tensorflow::Status(); +} + +inline Status AmplitudeDampingChannel(const Operation& op, + const unsigned int num_qubits, + const unsigned int time, + NoisyQsimCircuit* ncircuit) { + int q; + + float gamma; + Status u; + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + + u = ParseProtoArg(op, "gamma", {}, &gamma); + if (!u.ok()) { + return u; + } + auto chan = qsim::Cirq::AmplitudeDampingChannel::Create( + time, num_qubits - q - 1, gamma); + ncircuit->channels.push_back(chan); + return ::tensorflow::Status(); +} + +inline Status PhaseDampingChannel(const Operation& op, + const unsigned int num_qubits, + const unsigned int time, + NoisyQsimCircuit* ncircuit) { + int q; + + float gamma; + Status u; + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + + u = ParseProtoArg(op, "gamma", {}, &gamma); + if (!u.ok()) { + return u; + } + + auto chan = qsim::Cirq::PhaseDampingChannel::Create( + time, num_qubits - q - 1, gamma); + ncircuit->channels.push_back(chan); + return ::tensorflow::Status(); +} + +inline Status PhaseFlipChannel(const Operation& op, + const unsigned int num_qubits, + const unsigned int time, + NoisyQsimCircuit* ncircuit) { + int q; + + float p; + Status u; + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + + u = ParseProtoArg(op, "p", {}, &p); + if (!u.ok()) { + return u; + } + + auto chan = + qsim::Cirq::PhaseFlipChannel::Create(time, num_qubits - q - 1, p); + ncircuit->channels.push_back(chan); + return ::tensorflow::Status(); +} + +inline Status BitFlipChannel(const Operation& op, const unsigned int num_qubits, + const unsigned int time, + NoisyQsimCircuit* ncircuit) { + int q; + + float p; + Status u; + [[maybe_unused]] bool unused; + unused = absl::SimpleAtoi(op.qubits(0).id(), &q); + + u = ParseProtoArg(op, "p", {}, &p); + if (!u.ok()) { + return u; + } + + auto chan = + qsim::Cirq::BitFlipChannel::Create(time, num_qubits - q - 1, p); + ncircuit->channels.push_back(chan); + return ::tensorflow::Status(); +} + +tensorflow::Status ParseAppendChannel(const Operation& op, + const unsigned int num_qubits, + const unsigned int time, + NoisyQsimCircuit* ncircuit) { + // map channel name -> callable to build qsim channel from operation proto. + static const absl::flat_hash_map< + std::string, std::function> + chan_func_map = { + {"DP", &DepolarizingChannel}, {"ADP", &AsymmetricDepolarizingChannel}, + {"GAD", &GADChannel}, {"AD", &AmplitudeDampingChannel}, + {"RST", &ResetChannel}, {"PD", &PhaseDampingChannel}, + {"PF", &PhaseFlipChannel}, {"BF", &BitFlipChannel}}; + + auto build_f = chan_func_map.find(op.gate().id()); + if (build_f == chan_func_map.end()) { + return Status(static_cast( + absl::StatusCode::kInvalidArgument), + absl::StrCat("Could not parse channel id: ", op.gate().id())); + } + return build_f->second(op, num_qubits, time, ncircuit); +} + } // namespace +tensorflow::Status NoisyQsimCircuitFromProgram(const Program& program, + const SymbolMap& param_map, + const int num_qubits, + const bool add_tmeasures, + NoisyQsimCircuit* ncircuit) { + // Special case empty. + ncircuit->num_qubits = num_qubits; + if (num_qubits <= 0) { + return ::tensorflow::Status(); + } + + int time = 0; + bool gate_found; + QsimCircuit placeholder; + placeholder.gates.reserve(2); + + for (const Moment& moment : program.circuit().moments()) { + for (const Operation& op : moment.operations()) { + placeholder.gates.clear(); + gate_found = false; + Status status = ParseAppendGate(op, param_map, num_qubits, time, + &placeholder, nullptr, &gate_found); + if (gate_found && !status.ok()) { + // gate found, failed when parsing proto. + return status; + } else if (status.ok()) { + // gate found. succeeded in parsing. + ncircuit->channels.push_back( + qsim::MakeChannelFromGate(time, placeholder.gates[0])); + } else { + // got not found. Attempt to find and append channel. + status = ParseAppendChannel(op, num_qubits, time, ncircuit); + } + + if (!status.ok()) { + return status; + } + } + time++; + } + + // Optionally add terminal measurements. + if (add_tmeasures) { + std::vector all_qbs(num_qubits); + std::iota(all_qbs.begin(), all_qbs.end(), 0); + ncircuit->channels.push_back( + {{qsim::KrausOperator::kMeasurement, + 1, + 1.0, + {qsim::gate::Measurement::Create(time, all_qbs)}}}); + } + + return ::tensorflow::Status(); +} + tensorflow::Status QsimCircuitFromProgram( const Program& program, const SymbolMap& param_map, const int num_qubits, QsimCircuit* circuit, std::vector>* fused_circuit, @@ -500,9 +866,11 @@ tensorflow::Status QsimCircuitFromProgram( // Convert proto to qsim internal representation. circuit->num_qubits = num_qubits; int time = 0; + [[maybe_unused]] bool unused; + // Special case empty. if (num_qubits <= 0) { - return Status::OK(); + return ::tensorflow::Status(); } circuit->gates.reserve(program.circuit().moments_size() * num_qubits); @@ -511,8 +879,8 @@ tensorflow::Status QsimCircuitFromProgram( } for (const Moment& moment : program.circuit().moments()) { for (const Operation& op : moment.operations()) { - Status status = - ParseAppendGate(op, param_map, num_qubits, time, circuit, metadata); + Status status = ParseAppendGate(op, param_map, num_qubits, time, circuit, + metadata, &unused); if (!status.ok()) { return status; } @@ -524,7 +892,7 @@ tensorflow::Status QsimCircuitFromProgram( *fused_circuit = qsim::BasicGateFuser().FuseGates( qsim::BasicGateFuser::Parameter(), circuit->num_qubits, circuit->gates); - return Status::OK(); + return ::tensorflow::Status(); } Status QsimCircuitFromPauliTerm( @@ -533,7 +901,7 @@ Status QsimCircuitFromPauliTerm( Program measurement_program; SymbolMap empty_map; measurement_program.mutable_circuit()->set_scheduling_strategy( - cirq::google::api::v2::Circuit::MOMENT_BY_MOMENT); + tfq::proto::Circuit::MOMENT_BY_MOMENT); Moment* term_moment = measurement_program.mutable_circuit()->add_moments(); for (const tfq::proto::PauliQubitPair& pair : term.paulis()) { Operation* new_op = term_moment->add_operations(); @@ -549,6 +917,12 @@ Status QsimCircuitFromPauliTerm( (*new_op->mutable_args())["exponent_scalar"] .mutable_arg_value() ->set_float_value(1.0); + (*new_op->mutable_args())["control_values"] + .mutable_arg_value() + ->set_string_value(""); + (*new_op->mutable_args())["control_qubits"] + .mutable_arg_value() + ->set_string_value(""); } return QsimCircuitFromProgram(measurement_program, empty_map, num_qubits, @@ -561,7 +935,7 @@ Status QsimZBasisCircuitFromPauliTerm( Program measurement_program; SymbolMap empty_map; measurement_program.mutable_circuit()->set_scheduling_strategy( - cirq::google::api::v2::Circuit::MOMENT_BY_MOMENT); + tfq::proto::Circuit::MOMENT_BY_MOMENT); Moment* term_moment = measurement_program.mutable_circuit()->add_moments(); float transform_exponent = 0.0; std::string gate_type; @@ -593,6 +967,12 @@ Status QsimZBasisCircuitFromPauliTerm( (*new_op->mutable_args())["exponent_scalar"] .mutable_arg_value() ->set_float_value(1.0); + (*new_op->mutable_args())["control_values"] + .mutable_arg_value() + ->set_string_value(""); + (*new_op->mutable_args())["control_qubits"] + .mutable_arg_value() + ->set_string_value(""); } return QsimCircuitFromProgram(measurement_program, empty_map, num_qubits, diff --git a/tensorflow_quantum/core/src/circuit_parser_qsim.h b/tensorflow_quantum/core/src/circuit_parser_qsim.h index 493dd3546..e2966407d 100644 --- a/tensorflow_quantum/core/src/circuit_parser_qsim.h +++ b/tensorflow_quantum/core/src/circuit_parser_qsim.h @@ -20,12 +20,13 @@ limitations under the License. #include #include "../qsim/lib/circuit.h" +#include "../qsim/lib/circuit_noisy.h" #include "../qsim/lib/fuser.h" #include "../qsim/lib/gates_cirq.h" #include "absl/container/flat_hash_map.h" -#include "cirq/google/api/v2/program.pb.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 { @@ -67,12 +68,24 @@ struct GateMetaData { // ingests a Cirq Circuit proto and produces a resolved qsim Circuit, // as well as a fused circuit. tensorflow::Status QsimCircuitFromProgram( - const cirq::google::api::v2::Program& program, + const tfq::proto::Program& program, const absl::flat_hash_map>& param_map, const int num_qubits, qsim::Circuit>* circuit, std::vector>>* fused_circuit, std::vector* metdata = nullptr); +// parse a serialized Cirq program into a qsim representation. +// ingests a Cirq Circuit proto and produces a resolved Noisy qsim Circuit. +// If add_tmeasures is true then terminal measurements are added on all +// qubits. +// Note: no metadata or fused circuits are produced as the qsim api for +// noisy simulation appears to take care of a lot of this for us. +tensorflow::Status NoisyQsimCircuitFromProgram( + const tfq::proto::Program& program, + const absl::flat_hash_map>& param_map, + const int num_qubits, const bool add_tmeasures, + qsim::NoisyCircuit>* ncircuit); + // parse a serialized pauliTerm from a larger cirq.Paulisum proto // into a qsim Circuit and fused circuit. tensorflow::Status QsimCircuitFromPauliTerm( diff --git a/tensorflow_quantum/core/src/circuit_parser_qsim_test.cc b/tensorflow_quantum/core/src/circuit_parser_qsim_test.cc index 9888ce170..811ecd430 100644 --- a/tensorflow_quantum/core/src/circuit_parser_qsim_test.cc +++ b/tensorflow_quantum/core/src/circuit_parser_qsim_test.cc @@ -17,28 +17,34 @@ limitations under the License. #include +#include "../qsim/lib/channel.h" +#include "../qsim/lib/channels_cirq.h" #include "../qsim/lib/circuit.h" +#include "../qsim/lib/circuit_noisy.h" #include "../qsim/lib/gates_cirq.h" #include "absl/container/flat_hash_map.h" +#include "absl/status/status.h" #include "absl/strings/numbers.h" -#include "cirq/google/api/v2/program.pb.h" #include "gtest/gtest.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow_quantum/core/proto/program.pb.h" namespace tfq { namespace { typedef absl::flat_hash_map> SymbolMap; +typedef qsim::Cirq::Channel QsimChannel; typedef qsim::Cirq::GateCirq QsimGate; typedef qsim::Circuit QsimCircuit; +typedef qsim::NoisyCircuit NoisyQsimCircuit; -using ::cirq::google::api::v2::Arg; -using ::cirq::google::api::v2::Circuit; -using ::cirq::google::api::v2::Gate; -using ::cirq::google::api::v2::Moment; -using ::cirq::google::api::v2::Operation; -using ::cirq::google::api::v2::Program; -using ::cirq::google::api::v2::Qubit; +using ::tfq::proto::Arg; +using ::tfq::proto::Circuit; +using ::tfq::proto::Gate; +using ::tfq::proto::Moment; +using ::tfq::proto::Operation; +using ::tfq::proto::Program; +using ::tfq::proto::Qubit; Arg MakeArg(float val) { Arg arg; @@ -52,12 +58,26 @@ Arg MakeArg(const std::string& val) { return arg; } +Arg MakeControlArg(const std::string& val) { + Arg arg; + arg.mutable_arg_value()->set_string_value(val); + return arg; +} + +inline void AssertControlEqual(const QsimGate& a, const QsimGate& b) { + for (size_t i = 0; i < a.controlled_by.size(); i++) { + ASSERT_EQ(a.controlled_by[i], b.controlled_by[i]); + } + ASSERT_EQ(a.cmask, b.cmask); +} + inline void AssertTwoQubitEqual(const QsimGate& a, const QsimGate& b) { for (int i = 0; i < 32; i++) { ASSERT_NEAR(a.matrix[i], b.matrix[i], 1e-5); } ASSERT_EQ(a.qubits[0], b.qubits[0]); ASSERT_EQ(a.qubits[1], b.qubits[1]); + AssertControlEqual(a, b); } inline void AssertOneQubitEqual(const QsimGate& a, const QsimGate& b) { @@ -65,6 +85,22 @@ inline void AssertOneQubitEqual(const QsimGate& a, const QsimGate& b) { ASSERT_NEAR(a.matrix[i], b.matrix[i], 1e-5); } ASSERT_EQ(a.qubits[0], b.qubits[0]); + AssertControlEqual(a, b); +} + +inline void AssertChannelEqual(const QsimChannel& a, const QsimChannel& b) { + ASSERT_EQ(a.size(), b.size()); + for (size_t i = 0; i < a.size(); i++) { + ASSERT_EQ(a[i].kind, b[i].kind); + ASSERT_EQ(a[i].unitary, b[i].unitary); + ASSERT_NEAR(a[i].prob, b[i].prob, 1e-5); + auto a_k_ops = a[i].ops; + auto b_k_ops = b[i].ops; + EXPECT_EQ(a_k_ops.size(), b_k_ops.size()); + for (size_t j = 0; j < a_k_ops.size(); j++) { + AssertOneQubitEqual(a_k_ops[j], b_k_ops[j]); + } + } } class TwoQubitEigenFixture @@ -96,6 +132,10 @@ TEST_P(TwoQubitEigenFixture, TwoEigenGate) { (*args_proto)["exponent"] = MakeArg("placeholder"); (*args_proto)["exponent_scalar"] = MakeArg(0.5); + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + // Set the qubits. Qubit* qubits_proto = operations_proto->add_qubits(); qubits_proto->set_id("0"); @@ -110,7 +150,7 @@ TEST_P(TwoQubitEigenFixture, TwoEigenGate) { // Test case where we have a placeholder. ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 2, &test_circuit, &fused_circuit, &metadata), - tensorflow::Status::OK()); + ::tensorflow::Status()); AssertTwoQubitEqual(test_circuit.gates[0], ref_gate); EXPECT_EQ(metadata[0].index, 0); EXPECT_EQ(metadata[0].symbol_values[0], "placeholder"); @@ -133,7 +173,7 @@ TEST_P(TwoQubitEigenFixture, TwoEigenGate) { // Test case where we have all float values. ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 2, &test_circuit, &fused_circuit, &metadata), - tensorflow::Status::OK()); + ::tensorflow::Status()); AssertTwoQubitEqual(test_circuit.gates[0], ref_gate); EXPECT_EQ(metadata[0].index, 0); EXPECT_NEAR(metadata[0].gate_params[0], exp, 1e-5); @@ -152,7 +192,8 @@ TEST_P(TwoQubitEigenFixture, TwoEigenGate) { // Test case where proto arg missing. ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 2, &test_circuit, &fused_circuit), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), "Could not find arg: exponent in op.")); test_circuit.gates.clear(); @@ -164,10 +205,68 @@ TEST_P(TwoQubitEigenFixture, TwoEigenGate) { ASSERT_EQ( QsimCircuitFromProgram(program_proto, symbol_map, 2, &test_circuit, &fused_circuit), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), "Could not find symbol in parameter map: alpha")); } +TEST_P(TwoQubitEigenFixture, TwoEigenGateControlled) { + float exp = 1.1234; + float gs = 2.2345; + + // Get gate name and reference qsim gate. + std::string name = std::get<0>(GetParam()); + auto ref_gate = + std::get<1>(GetParam())(0, 1, 0, exp, gs).ControlledBy({2, 3}, {0, 0}); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add gate. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id(name); + + // Set args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["global_shift"] = MakeArg(gs); + (*args_proto)["exponent"] = MakeArg("placeholder"); + (*args_proto)["exponent_scalar"] = MakeArg(0.5); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg("1,0"); + (*args_proto)["control_values"] = MakeControlArg("0,0"); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("2"); + qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("3"); + + QsimCircuit test_circuit; + std::vector> fused_circuit; + SymbolMap symbol_map = {{"placeholder", std::pair(1, 2 * exp)}}; + std::vector metadata; + + // Test case where we have a placeholder. + ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 4, &test_circuit, + &fused_circuit, &metadata), + ::tensorflow::Status()); + AssertTwoQubitEqual(test_circuit.gates[0], ref_gate); + EXPECT_EQ(metadata[0].index, 0); + EXPECT_EQ(metadata[0].symbol_values[0], "placeholder"); + EXPECT_EQ(metadata[0].placeholder_names[0], GateParamNames::kExponent); + EXPECT_NEAR(metadata[0].gate_params[0], 2 * exp, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[1], 0.5, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[2], gs, 1e-5); + EXPECT_EQ(metadata.size(), 1); + EXPECT_EQ(metadata[0].gate_params.size(), 3); + EXPECT_EQ(metadata[0].symbol_values.size(), 1); + EXPECT_EQ(metadata[0].placeholder_names.size(), 1); +} + INSTANTIATE_TEST_CASE_P( TwoQubitEigenTests, TwoQubitEigenFixture, ::testing::Values( @@ -208,6 +307,10 @@ TEST_P(SingleQubitEigenFixture, SingleEigenGate) { (*args_proto)["exponent"] = MakeArg("placeholder"); (*args_proto)["exponent_scalar"] = MakeArg(0.5); + // Set the control args to empty. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + // Set the qubits. Qubit* qubits_proto = operations_proto->add_qubits(); qubits_proto->set_id("0"); @@ -219,7 +322,7 @@ TEST_P(SingleQubitEigenFixture, SingleEigenGate) { ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 1, &test_circuit, &fused_circuit, &metadata), - tensorflow::Status::OK()); + ::tensorflow::Status()); AssertOneQubitEqual(test_circuit.gates[0], ref_gate); EXPECT_EQ(metadata[0].index, 0); EXPECT_EQ(metadata[0].symbol_values[0], "placeholder"); @@ -242,7 +345,7 @@ TEST_P(SingleQubitEigenFixture, SingleEigenGate) { // Test case where we have all float values. ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 1, &test_circuit, &fused_circuit, &metadata), - tensorflow::Status::OK()); + ::tensorflow::Status()); AssertOneQubitEqual(test_circuit.gates[0], ref_gate); EXPECT_EQ(metadata[0].index, 0); EXPECT_NEAR(metadata[0].gate_params[0], exp, 1e-5); @@ -261,7 +364,8 @@ TEST_P(SingleQubitEigenFixture, SingleEigenGate) { // Test case where proto arg missing. ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 1, &test_circuit, &fused_circuit), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), "Could not find arg: exponent in op.")); test_circuit.gates.clear(); @@ -273,10 +377,66 @@ TEST_P(SingleQubitEigenFixture, SingleEigenGate) { ASSERT_EQ( QsimCircuitFromProgram(program_proto, symbol_map, 1, &test_circuit, &fused_circuit), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), "Could not find symbol in parameter map: alpha")); } +TEST_P(SingleQubitEigenFixture, SingleEigenGateControlled) { + float exp = 1.1234; + float gs = 2.2345; + + // Get gate name and reference qsim gate. + std::string name = std::get<0>(GetParam()); + auto ref_gate = + std::get<1>(GetParam())(0, 0, exp, gs).ControlledBy({1, 2}, {0, 0}); + // Try symbol resolution. + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add gate. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id(name); + + // Set args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["global_shift"] = MakeArg(gs); + (*args_proto)["exponent"] = MakeArg("placeholder"); + (*args_proto)["exponent_scalar"] = MakeArg(0.5); + + // Set the control args to empty. + (*args_proto)["control_qubits"] = MakeControlArg("1,0"); + (*args_proto)["control_values"] = MakeControlArg("0,0"); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("2"); + + QsimCircuit test_circuit; + std::vector> fused_circuit; + SymbolMap symbol_map = {{"placeholder", std::pair(1, 2 * exp)}}; + std::vector metadata; + + ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 3, &test_circuit, + &fused_circuit, &metadata), + ::tensorflow::Status()); + AssertOneQubitEqual(test_circuit.gates[0], ref_gate); + EXPECT_EQ(metadata[0].index, 0); + EXPECT_EQ(metadata[0].symbol_values[0], "placeholder"); + EXPECT_EQ(metadata[0].placeholder_names[0], GateParamNames::kExponent); + EXPECT_NEAR(metadata[0].gate_params[0], 2 * exp, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[1], 0.5, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[2], gs, 1e-5); + EXPECT_EQ(metadata.size(), 1); + EXPECT_EQ(metadata[0].gate_params.size(), 3); + EXPECT_EQ(metadata[0].symbol_values.size(), 1); + EXPECT_EQ(metadata[0].placeholder_names.size(), 1); +} + INSTANTIATE_TEST_CASE_P( SingleQubitEigenTests, SingleQubitEigenFixture, ::testing::Values( @@ -299,6 +459,12 @@ TEST(QsimCircuitParserTest, SingleConstantGate) { Gate* gate_proto = operations_proto->mutable_gate(); gate_proto->set_id(kv.first); + // Set the control args to empty. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + // Set the qubits. Qubit* qubits_proto = operations_proto->add_qubits(); qubits_proto->set_id("0"); @@ -310,7 +476,47 @@ TEST(QsimCircuitParserTest, SingleConstantGate) { ASSERT_EQ(QsimCircuitFromProgram(program_proto, empty_map, 1, &test_circuit, &fused_circuit, &metadata), - tensorflow::Status::OK()); + ::tensorflow::Status()); + AssertOneQubitEqual(test_circuit.gates[0], kv.second); + EXPECT_EQ(metadata.size(), 1); + EXPECT_EQ(metadata[0].placeholder_names.size(), 0); + EXPECT_EQ(metadata[0].symbol_values.size(), 0); + EXPECT_EQ(metadata[0].gate_params.size(), 0); + } +} + +TEST(QsimCircuitParserTest, SingleConstantGateControlled) { + absl::flat_hash_map reference = { + {"I", qsim::Cirq::I1::Create(0, 0).ControlledBy({1, 2}, {0, 0})}}; + for (auto kv : reference) { + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add gate. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id(kv.first); + + // Set the control args to empty. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["control_qubits"] = MakeControlArg("1,0"); + (*args_proto)["control_values"] = MakeControlArg("0,0"); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("2"); + + QsimCircuit test_circuit; + std::vector> fused_circuit; + SymbolMap empty_map; + std::vector metadata; + + ASSERT_EQ(QsimCircuitFromProgram(program_proto, empty_map, 3, &test_circuit, + &fused_circuit, &metadata), + ::tensorflow::Status()); AssertOneQubitEqual(test_circuit.gates[0], kv.second); EXPECT_EQ(metadata.size(), 1); EXPECT_EQ(metadata[0].placeholder_names.size(), 0); @@ -333,6 +539,12 @@ TEST(QsimCircuitParserTest, TwoConstantGate) { Gate* gate_proto = operations_proto->mutable_gate(); gate_proto->set_id(kv.first); + // Set the control args to empty. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + // Set the qubits. Qubit* qubits_proto = operations_proto->add_qubits(); qubits_proto->set_id("0"); @@ -346,7 +558,50 @@ TEST(QsimCircuitParserTest, TwoConstantGate) { ASSERT_EQ(QsimCircuitFromProgram(program_proto, empty_map, 2, &test_circuit, &fused_circuit, &metadata), - tensorflow::Status::OK()); + ::tensorflow::Status()); + AssertTwoQubitEqual(test_circuit.gates[0], kv.second); + EXPECT_EQ(metadata.size(), 1); + EXPECT_EQ(metadata[0].placeholder_names.size(), 0); + EXPECT_EQ(metadata[0].symbol_values.size(), 0); + EXPECT_EQ(metadata[0].gate_params.size(), 0); + } +} + +TEST(QsimCircuitParserTest, TwoConstantGateControlled) { + absl::flat_hash_map reference = { + {"I2", + qsim::Cirq::I2::Create(0, 1, 0).ControlledBy({2, 3}, {0, 0})}}; + for (auto kv : reference) { + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add gate. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id(kv.first); + + // Set the control args to empty. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["control_qubits"] = MakeControlArg("1,0"); + (*args_proto)["control_values"] = MakeControlArg("0,0"); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("2"); + qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("3"); + + QsimCircuit test_circuit; + std::vector> fused_circuit; + SymbolMap empty_map; + std::vector metadata; + + ASSERT_EQ(QsimCircuitFromProgram(program_proto, empty_map, 4, &test_circuit, + &fused_circuit, &metadata), + ::tensorflow::Status()); AssertTwoQubitEqual(test_circuit.gates[0], kv.second); EXPECT_EQ(metadata.size(), 1); EXPECT_EQ(metadata[0].placeholder_names.size(), 0); @@ -355,7 +610,7 @@ TEST(QsimCircuitParserTest, TwoConstantGate) { } } -TEST(QsimCircuitParserTest, FsimGateTest) { +TEST(QsimCircuitParserTest, FsimGate) { float theta = 0.1234; float phi = 0.4567; auto reference = qsim::Cirq::FSimGate::Create(0, 0, 1, theta, phi); @@ -377,6 +632,10 @@ TEST(QsimCircuitParserTest, FsimGateTest) { (*args_proto)["phi"] = MakeArg("beta"); (*args_proto)["phi_scalar"] = MakeArg(0.2); + // Set the control args to empty. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + // Set the qubits. Qubit* qubits_proto = operations_proto->add_qubits(); qubits_proto->set_id("0"); @@ -392,7 +651,7 @@ TEST(QsimCircuitParserTest, FsimGateTest) { // Test symbol resolution. ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 2, &test_circuit, &fused_circuit, &metadata), - tensorflow::Status::OK()); + ::tensorflow::Status()); AssertTwoQubitEqual(test_circuit.gates[0], reference); EXPECT_EQ(metadata.size(), 1); EXPECT_EQ(metadata[0].placeholder_names.size(), 2); @@ -419,7 +678,7 @@ TEST(QsimCircuitParserTest, FsimGateTest) { // Test float values only. ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 2, &test_circuit, &fused_circuit, &metadata), - tensorflow::Status::OK()); + ::tensorflow::Status()); AssertTwoQubitEqual(test_circuit.gates[0], reference); EXPECT_EQ(metadata.size(), 1); EXPECT_EQ(metadata[0].placeholder_names.size(), 0); @@ -437,7 +696,8 @@ TEST(QsimCircuitParserTest, FsimGateTest) { // Test case where proto arg missing. ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 2, &test_circuit, &fused_circuit), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), "Could not find arg: theta in op.")); test_circuit.gates.clear(); @@ -449,11 +709,70 @@ TEST(QsimCircuitParserTest, FsimGateTest) { ASSERT_EQ( QsimCircuitFromProgram(program_proto, symbol_map, 2, &test_circuit, &fused_circuit), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), "Could not find symbol in parameter map: alpha")); } -TEST(QsimCircuitParserTest, PhasedISwapTest) { +TEST(QsimCircuitParserTest, FsimGateControlled) { + float theta = 0.1234; + float phi = 0.4567; + auto reference = qsim::Cirq::FSimGate::Create(0, 0, 1, theta, phi) + .ControlledBy({2, 3}, {0, 0}); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add gate. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("FSIM"); + + // Set the args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["theta"] = MakeArg("alpha"); + (*args_proto)["theta_scalar"] = MakeArg(0.5); + (*args_proto)["phi"] = MakeArg("beta"); + (*args_proto)["phi_scalar"] = MakeArg(0.2); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg("1,0"); + (*args_proto)["control_values"] = MakeControlArg("0,0"); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("2"); + qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("3"); + + QsimCircuit test_circuit; + std::vector> fused_circuit; + SymbolMap symbol_map = {{"alpha", std::pair(0, 2 * theta)}, + {"beta", std::pair(1, 5 * phi)}}; + std::vector metadata; + + // Test symbol resolution. + ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 4, &test_circuit, + &fused_circuit, &metadata), + ::tensorflow::Status()); + AssertTwoQubitEqual(test_circuit.gates[0], reference); + EXPECT_EQ(metadata.size(), 1); + EXPECT_EQ(metadata[0].placeholder_names.size(), 2); + EXPECT_EQ(metadata[0].symbol_values.size(), 2); + EXPECT_EQ(metadata[0].gate_params.size(), 4); + EXPECT_NEAR(metadata[0].gate_params[0], 2 * theta, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[1], 0.5, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[2], 5 * phi, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[3], 0.2, 1e-5); + EXPECT_EQ(metadata[0].symbol_values[0], "alpha"); + EXPECT_EQ(metadata[0].symbol_values[1], "beta"); + EXPECT_EQ(metadata[0].placeholder_names[0], GateParamNames::kTheta); + EXPECT_EQ(metadata[0].placeholder_names[1], GateParamNames::kPhi); +} + +TEST(QsimCircuitParserTest, PhasedISwap) { float exponent = 0.1234; float phase_exponent = 0.4567; auto reference = qsim::Cirq::PhasedISwapPowGate::Create( @@ -476,6 +795,10 @@ TEST(QsimCircuitParserTest, PhasedISwapTest) { (*args_proto)["exponent"] = MakeArg("beta"); (*args_proto)["exponent_scalar"] = MakeArg(0.2); + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + // Set the qubits. Qubit* qubits_proto = operations_proto->add_qubits(); qubits_proto->set_id("0"); @@ -492,7 +815,7 @@ TEST(QsimCircuitParserTest, PhasedISwapTest) { // Test symbol resolution. ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 2, &test_circuit, &fused_circuit, &metadata), - tensorflow::Status::OK()); + ::tensorflow::Status()); AssertTwoQubitEqual(test_circuit.gates[0], reference); EXPECT_EQ(metadata.size(), 1); EXPECT_EQ(metadata[0].placeholder_names.size(), 2); @@ -519,7 +842,7 @@ TEST(QsimCircuitParserTest, PhasedISwapTest) { // Test float values only. ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 2, &test_circuit, &fused_circuit, &metadata), - tensorflow::Status::OK()); + ::tensorflow::Status()); AssertTwoQubitEqual(test_circuit.gates[0], reference); EXPECT_EQ(metadata.size(), 1); EXPECT_EQ(metadata[0].placeholder_names.size(), 0); @@ -537,7 +860,8 @@ TEST(QsimCircuitParserTest, PhasedISwapTest) { // Test case where proto arg missing. ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 2, &test_circuit, &fused_circuit), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), "Could not find arg: phase_exponent in op.")); test_circuit.gates.clear(); @@ -549,16 +873,17 @@ TEST(QsimCircuitParserTest, PhasedISwapTest) { ASSERT_EQ( QsimCircuitFromProgram(program_proto, symbol_map, 2, &test_circuit, &fused_circuit), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), "Could not find symbol in parameter map: alpha")); } -TEST(QsimCircuitParserTest, PhasedXPowTest) { +TEST(QsimCircuitParserTest, PhasedISwapControlled) { float exponent = 0.1234; float phase_exponent = 0.4567; - float gs = 0.8910; - auto reference = qsim::Cirq::PhasedXPowGate::Create( - 0, 0, phase_exponent, exponent, gs); + auto reference = qsim::Cirq::PhasedISwapPowGate::Create( + 0, 1, 0, phase_exponent, exponent) + .ControlledBy({2, 3}, {0, 0}); Program program_proto; Circuit* circuit_proto = program_proto.mutable_circuit(); circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); @@ -567,7 +892,7 @@ TEST(QsimCircuitParserTest, PhasedXPowTest) { // Add gate. Operation* operations_proto = moments_proto->add_operations(); Gate* gate_proto = operations_proto->mutable_gate(); - gate_proto->set_id("PXP"); + gate_proto->set_id("PISP"); // Set the args. google::protobuf::Map* args_proto = @@ -576,11 +901,16 @@ TEST(QsimCircuitParserTest, PhasedXPowTest) { (*args_proto)["phase_exponent_scalar"] = MakeArg(0.5); (*args_proto)["exponent"] = MakeArg("beta"); (*args_proto)["exponent_scalar"] = MakeArg(0.2); - (*args_proto)["global_shift"] = MakeArg(gs); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg("1,0"); + (*args_proto)["control_values"] = MakeControlArg("0,0"); // Set the qubits. Qubit* qubits_proto = operations_proto->add_qubits(); - qubits_proto->set_id("0"); + qubits_proto->set_id("2"); + qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("3"); QsimCircuit test_circuit; std::vector> fused_circuit; @@ -590,38 +920,97 @@ TEST(QsimCircuitParserTest, PhasedXPowTest) { std::vector metadata; // Test symbol resolution. - ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 1, &test_circuit, + ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 4, &test_circuit, &fused_circuit, &metadata), - tensorflow::Status::OK()); - AssertOneQubitEqual(test_circuit.gates[0], reference); + ::tensorflow::Status()); + AssertTwoQubitEqual(test_circuit.gates[0], reference); EXPECT_EQ(metadata.size(), 1); EXPECT_EQ(metadata[0].placeholder_names.size(), 2); EXPECT_EQ(metadata[0].symbol_values.size(), 2); - EXPECT_EQ(metadata[0].gate_params.size(), 5); + EXPECT_EQ(metadata[0].gate_params.size(), 4); EXPECT_NEAR(metadata[0].gate_params[0], 2 * phase_exponent, 1e-5); EXPECT_NEAR(metadata[0].gate_params[1], 0.5, 1e-5); EXPECT_NEAR(metadata[0].gate_params[2], 5 * exponent, 1e-5); EXPECT_NEAR(metadata[0].gate_params[3], 0.2, 1e-5); - EXPECT_NEAR(metadata[0].gate_params[4], gs, 1e-5); EXPECT_EQ(metadata[0].symbol_values[0], "alpha"); EXPECT_EQ(metadata[0].symbol_values[1], "beta"); EXPECT_EQ(metadata[0].placeholder_names[0], GateParamNames::kPhaseExponent); EXPECT_EQ(metadata[0].placeholder_names[1], GateParamNames::kExponent); +} - symbol_map.clear(); - test_circuit.gates.clear(); - fused_circuit.clear(); - metadata.clear(); - (*args_proto)["phase_exponent"] = MakeArg(phase_exponent); - (*args_proto)["phase_exponent_scalar"] = MakeArg(1.0); - (*args_proto)["exponent"] = MakeArg(exponent); - (*args_proto)["exponent_scalar"] = MakeArg(1.0); - (*args_proto)["global_shift"] = MakeArg(gs); +TEST(QsimCircuitParserTest, PhasedXPow) { + float exponent = 0.1234; + float phase_exponent = 0.4567; + float gs = 0.8910; + auto reference = qsim::Cirq::PhasedXPowGate::Create( + 0, 0, phase_exponent, exponent, gs); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); - // Test float values only. - ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 1, &test_circuit, - &fused_circuit, &metadata), - tensorflow::Status::OK()); + // Add gate. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("PXP"); + + // Set the args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["phase_exponent"] = MakeArg("alpha"); + (*args_proto)["phase_exponent_scalar"] = MakeArg(0.5); + (*args_proto)["exponent"] = MakeArg("beta"); + (*args_proto)["exponent_scalar"] = MakeArg(0.2); + (*args_proto)["global_shift"] = MakeArg(gs); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("0"); + + QsimCircuit test_circuit; + std::vector> fused_circuit; + SymbolMap symbol_map = { + {"alpha", std::pair(0, 2 * phase_exponent)}, + {"beta", std::pair(1, 5 * exponent)}}; + std::vector metadata; + + // Test symbol resolution. + ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 1, &test_circuit, + &fused_circuit, &metadata), + ::tensorflow::Status()); + AssertOneQubitEqual(test_circuit.gates[0], reference); + EXPECT_EQ(metadata.size(), 1); + EXPECT_EQ(metadata[0].placeholder_names.size(), 2); + EXPECT_EQ(metadata[0].symbol_values.size(), 2); + EXPECT_EQ(metadata[0].gate_params.size(), 5); + EXPECT_NEAR(metadata[0].gate_params[0], 2 * phase_exponent, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[1], 0.5, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[2], 5 * exponent, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[3], 0.2, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[4], gs, 1e-5); + EXPECT_EQ(metadata[0].symbol_values[0], "alpha"); + EXPECT_EQ(metadata[0].symbol_values[1], "beta"); + EXPECT_EQ(metadata[0].placeholder_names[0], GateParamNames::kPhaseExponent); + EXPECT_EQ(metadata[0].placeholder_names[1], GateParamNames::kExponent); + + symbol_map.clear(); + test_circuit.gates.clear(); + fused_circuit.clear(); + metadata.clear(); + (*args_proto)["phase_exponent"] = MakeArg(phase_exponent); + (*args_proto)["phase_exponent_scalar"] = MakeArg(1.0); + (*args_proto)["exponent"] = MakeArg(exponent); + (*args_proto)["exponent_scalar"] = MakeArg(1.0); + (*args_proto)["global_shift"] = MakeArg(gs); + + // Test float values only. + ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 1, &test_circuit, + &fused_circuit, &metadata), + ::tensorflow::Status()); AssertOneQubitEqual(test_circuit.gates[0], reference); EXPECT_EQ(metadata.size(), 1); EXPECT_EQ(metadata[0].placeholder_names.size(), 0); @@ -639,7 +1028,8 @@ TEST(QsimCircuitParserTest, PhasedXPowTest) { // Test case where proto arg missing. ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 1, &test_circuit, &fused_circuit), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), "Could not find arg: phase_exponent in op.")); test_circuit.gates.clear(); @@ -651,10 +1041,139 @@ TEST(QsimCircuitParserTest, PhasedXPowTest) { ASSERT_EQ( QsimCircuitFromProgram(program_proto, symbol_map, 1, &test_circuit, &fused_circuit), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), "Could not find symbol in parameter map: alpha")); } +TEST(QsimCircuitParserTest, PhasedXPowControlled) { + float exponent = 0.1234; + float phase_exponent = 0.4567; + float gs = 0.8910; + auto reference = qsim::Cirq::PhasedXPowGate::Create( + 0, 0, phase_exponent, exponent, gs) + .ControlledBy({1, 2}, {0, 0}); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add gate. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("PXP"); + + // Set the args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["phase_exponent"] = MakeArg("alpha"); + (*args_proto)["phase_exponent_scalar"] = MakeArg(0.5); + (*args_proto)["exponent"] = MakeArg("beta"); + (*args_proto)["exponent_scalar"] = MakeArg(0.2); + (*args_proto)["global_shift"] = MakeArg(gs); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg("1,0"); + (*args_proto)["control_values"] = MakeControlArg("0,0"); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("2"); + + QsimCircuit test_circuit; + std::vector> fused_circuit; + SymbolMap symbol_map = { + {"alpha", std::pair(0, 2 * phase_exponent)}, + {"beta", std::pair(1, 5 * exponent)}}; + std::vector metadata; + + // Test symbol resolution. + ASSERT_EQ(QsimCircuitFromProgram(program_proto, symbol_map, 3, &test_circuit, + &fused_circuit, &metadata), + ::tensorflow::Status()); + AssertOneQubitEqual(test_circuit.gates[0], reference); + EXPECT_EQ(metadata.size(), 1); + EXPECT_EQ(metadata[0].placeholder_names.size(), 2); + EXPECT_EQ(metadata[0].symbol_values.size(), 2); + EXPECT_EQ(metadata[0].gate_params.size(), 5); + EXPECT_NEAR(metadata[0].gate_params[0], 2 * phase_exponent, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[1], 0.5, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[2], 5 * exponent, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[3], 0.2, 1e-5); + EXPECT_NEAR(metadata[0].gate_params[4], gs, 1e-5); + EXPECT_EQ(metadata[0].symbol_values[0], "alpha"); + EXPECT_EQ(metadata[0].symbol_values[1], "beta"); + EXPECT_EQ(metadata[0].placeholder_names[0], GateParamNames::kPhaseExponent); + EXPECT_EQ(metadata[0].placeholder_names[1], GateParamNames::kExponent); +} + +TEST(QsimCircuitParserTest, InvalidControlValues) { + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add gate. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("I"); + + // Set the control args to empty. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["control_qubits"] = MakeControlArg("1,0"); + (*args_proto)["control_values"] = MakeControlArg("0,junk"); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("2"); + + QsimCircuit test_circuit; + std::vector> fused_circuit; + SymbolMap empty_map; + std::vector metadata; + + ASSERT_EQ(QsimCircuitFromProgram(program_proto, empty_map, 3, &test_circuit, + &fused_circuit, &metadata), + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), + "Unparseable control value: junk")); +} + +TEST(QsimCircuitParserTest, MismatchControlNum) { + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add gate. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("I"); + + // Set the control args to empty. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["control_qubits"] = MakeControlArg("1,0"); + (*args_proto)["control_values"] = MakeControlArg("0"); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("2"); + + QsimCircuit test_circuit; + std::vector> fused_circuit; + SymbolMap empty_map; + std::vector metadata; + + ASSERT_EQ(QsimCircuitFromProgram(program_proto, empty_map, 3, &test_circuit, + &fused_circuit, &metadata), + tensorflow::Status( + static_cast( + absl::StatusCode::kInvalidArgument), + "Mistmatched number of control qubits and control values.")); +} + TEST(QsimCircuitParserTest, EmptyTest) { Program program_proto; Circuit* circuit_proto = program_proto.mutable_circuit(); @@ -668,12 +1187,396 @@ TEST(QsimCircuitParserTest, EmptyTest) { // Ensure that nothing bad happens with an empty circuit. ASSERT_EQ(QsimCircuitFromProgram(program_proto, empty_map, 2, &test_circuit, &fused_circuit, &metadata), - tensorflow::Status::OK()); + ::tensorflow::Status()); ASSERT_EQ(test_circuit.gates.size(), 0); ASSERT_EQ(fused_circuit.size(), 0); ASSERT_EQ(metadata.size(), 0); } +TEST(QsimCircuitParserTest, CompoundCircuit) { + float p = 0.1234; + auto ref_chan = qsim::Cirq::DepolarizingChannel::Create(0, 0, p); + auto ref_gate = qsim::Cirq::I1::Create(0, 1); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add channel. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("DP"); + + // Set the args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["p"] = MakeArg(p); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("1"); + + // Add gate. + operations_proto = moments_proto->add_operations(); + gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("I"); + + // Set the args. + args_proto = operations_proto->mutable_args(); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + + // Set the qubits. + qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("0"); + + NoisyQsimCircuit test_circuit; + + ASSERT_EQ( + NoisyQsimCircuitFromProgram(program_proto, {}, 2, true, &test_circuit), + ::tensorflow::Status()); + AssertChannelEqual(test_circuit.channels[0], ref_chan); + AssertOneQubitEqual(test_circuit.channels[1][0].ops[0], ref_gate); + ASSERT_EQ(test_circuit.channels.size(), + 3); // 2 gates + 1 layer of measurement. + ASSERT_EQ(test_circuit.num_qubits, 2); +} + +TEST(QsimCircuitParserTest, AsymmetricDepolarizing) { + float p_x = 0.123; + float p_y = 0.456; + float p_z = 0.789; + auto reference = qsim::Cirq::AsymmetricDepolarizingChannel::Create( + 0, 0, p_x, p_y, p_z); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add channel. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("ADP"); + + // Set the args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["p_x"] = MakeArg(p_x); + (*args_proto)["p_y"] = MakeArg(p_y); + (*args_proto)["p_z"] = MakeArg(p_z); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("0"); + + NoisyQsimCircuit test_circuit; + + ASSERT_EQ( + NoisyQsimCircuitFromProgram(program_proto, {}, 1, false, &test_circuit), + ::tensorflow::Status()); + AssertChannelEqual(test_circuit.channels[0], reference); + ASSERT_EQ(test_circuit.channels.size(), 1); + ASSERT_EQ(test_circuit.num_qubits, 1); +} + +TEST(QsimCircuitParserTest, AmplitudeDamping) { + float gamma = 0.1234; + auto reference = + qsim::Cirq::AmplitudeDampingChannel::Create(0, 0, gamma); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add channel. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("AD"); + + // Set the args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["gamma"] = MakeArg(gamma); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("0"); + + NoisyQsimCircuit test_circuit; + + ASSERT_EQ( + NoisyQsimCircuitFromProgram(program_proto, {}, 1, false, &test_circuit), + ::tensorflow::Status()); + AssertChannelEqual(test_circuit.channels[0], reference); + ASSERT_EQ(test_circuit.channels.size(), 1); + ASSERT_EQ(test_circuit.num_qubits, 1); +} + +TEST(QsimCircuitParserTest, Depolarizing) { + float p = 0.1234; + auto reference = qsim::Cirq::DepolarizingChannel::Create(0, 0, p); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add channel. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("DP"); + + // Set the args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["p"] = MakeArg(p); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("0"); + + NoisyQsimCircuit test_circuit; + + ASSERT_EQ( + NoisyQsimCircuitFromProgram(program_proto, {}, 1, false, &test_circuit), + ::tensorflow::Status()); + AssertChannelEqual(test_circuit.channels[0], reference); + ASSERT_EQ(test_circuit.channels.size(), 1); + ASSERT_EQ(test_circuit.num_qubits, 1); +} + +TEST(QsimCircuitParserTest, GeneralizedAmplitudeDamping) { + float p = 0.123; + float gamma = 0.456; + auto reference = + qsim::Cirq::GeneralizedAmplitudeDampingChannel::Create(0, 0, p, + gamma); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add channel. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("GAD"); + + // Set the args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["p"] = MakeArg(p); + (*args_proto)["gamma"] = MakeArg(gamma); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("0"); + + NoisyQsimCircuit test_circuit; + + ASSERT_EQ( + NoisyQsimCircuitFromProgram(program_proto, {}, 1, false, &test_circuit), + ::tensorflow::Status()); + AssertChannelEqual(test_circuit.channels[0], reference); + ASSERT_EQ(test_circuit.channels.size(), 1); + ASSERT_EQ(test_circuit.num_qubits, 1); +} + +TEST(QsimCircuitParserTest, Reset) { + auto reference = qsim::Cirq::ResetChannel::Create(0, 0); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add channel. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("RST"); + + // Set the args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("0"); + + NoisyQsimCircuit test_circuit; + + ASSERT_EQ( + NoisyQsimCircuitFromProgram(program_proto, {}, 1, false, &test_circuit), + ::tensorflow::Status()); + AssertChannelEqual(test_circuit.channels[0], reference); + ASSERT_EQ(test_circuit.channels.size(), 1); + ASSERT_EQ(test_circuit.num_qubits, 1); +} + +TEST(QsimCircuitParserTest, PhaseDamping) { + float gamma = 0.1234; + auto reference = qsim::Cirq::PhaseDampingChannel::Create(0, 0, gamma); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add channel. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("PD"); + + // Set the args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["gamma"] = MakeArg(gamma); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("0"); + + NoisyQsimCircuit test_circuit; + + ASSERT_EQ( + NoisyQsimCircuitFromProgram(program_proto, {}, 1, false, &test_circuit), + ::tensorflow::Status()); + AssertChannelEqual(test_circuit.channels[0], reference); + ASSERT_EQ(test_circuit.channels.size(), 1); + ASSERT_EQ(test_circuit.num_qubits, 1); +} + +TEST(QsimCircuitParserTest, PhaseFlip) { + float p = 0.1234; + auto reference = qsim::Cirq::PhaseFlipChannel::Create(0, 0, p); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add channel. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("PF"); + + // Set the args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["p"] = MakeArg(p); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("0"); + + NoisyQsimCircuit test_circuit; + + ASSERT_EQ( + NoisyQsimCircuitFromProgram(program_proto, {}, 1, false, &test_circuit), + ::tensorflow::Status()); + AssertChannelEqual(test_circuit.channels[0], reference); + ASSERT_EQ(test_circuit.channels.size(), 1); + ASSERT_EQ(test_circuit.num_qubits, 1); +} + +TEST(QsimCircuitParserTest, BitFlip) { + float p = 0.1234; + auto reference = qsim::Cirq::BitFlipChannel::Create(0, 0, p); + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add channel. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("BF"); + + // Set the args. + google::protobuf::Map* args_proto = + operations_proto->mutable_args(); + (*args_proto)["p"] = MakeArg(p); + + // Set the control args. + (*args_proto)["control_qubits"] = MakeControlArg(""); + (*args_proto)["control_values"] = MakeControlArg(""); + + // Set the qubits. + Qubit* qubits_proto = operations_proto->add_qubits(); + qubits_proto->set_id("0"); + + NoisyQsimCircuit test_circuit; + + ASSERT_EQ( + NoisyQsimCircuitFromProgram(program_proto, {}, 1, false, &test_circuit), + ::tensorflow::Status()); + AssertChannelEqual(test_circuit.channels[0], reference); + ASSERT_EQ(test_circuit.channels.size(), 1); + ASSERT_EQ(test_circuit.num_qubits, 1); +} + +TEST(QsimCircuitParserTest, NoisyEmpty) { + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + (void)circuit_proto->add_moments(); + + NoisyQsimCircuit test_circuit; + ASSERT_EQ( + NoisyQsimCircuitFromProgram(program_proto, {}, 0, false, &test_circuit), + ::tensorflow::Status()); + ASSERT_EQ(test_circuit.channels.size(), 0); + ASSERT_EQ(test_circuit.num_qubits, 0); +} + +TEST(QsimCircuitParserTest, NoisyBadProto) { + Program program_proto; + Circuit* circuit_proto = program_proto.mutable_circuit(); + circuit_proto->set_scheduling_strategy(circuit_proto->MOMENT_BY_MOMENT); + Moment* moments_proto = circuit_proto->add_moments(); + + // Add channel. + Operation* operations_proto = moments_proto->add_operations(); + Gate* gate_proto = operations_proto->mutable_gate(); + gate_proto->set_id("ABCDEFG"); + + NoisyQsimCircuit test_circuit; + ASSERT_EQ( + NoisyQsimCircuitFromProgram(program_proto, {}, 1, false, &test_circuit), + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), + "Could not parse channel id: ABCDEFG")); +} + TEST(QsimCircuitParserTest, CircuitFromPauliTermPauli) { tfq::proto::PauliTerm pauli_proto; // The created circuit should not depend on the coefficient @@ -691,7 +1594,7 @@ TEST(QsimCircuitParserTest, CircuitFromPauliTermPauli) { // Check conversion status = QsimCircuitFromPauliTerm(pauli_proto, 1, &test_circuit, &fused_circuit); - ASSERT_EQ(status, tensorflow::Status::OK()); + ASSERT_EQ(status, tensorflow::Status()); ASSERT_EQ(test_circuit.num_qubits, 1); ASSERT_EQ(test_circuit.gates.size(), 1); AssertOneQubitEqual(test_circuit.gates[0], reference); @@ -704,7 +1607,7 @@ TEST(QsimCircuitParserTest, CircuitFromPauliTermEmpty) { std::vector> fused_circuit; status = QsimCircuitFromPauliTerm(pauli_proto, 0, &test_circuit, &fused_circuit); - ASSERT_EQ(status, tensorflow::Status::OK()); + ASSERT_EQ(status, tensorflow::Status()); ASSERT_EQ(test_circuit.num_qubits, 0); ASSERT_EQ(test_circuit.gates.size(), 0); } @@ -726,7 +1629,7 @@ TEST(QsimCircuitParserTest, ZBasisCircuitFromPauliTermPauliX) { // Check conversion status = QsimZBasisCircuitFromPauliTerm(pauli_proto, 1, &test_circuit, &fused_circuit); - ASSERT_EQ(status, tensorflow::Status::OK()); + ASSERT_EQ(status, tensorflow::Status()); ASSERT_EQ(test_circuit.num_qubits, 1); ASSERT_EQ(test_circuit.gates.size(), 1); AssertOneQubitEqual(test_circuit.gates[0], reference); @@ -749,7 +1652,7 @@ TEST(QsimCircuitParserTest, ZBasisCircuitFromPauliTermPauliY) { // Check conversion status = QsimZBasisCircuitFromPauliTerm(pauli_proto, 1, &test_circuit, &fused_circuit); - ASSERT_EQ(status, tensorflow::Status::OK()); + ASSERT_EQ(status, tensorflow::Status()); ASSERT_EQ(test_circuit.num_qubits, 1); ASSERT_EQ(test_circuit.gates.size(), 1); AssertOneQubitEqual(test_circuit.gates[0], reference); @@ -771,7 +1674,7 @@ TEST(QsimCircuitParserTest, ZBasisCircuitFromPauliTermPauliZ) { // Check conversion status = QsimZBasisCircuitFromPauliTerm(pauli_proto, 1, &test_circuit, &fused_circuit); - ASSERT_EQ(status, tensorflow::Status::OK()); + ASSERT_EQ(status, tensorflow::Status()); ASSERT_EQ(test_circuit.num_qubits, 1); ASSERT_EQ(test_circuit.gates.size(), 0); } @@ -798,7 +1701,7 @@ TEST(QsimCircuitParserTest, ZBasisCircuitFromPauliTermPauliCompound) { // Check conversion status = QsimZBasisCircuitFromPauliTerm(pauli_proto, 2, &test_circuit, &fused_circuit); - ASSERT_EQ(status, tensorflow::Status::OK()); + ASSERT_EQ(status, tensorflow::Status()); ASSERT_EQ(test_circuit.num_qubits, 2); ASSERT_EQ(test_circuit.gates.size(), 2); AssertOneQubitEqual(test_circuit.gates[0], reference1); @@ -812,7 +1715,7 @@ TEST(QsimCircuitParserTest, ZBasisCircuitFromPauliTermEmpty) { std::vector> fused_circuit; status = QsimZBasisCircuitFromPauliTerm(pauli_proto, 0, &test_circuit, &fused_circuit); - ASSERT_EQ(status, tensorflow::Status::OK()); + ASSERT_EQ(status, tensorflow::Status()); ASSERT_EQ(test_circuit.num_qubits, 0); ASSERT_EQ(test_circuit.gates.size(), 0); } diff --git a/tensorflow_quantum/core/src/program_resolution.cc b/tensorflow_quantum/core/src/program_resolution.cc index 1585146c3..86e3ab897 100644 --- a/tensorflow_quantum/core/src/program_resolution.cc +++ b/tensorflow_quantum/core/src/program_resolution.cc @@ -20,55 +20,99 @@ limitations under the License. #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" +#include "absl/status/status.h" #include "absl/strings/str_cat.h" +#include "absl/strings/str_join.h" #include "absl/strings/str_split.h" -#include "cirq/google/api/v2/program.pb.h" +#include "absl/strings/string_view.h" #include "tensorflow/core/lib/core/error_codes.pb.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 { -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 cirq::google::api::v2::Qubit; using tensorflow::Status; +using tfq::proto::Arg; +using tfq::proto::Moment; +using tfq::proto::Operation; using tfq::proto::PauliQubitPair; using tfq::proto::PauliSum; using tfq::proto::PauliTerm; +using tfq::proto::Program; +using tfq::proto::Qubit; + +inline absl::string_view IntMaxStr() { + static constexpr char kMaxVal[] = "2147483647"; + return kMaxVal; +} + +Status RegisterQubits( + absl::string_view qb_string, + absl::flat_hash_set, std::string>>* id_set) { + // Inserts qubits found in qb_string into id_set. + // Supported GridQubit wire formats and line qubit wire formats. + + if (qb_string.empty()) { + return ::tensorflow::Status(); // no control-default value specified in + // serializer.py + } + + const std::vector qb_list = absl::StrSplit(qb_string, ','); + for (auto qb : qb_list) { + int r, c; + std::vector splits = absl::StrSplit(qb, '_'); + if (splits.size() == 1) { // Pad the front of linequbit with INTMAX. + splits.insert(splits.begin(), IntMaxStr()); + } + + if (splits.size() != 2) { + return Status(static_cast( + absl::StatusCode::kInvalidArgument), + absl::StrCat("Unable to parse qubit: ", qb)); + } + if (!absl::SimpleAtoi(splits[0], &r)) { + return Status(static_cast( + absl::StatusCode::kInvalidArgument), + absl::StrCat("Unable to parse qubit: ", qb)); + } + if (!absl::SimpleAtoi(splits[1], &c)) { + return Status(static_cast( + absl::StatusCode::kInvalidArgument), + absl::StrCat("Unable to parse qubit: ", qb)); + } + auto locs = std::pair, std::string>( + std::pair(r, c), std::string(qb)); + id_set->insert(locs); + } + return ::tensorflow::Status(); +} Status ResolveQubitIds(Program* program, unsigned int* num_qubits, - std::vector* p_sums /*=nullptr*/) { + std::vector* p_sums /*=nullptr*/, + bool swap_endianness /*=false*/) { if (program->circuit().moments().empty()) { // (#679) Just ignore empty program. // Number of qubits in empty programs is zero. *num_qubits = 0; - return Status::OK(); + return ::tensorflow::Status(); } absl::flat_hash_set, std::string>> id_set; for (const Moment& moment : program->circuit().moments()) { for (const Operation& operation : moment.operations()) { + Status s; for (const Qubit& qubit : operation.qubits()) { - int r, c; - const std::vector splits = absl::StrSplit(qubit.id(), "_"); - if (splits.size() != 2) { - return Status(tensorflow::error::INVALID_ARGUMENT, - "Unable to parse qubit: " + qubit.id()); - } - if (!absl::SimpleAtoi(splits[0], &r)) { - return Status(tensorflow::error::INVALID_ARGUMENT, - "Unable to parse qubit: " + qubit.id()); - } - if (!absl::SimpleAtoi(splits[1], &c)) { - return Status(tensorflow::error::INVALID_ARGUMENT, - "Unable to parse qubit: " + qubit.id()); + s = RegisterQubits(qubit.id(), &id_set); + if (!s.ok()) { + return s; } - auto locs = std::pair, std::string>( - std::pair(r, c), qubit.id()); - id_set.insert(locs); + } + s = RegisterQubits( + operation.args().at("control_qubits").arg_value().string_value(), + &id_set); + if (!s.ok()) { + return s; } } } @@ -79,6 +123,10 @@ Status ResolveQubitIds(Program* program, unsigned int* num_qubits, id_set.end()); std::sort(ids.begin(), ids.end()); + // reverse endian. + if (swap_endianness) { + std::reverse(ids.begin(), ids.end()); + } absl::flat_hash_map id_to_index; for (size_t i = 0; i < ids.size(); i++) { id_to_index[ids[i].second] = absl::StrCat(i); @@ -87,9 +135,33 @@ Status ResolveQubitIds(Program* program, unsigned int* num_qubits, // Replace the Program Qubit ids with the indices. for (Moment& moment : *program->mutable_circuit()->mutable_moments()) { for (Operation& operation : *moment.mutable_operations()) { + // Resolve qubit ids. for (Qubit& qubit : *operation.mutable_qubits()) { qubit.set_id(id_to_index.at(qubit.id())); } + // reverse endian. + if (swap_endianness) { + std::reverse(operation.mutable_qubits()->begin(), + operation.mutable_qubits()->end()); + } + // Resolve control qubit ids found in the control_qubits arg. + absl::string_view control_qubits = + operation.args().at("control_qubits").arg_value().string_value(); + // explicit empty value set in serializer.py. + if (control_qubits.empty()) { + continue; + } + std::vector control_ids = + absl::StrSplit(control_qubits, ','); + std::vector control_indexs; + control_indexs.reserve(control_ids.size()); + for (auto id : control_ids) { + control_indexs.push_back(id_to_index.at(id)); + } + operation.mutable_args() + ->at("control_qubits") + .mutable_arg_value() + ->set_string_value(absl::StrJoin(control_indexs, ",")); } } @@ -101,7 +173,8 @@ Status ResolveQubitIds(Program* program, unsigned int* num_qubits, const auto result = id_to_index.find(pair.qubit_id()); if (result == id_to_index.end()) { return Status( - tensorflow::error::INVALID_ARGUMENT, + static_cast( + absl::StatusCode::kInvalidArgument), "Found a Pauli sum operating on qubits not found in circuit."); } pair.set_qubit_id(result->second); @@ -110,7 +183,7 @@ Status ResolveQubitIds(Program* program, unsigned int* num_qubits, } } - return Status::OK(); + return ::tensorflow::Status(); } Status ResolveQubitIds(Program* program, unsigned int* num_qubits, @@ -119,30 +192,24 @@ Status ResolveQubitIds(Program* program, unsigned int* num_qubits, // (#679) Just ignore empty program. // Number of qubits in empty programs is zero. *num_qubits = 0; - return Status::OK(); + return ::tensorflow::Status(); } absl::flat_hash_set, std::string>> id_set; for (const Moment& moment : program->circuit().moments()) { for (const Operation& operation : moment.operations()) { + Status s; for (const Qubit& qubit : operation.qubits()) { - int r, c; - const std::vector splits = absl::StrSplit(qubit.id(), "_"); - if (splits.size() != 2) { - return Status(tensorflow::error::INVALID_ARGUMENT, - "Unable to parse qubit: " + qubit.id()); - } - if (!absl::SimpleAtoi(splits[0], &r)) { - return Status(tensorflow::error::INVALID_ARGUMENT, - "Unable to parse qubit: " + qubit.id()); + s = RegisterQubits(qubit.id(), &id_set); + if (!s.ok()) { + return s; } - if (!absl::SimpleAtoi(splits[1], &c)) { - return Status(tensorflow::error::INVALID_ARGUMENT, - "Unable to parse qubit: " + qubit.id()); - } - auto locs = std::pair, std::string>( - std::pair(r, c), qubit.id()); - id_set.insert(locs); + } + s = RegisterQubits( + operation.args().at("control_qubits").arg_value().string_value(), + &id_set); + if (!s.ok()) { + return s; } } } @@ -166,6 +233,24 @@ Status ResolveQubitIds(Program* program, unsigned int* num_qubits, for (Qubit& qubit : *operation.mutable_qubits()) { qubit.set_id(id_to_index.at(qubit.id())); } + // Resolve control qubit ids found in the control_qubits arg. + absl::string_view control_qubits = + operation.args().at("control_qubits").arg_value().string_value(); + // explicit empty value set in serializer.py. + if (control_qubits.empty()) { + continue; + } + std::vector control_ids = + absl::StrSplit(control_qubits, ','); + std::vector control_indexs; + control_indexs.reserve(control_ids.size()); + for (auto id : control_ids) { + control_indexs.push_back(id_to_index.at(id)); + } + operation.mutable_args() + ->at("control_qubits") + .mutable_arg_value() + ->set_string_value(absl::StrJoin(control_indexs, ",")); } } @@ -175,26 +260,56 @@ Status ResolveQubitIds(Program* program, unsigned int* num_qubits, for (Moment& moment : *(other_programs->at(i)).mutable_circuit()->mutable_moments()) { for (Operation& operation : *moment.mutable_operations()) { + // Resolve qubit ids. for (Qubit& qubit : *operation.mutable_qubits()) { visited_qubits.erase(qubit.id()); const auto result = id_to_index.find(qubit.id()); if (result == id_to_index.end()) { - return Status(tensorflow::error::INVALID_ARGUMENT, + return Status(static_cast( + absl::StatusCode::kInvalidArgument), "A paired circuit contains qubits not found in " "reference circuit."); } qubit.set_id(result->second); } + // Resolve control qubit ids. + absl::string_view control_qubits = operation.mutable_args() + ->at("control_qubits") + .arg_value() + .string_value(); + if (control_qubits.empty()) { // explicit empty value. + continue; + } + std::vector control_ids = + absl::StrSplit(control_qubits, ','); + std::vector control_indexs; + control_indexs.reserve(control_ids.size()); + for (auto id : control_ids) { + visited_qubits.erase(id); + const auto result = id_to_index.find(id); + if (result == id_to_index.end()) { + return Status(static_cast( + absl::StatusCode::kInvalidArgument), + "A paired circuit contains qubits not found in " + "reference circuit."); + } + control_indexs.push_back(result->second); + } + operation.mutable_args() + ->at("control_qubits") + .mutable_arg_value() + ->set_string_value(absl::StrJoin(control_indexs, ",")); } } if (!visited_qubits.empty()) { return Status( - tensorflow::error::INVALID_ARGUMENT, + static_cast( + absl::StatusCode::kInvalidArgument), "A reference circuit contains qubits not found in paired circuit."); } } - return Status::OK(); + return ::tensorflow::Status(); } Status ResolveSymbols( @@ -209,7 +324,8 @@ Status ResolveSymbols( if (iter == param_map.end()) { if (resolve_all) { return Status( - tensorflow::error::INVALID_ARGUMENT, + static_cast( + absl::StatusCode::kInvalidArgument), "Could not find symbol in parameter map: " + arg.symbol()); } continue; @@ -220,7 +336,64 @@ Status ResolveSymbols( } } - return Status::OK(); + return ::tensorflow::Status(); +} + +Status CheckMPSSupported(const Program& program) { + // Check if (1) there are only 1-qubit or 2-qubit gates. + // (2) each two qubit gate has neighbor qubits only. + // + // Requires: program have qubit ids resolved. + if (program.circuit().moments().empty()) { + return ::tensorflow::Status(); + } + + for (auto moment : program.circuit().moments()) { + for (auto operation : moment.operations()) { + // Count the number of qubits in this operation. + auto qs = operation.qubits(); + std::vector qubits(qs.begin(), qs.end()); + std::vector control_ids({}); + + if (operation.args().find("control_qubits") != operation.args().end()) { + absl::string_view control_qubits = + operation.args().at("control_qubits").arg_value().string_value(); + if (!control_qubits.empty()) { + control_ids = absl::StrSplit(control_qubits, ','); + } + } + const int total_num_qubits = qubits.size() + control_ids.size(); + if (total_num_qubits > 2) { + return Status( + static_cast( + absl::StatusCode::kInvalidArgument), + absl::StrCat("1D operations only support 1 and 2 qubit gates. " + "Found: ", + total_num_qubits, " qubit gate.")); + } + + if (total_num_qubits == 2) { + size_t j = 0; + std::vector qids(2, -1234); + for (; j < qubits.size(); j++) { + (void)absl::SimpleAtoi(qubits[j].id(), &qids[j]); + } + for (; j < 2; j++) { + (void)absl::SimpleAtoi(control_ids[j], &qids[j]); + } + + // Are the two qubits not neighbors? + if (std::abs((int)qids[0] - (int)qids[1]) > 1) { + return Status(static_cast( + absl::StatusCode::kInvalidArgument), + "A program is not in 1D topology. It contains an" + " operation with qubits not neighbors each other."); + } + } + } + } + + return ::tensorflow::Status(); } } // namespace tfq diff --git a/tensorflow_quantum/core/src/program_resolution.h b/tensorflow_quantum/core/src/program_resolution.h index 88f7fdf4e..40d5760dd 100644 --- a/tensorflow_quantum/core/src/program_resolution.h +++ b/tensorflow_quantum/core/src/program_resolution.h @@ -22,9 +22,9 @@ limitations under the License. #include #include "absl/container/flat_hash_map.h" -#include "cirq/google/api/v2/program.pb.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 { @@ -36,16 +36,17 @@ namespace tfq { // // The number of qubits in the program is recorded in `num_qubits`. tensorflow::Status ResolveQubitIds( - cirq::google::api::v2::Program* program, unsigned int* num_qubits, - std::vector* p_sums = nullptr); + tfq::proto::Program* program, unsigned int* num_qubits, + std::vector* p_sums = nullptr, + bool swap_endianness = false); // Overload which allows for strict resolution of multiple programs. // Will resolve GridQubits in `program` and then double check that // all qubits in `other_programs` match and resolve them. // Note: no nullptr default is done here to avoid signature resolutions issues. tensorflow::Status ResolveQubitIds( - cirq::google::api::v2::Program* program, unsigned int* num_qubits, - std::vector* other_programs); + tfq::proto::Program* program, unsigned int* num_qubits, + std::vector* other_programs); // Resolves all of the symbols present in the Program. Iterates through all // operations in all moments, and if any Args have a symbol, replaces the one-of @@ -56,7 +57,10 @@ tensorflow::Status ResolveQubitIds( // isn't used. tensorflow::Status ResolveSymbols( const absl::flat_hash_map>& param_map, - cirq::google::api::v2::Program* program, bool resolve_all = true); + tfq::proto::Program* program, bool resolve_all = true); + +// Checks if the qubits are in 1D topology. +tensorflow::Status CheckMPSSupported(const tfq::proto::Program& program); } // namespace tfq diff --git a/tensorflow_quantum/core/src/program_resolution_test.cc b/tensorflow_quantum/core/src/program_resolution_test.cc index 12d621ba0..450d5d1cf 100644 --- a/tensorflow_quantum/core/src/program_resolution_test.cc +++ b/tensorflow_quantum/core/src/program_resolution_test.cc @@ -20,445 +20,546 @@ limitations under the License. #include #include "absl/container/flat_hash_map.h" -#include "cirq/google/api/v2/program.pb.h" +#include "absl/status/status.h" #include "gtest/gtest.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow_quantum/core/proto/program.pb.h" namespace tfq { namespace { -using cirq::google::api::v2::Program; - -TEST(ProgramResolutionTest, ResolveQubitIdsInvalidArg) { - const std::string text = R"( - circuit { - moments { - operations { - qubits { - id: "0_0" - } - qubits { - id: "1_0" +using tensorflow::Status; +using tfq::proto::PauliSum; +using tfq::proto::Program; + +const std::string valid_program = R"( + circuit { + moments { + operations { + args { + key: "control_qubits" + value { + arg_value { + string_value: "0_0" + } } } + qubits { + id: "0_1" + } + qubits { + id: "0_2" + } } } - )"; - - const std::string bad_text = R"( - circuit { - moments { - operations { - qubits { - id: "0_0" - } - qubits { - id: "1_junk" + } +)"; + +const std::string valid_line_program = R"( + circuit { + moments { + operations { + args { + key: "control_qubits" + value { + arg_value { + string_value: "0_1" + } } } + qubits { + id: "1" + } + qubits { + id: "2" + } } } - )"; - - const std::string bad_text2 = R"( - circuit { - moments { - operations { - qubits { - id: "0_0" - } - qubits { - id: "junk_1" + } +)"; + +const std::string valid_psum = R"( + terms { + coefficient_real: 1.0 + coefficient_imag: 0.0 + paulis { + qubit_id: "0_0" + pauli_type: "X" + } + } + terms { + coefficient_real: 5.0 + coefficient_imag: 0.0 + paulis { + qubit_id: "0_2" + pauli_type: "Y" + } + paulis { + qubit_id: "0_1" + pauli_type: "Z" + } + } +)"; + +const std::string valid_symbol_program = R"( + circuit { + scheduling_strategy: MOMENT_BY_MOMENT + moments { + operations { + args { + key: "exponent" + value { + symbol: "v1" } } } } - )"; - - const std::string bad_text3 = R"( - circuit { - moments { - operations { - qubits { - id: "0_0" - } - qubits { - id: "1_2_3" + moments { + operations { + args { + key: "exponent" + value { + symbol: "v2" } } } } - )"; - - const std::string text_good_p_sum = R"( - terms { - coefficient_real: 1.0 - coefficient_imag: 0.0 - paulis { - qubit_id: "0_0" - pauli_type: "Z" + } +)"; + +const std::string three_qubit_op_program = R"( + circuit { + moments { + operations { + qubits { + id: "0_0" + } + qubits { + id: "0_1" + } + qubits { + id: "0_2" + } } } - )"; - - const std::string text_bad_p_sum = R"( - terms { - coefficient_real: 1.0 - coefficient_imag: 0.0 - paulis { - qubit_id: "0_1" - pauli_type: "X" + } +)"; + +/* Qubit topology: + 1 -- 0 -- 2 + | + | + 3 +*/ +const std::string resolved_qubit_program_not_1d = R"( + circuit { + moments { + operations { + qubits { + id: "0" + } + qubits { + id: "1" + } + } + operations { + qubits { + id: "0" + } + qubits { + id: "2" + } + } + operations { + qubits { + id: "0" + } + qubits { + id: "3" + } } } - )"; - - std::vector p_sums; - tfq::proto::PauliSum p_sum_good, p_sum_bad; - ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(text_good_p_sum, - &p_sum_good)); - ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(text_bad_p_sum, - &p_sum_bad)); - p_sums.push_back(p_sum_good); - p_sums.push_back(p_sum_bad); + } +)"; +TEST(ProgramResolutionTest, ResolveQubitIdsValid) { Program program; - ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(text, &program)); + unsigned int qubit_count; + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &program)); - unsigned int num_qubits; - EXPECT_EQ(ResolveQubitIds(&program, &num_qubits, &p_sums), - tensorflow::Status( - tensorflow::error::INVALID_ARGUMENT, - "Found a Pauli sum operating on qubits not found in circuit.")); + EXPECT_EQ(ResolveQubitIds(&program, &qubit_count), Status()); + EXPECT_EQ(qubit_count, 3); + EXPECT_EQ(program.circuit().moments(0).operations(0).qubits(0).id(), "1"); + EXPECT_EQ(program.circuit().moments(0).operations(0).qubits(1).id(), "2"); + EXPECT_EQ(program.circuit() + .moments(0) + .operations(0) + .args() + .at("control_qubits") + .arg_value() + .string_value(), + "0"); +} - ASSERT_TRUE( - google::protobuf::TextFormat::ParseFromString(bad_text, &program)); - EXPECT_EQ(ResolveQubitIds(&program, &num_qubits, &p_sums), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, - "Unable to parse qubit: 1_junk")); +TEST(ProgramResolutionTest, ResolveQubitIdsValidLine) { + Program program; + unsigned int qubit_count; + ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(valid_line_program, + &program)); - ASSERT_TRUE( - google::protobuf::TextFormat::ParseFromString(bad_text2, &program)); - EXPECT_EQ(ResolveQubitIds(&program, &num_qubits, &p_sums), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, - "Unable to parse qubit: junk_1")); + EXPECT_EQ(ResolveQubitIds(&program, &qubit_count), Status()); + EXPECT_EQ(qubit_count, 3); + EXPECT_EQ(program.circuit().moments(0).operations(0).qubits(0).id(), "1"); + EXPECT_EQ(program.circuit().moments(0).operations(0).qubits(1).id(), "2"); + EXPECT_EQ(program.circuit() + .moments(0) + .operations(0) + .args() + .at("control_qubits") + .arg_value() + .string_value(), + "0"); +} +TEST(ProgramResolutionTest, ResolveQubitIdsInvalidControlQubit) { + Program program; + unsigned int qubit_count; ASSERT_TRUE( - google::protobuf::TextFormat::ParseFromString(bad_text3, &program)); - EXPECT_EQ(ResolveQubitIds(&program, &num_qubits, &p_sums), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, - "Unable to parse qubit: 1_2_3")); + google::protobuf::TextFormat::ParseFromString(valid_program, &program)); + + program.mutable_circuit() + ->mutable_moments(0) + ->mutable_operations(0) + ->mutable_args() + ->at("control_qubits") + .mutable_arg_value() + ->set_string_value("junk"); + EXPECT_EQ(ResolveQubitIds(&program, &qubit_count), + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), + "Unable to parse qubit: junk")); } -TEST(ProgramResolutionTest, ResolveQubitIds) { - const std::string text = R"( - circuit { - moments { - operations { - qubits { - id: "0_0" - } - qubits { - id: "1_0" - } - } - } - moments { - operations { - qubits { - id: "0_0" - } - qubits { - id: "0_1" - } - } - } - } - )"; - - const std::string text_p_sum_0 = R"( - terms { - coefficient_real: 1.0 - coefficient_imag: 0.0 - paulis { - qubit_id: "0_0" - pauli_type: "Z" - } - } - )"; - - const std::string text_p_sum_1 = R"( - terms { - coefficient_real: 1.0 - coefficient_imag: 0.0 - paulis { - qubit_id: "1_0" - pauli_type: "X" - } - } - )"; - - const std::string text_alphabet = R"( - circuit { - moments { - operations { - qubits { - id: "0_0" - } - qubits { - id: "0_1" - } - } - } - moments { - operations { - qubits { - id: "0_2" - } - qubits { - id: "0_3" - } - } - } - } - )"; - - const std::string text_alphabet_p_sum_0 = R"( - terms { - coefficient_real: 1.0 - coefficient_imag: 0.0 - paulis { - qubit_id: "0_1" - pauli_type: "Z" - } - } - )"; - - const std::string text_alphabet_p_sum_1 = R"( - terms { - coefficient_real: 1.0 - coefficient_imag: 0.0 - paulis { - qubit_id: "0_0" - pauli_type: "X" - } - } - )"; - - const std::string text_empty = R"( - circuit { - } - )"; +TEST(ProgramResolutionTest, ResolveQubitIdsInvalidQubit) { + Program program; + unsigned int qubit_count; + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &program)); + + program.mutable_circuit() + ->mutable_moments(0) + ->mutable_operations(0) + ->mutable_qubits(0) + ->set_id("junk"); + EXPECT_EQ(ResolveQubitIds(&program, &qubit_count), + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), + "Unable to parse qubit: junk")); +} - std::vector p_sums, p_sums_alphabet; - tfq::proto::PauliSum p_sum_0, p_sum_1; +TEST(ProgramResolutionTest, ResolveQubitIdsWithPauliSum) { + Program program; + unsigned int qubit_count; ASSERT_TRUE( - google::protobuf::TextFormat::ParseFromString(text_p_sum_0, &p_sum_0)); + google::protobuf::TextFormat::ParseFromString(valid_program, &program)); + + PauliSum p_sum; ASSERT_TRUE( - google::protobuf::TextFormat::ParseFromString(text_p_sum_1, &p_sum_1)); - p_sums.push_back(p_sum_0); - p_sums.push_back(p_sum_1); - tfq::proto::PauliSum alphabet_p_sum_0, alphabet_p_sum_1; - ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( - text_alphabet_p_sum_0, &alphabet_p_sum_0)); - ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( - text_alphabet_p_sum_1, &alphabet_p_sum_1)); - p_sums_alphabet.push_back(alphabet_p_sum_0); - p_sums_alphabet.push_back(alphabet_p_sum_1); - - Program program, empty_program, alphabet_program; - ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(text, &program)); - ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(text_empty, - &empty_program)); - ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(text_alphabet, - &alphabet_program)); - - unsigned int num_qubits, num_qubits_empty, num_qubits_alphabet; - EXPECT_TRUE(ResolveQubitIds(&program, &num_qubits, &p_sums).ok()); - EXPECT_TRUE(ResolveQubitIds(&empty_program, &num_qubits_empty).ok()); - EXPECT_TRUE( - ResolveQubitIds(&alphabet_program, &num_qubits_alphabet, &p_sums_alphabet) - .ok()); - - EXPECT_EQ(program.circuit().moments(0).operations(0).qubits(0).id(), "0"); - EXPECT_EQ(program.circuit().moments(0).operations(0).qubits(1).id(), "2"); - EXPECT_EQ(program.circuit().moments(1).operations(0).qubits(0).id(), "0"); - EXPECT_EQ(program.circuit().moments(1).operations(0).qubits(1).id(), "1"); + google::protobuf::TextFormat::ParseFromString(valid_psum, &p_sum)); + std::vector p_sums = {p_sum, p_sum}; - EXPECT_EQ(alphabet_program.circuit().moments(0).operations(0).qubits(0).id(), + EXPECT_EQ(ResolveQubitIds(&program, &qubit_count, &p_sums), Status()); + EXPECT_EQ(qubit_count, 3); + EXPECT_EQ(program.circuit().moments(0).operations(0).qubits(0).id(), "1"); + EXPECT_EQ(program.circuit().moments(0).operations(0).qubits(1).id(), "2"); + EXPECT_EQ(program.circuit() + .moments(0) + .operations(0) + .args() + .at("control_qubits") + .arg_value() + .string_value(), "0"); - EXPECT_EQ(alphabet_program.circuit().moments(0).operations(0).qubits(1).id(), - "1"); - EXPECT_EQ(alphabet_program.circuit().moments(1).operations(0).qubits(0).id(), - "2"); - EXPECT_EQ(alphabet_program.circuit().moments(1).operations(0).qubits(1).id(), - "3"); - - EXPECT_EQ(p_sums.at(0).terms(0).paulis(0).qubit_id(), "0"); - EXPECT_EQ(p_sums.at(1).terms(0).paulis(0).qubit_id(), "2"); - - EXPECT_EQ(p_sums_alphabet.at(0).terms(0).paulis(0).qubit_id(), "1"); - EXPECT_EQ(p_sums_alphabet.at(1).terms(0).paulis(0).qubit_id(), "0"); - - EXPECT_EQ(num_qubits, 3); - EXPECT_EQ(num_qubits_empty, 0); - EXPECT_EQ(num_qubits_alphabet, 4); -} -TEST(ProgramResolutionTest, ResolveQubitIdsPrograms) { - const std::string text = R"( - circuit { - moments { - operations { - qubits { - id: "0_0" - } - qubits { - id: "1_0" - } - } - } - moments { - operations { - qubits { - id: "0_0" - } - qubits { - id: "0_1" - } - } - } - } - )"; - - const std::string text_alphabet = R"( - circuit { - moments { - operations { - qubits { - id: "0_0" - } - qubits { - id: "1_0" - } - } - } - moments { - operations { - qubits { - id: "0_1" - } - qubits { - id: "0_3" - } - } - } - } - )"; + for (int i = 0; i < 2; i++) { + EXPECT_EQ(p_sums[i].terms(0).paulis(0).qubit_id(), "0"); + EXPECT_EQ(p_sums[i].terms(1).paulis(0).qubit_id(), "2"); + EXPECT_EQ(p_sums[i].terms(1).paulis(1).qubit_id(), "1"); + } +} - const std::string text_empty = R"( - circuit { - } - )"; +TEST(ProgramResolutionTest, ResolveQubitIdsWithInvalidPauliSum) { + Program program; + unsigned int qubit_count; + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &program)); - Program program, program_copy, empty_program; - ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(text, &program)); + PauliSum p_sum; ASSERT_TRUE( - google::protobuf::TextFormat::ParseFromString(text, &program_copy)); + google::protobuf::TextFormat::ParseFromString(valid_psum, &p_sum)); + p_sum.mutable_terms(0)->mutable_paulis(0)->set_qubit_id("1_1"); + std::vector p_sums = {p_sum, p_sum}; - unsigned int num_qubits, num_qubits_empty; - std::vector vec({program_copy}); - EXPECT_TRUE(ResolveQubitIds(&program, &num_qubits, &vec).ok()); + EXPECT_EQ(ResolveQubitIds(&program, &qubit_count, &p_sums), + tensorflow::Status( + static_cast( + absl::StatusCode::kInvalidArgument), + "Found a Pauli sum operating on qubits not found in circuit.")); +} - // Test case where circuits are aligned. - EXPECT_EQ(program.circuit().moments(0).operations(0).qubits(0).id(), "0"); +TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgram) { + Program program, other; + unsigned int qubit_count; + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &program)); + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &other)); + + // Re-arrange qubits on other. + other.mutable_circuit() + ->mutable_moments(0) + ->mutable_operations(0) + ->mutable_qubits(1) + ->set_id("0_0"); // turn 0_2 -> 0_0! + other.mutable_circuit() + ->mutable_moments(0) + ->mutable_operations(0) + ->mutable_args() + ->at("control_qubits") + .mutable_arg_value() + ->set_string_value("0_2"); // turn 0_0 -> 0_2! + + std::vector other_programs = {other, other}; + EXPECT_EQ(ResolveQubitIds(&program, &qubit_count, &other_programs), Status()); + EXPECT_EQ(qubit_count, 3); + EXPECT_EQ(program.circuit().moments(0).operations(0).qubits(0).id(), "1"); EXPECT_EQ(program.circuit().moments(0).operations(0).qubits(1).id(), "2"); - EXPECT_EQ(program.circuit().moments(1).operations(0).qubits(0).id(), "0"); - EXPECT_EQ(program.circuit().moments(1).operations(0).qubits(1).id(), "1"); + EXPECT_EQ(program.circuit() + .moments(0) + .operations(0) + .args() + .at("control_qubits") + .arg_value() + .string_value(), + "0"); - EXPECT_EQ(vec[0].circuit().moments(0).operations(0).qubits(0).id(), "0"); - EXPECT_EQ(vec[0].circuit().moments(0).operations(0).qubits(1).id(), "2"); - EXPECT_EQ(vec[0].circuit().moments(1).operations(0).qubits(0).id(), "0"); - EXPECT_EQ(vec[0].circuit().moments(1).operations(0).qubits(1).id(), "1"); + for (int i = 0; i < 2; i++) { + EXPECT_EQ( + other_programs[i].circuit().moments(0).operations(0).qubits(0).id(), + "1"); + EXPECT_EQ( + other_programs[i].circuit().moments(0).operations(0).qubits(1).id(), + "0"); + EXPECT_EQ(other_programs[i] + .circuit() + .moments(0) + .operations(0) + .args() + .at("control_qubits") + .arg_value() + .string_value(), + "2"); + } +} - // Test case where source circuit is smaller than paired circuit: - program.Clear(); - program_copy.Clear(); - ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(text, &program)); - ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(text_alphabet, - &program_copy)); +TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgramInvalid) { + Program program, other; + unsigned int qubit_count; + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &program)); + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &other)); + program.mutable_circuit() + ->mutable_moments(0) + ->mutable_operations(0) + ->mutable_qubits(0) + ->set_id("junk"); + std::vector others = {other, other}; + EXPECT_EQ(ResolveQubitIds(&program, &qubit_count, &others), + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), + "Unable to parse qubit: junk")); +} - std::vector vec2({program_copy}); +TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgramInvalidControl) { + Program program, other; + unsigned int qubit_count; + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &program)); + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &other)); + program.mutable_circuit() + ->mutable_moments(0) + ->mutable_operations(0) + ->mutable_args() + ->at("control_qubits") + .mutable_arg_value() + ->set_string_value("junk"); + std::vector others = {other, other}; + EXPECT_EQ(ResolveQubitIds(&program, &qubit_count, &others), + tensorflow::Status(static_cast( + absl::StatusCode::kInvalidArgument), + "Unable to parse qubit: junk")); +} +TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgramMismatch) { + Program program, other; + unsigned int qubit_count; + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &program)); + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &other)); + program.mutable_circuit() + ->mutable_moments(0) + ->mutable_operations(0) + ->mutable_qubits(0) + ->set_id("0_5"); + std::vector others = {other, other}; EXPECT_EQ( - ResolveQubitIds(&program, &num_qubits, &vec2), + ResolveQubitIds(&program, &qubit_count, &others), tensorflow::Status( - tensorflow::error::INVALID_ARGUMENT, + static_cast( + absl::StatusCode::kInvalidArgument), "A paired circuit contains qubits not found in reference circuit.")); +} - // Test case where paired circuit is smaller than source circuit: - program.Clear(); - program_copy.Clear(); +TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgramMismatchControl) { + Program program, other; + unsigned int qubit_count; ASSERT_TRUE( - google::protobuf::TextFormat::ParseFromString(text_alphabet, &program)); + google::protobuf::TextFormat::ParseFromString(valid_program, &program)); ASSERT_TRUE( - google::protobuf::TextFormat::ParseFromString(text, &program_copy)); + google::protobuf::TextFormat::ParseFromString(valid_program, &other)); + program.mutable_circuit() + ->mutable_moments(0) + ->mutable_operations(0) + ->mutable_args() + ->at("control_qubits") + .mutable_arg_value() + ->set_string_value("0_5"); + std::vector others = {other, other}; + EXPECT_EQ( + ResolveQubitIds(&program, &qubit_count, &others), + tensorflow::Status( + static_cast( + absl::StatusCode::kInvalidArgument), + "A paired circuit contains qubits not found in reference circuit.")); +} - std::vector vec3({program_copy}); +TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgramSmaller) { + Program program, other; + unsigned int qubit_count; + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &program)); + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &other)); + other.mutable_circuit() + ->mutable_moments(0) + ->mutable_operations(0) + ->mutable_qubits(0) + ->set_id("0_2"); + std::vector others = {other, other}; + EXPECT_EQ( + ResolveQubitIds(&program, &qubit_count, &others), + tensorflow::Status( + static_cast( + absl::StatusCode::kInvalidArgument), + "A reference circuit contains qubits not found in paired circuit.")); +} +TEST(ProgramResolutionTest, ResolveQubitIdsMultiProgramSmallerControl) { + Program program, other; + unsigned int qubit_count; + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &program)); + ASSERT_TRUE( + google::protobuf::TextFormat::ParseFromString(valid_program, &other)); + other.mutable_circuit() + ->mutable_moments(0) + ->mutable_operations(0) + ->mutable_args() + ->at("control_qubits") + .mutable_arg_value() + ->set_string_value("0_2"); + std::vector others = {other, other}; EXPECT_EQ( - ResolveQubitIds(&program, &num_qubits, &vec3), + ResolveQubitIds(&program, &qubit_count, &others), tensorflow::Status( - tensorflow::error::INVALID_ARGUMENT, + static_cast( + absl::StatusCode::kInvalidArgument), "A reference circuit contains qubits not found in paired circuit.")); +} - // Ensure empty case is consistent. - std::vector vec4; - EXPECT_TRUE(ResolveQubitIds(&empty_program, &num_qubits_empty, &vec4).ok()); - EXPECT_EQ(num_qubits_empty, 0); +TEST(ProgramResolutionTest, ResolveSymbolsPartial) { + Program symbol_program; + ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( + valid_symbol_program, &symbol_program)); + const absl::flat_hash_map> param_map = { + {"v1", {0, 1.0}}}; + EXPECT_EQ(ResolveSymbols(param_map, &symbol_program, false), Status()); + EXPECT_EQ(symbol_program.circuit() + .moments(0) + .operations(0) + .args() + .at("exponent") + .arg_value() + .float_value(), + 1.0); + EXPECT_EQ(symbol_program.circuit() + .moments(1) + .operations(0) + .args() + .at("exponent") + .symbol(), + "v2"); } -TEST(ProgramResolutionTest, ResolveSymbolsInvalidArg) { - const std::string text = R"( - circuit { - scheduling_strategy: MOMENT_BY_MOMENT - moments { - operations { - args { - key: "exponent" - value { - symbol: "v1" - } - } - } - } - moments { - operations { - args { - key: "exponent" - value { - symbol: "v2" - } - } - } - } - } - )"; +TEST(ProgramResolutionTest, ResolveSymbolsFull) { + Program symbol_program; + ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( + valid_symbol_program, &symbol_program)); + const absl::flat_hash_map> param_map = { + {"v1", {0, 1.0}}, {"v2", {1, 2.0f}}}; + EXPECT_EQ(ResolveSymbols(param_map, &symbol_program, false), Status()); + EXPECT_EQ(symbol_program.circuit() + .moments(0) + .operations(0) + .args() + .at("exponent") + .arg_value() + .float_value(), + 1.0); + EXPECT_EQ(symbol_program.circuit() + .moments(1) + .operations(0) + .args() + .at("exponent") + .arg_value() + .float_value(), + 2.0); +} - // Test with strict replacement - Program program_strict; - ASSERT_TRUE( - google::protobuf::TextFormat::ParseFromString(text, &program_strict)); +TEST(ProgramResolutionTest, ResolveSymbolsStrictPartial) { + Program symbol_program; + ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( + valid_symbol_program, &symbol_program)); const absl::flat_hash_map> param_map = { {"v1", {0, 1.0}}}; - EXPECT_EQ(ResolveSymbols(param_map, &program_strict, true), - tensorflow::Status(tensorflow::error::INVALID_ARGUMENT, - "Could not find symbol in parameter map: v2")); + EXPECT_EQ(ResolveSymbols(param_map, &symbol_program, true), + Status(static_cast( + absl::StatusCode::kInvalidArgument), + "Could not find symbol in parameter map: v2")); +} - // Test with non-strict replacement - Program program; - ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString(text, &program)); - EXPECT_TRUE(ResolveSymbols(param_map, &program, false).ok()); - EXPECT_EQ(program.circuit() +TEST(ProgramResolutionTest, ResolveSymbolsStrictFull) { + Program symbol_program; + ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( + valid_symbol_program, &symbol_program)); + const absl::flat_hash_map> param_map = { + {"v1", {0, 1.0}}, {"v2", {1, 2.0f}}}; + EXPECT_EQ(ResolveSymbols(param_map, &symbol_program, true), Status()); + EXPECT_EQ(symbol_program.circuit() .moments(0) .operations(0) .args() @@ -466,9 +567,53 @@ TEST(ProgramResolutionTest, ResolveSymbolsInvalidArg) { .arg_value() .float_value(), 1.0); - EXPECT_EQ( - program.circuit().moments(1).operations(0).args().at("exponent").symbol(), - "v2"); + EXPECT_EQ(symbol_program.circuit() + .moments(1) + .operations(0) + .args() + .at("exponent") + .arg_value() + .float_value(), + 2.0); +} + +TEST(ProgramResolutionTest, CheckMPSSupportedEmpty) { + Program empty; + EXPECT_EQ(CheckMPSSupported(empty), Status()); +} + +TEST(ProgramResolutionTest, CheckQubitsIn1DFailedByOpWithMoreThan2Qubits) { + Program program_with_3qubit_op; + ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( + three_qubit_op_program, &program_with_3qubit_op)); + EXPECT_EQ(CheckMPSSupported(program_with_3qubit_op), + Status(static_cast( + absl::StatusCode::kInvalidArgument), + "1D operations only support 1 and 2 qubit gates. " + "Found: 3 qubit gate.")); +} + +TEST(ProgramResolutionTest, + CheckQubitsIn1DFailedByOpWithMoreThan2QubitsOnControlQubits) { + Program program_with_3qubit_op; + ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( + valid_program, &program_with_3qubit_op)); + EXPECT_EQ(CheckMPSSupported(program_with_3qubit_op), + Status(static_cast( + absl::StatusCode::kInvalidArgument), + "1D operations only support 1 and 2 qubit gates. " + "Found: 3 qubit gate.")); +} + +TEST(ProgramResolutionTest, CheckQubitsIn1DFailedByNot1DTopology) { + Program program_not_1d; + ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( + resolved_qubit_program_not_1d, &program_not_1d)); + EXPECT_EQ(CheckMPSSupported(program_not_1d), + Status(static_cast( + absl::StatusCode::kInvalidArgument), + "A program is not in 1D topology. It contains an" + " operation with qubits not neighbors each other.")); } } // namespace diff --git a/tensorflow_quantum/core/src/util_qsim.h b/tensorflow_quantum/core/src/util_qsim.h index 5024d47bf..adf38705e 100644 --- a/tensorflow_quantum/core/src/util_qsim.h +++ b/tensorflow_quantum/core/src/util_qsim.h @@ -18,6 +18,9 @@ limitations under the License. #include #include +#include +#include +#include #include #include "../qsim/lib/circuit.h" @@ -27,6 +30,7 @@ limitations under the License. #include "../qsim/lib/matrix.h" #include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/random/simple_philox.h" #include "tensorflow/core/platform/threadpool.h" #include "tensorflow_quantum/core/proto/pauli_sum.pb.h" #include "tensorflow_quantum/core/src/circuit_parser_qsim.h" @@ -35,6 +39,7 @@ namespace tfq { typedef qsim::Cirq::GateCirq QsimGate; typedef qsim::Circuit QsimCircuit; +typedef std::vector> QsimFusedCircuit; // Custom FOR loop struct to use TF threadpool instead of native // qsim OpenMP or serial FOR implementations. @@ -139,10 +144,11 @@ tensorflow::Status ComputeExpectationQsim(const tfq::proto::PauliSum& p_sum, const SimT& sim, const StateSpaceT& ss, StateT& state, StateT& scratch, - float* expectation_value) { + float* expectation_value, + bool fuse_paulis = true) { // apply the gates of the pauliterms to a copy of the state vector // and add up expectation value term by term. - tensorflow::Status status = tensorflow::Status::OK(); + tensorflow::Status status = ::tensorflow::Status(); for (const tfq::proto::PauliTerm& term : p_sum.terms()) { // catch identity terms if (term.paulis_size() == 0) { @@ -162,8 +168,14 @@ tensorflow::Status ComputeExpectationQsim(const tfq::proto::PauliSum& p_sum, } // copy from src to scratch. ss.Copy(state, scratch); - for (const qsim::GateFused& fused_gate : fused_circuit) { - qsim::ApplyFusedGate(sim, fused_gate, scratch); + if (fuse_paulis) { + for (const qsim::GateFused& fused_gate : fused_circuit) { + qsim::ApplyFusedGate(sim, fused_gate, scratch); + } + } else { + for (const auto& unfused_gate : main_circuit.gates) { + qsim::ApplyGate(sim, unfused_gate, scratch); + } } if (!status.ok()) { @@ -188,13 +200,15 @@ template tensorflow::Status ComputeSampledExpectationQsim( const tfq::proto::PauliSum& p_sum, const SimT& sim, const StateSpaceT& ss, StateT& state, StateT& scratch, const int num_samples, - float* expectation_value) { + tensorflow::random::SimplePhilox& random_source, float* expectation_value) { + std::uniform_int_distribution<> distrib(1, 1 << 30); + if (num_samples == 0) { - return tensorflow::Status::OK(); + return ::tensorflow::Status(); } // apply the gates of the pauliterms to a copy of the state vector // and add up expectation value term by term. - tensorflow::Status status = tensorflow::Status::OK(); + tensorflow::Status status = ::tensorflow::Status(); for (const tfq::proto::PauliTerm& term : p_sum.terms()) { // catch identity terms if (term.paulis_size() == 0) { @@ -221,9 +235,8 @@ tensorflow::Status ComputeSampledExpectationQsim( if (!status.ok()) { return status; } - - const int seed = 1234; - std::vector state_samples = ss.Sample(scratch, num_samples, seed); + std::vector state_samples = + ss.Sample(scratch, num_samples, random_source.Rand32()); // Find qubits on which to measure parity std::vector parity_bits; @@ -231,7 +244,7 @@ tensorflow::Status ComputeSampledExpectationQsim( unsigned int location; // GridQubit id should be parsed down to integer at this upstream // so it is safe to just use atoi. - bool unused = absl::SimpleAtoi(pair.qubit_id(), &location); + (void)absl::SimpleAtoi(pair.qubit_id(), &location); // Parity functions use little-endian indexing parity_bits.push_back(state.num_qubits() - location - 1); } @@ -256,6 +269,91 @@ tensorflow::Status ComputeSampledExpectationQsim( return status; } +// Overloading for MPS : it requires more scratch states. +// bad style standards here that we are forced to follow from qsim. +// computes the expectation value using +// scratch to save on memory. Implementation does this: +// 1. Copy state onto scratch +// 2. Convert scratch to Z basis +// 3. Compute < state | scratch > via sampling. +// 4. Sum and repeat. +// scratch is required to have memory initialized, but does not require +// values in memory to be set. +template +tensorflow::Status ComputeMPSSampledExpectationQsim( + const tfq::proto::PauliSum& p_sum, const SimT& sim, const StateSpaceT& ss, + StateT& state, StateT& scratch, StateT& scratch2, StateT& scratch3, + const int num_samples, tensorflow::random::SimplePhilox& random_source, + float* expectation_value) { + std::uniform_int_distribution<> distrib(1, 1 << 30); + + if (num_samples == 0) { + return ::tensorflow::Status(); + } + // apply the gates of the pauliterms to a copy of the state vector + // and add up expectation value term by term. + tensorflow::Status status = ::tensorflow::Status(); + for (const tfq::proto::PauliTerm& term : p_sum.terms()) { + // catch identity terms + if (term.paulis_size() == 0) { + *expectation_value += term.coefficient_real(); + // TODO(zaqqwerty): error somewhere if identities have any imaginary part + continue; + } + + // Transform state into the measurement basis and sample it + QsimCircuit main_circuit; + std::vector> fused_circuit; + + status = QsimZBasisCircuitFromPauliTerm(term, state.num_qubits(), + &main_circuit, &fused_circuit); + if (!status.ok()) { + return status; + } + // copy from src to scratch. + ss.Copy(state, scratch); + for (const auto& unfused_gate : main_circuit.gates) { + qsim::ApplyGate(sim, unfused_gate, scratch); + } + + if (!status.ok()) { + return status; + } + std::vector> state_samples(num_samples, + std::vector({})); + + ss.Sample(scratch, scratch2, scratch3, num_samples, random_source.Rand32(), + &state_samples); + + // Find qubits on which to measure parity and compute the BitMask. + const unsigned int max_num_qubits = state.num_qubits(); + std::vector mask(max_num_qubits, false); + for (const tfq::proto::PauliQubitPair& pair : term.paulis()) { + unsigned int location; + // GridQubit id should be parsed down to integer at this upstream + // so it is safe to just use atoi. + (void)absl::SimpleAtoi(pair.qubit_id(), &location); + // Parity functions use little-endian indexing + mask[max_num_qubits - location - 1] = 1; + } + + // Compute the running parity. + int parity_total(0); + int count = 0; + for (std::vector& state_sample : state_samples) { + std::transform(mask.begin(), mask.end(), state_sample.begin(), + state_sample.begin(), + [](bool x, bool y) -> bool { return x & y; }); + count = std::accumulate(state_sample.begin(), state_sample.end(), 0); + parity_total += (count & 1) ? -1 : 1; + } + *expectation_value += static_cast(parity_total) * + term.coefficient_real() / + static_cast(num_samples); + } + return status; +} + // Assumes p_sums.size() == op_coeffs.size() // state stores |psi>. scratch has been created, but does not // require initialization. dest has been created, but does not require @@ -269,7 +367,7 @@ tensorflow::Status AccumulateOperators( // apply the gates of the pauliterms to a copy of the state vector // accumulating results as we go. Effectively doing O|psi> for an arbitrary // O. Result is stored on scratch. - tensorflow::Status status = tensorflow::Status::OK(); + tensorflow::Status status = ::tensorflow::Status(); ss.Copy(source, scratch); ss.SetAllZeros(dest); @@ -315,6 +413,123 @@ tensorflow::Status AccumulateOperators( return status; } +// Assumes coefficients.size() == fused_circuits.size(). +// These are checked at the upstream. +// scratch has been created, but does not require initialization. +// dest has been created, but does not require initialization. +// scratch has garbage value. +// |psi> = sum_i coefficients[i]*|phi[i]> +template +tensorflow::Status AccumulateFusedCircuits( + const std::vector& coefficients, + const std::vector& fused_circuits, const SimT& sim, + const StateSpaceT& ss, StateT& scratch, StateT& dest) { + tensorflow::Status status = ::tensorflow::Status(); + ss.SetAllZeros(dest); + + for (std::vector>::size_type i = 0; + i < fused_circuits.size(); i++) { + ss.SetStateZero(scratch); + for (std::vector>::size_type j = 0; + j < fused_circuits[i].size(); j++) { + qsim::ApplyFusedGate(sim, fused_circuits[i][j], scratch); + } + ss.Multiply(coefficients[i], scratch); + ss.Add(scratch, dest); + } + + return status; +} + +// Balance the number of trajectory computations done between +// threads. num_samples is a 2d vector containing the number of reps +// requested for each pauli_sum[i,j]. After running thread_offsets +// contains 0/-1 values that will offset the work for each thread. +// to make it as close to uniform as possible. **Assumes circuits +// have rouhgly equal simulation cost** +static void BalanceTrajectory(const std::vector>& num_samples, + const int& num_threads, + std::vector>* thread_offsets) { + std::vector rep_limits(num_samples.size(), -1); + std::vector height(num_threads, 0); + + for (size_t i = 0; i < num_samples.size(); i++) { + for (size_t j = 0; j < num_samples[i].size(); j++) { + rep_limits[i] = std::max(rep_limits[i], num_samples[i][j]); + } + } + int prev_max_height = -1; + for (size_t j = 0; j < num_samples.size(); j++) { + int run_ceiling = ((rep_limits[j] + num_threads - 1) / num_threads); + int num_lo = num_threads * run_ceiling - rep_limits[j]; + int num_hi = num_threads - num_lo; + int cur_max = prev_max_height; + for (int i = 0; i < num_threads; i++) { + if (height[i] == cur_max && num_lo) { + // previously had extra work on this thread and + // have remaining low budget to give. + height[i]++; + (*thread_offsets)[i][j] = -1; + num_lo--; + } else if (height[i] == cur_max - 1 && num_hi) { + // previously had less work on this thread and + // remaining high budget to give. + height[i] += 2; + (*thread_offsets)[i][j] = 0; + num_hi--; + } else if (num_hi) { + height[i] += 2; + (*thread_offsets)[i][j] = 0; + num_hi--; + } else { + height[i]++; + (*thread_offsets)[i][j] = -1; + num_lo--; + } + prev_max_height = std::max(height[i], prev_max_height); + } + } +} + +// Simpler case of TrajectoryBalance where num_samples is fixed +// across all circuits. +static void BalanceTrajectory(const int& num_samples, const int& num_threads, + std::vector>* thread_offsets) { + std::vector height(num_threads, 0); + + int prev_max_height = -1; + for (size_t j = 0; j < (*thread_offsets)[0].size(); j++) { + int run_ceiling = ((num_samples + num_threads - 1) / num_threads); + int num_lo = num_threads * run_ceiling - num_samples; + int num_hi = num_threads - num_lo; + int cur_max = prev_max_height; + for (int i = 0; i < num_threads; i++) { + if (height[i] == cur_max && num_lo) { + // previously had extra work on this thread and + // have remaining low budget to give. + height[i]++; + (*thread_offsets)[i][j] = -1; + num_lo--; + } else if (height[i] == cur_max - 1 && num_hi) { + // previously had less work on this thread and + // remaining high budget to give. + height[i] += 2; + (*thread_offsets)[i][j] = 0; + num_hi--; + } else if (num_hi) { + height[i] += 2; + (*thread_offsets)[i][j] = 0; + num_hi--; + } else { + height[i]++; + (*thread_offsets)[i][j] = -1; + num_lo--; + } + prev_max_height = std::max(height[i], prev_max_height); + } + } +} + } // namespace tfq #endif // UTIL_QSIM_H_ diff --git a/tensorflow_quantum/core/src/util_qsim_test.cc b/tensorflow_quantum/core/src/util_qsim_test.cc index 324d547bd..400c16d76 100644 --- a/tensorflow_quantum/core/src/util_qsim_test.cc +++ b/tensorflow_quantum/core/src/util_qsim_test.cc @@ -27,6 +27,10 @@ limitations under the License. #include "../qsim/lib/simmux.h" #include "absl/container/flat_hash_map.h" #include "gtest/gtest.h" +#include "tensorflow/core/lib/random/random.h" +#include "tensorflow/core/lib/random/simple_philox.h" +#include "tensorflow/core/platform/mutex.h" +#include "tensorflow/core/util/guarded_philox_random.h" #include "tensorflow_quantum/core/proto/pauli_sum.pb.h" namespace tfq { @@ -40,6 +44,7 @@ using ::tfq::proto::PauliTerm; typedef absl::flat_hash_map> SymbolMap; typedef qsim::Cirq::GateCirq QsimGate; typedef qsim::Circuit QsimCircuit; +typedef std::vector> QsimFusedCircuit; class TwoTermSampledExpectationFixture : public ::testing::TestWithParam> {}; @@ -87,10 +92,14 @@ TEST_P(TwoTermSampledExpectationFixture, CorrectnessTest) { // Compute expectation and compare to reference values. float exp_v = 0; + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + auto local_gen = random_gen.ReserveSamples32(2 * 1000000); + tensorflow::random::SimplePhilox rand_source(&local_gen); Status s = tfq::ComputeSampledExpectationQsim(p_sum, sim, ss, sv, scratch, - 1000000, &exp_v); + 1000000, rand_source, &exp_v); - EXPECT_NEAR(exp_v, std::get<1>(GetParam()), 1e-3); + EXPECT_NEAR(exp_v, std::get<1>(GetParam()), 1e-2); } // clang-format off @@ -190,8 +199,12 @@ TEST(UtilQsimTest, SampledEmptyTermCase) { // Compute expectation and compare to reference values. float exp_v = 0; - Status s = tfq::ComputeSampledExpectationQsim(p_sum_empty, sim, ss, sv, - scratch, 100, &exp_v); + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + auto local_gen = random_gen.ReserveSamples32(2 * 100); + tensorflow::random::SimplePhilox rand_source(&local_gen); + Status s = tfq::ComputeSampledExpectationQsim( + p_sum_empty, sim, ss, sv, scratch, 100, rand_source, &exp_v); EXPECT_NEAR(exp_v, 0.1234, 1e-5); } @@ -273,10 +286,14 @@ TEST(UtilQsimTest, SampledCompoundCase) { p_term_scratch->set_coefficient_real(4.0); // Compute expectation and compare to reference values. float exp_v = 0; + tensorflow::GuardedPhiloxRandom random_gen; + random_gen.Init(tensorflow::random::New64(), tensorflow::random::New64()); + auto local_gen = random_gen.ReserveSamples32(2 * 1000000); + tensorflow::random::SimplePhilox rand_source(&local_gen); Status s = tfq::ComputeSampledExpectationQsim(p_sum, sim, ss, sv, scratch, - 10000000, &exp_v); + 10000000, rand_source, &exp_v); - EXPECT_NEAR(exp_v, 4.1234, 1e-3); + EXPECT_NEAR(exp_v, 4.1234, 1e-2); } TEST(UtilQsimTest, CompoundCase) { @@ -476,7 +493,8 @@ TEST(UtilQsimTest, AccumulateOperatorsBasic) { p_term_scratch2->set_coefficient_real(-5.0); // 0.5 * (0.123ZX -3X + 4I) + 0.25 * (-5I) applied onto psi. - AccumulateOperators({p_sum, p_sum2}, {0.5, 0.25}, sim, ss, sv, scratch, dest); + (void)AccumulateOperators({p_sum, p_sum2}, {0.5, 0.25}, sim, ss, sv, scratch, + dest); // Check that dest got accumulated onto. EXPECT_NEAR(ss.GetAmpl(dest, 0).real(), 0.577925, 1e-5); @@ -518,7 +536,7 @@ TEST(UtilQsimTest, AccumulateOperatorsEmpty) { auto scratch = ss.Create(2); auto dest = ss.Create(2); - AccumulateOperators({}, {}, sim, ss, sv, scratch, dest); + (void)AccumulateOperators({}, {}, sim, ss, sv, scratch, dest); // Check sv is still in zero state. EXPECT_NEAR(ss.GetAmpl(sv, 0).real(), 1.0, 1e-5); @@ -551,5 +569,198 @@ TEST(UtilQsimTest, AccumulateOperatorsEmpty) { EXPECT_NEAR(ss.GetAmpl(scratch, 3).imag(), 0.0, 1e-5); } +TEST(UtilQsimTest, AccumulateFusedCircuitsBasic) { + // Create circuit to prepare initial state. + std::vector simple_circuits(2, QsimCircuit()); + simple_circuits[0].num_qubits = 2; + simple_circuits[0].gates.push_back( + qsim::Cirq::XPowGate::Create(0, 1, 0.25, 0.0)); + simple_circuits[1].num_qubits = 2; + simple_circuits[1].gates.push_back( + qsim::Cirq::CXPowGate::Create(1, 1, 0, 1.0, 0.0)); + simple_circuits[1].gates.push_back( + qsim::Cirq::YPowGate::Create(2, 0, 0.5, 0.0)); + + // Initialize fused circuits. + std::vector fused_circuits; + for (int i = 0; i < 2; i++) { + fused_circuits.push_back( + qsim::BasicGateFuser().FuseGates( + qsim::BasicGateFuser::Parameter(), + simple_circuits[i].num_qubits, simple_circuits[i].gates)); + } + + // Instantiate qsim objects. + qsim::Simulator sim(1); + qsim::Simulator::StateSpace ss(1); + auto sv = ss.Create(2); + auto scratch = ss.Create(2); + auto dest = ss.Create(2); + + // Initialize coeffs. + std::vector coeffs = {1.23, 4.56}; + + (void)AccumulateFusedCircuits(coeffs, fused_circuits, sim, ss, scratch, dest); + + // Scratch has coeffs[r][c] * fused circuits[r][c] where r, c = last indices. + // Check that dest got accumulated onto. + double accumulated_real[4] = {0.0, 0.0, 0.0, 0.0}; + double accumulated_imag[4] = {0.0, 0.0, 0.0, 0.0}; + for (unsigned int i = 0; i < 2; i++) { + ss.SetStateZero(sv); + for (const qsim::GateFused& fused_gate : fused_circuits[i]) { + qsim::ApplyFusedGate(sim, fused_gate, sv); + } + for (unsigned int k = 0; k < 4; k++) { + accumulated_real[k] += coeffs[i] * ss.GetAmpl(sv, k).real(); + accumulated_imag[k] += coeffs[i] * ss.GetAmpl(sv, k).imag(); + } + } + for (unsigned int k = 0; k < 4; k++) { + EXPECT_NEAR(ss.GetAmpl(dest, k).real(), accumulated_real[k], 1e-5); + EXPECT_NEAR(ss.GetAmpl(dest, k).imag(), accumulated_imag[k], 1e-5); + } +} + +TEST(UtilQsimTest, AccumulateFusedCircuitsEmpty) { + // Instantiate qsim objects. + qsim::Simulator sim(1); + qsim::Simulator::StateSpace ss(1); + auto scratch = ss.Create(2); + auto dest = ss.Create(2); + + (void)AccumulateFusedCircuits({}, {}, sim, ss, scratch, dest); + + // scratch has garbage value. + // Check that dest contains all zeros. + EXPECT_NEAR(ss.GetAmpl(dest, 0).real(), 0.0, 1e-5); + EXPECT_NEAR(ss.GetAmpl(dest, 0).imag(), 0.0, 1e-5); + EXPECT_NEAR(ss.GetAmpl(dest, 1).real(), 0.0, 1e-5); + EXPECT_NEAR(ss.GetAmpl(dest, 1).imag(), 0.0, 1e-5); + EXPECT_NEAR(ss.GetAmpl(dest, 2).real(), 0.0, 1e-5); + EXPECT_NEAR(ss.GetAmpl(dest, 2).imag(), 0.0, 1e-5); + EXPECT_NEAR(ss.GetAmpl(dest, 3).real(), 0.0, 1e-5); +} + +static void AssertWellBalanced(const std::vector>& n_reps, + const int& num_threads, + const std::vector>& offsets) { + auto max_work = std::vector(n_reps.size(), -1); + for (size_t i = 0; i < n_reps.size(); i++) { + for (size_t j = 0; j < n_reps[0].size(); j++) { + max_work[i] = std::max(max_work[i], n_reps[i][j]); + } + } + + for (size_t i = 0; i < n_reps.size(); i++) { + int sum = 0; + int prev_local_work = 0; + for (int k = 0; k < num_threads; k++) { + int local_work = (max_work[i] + num_threads - 1) / num_threads; + local_work += offsets[k][i]; + sum += local_work; + if (k > 0) { + EXPECT_LT(abs(local_work - prev_local_work), 2); + } + prev_local_work = local_work; + } + EXPECT_EQ(sum, max_work[i]); + } +} + +TEST(UtilQsimTest, BalanceTrajectorySimple) { + std::vector> n_reps = {{1, 3, 5, 10, 15}, + {1, 10, 20, 30, 40}, + {50, 70, 100, 100, 100}, + {100, 200, 200, 200, 200}}; + const int num_threads = 3; + // [num_threads, n_reps.size()] + std::vector> offsets = { + {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}; + + BalanceTrajectory(n_reps, num_threads, &offsets); + AssertWellBalanced(n_reps, num_threads, offsets); +} + +TEST(UtilQsimTest, BalanceTrajectoryPreventIdle) { + std::vector> n_reps = {{1, 1, 1, 1, 11}, + {1, 1, 1, 11, 1}, + {1, 1, 11, 1, 1}, + {1, 11, 1, 1, 1}, + {11, 1, 1, 1, 1}}; + const int num_threads = 10; + // [num_threads, n_reps.size()] + std::vector> offsets = { + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}; + + BalanceTrajectory(n_reps, num_threads, &offsets); + AssertWellBalanced(n_reps, num_threads, offsets); +} + +TEST(UtilQsimTest, BalanceTrajectoryLowRep) { + std::vector> n_reps = { + {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}}; + const int num_threads = 5; + // [num_threads, n_reps.size()] + std::vector> offsets = {{0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}}; + + BalanceTrajectory(n_reps, num_threads, &offsets); + AssertWellBalanced(n_reps, num_threads, offsets); +} + +TEST(UtilQsimTest, BalanceTrajectoryFewHigh) { + std::vector> n_reps = { + {1, 100, 1, 1, 1}, {1, 1, 1, 1, 1000}, {1, 1, 1, 1, 1}, {1, 1, 1, 1, 1}, + {1, 1, 1, 1, 1}, {1, 10, 1, 1, 1}, {1, 1, 1, 1, 1000}}; + const int num_threads = 5; + // [num_threads, n_reps.size()] + std::vector> offsets = {{0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}}; + + BalanceTrajectory(n_reps, num_threads, &offsets); + AssertWellBalanced(n_reps, num_threads, offsets); +} + +TEST(UtilQsimTest, BalanceTrajectory1D) { + const int n_reps = 100; + const int num_threads = 5; + // [num_threads, batch_size] + std::vector> offsets = {{0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, 0}}; + + std::vector> tmp(offsets[0].size(), + std::vector(2, n_reps)); + BalanceTrajectory(n_reps, num_threads, &offsets); + AssertWellBalanced(tmp, num_threads, offsets); +} + +TEST(UtilQsimTest, BalanceTrajectory1D_2) { + const int n_reps = 11; + const int num_threads = 10; + // [num_threads, batch_size] + std::vector> offsets = { + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, {0, 0, 0, 0, 0}}; + + std::vector> tmp(offsets[0].size(), + std::vector(2, n_reps)); + BalanceTrajectory(n_reps, num_threads, &offsets); + AssertWellBalanced(tmp, num_threads, offsets); +} + } // namespace } // namespace tfq diff --git a/tensorflow_quantum/datasets/BUILD b/tensorflow_quantum/datasets/BUILD index f90a77b3d..cabfb790f 100644 --- a/tensorflow_quantum/datasets/BUILD +++ b/tensorflow_quantum/datasets/BUILD @@ -5,14 +5,26 @@ licenses(["notice"]) # Export for the PIP package. exports_files(["__init__.py"]) +py_library( + name = "datasets", + srcs = ["__init__.py"], + srcs_version = "PY3", + deps = [ + ":cluster_state", + ":spin_system", + ], +) + py_library( name = "cluster_state", srcs = ["cluster_state.py"], + srcs_version = "PY3", ) py_library( name = "spin_system", srcs = ["spin_system.py"], + srcs_version = "PY3", ) py_test( @@ -26,6 +38,7 @@ py_test( py_test( name = "spin_system_test", + timeout = "eternal", srcs = ["spin_system_test.py"], python_version = "PY3", deps = [ diff --git a/tensorflow_quantum/datasets/__init__.py b/tensorflow_quantum/datasets/__init__.py index de1192fd4..8ec6a1e5a 100644 --- a/tensorflow_quantum/datasets/__init__.py +++ b/tensorflow_quantum/datasets/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Experimental location for interesting quantum datasets.""" # Import to the tensorflow_quantum.datasets.* level.""" from tensorflow_quantum.datasets.cluster_state import excited_cluster_states diff --git a/tensorflow_quantum/datasets/cluster_state.py b/tensorflow_quantum/datasets/cluster_state.py index 2c7f5a909..59c35997f 100644 --- a/tensorflow_quantum/datasets/cluster_state.py +++ b/tensorflow_quantum/datasets/cluster_state.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Toy dataset showing boilerplate code for a cluster state example.""" import numpy as np import cirq diff --git a/tensorflow_quantum/datasets/cluster_state_test.py b/tensorflow_quantum/datasets/cluster_state_test.py index 195081a35..0b675d145 100644 --- a/tensorflow_quantum/datasets/cluster_state_test.py +++ b/tensorflow_quantum/datasets/cluster_state_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test the cluster state dataset.""" +# 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 + import tensorflow as tf import cirq diff --git a/tensorflow_quantum/datasets/spin_system.py b/tensorflow_quantum/datasets/spin_system.py index a9f3170d1..3d53d5eae 100644 --- a/tensorflow_quantum/datasets/spin_system.py +++ b/tensorflow_quantum/datasets/spin_system.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Quantum datasets for quantum many-body spin systems.""" from collections import namedtuple @@ -280,7 +280,7 @@ def tfi_chain(qubits, boundary_condition="closed", data_dir=None): / np.pi # Parameters are stored as np.float32, but cirq expects np.float64 # See https://github.com/quantumlib/Cirq/issues/3359 - params = params.astype(np.float) + params = params.astype(float) additional_info.append( SpinSystemInfo(g=g, gs=np.load( @@ -517,7 +517,7 @@ def xxz_chain(qubits, boundary_condition="closed", data_dir=None): / np.pi # Parameters are stored as np.float32, but cirq expects np.float64 # See https://github.com/quantumlib/Cirq/issues/3359 - params = params.astype(np.float) + params = params.astype(float) additional_info.append( SpinSystemInfo(g=g, gs=np.load( diff --git a/tensorflow_quantum/datasets/spin_system_test.py b/tensorflow_quantum/datasets/spin_system_test.py index 36aa1f32f..200120a65 100644 --- a/tensorflow_quantum/datasets/spin_system_test.py +++ b/tensorflow_quantum/datasets/spin_system_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test the spin system dataset""" +# 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 + import tensorflow as tf import numpy as np import cirq @@ -20,7 +28,8 @@ from tensorflow_quantum.datasets.spin_system import SpinSystemInfo -class TFIChainTest(tf.test.TestCase): +# TODO(#748): Inherit this class from tf.test.TestCase after fixing the issue. +class TFIChainTest: """Testing tfi_chain.""" # pylint: disable=C0103 @@ -217,7 +226,8 @@ def test_param_resolver(self): rtol=1e-3) -class TFIRectangularTest(tf.test.TestCase): +# TODO(#748): Inherit this class from tf.test.TestCase after fixing the issue. +class TFIRectangularTest: """Testing tfi_rectangular.""" # pylint: disable=C0103 diff --git a/tensorflow_quantum/python/BUILD b/tensorflow_quantum/python/BUILD index 51d47c3ad..d69396775 100644 --- a/tensorflow_quantum/python/BUILD +++ b/tensorflow_quantum/python/BUILD @@ -5,21 +5,38 @@ licenses(["notice"]) # Export for the PIP package. exports_files(["__init__.py"]) +py_library( + name = "python", + srcs = ["__init__.py"], + srcs_version = "PY3", + deps = [ + ":quantum_context", + ":util", + "//tensorflow_quantum/python/differentiators", + "//tensorflow_quantum/python/layers", + "//tensorflow_quantum/python/optimizers", + ], +) + py_library( name = "quantum_context", - srcs = ["quantum_context.py"] + srcs = ["quantum_context.py"], + srcs_version = "PY3", ) py_test( name = "quantum_context_test", srcs = ["quantum_context_test.py"], - deps = [":quantum_context"] + python_version = "PY3", + deps = [":quantum_context"], ) py_library( name = "util", srcs = ["util.py"], + srcs_version = "PY3", deps = [ + "//tensorflow_quantum/core/proto:program_py_proto", "//tensorflow_quantum/core/serialize:serializer", ], ) diff --git a/tensorflow_quantum/python/__init__.py b/tensorflow_quantum/python/__init__.py index d4e4b5c82..a66da1f02 100644 --- a/tensorflow_quantum/python/__init__.py +++ b/tensorflow_quantum/python/__init__.py @@ -11,10 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module definitions for tensorflow_quantum.python.util.*""" from tensorflow_quantum.python.util import ( # Utility functions. + get_supported_channels, get_supported_gates, exponential, ) diff --git a/tensorflow_quantum/python/differentiators/BUILD b/tensorflow_quantum/python/differentiators/BUILD index fe5927ec5..33103e4e7 100644 --- a/tensorflow_quantum/python/differentiators/BUILD +++ b/tensorflow_quantum/python/differentiators/BUILD @@ -1,3 +1,5 @@ +load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured") + package(default_visibility = ["//visibility:public"]) licenses(["notice"]) @@ -5,33 +7,52 @@ licenses(["notice"]) # Export for the PIP package. exports_files(["__init__.py"]) +py_library( + name = "differentiators", + srcs = ["__init__.py"], + srcs_version = "PY3", + deps = [ + ":adjoint", + ":differentiator", + ":linear_combination", + ":parameter_shift", + ":parameter_shift_util", + ], +) + py_library( name = "adjoint", srcs = ["adjoint.py"], + srcs_version = "PY3", deps = [ ":differentiator", "//tensorflow_quantum/core/ops:tfq_adj_grad_op_py", - ], + ] + if_cuda_is_configured([ + "//tensorflow_quantum/core/ops:tfq_adj_grad_op_cuquantum_py", + ]), ) py_test( name = "adjoint_test", srcs = ["adjoint_test.py"], + python_version = "PY3", deps = [ ":adjoint", "//tensorflow_quantum/core/ops:circuit_execution_ops", + "//tensorflow_quantum/python:util", ], ) - py_library( name = "differentiator", srcs = ["differentiator.py"], + srcs_version = "PY3", ) py_library( name = "linear_combination", srcs = ["linear_combination.py"], + srcs_version = "PY3", deps = [ ":differentiator", ], @@ -40,6 +61,7 @@ py_library( py_library( name = "parameter_shift", srcs = ["parameter_shift.py"], + srcs_version = "PY3", deps = [ ":differentiator", ":parameter_shift_util", @@ -49,6 +71,7 @@ py_library( py_library( name = "parameter_shift_util", srcs = ["parameter_shift_util.py"], + srcs_version = "PY3", deps = [ "//tensorflow_quantum/core/ops:tfq_ps_util_ops_py", ], @@ -100,6 +123,7 @@ py_test( py_test( name = "gradient_test", timeout = "eternal", + shard_count = 5, srcs = ["gradient_test.py"], python_version = "PY3", deps = [ @@ -108,6 +132,8 @@ py_test( ":parameter_shift", "//tensorflow_quantum/core/ops:batch_util", "//tensorflow_quantum/core/ops:circuit_execution_ops", + "//tensorflow_quantum/core/ops/noise:noisy_expectation_op_py", + "//tensorflow_quantum/core/ops/noise:noisy_sampled_expectation_op_py", "//tensorflow_quantum/python:util", ], ) diff --git a/tensorflow_quantum/python/differentiators/__init__.py b/tensorflow_quantum/python/differentiators/__init__.py index ab386b22c..8ce0a4889 100644 --- a/tensorflow_quantum/python/differentiators/__init__.py +++ b/tensorflow_quantum/python/differentiators/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module functions for tfq.differentiators.*""" from tensorflow_quantum.python.differentiators.adjoint import ( diff --git a/tensorflow_quantum/python/differentiators/adjoint.py b/tensorflow_quantum/python/differentiators/adjoint.py index ec9c33e3a..57ccd304b 100644 --- a/tensorflow_quantum/python/differentiators/adjoint.py +++ b/tensorflow_quantum/python/differentiators/adjoint.py @@ -11,11 +11,18 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Compute gradients by combining function values linearly.""" import tensorflow as tf from tensorflow_quantum.core.ops import tfq_adj_grad_op +try: + from tensorflow_quantum.core.ops import tfq_adj_grad_op_cuquantum + _ENABLE_USE_CUQUANTUM = True +except: + _ENABLE_USE_CUQUANTUM = False + tfq_adj_grad_op_cuquantum = tfq_adj_grad_op + from tensorflow_quantum.python.differentiators import differentiator @@ -32,9 +39,10 @@ class Adjoint(differentiator.Differentiator): https://academic.oup.com/gji/article-pdf/167/2/495/1492368/167-2-495.pdf). The Adjoint method differentiates the input circuits in roughly one forward and backward pass over the circuits, to calculate the gradient of - a symbol only a constant number of gate operations need to be applied to the - circuits state. When the number of parameters in a circuit is very large, - this differentiator performs much better than all the others found in TFQ. + a symbol only a constant number of gate operations need to be applied to + the circuits state. When the number of parameters in a circuit is very + large, this differentiator performs much better than all the others found + in TFQ. >>> my_op = tfq.get_expectation_op() @@ -48,20 +56,25 @@ class Adjoint(differentiator.Differentiator): ... cirq.Circuit(cirq.X(qubit) ** sympy.Symbol('alpha')) ... ]) >>> psums = tfq.convert_to_tensor([[cirq.Z(qubit)]]) - >>> symbol_values_array = np.array([[0.123]], dtype=np.float32) + >>> symbol_values = np.array([[0.123]], dtype=np.float32) >>> # Calculate tfq gradient. - >>> symbol_values_tensor = tf.convert_to_tensor(symbol_values_array) + >>> symbol_values_t = tf.convert_to_tensor(symbol_values) + >>> symbol_names = tf.convert_to_tensor(['alpha']) >>> with tf.GradientTape() as g: - ... g.watch(symbol_values_tensor) - ... expectations = op(circuit, ['alpha'], symbol_values_tensor, psums + ... g.watch(symbol_values_t) + ... expectations = op(circuit, symbol_names, symbol_values_t, psums ... ) - >>> grads = g.gradient(expectations, symbol_values_tensor) + >>> grads = g.gradient(expectations, symbol_values_t) >>> grads tf.Tensor([[-1.1839]], shape=(1, 1), dtype=float32) """ - def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): + def generate_differentiable_op(self, + *, + sampled_op=None, + analytic_op=None, + use_cuquantum=False): """Generate a differentiable op by attaching self to an op. See `tfq.differentiators.Differentiator`. This has been partially @@ -74,6 +87,8 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): using this differentiator's `differentiate_sampled` method. analytic_op: A `callable` op that you want to make differentiable using this differentiators `differentiate_analytic` method. + use_cuquantum: A `bool` indicating whether to use the cuQuantum + version of the adjoint gradient op. Returns: A `callable` op that who's gradients are now registered to be @@ -84,8 +99,10 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): raise ValueError("sample base backends are not supported by the " "Adjoint method, please use analytic expectation" " or choose another differentiator.") + use_cuquantum = _ENABLE_USE_CUQUANTUM and use_cuquantum - return super().generate_differentiable_op(analytic_op=analytic_op) + return super().generate_differentiable_op(analytic_op=analytic_op, + use_cuquantum=use_cuquantum) @tf.function def get_gradient_circuits(self, programs, symbol_names, symbol_values): @@ -94,14 +111,62 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values): "Adjoint differentiator cannot run on a real QPU, " "therefore it has no accessible gradient circuits.") + @differentiator.catch_empty_inputs + @tf.function + def differentiate_analytic_cuquantum( + self, + programs, + symbol_names, + symbol_values, + pauli_sums, + forward_pass_vals, + grad, + ): + """Returns cuquantum adjoint gradient op result.""" + return tfq_adj_grad_op_cuquantum.tfq_adj_grad(programs, symbol_names, + symbol_values, pauli_sums, + grad) + + @differentiator.catch_empty_inputs @tf.function - def differentiate_analytic(self, programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad): + def differentiate_analytic( + self, + programs, + symbol_names, + symbol_values, + pauli_sums, + forward_pass_vals, + grad, + ): + """Returns cpu adjoint gradient op result.""" return tfq_adj_grad_op.tfq_adj_grad(programs, symbol_names, symbol_values, pauli_sums, grad) - def differentiate_sampled(self, programs, symbol_names, symbol_values, - pauli_sums, num_samples, forward_pass_vals, grad): + def differentiate_sampled_cuquantum( + self, + programs, + symbol_names, + symbol_values, + pauli_sums, + num_samples, + forward_pass_vals, + grad, + ): + raise NotImplementedError( + "Adjoint state methods are not supported in sample based settings." + " Please use analytic expectation calculation or a different " + "tfq.differentiator.") + + def differentiate_sampled( + self, + programs, + symbol_names, + symbol_values, + pauli_sums, + num_samples, + forward_pass_vals, + grad, + ): raise NotImplementedError( "Adjoint state methods are not supported in sample based settings." " Please use analytic expectation calculation or a different " diff --git a/tensorflow_quantum/python/differentiators/adjoint_test.py b/tensorflow_quantum/python/differentiators/adjoint_test.py index 85a79c2f7..9cb5c30a9 100644 --- a/tensorflow_quantum/python/differentiators/adjoint_test.py +++ b/tensorflow_quantum/python/differentiators/adjoint_test.py @@ -11,21 +11,74 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for the differentiator abstract class.""" +# 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 +from unittest import mock + +from absl.testing import parameterized +import cirq +import numpy as np +import sympy import tensorflow as tf -from tensorflow_quantum.python.differentiators import adjoint from tensorflow_quantum.core.ops import circuit_execution_ops +from tensorflow_quantum.python import util +from tensorflow_quantum.python.differentiators import adjoint -class AdjointTest(tf.test.TestCase): +class AdjointTest(tf.test.TestCase, parameterized.TestCase): """Test that we can properly subclass differentiator.""" def test_instantiation(self): """Test that adjoint can be created.""" adjoint.Adjoint() + @parameterized.parameters( + list(util.kwargs_cartesian_product(**{ + 'use_cuquantum': [False, True], + }))) + def test_use_cuquantum(self, use_cuquantum): + """Ensure that use_cuquantum switches to cuquantum ops well.""" + if not circuit_execution_ops.is_gpu_configured(): + # Ignores this test if gpu is not configured. + self.skipTest("GPU is not set. Ignoring gpu tests...") + # Prepares a simple circuit. + qubit = cirq.GridQubit(0, 0) + circuit = util.convert_to_tensor( + [cirq.Circuit(cirq.X(qubit)**sympy.Symbol('alpha'))]) + psums = util.convert_to_tensor([[cirq.Z(qubit)]]) + symbol_values_array = np.array([[0.123]], dtype=np.float32) + symbol_values_tensor = tf.convert_to_tensor(symbol_values_array) + + # Mocks `Adjoint.differentiate_analytic*()` to check if + # it's called once correctly. + method_name = ("differentiate_analytic_cuquantum" + if use_cuquantum else "differentiate_analytic") + with mock.patch.object(adjoint.Adjoint, + method_name, + return_value=None, + autospec=True) as mock_adj: + dif = adjoint.Adjoint() + op = circuit_execution_ops.get_expectation_op( + use_cuquantum=use_cuquantum, quantum_concurrent=False) + diff_op = dif.generate_differentiable_op( + analytic_op=op, use_cuquantum=use_cuquantum) + + # Calculate tfq gradient. + with tf.GradientTape() as g: + g.watch(symbol_values_tensor) + expectations = diff_op(circuit, tf.convert_to_tensor(['alpha']), + symbol_values_tensor, psums) + _ = g.gradient(expectations, symbol_values_tensor) + mock_adj.assert_called_once() + def test_sample_errors(self): """Ensure that the adjoint method won't attach to sample ops.""" @@ -33,6 +86,8 @@ def test_sample_errors(self): op = circuit_execution_ops.get_sampled_expectation_op() with self.assertRaisesRegex(ValueError, expected_regex='not supported'): dif.generate_differentiable_op(sampled_op=op) + with self.assertRaisesRegex(ValueError, expected_regex='not supported'): + dif.generate_differentiable_op(sampled_op=op, use_cuquantum=True) def test_no_gradient_circuits(self): """Confirm the adjoint differentiator has no gradient circuits.""" diff --git a/tensorflow_quantum/python/differentiators/differentiator.py b/tensorflow_quantum/python/differentiators/differentiator.py index 8b5fe03ca..72ee25e28 100644 --- a/tensorflow_quantum/python/differentiators/differentiator.py +++ b/tensorflow_quantum/python/differentiators/differentiator.py @@ -11,14 +11,41 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Testing consistency in values across differentiation methods.""" import abc import inspect +import functools import tensorflow as tf +def catch_empty_inputs(func): + """Helper function for differentiators to correctly handle empty cases. + + Adds support to decorated function for the case when `programs` or + `symbol_values` is empty which requires output to be + `tf.zeros_like(symbol_values)`. + """ + + @functools.wraps(func) + def new_diff(*args, **kwargs): + # args[1]=programs. args[2]=symbol_names. args[3]=symbol_values + programs = args[1] + symbol_names = args[2] + symbol_values = args[3] + empty_args = tf.equal(tf.size(programs), 0) + empty_vals = tf.equal(tf.size(symbol_values), 0) + empty_symbols = tf.equal(tf.size(symbol_names), 0) + + ret_zero = tf.logical_or(empty_args, empty_vals) + ret_zero = tf.logical_or(ret_zero, empty_symbols) + return tf.cond(ret_zero, lambda: tf.zeros_like(symbol_values), + lambda: func(*args, **kwargs)) + + return new_diff + + class Differentiator(metaclass=abc.ABCMeta): """Interface that defines how to specify gradients for a quantum circuit. @@ -28,12 +55,16 @@ class Differentiator(metaclass=abc.ABCMeta): to backpropagate through a quantum circuit. """ - def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): + def generate_differentiable_op(self, + *, + sampled_op=None, + analytic_op=None, + use_cuquantum=False): """Generate a differentiable op by attaching self to an op. This function returns a `tf.function` that passes values through to - `forward_op` during the forward pass and this differentiator (`self`) to - backpropagate through the op during the backward pass. If sampled_op + `forward_op` during the forward pass and this differentiator (`self`) + to backpropagate through the op during the backward pass. If sampled_op is provided the differentiators `differentiate_sampled` method will be invoked (which requires sampled_op to be a sample based expectation op with num_samples input tensor). If analytic_op is provided the @@ -53,6 +84,8 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): using this differentiator's `differentiate_sampled` method. analytic_op: A `callable` op that you want to make differentiable using this differentiators `differentiate_analytic` method. + use_cuquantum: A `bool` indicating whether to use cuQuantum version + op. Returns: A `callable` op that who's gradients are now registered to be @@ -85,6 +118,9 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): raise TypeError('Provided arguments must be callable tensorflow ' 'ops.') + if not isinstance(use_cuquantum, bool): + raise TypeError('use_cuquantum should be boolean.') + # TODO (mbbrough): find a better workaround than this to ensure # that the correct sample based expectation wasn't accidentally # put inside of the analytical_op argument or vice versa. @@ -101,12 +137,14 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): 'Given arg: {}.'.format(str(key)) + '' 'The signature should contain: {}.'.format( list(expected_signature)) + '' - ' Given: {}'.format(list(signature))) + ' Given: {}'.format(list(signature)) + '' + 'Note: noisy ops should use sampled_op') if 'num_samples' in signature: raise ValueError('found num_samples in analytic_op. Please ' 'ensure that you are providing an analytical ' - 'expectation op in the analytic_op arg.') + 'expectation op in the analytic_op arg.' + 'Note: noisy ops should use sampled_op') if sampled_op is not None: signature = inspect.signature(sampled_op).parameters @@ -120,6 +158,12 @@ def generate_differentiable_op(self, *, sampled_op=None, analytic_op=None): 'Given arg: {}.'.format(str(key)) + '' 'The signature should contain: {}.'.format( list(expected_signature))) + if use_cuquantum: + _differentiate_ana, _differentiate_sam = ( + self._differentiate_ana_cq, self._differentiate_sam_cq) + else: + _differentiate_ana, _differentiate_sam = (self._differentiate_ana, + self._differentiate_sam) @tf.custom_gradient def op_wrapper_analytic(programs, symbol_names, symbol_values, @@ -128,9 +172,8 @@ def op_wrapper_analytic(programs, symbol_names, symbol_values, symbol_values, pauli_sums) def gradient(grad): - return self._differentiate_ana(programs, symbol_names, - symbol_values, pauli_sums, - forward_pass_vals, grad) + return _differentiate_ana(programs, symbol_names, symbol_values, + pauli_sums, forward_pass_vals, grad) return forward_pass_vals, gradient @@ -142,10 +185,9 @@ def op_wrapper_sampled(programs, symbol_names, symbol_values, num_samples) def gradient(grad): - return self._differentiate_sam(programs, symbol_names, - symbol_values, pauli_sums, - num_samples, forward_pass_vals, - grad) + return _differentiate_sam(programs, symbol_names, symbol_values, + pauli_sums, num_samples, + forward_pass_vals, grad) return forward_pass_vals, gradient @@ -157,6 +199,13 @@ def gradient(grad): return return_func + def _differentiate_ana_cq(self, programs, symbol_names, symbol_values, + pauli_sums, forward_pass_vals, grad): + return None, None, self.differentiate_analytic_cuquantum( + programs, symbol_names, symbol_values, + pauli_sums, forward_pass_vals, grad), \ + None + def _differentiate_ana(self, programs, symbol_names, symbol_values, pauli_sums, forward_pass_vals, grad): return None, None, self.differentiate_analytic( @@ -164,6 +213,13 @@ def _differentiate_ana(self, programs, symbol_names, symbol_values, pauli_sums, forward_pass_vals, grad), \ None + def _differentiate_sam_cq(self, programs, symbol_names, symbol_values, + pauli_sums, num_samples, forward_pass_vals, grad): + return None, None, self.differentiate_sampled_cuquantum( + programs, symbol_names, symbol_values, + pauli_sums, num_samples, forward_pass_vals, grad), \ + None, None + def _differentiate_sam(self, programs, symbol_names, symbol_values, pauli_sums, num_samples, forward_pass_vals, grad): return None, None, self.differentiate_sampled( @@ -189,6 +245,15 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values): `tf.Tensor` objects give all necessary information to recreate the internal logic of the differentiator. + This base class defines the standard way to use the outputs of this + function to obtain either analytic gradients or sample gradients. + Below is code that is copied directly from the `differentiate_analytic` + default implementation, which is then compared to how one could + automatically get this gradient. The point is that the derivatives of + some functions cannot be calculated via the available auto-diff (such + as when the function is not expressible efficiently as a PauliSum), + and then one would need to use `get_gradient_circuits` the manual way. + Suppose we have some inputs `programs`, `symbol_names`, and `symbol_values`. To get the derivative of the expectation values of a tensor of PauliSums `pauli_sums` with respect to these inputs, do: @@ -197,13 +262,13 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values): >>> diff = () >>> ( ... batch_programs, new_symbol_names, batch_symbol_values, - ... batch_mapper + ... batch_weights, batch_mapper ... ) = diff.get_gradient_circuits( ... programs, symbol_names, symbol_values) >>> exp_layer = tfq.layers.Expectation() >>> batch_pauli_sums = tf.tile( ... tf.expand_dims(pauli_sums, 1), - ... [1, tf.shape(batch_mapper)[2], 1]) + ... [1, tf.shape(batch_programs)[1], 1]) >>> n_batch_programs = tf.reduce_prod(tf.shape(batch_programs)) >>> n_symbols = tf.shape(new_symbol_names)[0] >>> n_ops = tf.shape(pauli_sums)[1] @@ -216,8 +281,11 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values): ... batch_pauli_sums, [n_batch_programs, n_ops])) >>> batch_expectations = tf.reshape( ... batch_expectations, tf.shape(batch_pauli_sums)) - >>> grad_manual = tf.reduce_sum( - ... tf.einsum('ikm,jmp->ikp', batch_mapper, batch_expectations), -1) + >>> batch_jacobian = tf.map_fn( + ... lambda x: tf.einsum('km,kmp->kp', x[0], tf.gather(x[1], x[2])), + ... (batch_weights, batch_expectations, batch_mapper), + ... fn_output_signature=tf.float32) + >>> grad_manual = tf.reduce_sum(batch_jacobian, -1) To perform the same gradient calculation automatically: @@ -266,24 +334,60 @@ def get_gradient_circuits(self, programs, symbol_names, symbol_values): `new_symbol_names`. Thus, at each index `i` in the first dimension is the 2-D tensor of parameter values to fill in to `batch_programs[i]`. - batch_mapper: 3-D `tf.Tensor` of DType `tf.float32` which defines + batch_weights: 3-D `tf.Tensor` of DType `tf.float32` which defines + how much weight to give to each program when computing the + derivatives. First dimension is the length of the input + `programs`, second dimension is the length of the input + `symbol_names`, and the third dimension is determined by the + inheriting differentiator. + batch_mapper: 3-D `tf.Tensor` of DType `tf.int32` which defines how to map expectation values of the circuits generated by this differentiator to the derivatives of the original circuits. + It says which indices of the returned programs are relevant for + the derivative of each symbol, for use by `tf.gather`. The first dimension is the length of the input `programs`, the second dimension is the length of the input `symbol_names`, - and the third dimension is the length of the second dimension of - the output `batch_programs`. + and the third dimension is the length of the last dimension of + the output `batch_weights`. """ - @abc.abstractmethod + @catch_empty_inputs + @tf.function + def differentiate_analytic_cuquantum(self, programs, symbol_names, + symbol_values, pauli_sums, + forward_pass_vals, grad): + """Differentiate a circuit with analytical expectation with GPU ops.""" + # `self.expectation_op` is already set to cuquantum op at + # generate_differentiable_op._differentiate_ana. + return self.differentiate_analytic(programs, symbol_names, + symbol_values, pauli_sums, + forward_pass_vals, grad) + + @catch_empty_inputs + @tf.function + def differentiate_sampled_cuquantum(self, programs, symbol_names, + symbol_values, pauli_sums, num_samples, + forward_pass_vals, grad): + """Differentiate a circuit with sampled expectation with GPU ops.""" + # `self.expectation_op` is already set to cuquantum op at + # generate_differentiable_op._differentiate_sam. + return self.differentiate_sampled(programs, symbol_names, symbol_values, + pauli_sums, num_samples, + forward_pass_vals, grad) + + @catch_empty_inputs + @tf.function def differentiate_analytic(self, programs, symbol_names, symbol_values, pauli_sums, forward_pass_vals, grad): - """Specify how to differentiate a circuit with analytical expectation. + """Differentiate a circuit with analytical expectation. This is called at graph runtime by TensorFlow. `differentiate_analytic` - should calculate the gradient of a batch of circuits and return it - formatted as indicated below. See - `tfq.differentiators.ForwardDifference` for an example. + calls he inheriting differentiator's `get_gradient_circuits` and uses + those components to construct the gradient. + + Note: the default implementation does not use `forward_pass_vals`; the + inheriting differentiator is free to override the default implementation + and use this argument if desired. Args: programs: `tf.Tensor` of strings with shape [batch_size] containing @@ -311,16 +415,43 @@ def differentiate_analytic(self, programs, symbol_names, symbol_values, the gradient backpropageted to the `symbol_values` input of the op you are differentiating through. """ - - @abc.abstractmethod + (batch_programs, new_symbol_names, batch_symbol_values, batch_weights, + batch_mapper) = self.get_gradient_circuits(programs, symbol_names, + symbol_values) + m_i = tf.shape(batch_programs)[1] + batch_pauli_sums = tf.tile(tf.expand_dims(pauli_sums, 1), [1, m_i, 1]) + n_batch_programs = tf.reduce_prod(tf.shape(batch_programs)) + n_symbols = tf.shape(new_symbol_names)[0] + n_ops = tf.shape(pauli_sums)[1] + batch_expectations = self.expectation_op( + tf.reshape(batch_programs, [n_batch_programs]), new_symbol_names, + tf.reshape(batch_symbol_values, [n_batch_programs, n_symbols]), + tf.reshape(batch_pauli_sums, [n_batch_programs, n_ops])) + batch_expectations = tf.reshape(batch_expectations, + tf.shape(batch_pauli_sums)) + + # has shape [n_programs, n_symbols, n_ops] + batch_jacobian = tf.map_fn( + lambda x: tf.einsum('sm,smo->so', x[0], tf.gather(x[1], x[2])), + (batch_weights, batch_expectations, batch_mapper), + fn_output_signature=tf.float32) + + # now apply the chain rule + return tf.einsum('pso,po->ps', batch_jacobian, grad) + + @catch_empty_inputs + @tf.function def differentiate_sampled(self, programs, symbol_names, symbol_values, pauli_sums, num_samples, forward_pass_vals, grad): - """Specify how to differentiate a circuit with sampled expectation. + """Differentiate a circuit with sampled expectation. This is called at graph runtime by TensorFlow. `differentiate_sampled` - should calculate the gradient of a batch of circuits and return it - formatted as indicated below. See - `tfq.differentiators.ForwardDifference` for an example. + calls he inheriting differentiator's `get_gradient_circuits` and uses + those components to construct the gradient. + + Note: the default implementation does not use `forward_pass_vals`; the + inheriting differentiator is free to override the default implementation + and use this argument if desired. Args: programs: `tf.Tensor` of strings with shape [batch_size] containing @@ -351,3 +482,28 @@ def differentiate_sampled(self, programs, symbol_names, symbol_values, the gradient backpropageted to the `symbol_values` input of the op you are differentiating through. """ + (batch_programs, new_symbol_names, batch_symbol_values, batch_weights, + batch_mapper) = self.get_gradient_circuits(programs, symbol_names, + symbol_values) + m_i = tf.shape(batch_programs)[1] + batch_pauli_sums = tf.tile(tf.expand_dims(pauli_sums, 1), [1, m_i, 1]) + batch_num_samples = tf.tile(tf.expand_dims(num_samples, 1), [1, m_i, 1]) + n_batch_programs = tf.reduce_prod(tf.shape(batch_programs)) + n_symbols = tf.shape(new_symbol_names)[0] + n_ops = tf.shape(pauli_sums)[1] + batch_expectations = self.expectation_op( + tf.reshape(batch_programs, [n_batch_programs]), new_symbol_names, + tf.reshape(batch_symbol_values, [n_batch_programs, n_symbols]), + tf.reshape(batch_pauli_sums, [n_batch_programs, n_ops]), + tf.reshape(batch_num_samples, [n_batch_programs, n_ops])) + batch_expectations = tf.reshape(batch_expectations, + tf.shape(batch_pauli_sums)) + + # has shape [n_programs, n_symbols, n_ops] + batch_jacobian = tf.map_fn( + lambda x: tf.einsum('sm,smo->so', x[0], tf.gather(x[1], x[2])), + (batch_weights, batch_expectations, batch_mapper), + fn_output_signature=tf.float32) + + # now apply the chain rule + return tf.einsum('pso,po->ps', batch_jacobian, grad) diff --git a/tensorflow_quantum/python/differentiators/differentiator_test.py b/tensorflow_quantum/python/differentiators/differentiator_test.py index ce98f110f..f4d4544fc 100644 --- a/tensorflow_quantum/python/differentiators/differentiator_test.py +++ b/tensorflow_quantum/python/differentiators/differentiator_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for the differentiator abstract class.""" +# 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 + import tensorflow as tf from tensorflow_quantum.python.differentiators import differentiator @@ -23,14 +31,6 @@ class WorkingDifferentiator(differentiator.Differentiator): def get_gradient_circuits(self, programs, symbol_names, symbol_values): """test.""" - def differentiate_analytic(self, programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad): - """test.""" - - def differentiate_sampled(self, programs, symbol_names, symbol_values, - num_samples, pauli_sums, forward_pass_vals, grad): - """test.""" - class DifferentiatorTest(tf.test.TestCase): """Test that we can properly subclass differentiator.""" @@ -73,6 +73,26 @@ def test_generate_differentiable_op(self): WorkingDifferentiator().generate_differentiable_op( sampled_op=lambda programs, symbol_names, pauli_sums: 1) + def test_generate_differentiable_op_cuquantum(self): + """test the type checking on this method with `use_cuquantum`.""" + WorkingDifferentiator().generate_differentiable_op( + analytic_op=lambda programs, symbol_names, symbol_values, + pauli_sums: 1, + use_cuquantum=True) + WorkingDifferentiator().generate_differentiable_op( + sampled_op=lambda programs, symbol_names, symbol_values, pauli_sums, + num_samples: 1, + use_cuquantum=True) + with self.assertRaisesRegex(TypeError, expected_regex='boolean'): + WorkingDifferentiator().generate_differentiable_op( + analytic_op=lambda programs, symbol_names, symbol_values, + pauli_sums: 1, + use_cuquantum='junk') + with self.assertRaisesRegex(TypeError, expected_regex='boolean'): + WorkingDifferentiator().generate_differentiable_op( + sampled_op=lambda programs, symbol_names, pauli_sums: 1, + use_cuquantum='junk') + def test_single_op_link(self): """Tests if the `one-differentiator-per-op` policy is working well.""" wd = WorkingDifferentiator() diff --git a/tensorflow_quantum/python/differentiators/gradient_test.py b/tensorflow_quantum/python/differentiators/gradient_test.py index 4e82a68d9..9c06f4035 100644 --- a/tensorflow_quantum/python/differentiators/gradient_test.py +++ b/tensorflow_quantum/python/differentiators/gradient_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Testing for gradient calculation consistency in TFQ.""" +# 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 + import copy import numpy as np @@ -26,6 +34,10 @@ from tensorflow_quantum.python.differentiators import linear_combination from tensorflow_quantum.python.differentiators import parameter_shift from tensorflow_quantum.core.ops import circuit_execution_ops, batch_util +from tensorflow_quantum.core.ops.noise import noisy_expectation_op +from tensorflow_quantum.core.ops.noise import noisy_sampled_expectation_op + +RANDOM_SEED = 1234 ANALYTIC_DIFFS = [ linear_combination.ForwardDifference(grid_spacing=0.0001), @@ -36,8 +48,8 @@ ] SAMPLED_DIFFS = [ - linear_combination.ForwardDifference(grid_spacing=0.1), - linear_combination.CentralDifference(grid_spacing=0.1), + linear_combination.ForwardDifference(grid_spacing=0.05), + linear_combination.CentralDifference(grid_spacing=0.05), parameter_shift.ParameterShift(), ] @@ -45,28 +57,39 @@ ANALYTIC_OPS = [ circuit_execution_ops.get_expectation_op(cirq.sim.Simulator()), # WF - circuit_execution_ops.get_expectation_op( - cirq.DensityMatrixSimulator()), # DM circuit_execution_ops.get_expectation_op() # C++ ] +ANALYTIC_GPU_OPS = [ + circuit_execution_ops.get_expectation_op(use_cuquantum=True, + quantum_concurrent=False) +] + SAMPLED_OPS = [ circuit_execution_ops.get_sampled_expectation_op( cirq.sim.Simulator()), # WF - circuit_execution_ops.get_sampled_expectation_op( - cirq.DensityMatrixSimulator()), # DM circuit_execution_ops.get_sampled_expectation_op() # C++ ] +SAMPLED_GPU_OPS = [ + circuit_execution_ops.get_sampled_expectation_op(use_cuquantum=True, + quantum_concurrent=False) +] + +NOISY_OPS = [ + noisy_sampled_expectation_op.sampled_expectation, + noisy_expectation_op.expectation +] + def _cirq_simple_finite_difference(circuit_batch, resolvers, symbol_names, op_batch, + simulator, grid_spacing=0.0001): """A simple finite difference code that calculates the gradient of a batch of circuits using cirq.""" - simulator = cirq.sim.Simulator() init_vals = batch_util.batch_calculate_expectation(circuit_batch, resolvers, op_batch, simulator) @@ -107,19 +130,35 @@ class AnalyticGradientCorrectnessTest(tf.test.TestCase, parameterized.TestCase): @parameterized.parameters( list( - util.kwargs_cartesian_product(**{ - 'differentiator': ANALYTIC_DIFFS, - 'op': ANALYTIC_OPS - })) + [{ - 'differentiator': adjoint.Adjoint(), - 'op': circuit_execution_ops.get_expectation_op() - }]) - def test_backprop(self, differentiator, op): + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS, + 'op': ANALYTIC_OPS, + 'use_cuquantum': [False], + })) + [{ + 'differentiator': adjoint.Adjoint(), + 'op': circuit_execution_ops.get_expectation_op(), + 'use_cuquantum': False, + }] + + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS + [adjoint.Adjoint()], + 'op': ANALYTIC_GPU_OPS, + 'use_cuquantum': [True], + }))) + def test_backprop(self, differentiator, op, use_cuquantum): """Test that gradients are correctly backpropagated through a quantum circuit via comparison to analytical results. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") differentiator.refresh() - op = differentiator.generate_differentiable_op(analytic_op=op) + op = differentiator.generate_differentiable_op( + analytic_op=op, + use_cuquantum=use_cuquantum, + ) def exact_grad(theta): new_theta = 2 * np.pi * theta @@ -154,23 +193,42 @@ def exact_grad(theta): 'n_qubits': [5], 'n_programs': [3], 'n_ops': [3], - 'symbol_names': [['a', 'b']] + 'symbol_names': [['a', 'b']], + 'use_cuquantum': [False], })) + [{ 'differentiator': adjoint.Adjoint(), 'op': circuit_execution_ops.get_expectation_op(), - 'n_qubits': 5, + 'n_qubits': 10, 'n_programs': 5, 'n_ops': 3, - 'symbol_names': ['a', 'b'] - }]) + 'symbol_names': ['a', 'b'], + 'use_cuquantum': False, + }] + + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS + [adjoint.Adjoint()], + 'op': ANALYTIC_GPU_OPS, + 'n_qubits': [5], + 'n_programs': [3], + 'n_ops': [3], + 'symbol_names': [['a', 'b']], + 'use_cuquantum': [True], + }))) def test_gradients_vs_cirq_finite_difference(self, differentiator, op, n_qubits, n_programs, n_ops, - symbol_names): + symbol_names, use_cuquantum): """Compare TFQ differentiators to fine-grained noiseless cirq finite differencing. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") differentiator.refresh() - op = differentiator.generate_differentiable_op(analytic_op=op) + op = differentiator.generate_differentiable_op( + analytic_op=op, + use_cuquantum=use_cuquantum, + ) qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ @@ -201,25 +259,47 @@ def test_gradients_vs_cirq_finite_difference(self, differentiator, op, # scheme cirq_grads = _cirq_simple_finite_difference(circuit_batch, resolver_batch, - symbol_names, psums) + symbol_names, psums, + cirq.Simulator()) # will this be too tight? time will tell. - self.assertAllClose(cirq_grads, tfq_grads, rtol=1e-2, atol=1e-2) + self.assertAllClose(cirq_grads, tfq_grads, rtol=2e-2, atol=2e-2) @parameterized.parameters( list( - util.kwargs_cartesian_product(**{ - 'differentiator': ANALYTIC_DIFFS, - 'op': ANALYTIC_OPS, - })) + [{ - 'differentiator': adjoint.Adjoint(), - 'op': circuit_execution_ops.get_expectation_op(), - }]) - def test_analytic_value_with_simple_circuit(self, differentiator, op): + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS, + 'op': ANALYTIC_OPS, + 'use_cuquantum': [False], + })) + [{ + 'differentiator': adjoint.Adjoint(), + 'op': circuit_execution_ops.get_expectation_op(), + 'use_cuquantum': False, + }] + + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS + [adjoint.Adjoint()], + 'op': ANALYTIC_GPU_OPS, + 'use_cuquantum': [True], + }))) + def test_analytic_value_with_simple_circuit( + self, + differentiator, + op, + use_cuquantum, + ): """Test the value of differentiator with simple circuit.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") # Get an expectation op, with this differentiator attached. differentiator.refresh() - op = differentiator.generate_differentiable_op(analytic_op=op) + op = differentiator.generate_differentiable_op( + analytic_op=op, + use_cuquantum=use_cuquantum, + ) qubit = cirq.GridQubit(0, 0) circuit = util.convert_to_tensor( [cirq.Circuit(cirq.X(qubit)**sympy.Symbol('alpha'))]) @@ -235,9 +315,49 @@ def test_analytic_value_with_simple_circuit(self, differentiator, op): ground_truth_grads = np.array([[-1.1839752]]) self.assertAllClose(ground_truth_grads, grads, rtol=1e-2, atol=1e-2) + @parameterized.parameters( + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS, + 'op': ANALYTIC_OPS, + 'use_cuquantum': [False], + })) + [{ + 'differentiator': adjoint.Adjoint(), + 'op': circuit_execution_ops.get_expectation_op(), + 'use_cuquantum': False, + }] + + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': ANALYTIC_DIFFS + [adjoint.Adjoint()], + 'op': ANALYTIC_GPU_OPS, + 'use_cuquantum': [True], + }))) + def test_empty_circuit_grad(self, differentiator, op, use_cuquantum): + """Test that providing no circuits will fail gracefully.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + differentiator.refresh() + op = differentiator.generate_differentiable_op(analytic_op=op) + circuit = tf.convert_to_tensor([], dtype=tf.string) + psums = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + + # Calculate tfq gradient. + symbol_values_tensor = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + symbol_names_tensor = tf.convert_to_tensor([], dtype=tf.string) + with tf.GradientTape() as g: + g.watch(symbol_values_tensor) + expectations = op(circuit, symbol_names_tensor, + symbol_values_tensor, psums) + grads = g.gradient(expectations, symbol_values_tensor) + self.assertShapeEqual(grads.numpy(), + tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32)) + class SampledGradientCorrectnessTest(tf.test.TestCase, parameterized.TestCase): - """Test approximate correctness to analytical methods.""" + """Test approximate correctness to sampled methods.""" @parameterized.parameters( list( @@ -245,11 +365,23 @@ class SampledGradientCorrectnessTest(tf.test.TestCase, parameterized.TestCase): **{ 'differentiator': SAMPLED_DIFFS, 'op': SAMPLED_OPS, - 'num_samples': [10000] - }))) + 'num_samples': [20000], + 'use_cuquantum': [False], + })) + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': SAMPLED_DIFFS, + 'op': SAMPLED_GPU_OPS, + 'num_samples': [20000], + 'use_cuquantum': [True], + }))) def test_sampled_value_with_simple_circuit(self, differentiator, op, - num_samples): + num_samples, use_cuquantum): """Test the value of sampled differentiator with simple circuit.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) # Get an expectation op, with this differentiator attached. differentiator.refresh() op = differentiator.generate_differentiable_op(sampled_op=op) @@ -279,15 +411,33 @@ def test_sampled_value_with_simple_circuit(self, differentiator, op, 'n_programs': [5], 'n_ops': [2], 'symbol_names': [['a', 'b']], - 'num_samples': [30000] + 'num_samples': [30000], + 'use_cuquantum': [False], + })) + + list( + util.kwargs_cartesian_product( + **{ + 'diff_and_tol': zip(SAMPLED_DIFFS, SAMPLED_DIFFS_TOLS), + 'op': SAMPLED_GPU_OPS, + 'n_qubits': [3], + 'n_programs': [5], + 'n_ops': [2], + 'symbol_names': [['a', 'b']], + 'num_samples': [30000], + 'use_cuquantum': [True], }))) def test_approx_equality_shallow(self, diff_and_tol, op, n_qubits, symbol_names, n_ops, n_programs, - num_samples): + num_samples, use_cuquantum): """Test small circuits with limited depth.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) differentiator, tol = diff_and_tol differentiator.refresh() - op = differentiator.generate_differentiable_op(sampled_op=op) + op = differentiator.generate_differentiable_op( + sampled_op=op, use_cuquantum=use_cuquantum) qubits = cirq.GridQubit.rect(1, n_qubits) circuit_batch, resolver_batch = \ @@ -323,10 +473,165 @@ def test_approx_equality_shallow(self, diff_and_tol, op, n_qubits, # scheme cirq_grads = _cirq_simple_finite_difference(circuit_batch, resolver_batch, - symbol_names, psums) + symbol_names, psums, + cirq.Simulator()) self.assertAllClose(cirq_grads, tfq_grads, rtol=tol, atol=tol) + @parameterized.parameters( + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': SAMPLED_DIFFS, + 'op': SAMPLED_OPS, + 'use_cuquantum': [False], + })) + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': SAMPLED_DIFFS, + 'op': SAMPLED_GPU_OPS, + 'use_cuquantum': [True], + }))) + def test_empty_circuit_sampled_grad(self, differentiator, op, + use_cuquantum): + """Test that providing no circuits will fail gracefully.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + differentiator.refresh() + op = differentiator.generate_differentiable_op(sampled_op=op) + circuit = tf.convert_to_tensor([], dtype=tf.string) + psums = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + + # Calculate tfq gradient. + symbol_values_tensor = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + symbol_names_tensor = tf.convert_to_tensor([], dtype=tf.string) + n_samples_tensor = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.int32) + with tf.GradientTape() as g: + g.watch(symbol_values_tensor) + expectations = op(circuit, symbol_names_tensor, + symbol_values_tensor, psums, n_samples_tensor) + grads = g.gradient(expectations, symbol_values_tensor) + self.assertShapeEqual(grads.numpy(), + tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32)) + + +class NoisyGradientCorrectnessTest(tf.test.TestCase, parameterized.TestCase): + """Test approximate correctness of noisy methods.""" + + @parameterized.parameters( + list( + util.kwargs_cartesian_product( + **{ + 'differentiator': SAMPLED_DIFFS, + 'op': NOISY_OPS, + 'num_samples': [20000] + }))) + def test_sampled_value_with_simple_circuit(self, differentiator, op, + num_samples): + """Test the value of sampled differentiator with simple circuit.""" + # Get an expectation op, with this differentiator attached. + differentiator.refresh() + op = differentiator.generate_differentiable_op(sampled_op=op) + qubit = cirq.GridQubit(0, 0) + circuit = util.convert_to_tensor( + [cirq.Circuit(cirq.X(qubit)**sympy.Symbol('alpha'))]) + psums = util.convert_to_tensor([[cirq.Z(qubit)]]) + symbol_values_array = np.array([[0.123]], dtype=np.float32) + # Calculate tfq gradient. + symbol_values_tensor = tf.convert_to_tensor(symbol_values_array) + with tf.GradientTape() as g: + g.watch(symbol_values_tensor) + expectations = op(circuit, tf.convert_to_tensor(['alpha']), + symbol_values_tensor, psums, + tf.convert_to_tensor([[num_samples]])) + grads = g.gradient(expectations, symbol_values_tensor) + ground_truth_grads = np.array([[-1.1839752]]) + self.assertAllClose(ground_truth_grads, grads, rtol=0.2, atol=0.2) + + @parameterized.parameters( + list( + util.kwargs_cartesian_product( + **{ + 'diff_and_tol': zip(SAMPLED_DIFFS, SAMPLED_DIFFS_TOLS), + 'op': NOISY_OPS, + 'n_qubits': [5], + 'n_programs': [5], + 'n_ops': [2], + 'symbol_names': [['a', 'b']], + 'num_samples': [30000] + }))) + def test_approx_equality_shallow(self, diff_and_tol, op, n_qubits, + symbol_names, n_ops, n_programs, + num_samples): + """Test small circuits with limited depth.""" + differentiator, tol = diff_and_tol + differentiator.refresh() + op = differentiator.generate_differentiable_op(sampled_op=op) + + qubits = cirq.GridQubit.rect(1, n_qubits) + circuit_batch, resolver_batch = \ + util.random_symbol_circuit_resolver_batch( + cirq.GridQubit.rect(1, n_qubits), symbol_names, n_programs, + include_channels=True) + + # Prepare random pauli sums and add initial superposition gates. + psums = [] + for i in range(len(circuit_batch)): + psums.append(util.random_pauli_sums(qubits, 1, n_ops)) + circuit_batch[i] = cirq.Circuit( + cirq.H.on_each(qubits)) + circuit_batch[i] + + symbol_values_array = np.array( + [[resolver[symbol] + for symbol in symbol_names] + for resolver in resolver_batch], + dtype=np.float32) + + # calculate tfq gradient + symbol_values_tensor = tf.convert_to_tensor(symbol_values_array) + programs = util.convert_to_tensor(circuit_batch) + ops = util.convert_to_tensor(psums) + with tf.GradientTape() as g: + g.watch(symbol_values_tensor) + expectations = op( + programs, tf.convert_to_tensor(symbol_names), + symbol_values_tensor, ops, + tf.convert_to_tensor([[num_samples] * n_ops] * n_programs)) + tfq_grads = g.gradient(expectations, symbol_values_tensor) + + cirq_grads = _cirq_simple_finite_difference( + circuit_batch, resolver_batch, symbol_names, psums, + cirq.DensityMatrixSimulator()) + + self.assertAllClose(cirq_grads, tfq_grads, rtol=tol, atol=tol) + + @parameterized.parameters( + list( + util.kwargs_cartesian_product(**{ + 'differentiator': SAMPLED_DIFFS, + 'op': NOISY_OPS, + }))) + def test_empty_circuit_sampled_grad(self, differentiator, op): + """Test that providing no circuits will fail gracefully.""" + differentiator.refresh() + op = differentiator.generate_differentiable_op(sampled_op=op) + circuit = tf.convert_to_tensor([], dtype=tf.string) + psums = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.string) + + # Calculate tfq gradient. + symbol_values_tensor = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32) + symbol_names_tensor = tf.convert_to_tensor([], dtype=tf.string) + n_samples_tensor = tf.raw_ops.Empty(shape=(0, 0), dtype=tf.int32) + with tf.GradientTape() as g: + g.watch(symbol_values_tensor) + expectations = op(circuit, symbol_names_tensor, + symbol_values_tensor, psums, n_samples_tensor) + grads = g.gradient(expectations, symbol_values_tensor) + self.assertShapeEqual(grads.numpy(), + tf.raw_ops.Empty(shape=(0, 0), dtype=tf.float32)) + if __name__ == '__main__': tf.test.main() diff --git a/tensorflow_quantum/python/differentiators/linear_combination.py b/tensorflow_quantum/python/differentiators/linear_combination.py index 286aa002b..cee6959bd 100644 --- a/tensorflow_quantum/python/differentiators/linear_combination.py +++ b/tensorflow_quantum/python/differentiators/linear_combination.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Compute gradients by combining function values linearly.""" import numbers @@ -42,15 +42,16 @@ class LinearCombination(differentiator.Differentiator): ... cirq.Circuit(cirq.X(qubit) ** sympy.Symbol('alpha')) ... ]) >>> psums = tfq.convert_to_tensor([[cirq.Z(qubit)]]) - >>> symbol_values_array = np.array([[0.123]], dtype=np.float32) + >>> symbol_values = np.array([[0.123]], dtype=np.float32) >>> # Calculate tfq gradient. - >>> symbol_values_tensor = tf.convert_to_tensor(symbol_values_array) + >>> symbol_values_t = tf.convert_to_tensor(symbol_values) + >>> symbol_names = tf.convert_to_tensor(['alpha']) >>> with tf.GradientTape() as g: - ... g.watch(symbol_values_tensor) - ... expectations = op(circuit, ['alpha'], symbol_values_tensor, psums + ... g.watch(symbol_values_t) + ... expectations = op(circuit, symbol_names, symbol_values_t, psums ... ) >>> # Gradient would be: 5 * f(x+0) + 6 * f(x+0.5) + 7 * f(x+0.25) - >>> grads = g.gradient(expectations, symbol_values_tensor) + >>> grads = g.gradient(expectations, symbol_values_t) >>> # Note: this gradient visn't correct in value, but showcases >>> # the principle of how gradients can be defined in a very flexible >>> # fashion. @@ -89,303 +90,93 @@ def __init__(self, weights, perturbations): if not len(weights) == len(perturbations): raise ValueError("weights and perturbations must have the same " "length.") + if len(perturbations) < 2: + raise ValueError("Must specify at least two perturbations. " + "Providing only one perturbation is the same as " + "evaluating the circuit at a single location, " + "which is insufficient for differentiation.") + self.weights = tf.constant(weights, dtype=tf.float32) + self.n_perturbations = tf.constant(len(perturbations)) + self.perturbations = tf.constant(perturbations, dtype=tf.float32) + + # Uniqueness in particular ensures there at most one zero perturbation. if not len(list(set(perturbations))) == len(perturbations): raise ValueError("All values in perturbations must be unique.") - self.weights = tf.constant(weights) - self.n_perturbations = tf.constant(len(perturbations)) - self.perturbations = tf.constant(perturbations) + mask = tf.not_equal(self.perturbations, + tf.zeros_like(self.perturbations)) + self.non_zero_weights = tf.boolean_mask(self.weights, mask) + self.zero_weights = tf.boolean_mask(self.weights, + tf.math.logical_not(mask)) + self.non_zero_perturbations = tf.boolean_mask(self.perturbations, mask) + self.n_non_zero_perturbations = tf.gather( + tf.shape(self.non_zero_perturbations), 0) @tf.function def get_gradient_circuits(self, programs, symbol_names, symbol_values): """See base class description.""" - raise NotImplementedError( - "Gradient circuits are not currently available for " - "LinearCombination.") - - @tf.function - def differentiate_analytic(self, programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad): - - # these get used a lot - n_symbols = tf.gather(tf.shape(symbol_names), 0) n_programs = tf.gather(tf.shape(programs), 0) - n_ops = tf.gather(tf.shape(pauli_sums), 1) - - # STEP 1: Generate required inputs for executor - # in this case I can do this with existing tensorflow ops if i'm clever - - # don't do any computation for a perturbation of zero, just use - # forward pass values - mask = tf.not_equal(self.perturbations, - tf.zeros_like(self.perturbations)) - non_zero_perturbations = tf.boolean_mask(self.perturbations, mask) - non_zero_weights = tf.boolean_mask(self.weights, mask) - n_non_zero_perturbations = tf.gather(tf.shape(non_zero_perturbations), - 0) - - # tile up symbols to [n_non_zero_perturbations, n_programs, n_symbols] - perturbation_tiled_symbols = tf.tile( - tf.expand_dims(symbol_values, 0), - tf.stack([n_non_zero_perturbations, 1, 1])) - - def create_3d_perturbation(i, perturbation_values): - """Generate a tensor the same shape as perturbation_tiled_symbols - containing the perturbations specified by perturbation_values.""" - ones = tf.cast( - tf.concat([ - tf.zeros(tf.stack([n_non_zero_perturbations, n_programs, i - ])), - tf.ones(tf.stack([n_non_zero_perturbations, n_programs, 1 - ])), - tf.zeros( - tf.stack([ - n_non_zero_perturbations, n_programs, - tf.subtract(n_symbols, tf.add(i, 1)) - ])) - ], - axis=2), perturbation_values.dtype) - return tf.einsum('kij,k->kij', ones, perturbation_values) - - def generate_perturbation(i): - """Perturb each value in the ith column of - perturbation_tiled_symbols. - """ - return tf.add( - perturbation_tiled_symbols, - tf.cast(create_3d_perturbation(i, non_zero_perturbations), - perturbation_tiled_symbols.dtype)) - - # create a 4d tensor with the following dimensions: - # [n_symbols, n_perturbations, n_programs, n_symbols] - # the zeroth dimension represents the fact that we have to apply - # a perturbation in the direction of every parameter individually. - # the first dimension represents the number of perturbations that we - # have to apply, and the inner 2 dimensions represent the standard - # input format to the expectation ops - all_perturbations = tf.map_fn(generate_perturbation, - tf.range(n_symbols), - dtype=tf.float32) - - # reshape everything to fit into expectation op correctly - total_programs = tf.multiply( - tf.multiply(n_programs, n_non_zero_perturbations), n_symbols) - # tile up and then reshape to order programs correctly - flat_programs = tf.reshape( - tf.tile( - tf.expand_dims(programs, 0), - tf.stack([tf.multiply(n_symbols, n_non_zero_perturbations), - 1])), [total_programs]) - flat_perturbations = tf.reshape(all_perturbations, [ - tf.multiply(tf.multiply(n_symbols, n_non_zero_perturbations), - n_programs), n_symbols - ]) - # tile up and then reshape to order ops correctly - flat_ops = tf.reshape( - tf.tile( - tf.expand_dims(pauli_sums, 0), - tf.stack( - [tf.multiply(n_symbols, n_non_zero_perturbations), 1, 1])), - [total_programs, n_ops]) - - # STEP 2: calculate the required expectation values - expectations = self.expectation_op(flat_programs, symbol_names, - flat_perturbations, flat_ops) - - # STEP 3: generate gradients according to the results - - # we know the rows are grouped according to which parameter - # was perturbed, so reshape to reflect that - grouped_expectations = tf.reshape( - expectations, - [n_symbols, - tf.multiply(n_non_zero_perturbations, n_programs), -1]) - - # now we can calculate the partial of the circuit output with - # respect to each perturbed parameter - def rearrange_expectations(grouped): - - def split_vertically(i): - return tf.slice(grouped, [tf.multiply(i, n_programs), 0], - [n_programs, n_ops]) - - return tf.map_fn(split_vertically, - tf.range(n_non_zero_perturbations), - dtype=tf.float32) - - # reshape so that expectations calculated on different programs are - # separated by a dimension - rearranged_expectations = tf.map_fn(rearrange_expectations, - grouped_expectations) - - # now we will calculate all of the partial derivatives - - nonzero_partials = tf.einsum( - 'spco,p->sco', rearranged_expectations, - tf.cast(non_zero_weights, rearranged_expectations.dtype)) - - # now add the contribution of a zero term if required - - # find any zero terms - mask = tf.equal(self.perturbations, tf.zeros_like(self.perturbations)) - zero_weight = tf.boolean_mask(self.weights, mask) - n_zero_perturbations = tf.gather(tf.shape(zero_weight), 0) - - # this will have shape [n_symbols, n_programs, n_ops] - partials = tf.cond( - tf.equal(n_zero_perturbations, 0), lambda: nonzero_partials, - lambda: nonzero_partials + tf.multiply( - tf.tile(tf.expand_dims(forward_pass_vals, axis=0), - tf.stack([n_symbols, 1, 1])), - tf.cast(tf.gather(zero_weight, 0), forward_pass_vals.dtype))) - - # now apply the chain rule - return tf.einsum('sco,co -> cs', partials, grad) - - @tf.function - def differentiate_sampled(self, programs, symbol_names, symbol_values, - pauli_sums, num_samples, forward_pass_vals, grad): - - # these get used a lot n_symbols = tf.gather(tf.shape(symbol_names), 0) - n_programs = tf.gather(tf.shape(programs), 0) - n_ops = tf.gather(tf.shape(pauli_sums), 1) - - # STEP 1: Generate required inputs for executor - # in this case I can do this with existing tensorflow ops if i'm clever - # don't do any computation for a perturbation of zero, just use - # forward pass values - mask = tf.not_equal(self.perturbations, - tf.zeros_like(self.perturbations)) - non_zero_perturbations = tf.boolean_mask(self.perturbations, mask) - non_zero_weights = tf.boolean_mask(self.weights, mask) - n_non_zero_perturbations = tf.gather(tf.shape(non_zero_perturbations), - 0) - - # tile up symbols to [n_non_zero_perturbations, n_programs, n_symbols] - perturbation_tiled_symbols = tf.tile( - tf.expand_dims(symbol_values, 0), - tf.stack([n_non_zero_perturbations, 1, 1])) - - def create_3d_perturbation(i, perturbation_values): - """Generate a tensor the same shape as perturbation_tiled_symbols - containing the perturbations specified by perturbation_values.""" - ones = tf.cast( - tf.concat([ - tf.zeros(tf.stack([n_non_zero_perturbations, n_programs, i - ])), - tf.ones(tf.stack([n_non_zero_perturbations, n_programs, 1 - ])), - tf.zeros( - tf.stack([ - n_non_zero_perturbations, n_programs, - tf.subtract(n_symbols, tf.add(i, 1)) - ])) - ], - axis=2), perturbation_values.dtype) - return tf.einsum('kij,k->kij', ones, perturbation_values) - - def generate_perturbation(i): - """Perturb each value in the ith column of - perturbation_tiled_symbols. - """ - return tf.add( - perturbation_tiled_symbols, - tf.cast(create_3d_perturbation(i, non_zero_perturbations), - perturbation_tiled_symbols.dtype)) - - # create a 4d tensor with the following dimensions: - # [n_symbols, n_perturbations, n_programs, n_symbols] - # the zeroth dimension represents the fact that we have to apply - # a perturbation in the direction of every parameter individually. - # the first dimension represents the number of perturbations that we - # have to apply, and the inner 2 dimensions represent the standard - # input format to the expectation ops - all_perturbations = tf.map_fn(generate_perturbation, - tf.range(n_symbols), - dtype=tf.float32) - - # reshape everything to fit into expectation op correctly - total_programs = tf.multiply( - tf.multiply(n_programs, n_non_zero_perturbations), n_symbols) - # tile up and then reshape to order programs correctly - flat_programs = tf.reshape( - tf.tile( - tf.expand_dims(programs, 0), - tf.stack([tf.multiply(n_symbols, n_non_zero_perturbations), - 1])), [total_programs]) - flat_perturbations = tf.reshape(all_perturbations, [ - tf.multiply(tf.multiply(n_symbols, n_non_zero_perturbations), - n_programs), n_symbols - ]) - # tile up and then reshape to order ops correctly - flat_ops = tf.reshape( - tf.tile( - tf.expand_dims(pauli_sums, 0), - tf.stack( - [tf.multiply(n_symbols, n_non_zero_perturbations), 1, 1])), - [total_programs, n_ops]) - flat_num_samples = tf.reshape( - tf.tile( - tf.expand_dims(num_samples, 0), - tf.stack( - [tf.multiply(n_symbols, n_non_zero_perturbations), 1, 1])), - [total_programs, n_ops]) - - # STEP 2: calculate the required expectation values - expectations = self.expectation_op(flat_programs, symbol_names, - flat_perturbations, flat_ops, - flat_num_samples) - - # STEP 3: generate gradients according to the results - - # we know the rows are grouped according to which parameter - # was perturbed, so reshape to reflect that - grouped_expectations = tf.reshape( - expectations, - [n_symbols, - tf.multiply(n_non_zero_perturbations, n_programs), -1]) - - # now we can calculate the partial of the circuit output with - # respect to each perturbed parameter - def rearrange_expectations(grouped): - - def split_vertically(i): - return tf.slice(grouped, [tf.multiply(i, n_programs), 0], - [n_programs, n_ops]) - - return tf.map_fn(split_vertically, - tf.range(n_non_zero_perturbations), - dtype=tf.float32) - - # reshape so that expectations calculated on different programs are - # separated by a dimension - rearranged_expectations = tf.map_fn(rearrange_expectations, - grouped_expectations) - - # now we will calculate all of the partial derivatives - - nonzero_partials = tf.einsum( - 'spco,p->sco', rearranged_expectations, - tf.cast(non_zero_weights, rearranged_expectations.dtype)) - - # now add the contribution of a zero term if required - - # find any zero terms - mask = tf.equal(self.perturbations, tf.zeros_like(self.perturbations)) - zero_weight = tf.boolean_mask(self.weights, mask) - n_zero_perturbations = tf.gather(tf.shape(zero_weight), 0) - - # this will have shape [n_symbols, n_programs, n_ops] - partials = tf.cond( - tf.equal(n_zero_perturbations, 0), lambda: nonzero_partials, - lambda: nonzero_partials + tf.multiply( - tf.tile(tf.expand_dims(forward_pass_vals, axis=0), - tf.stack([n_symbols, 1, 1])), - tf.cast(tf.gather(zero_weight, 0), forward_pass_vals.dtype))) - - # now apply the chain rule - return tf.einsum('sco,co -> cs', partials, grad) + # A new copy of each program is run for each symbol and each + # non-zero perturbation, plus one more if there is a zero perturbation. + # `m` represents the last index of the batch mapper. + base_m_tile = n_symbols * self.n_non_zero_perturbations + m_tile = tf.cond(self.n_non_zero_perturbations < self.n_perturbations, + lambda: base_m_tile + 1, lambda: base_m_tile) + batch_programs = tf.tile(tf.expand_dims(programs, 1), [1, m_tile]) + + # LinearCombination does not add new symbols to the gradient circuits. + new_symbol_names = tf.identity(symbol_names) + + # Build the symbol value perturbations for a single input program. + perts_zeros_pad = tf.zeros([self.n_non_zero_perturbations], + dtype=tf.float32) + stacked_perts = tf.stack([perts_zeros_pad, self.non_zero_perturbations]) + # Identity matrix lets us tile the perturbations and simultaneously + # put zeros in all the symbol locations not being perturbed. + gathered_perts = tf.gather(stacked_perts, + tf.eye(n_symbols, dtype=tf.int32)) + transposed_perts = tf.transpose(gathered_perts, [0, 2, 1]) + reshaped_perts = tf.reshape(transposed_perts, [base_m_tile, n_symbols]) + symbol_zeros_pad = tf.zeros([1, n_symbols]) + single_program_perts = tf.cond( + self.n_non_zero_perturbations < self.n_perturbations, + lambda: tf.concat([symbol_zeros_pad, reshaped_perts], 0), + lambda: reshaped_perts) + # Make a copy of the perturbations tensor for each input program. + all_perts = tf.tile(tf.expand_dims(single_program_perts, 0), + [n_programs, 1, 1]) + # Apply perturbations to the forward pass symbol values. + bare_symbol_values = tf.tile(tf.expand_dims(symbol_values, 1), + [1, m_tile, 1]) + batch_symbol_values = bare_symbol_values + all_perts + + # The weights for all the programs. + tiled_weights = tf.tile(tf.expand_dims(self.non_zero_weights, 0), + [n_symbols, 1]) + tiled_zero_weights = tf.tile(tf.expand_dims(self.zero_weights, 0), + [n_symbols, 1]) + single_program_weights = tf.concat([tiled_zero_weights, tiled_weights], + 1) + # Mapping is also the same for each program. + batch_weights = tf.tile(tf.expand_dims(single_program_weights, 0), + [n_programs, 1, 1]) + + # The mapper selects the zero weight if it exists. + single_program_mapper_base = tf.reshape( + tf.range(n_symbols * self.n_non_zero_perturbations), + [n_symbols, self.n_non_zero_perturbations]) + single_program_mapper = tf.cond( + self.n_non_zero_perturbations < self.n_perturbations, + lambda: tf.concat([ + tf.zeros([n_symbols, 1], dtype=tf.int32), + single_program_mapper_base + 1 + ], 1), lambda: single_program_mapper_base) + batch_mapper = tf.tile(tf.expand_dims(single_program_mapper, 0), + [n_programs, 1, 1]) + + return (batch_programs, new_symbol_names, batch_symbol_values, + batch_weights, batch_mapper) class ForwardDifference(LinearCombination): @@ -488,7 +279,6 @@ class CentralDifference(LinearCombination): >>> grads tf.Tensor([[-1.1837807]], shape=(1, 1), dtype=float32) - """ def __init__(self, error_order=2, grid_spacing=0.001): diff --git a/tensorflow_quantum/python/differentiators/linear_combination_test.py b/tensorflow_quantum/python/differentiators/linear_combination_test.py index 85827c71d..ecb223816 100644 --- a/tensorflow_quantum/python/differentiators/linear_combination_test.py +++ b/tensorflow_quantum/python/differentiators/linear_combination_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Basic tests for the LinearCombinationDifferentiator""" +# 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 + import numpy as np from absl.testing import parameterized import tensorflow as tf @@ -63,16 +71,11 @@ def test_linear_combination_instantiate(self): linear_combination.LinearCombination([1, 1], [1, "junk"]) with self.assertRaisesRegex(ValueError, expected_regex="length"): linear_combination.LinearCombination([1, 1, 1], [1, 0]) + with self.assertRaisesRegex(ValueError, expected_regex="at least two"): + linear_combination.LinearCombination([1], [1]) with self.assertRaisesRegex(ValueError, expected_regex="unique"): linear_combination.LinearCombination([1, 1], [1, 1]) - def test_no_gradient_circuits(self): - """Confirm LinearCombination differentiator has no gradient circuits.""" - dif = linear_combination.LinearCombination([1, 1], [1, 0]) - with self.assertRaisesRegex(NotImplementedError, - expected_regex="not currently available"): - _ = dif.get_gradient_circuits(None, None, None) - def test_forward_instantiate(self): """Test ForwardDifference type checking.""" linear_combination.ForwardDifference() @@ -177,9 +180,9 @@ def test_analytic_functional(self, diff): rtol=1e-2) @parameterized.parameters([{ - 'diff': linear_combination.ForwardDifference() + 'diff': linear_combination.ForwardDifference(grid_spacing=0.01) }, { - 'diff': linear_combination.CentralDifference() + 'diff': linear_combination.CentralDifference(grid_spacing=0.01) }]) def test_sampled_functional(self, diff): """Test that the differentiate_sampled function WORKS.""" @@ -198,6 +201,78 @@ def test_sampled_functional(self, diff): atol=1e-1, rtol=1e-1) + def test_get_gradient_circuits(self): + """Test that the correct objects are returned.""" + + # Minimal linear combination. + input_weights = [1.0, -0.5] + input_perturbations = [1.0, -1.5] + diff = linear_combination.LinearCombination(input_weights, + input_perturbations) + + # Circuits to differentiate. + symbols = [sympy.Symbol("s0"), sympy.Symbol("s1")] + q0 = cirq.GridQubit(0, 0) + q1 = cirq.GridQubit(1, 2) + input_programs = util.convert_to_tensor([ + cirq.Circuit(cirq.X(q0)**symbols[0], + cirq.ry(symbols[1])(q1)), + cirq.Circuit(cirq.rx(symbols[0])(q0), + cirq.Y(q1)**symbols[1]), + ]) + input_symbol_names = tf.constant([str(s) for s in symbols]) + input_symbol_values = tf.constant([[1.5, -2.7], [-0.3, 0.9]]) + + # For each program in the input batch: LinearCombination creates a copy + # of that program for each symbol in the batch; then for each symbol, + # the program is copied for each non-zero perturbation; finally, a + # single copy is added for the zero perturbation (no zero pert here). + expected_batch_programs = tf.stack([[input_programs[0]] * 4, + [input_programs[1]] * 4]) + expected_new_symbol_names = input_symbol_names + + # For each program in the input batch: first, the input symbol_values + # for the program are tiled to the number of copies in the output. + tiled_symbol_values = tf.stack([[input_symbol_values[0]] * 4, + [input_symbol_values[1]] * 4]) + # Then we create the tensor of perturbations to apply to these symbol + # values: for each symbol we tile out the non-zero perturbations at that + # symbol's index, keeping all the other symbol perturbations at zero. + # Perturbations are the same for each program. + single_program_perturbations = tf.stack([[input_perturbations[0], 0.0], + [input_perturbations[1], 0.0], + [0.0, input_perturbations[0]], + [0.0, input_perturbations[1]]]) + tiled_perturbations = tf.stack( + [single_program_perturbations, single_program_perturbations]) + # Finally we add the perturbations to the original symbol values. + expected_batch_symbol_values = tiled_symbol_values + tiled_perturbations + + # The weights for LinearCombination is the same for every program. + individual_batch_weights = tf.stack( + [[input_weights[0], input_weights[1]], + [input_weights[0], input_weights[1]]]) + expected_batch_weights = tf.stack( + [individual_batch_weights, individual_batch_weights]) + + # The mapper selects the expectations. + single_program_mapper = tf.constant([[0, 1], [2, 3]]) + expected_batch_mapper = tf.tile( + tf.expand_dims(single_program_mapper, 0), [2, 1, 1]) + + (test_batch_programs, test_new_symbol_names, test_batch_symbol_values, + test_batch_weights, test_batch_mapper) = diff.get_gradient_circuits( + input_programs, input_symbol_names, input_symbol_values) + self.assertAllEqual(expected_batch_programs, test_batch_programs) + self.assertAllEqual(expected_new_symbol_names, test_new_symbol_names) + self.assertAllClose(expected_batch_symbol_values, + test_batch_symbol_values, + atol=1e-5) + self.assertAllClose(expected_batch_weights, + test_batch_weights, + atol=1e-5) + self.assertAllEqual(expected_batch_mapper, test_batch_mapper) + if __name__ == "__main__": tf.test.main() diff --git a/tensorflow_quantum/python/differentiators/parameter_shift.py b/tensorflow_quantum/python/differentiators/parameter_shift.py index df2cffd40..8a4ef9c3a 100644 --- a/tensorflow_quantum/python/differentiators/parameter_shift.py +++ b/tensorflow_quantum/python/differentiators/parameter_shift.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Compute analytic gradients by using general parameter-shift rule. """ import tensorflow as tf @@ -41,15 +41,16 @@ class ParameterShift(differentiator.Differentiator): ... cirq.Circuit(cirq.X(qubit) ** sympy.Symbol('alpha')) ... ]) >>> psums = tfq.convert_to_tensor([[cirq.Z(qubit)]]) - >>> symbol_values_array = np.array([[0.123]], dtype=np.float32) + >>> symbol_values = np.array([[0.123]], dtype=np.float32) >>> # Calculate tfq gradient. - >>> symbol_values_tensor = tf.convert_to_tensor(symbol_values_array) + >>> symbol_values_t = tf.convert_to_tensor(symbol_values) + >>> symbol_names = tf.convert_to_tensor(['alpha']) >>> with tf.GradientTape() as g: - ... g.watch(symbol_values_tensor) - ... expectations = op(circuit, ['alpha'], symbol_values_tensor, psums) + ... g.watch(symbol_values_t) + ... expectations = op(circuit, symbol_names, symbol_values_t, psums) >>> # This value is now computed via the ParameterShift rule. >>> # https://arxiv.org/abs/1905.13311 - >>> grads = g.gradient(expectations, symbol_values_tensor) + >>> grads = g.gradient(expectations, symbol_values_t) >>> grads tf.Tensor([[-1.1839752]], shape=(1, 1), dtype=float32) @@ -58,291 +59,50 @@ class ParameterShift(differentiator.Differentiator): @tf.function def get_gradient_circuits(self, programs, symbol_names, symbol_values): """See base class description.""" - raise NotImplementedError( - "Gradient circuits are not currently available for " - "ParameterShift.") - - @tf.function - def differentiate_analytic(self, programs, symbol_names, symbol_values, - pauli_sums, forward_pass_vals, grad): - """Calculate the gradient. - - The gradient calculations follows the following steps: - - 1. Compute the decomposition of the incoming circuits so that we have - their generator information (done using cirq in a tf.py_function) - 2. Use formula (31) from paper inside of TensorFlow to calculate - gradients from all the decomposed circuits. - 3. Sum up terms and reshape for the total gradient that is compatible - with TensorFlow. - - **CAUTION** - Analytic gradient measurements based on this ParameterShift generally - run at least K(=2) times SLOWER than the original circuit. - On top of it, since all parameters of gates are shifted individually, - the time complexity is linear in the number of parameterized gates L. - So, you will see O(KL) slower time & space complexity than the original - forward pass measurements. - - Args: - programs: `tf.Tensor` of strings with shape [batch_size] containing - the string representations of the circuits to be executed. - symbol_names: `tf.Tensor` of strings with shape [n_params], which - is used to specify the order in which the values in - `symbol_values` should be placed inside of the circuits in - `programs`. - symbol_values: `tf.Tensor` of real numbers with shape - [batch_size, n_params] specifying parameter values to resolve - into the circuits specified by programs, following the ordering - dictated by `symbol_names`. - pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] - containing the string representation of the operators that will - be used on all of the circuits in the expectation calculations. - forward_pass_vals: `tf.Tensor` of real numbers with shape - [batch_size, n_ops] containing the output of the forward pass - through the op you are differentiating. - grad: `tf.Tensor` of real numbers with shape [batch_size, n_ops] - representing the gradient backpropagated to the output of the - op you are differentiating through. - - Returns: - Backward gradient values for each program & each pauli sum. It has - the shape of [batch_size, n_symbols]. - """ - # these get used a lot n_symbols = tf.gather(tf.shape(symbol_names), 0) n_programs = tf.gather(tf.shape(programs), 0) - n_ops = tf.gather(tf.shape(pauli_sums), 1) - # Assume cirq.decompose() generates gates with at most two distinct - # eigenvalues, which results in two parameter shifts. - n_shifts = 2 - - # STEP 1: Generate required inputs for executor - # Deserialize programs and parse the whole parameterized gates - # new_programs has [n_symbols, n_param_gates, n_shifts, n_programs]. - # These new_programs has programs that parameter-shift rule is applied, - # so those programs has - (new_programs, weights, shifts, - n_param_gates) = parameter_shift_util.parse_programs( - programs, symbol_names, symbol_values, n_symbols) - - # Reshape & transpose new_programs, weights and shifts to fit into - # the input format of tensorflow_quantum simulator. - # [n_symbols, n_param_gates, n_shifts, n_programs] - new_programs = tf.transpose(new_programs, [0, 2, 3, 1]) - weights = tf.transpose(weights, [0, 2, 3, 1]) - shifts = tf.transpose(shifts, [0, 2, 3, 1]) - - # reshape everything to fit into expectation op correctly - total_programs = n_programs * n_shifts * n_param_gates * n_symbols - # tile up and then reshape to order programs correctly - flat_programs = tf.reshape(new_programs, [total_programs]) - flat_shifts = tf.reshape(shifts, [total_programs]) - - # tile up and then reshape to order ops correctly - n_tile = n_shifts * n_param_gates * n_symbols - flat_perturbations = tf.concat([ - tf.reshape( - tf.tile(tf.expand_dims(symbol_values, 0), - tf.stack([n_tile, 1, 1])), [total_programs, n_symbols]), - tf.expand_dims(flat_shifts, axis=1) - ], - axis=1) - flat_ops = tf.reshape( - tf.tile(tf.expand_dims(pauli_sums, 0), tf.stack([n_tile, 1, 1])), - [total_programs, n_ops]) - # Append impurity symbol into symbol name - new_symbol_names = tf.concat([ - symbol_names, - tf.expand_dims(tf.constant( - parameter_shift_util._PARAMETER_IMPURITY_NAME), - axis=0) - ], - axis=0) - - # STEP 2: calculate the required expectation values - expectations = self.expectation_op(flat_programs, new_symbol_names, - flat_perturbations, flat_ops) - - # STEP 3: generate gradients according to the results - - # we know the rows are grouped according to which parameter - # was perturbed, so reshape to reflect that - grouped_expectations = tf.reshape( - expectations, - [n_symbols, n_shifts * n_programs * n_param_gates, -1]) - - # now we can calculate the partial of the circuit output with - # respect to each perturbed parameter - def rearrange_expectations(grouped): - def split_vertically(i): - return tf.slice(grouped, [i * n_programs, 0], - [n_programs, n_ops]) - - return tf.map_fn(split_vertically, - tf.range(n_param_gates * n_shifts), - dtype=tf.float32) - - # reshape so that expectations calculated on different programs are - # separated by a dimension - rearranged_expectations = tf.map_fn(rearrange_expectations, - grouped_expectations) - - # now we will calculate all of the partial derivatives - partials = tf.einsum( - 'spco,spc->sco', rearranged_expectations, - tf.cast( - tf.reshape(weights, - [n_symbols, n_param_gates * n_shifts, n_programs]), - rearranged_expectations.dtype)) - - # now apply the chain rule - return tf.einsum('sco,co -> cs', partials, grad) - - @tf.function - def differentiate_sampled(self, programs, symbol_names, symbol_values, - pauli_sums, num_samples, forward_pass_vals, grad): - """Calculate the gradient. - - The gradient calculations follows the following steps: - - 1. Compute the decomposition of the incoming circuits so that we have - their generator information (done using cirq in a tf.py_function) - 2. Use formula (31) from paper inside of TensorFlow to calculate - gradients from all the decomposed circuits. - 3. Sum up terms and reshape for the total gradient that is compatible - with TensorFlow. - - **CAUTION** - Analytic gradient measurements based on this ParameterShift generally - run at least K(=2) times SLOW than the original circuit. - On top of it, since all parameters of gates are shifted individually, - the time complexity is linear in the number of parameterized gates L. - So, you will see O(KL) slower time & space complexity than the original - forward pass measurements. - - Args: - programs: `tf.Tensor` of strings with shape [batch_size] containing - the string representations of the circuits to be executed. - symbol_names: `tf.Tensor` of strings with shape [n_params], which - is used to specify the order in which the values in - `symbol_values` should be placed inside of the circuits in - `programs`. - symbol_values: `tf.Tensor` of real numbers with shape - [batch_size, n_params] specifying parameter values to resolve - into the circuits specified by programs, following the ordering - dictated by `symbol_names`. - pauli_sums: `tf.Tensor` of strings with shape [batch_size, n_ops] - containing the string representation of the operators that will - be used on all of the circuits in the expectation calculations. - num_samples: `tf.Tensor` of positiver integers indicating the number - of samples used per term to calculate the expectation value - in the forward pass. - forward_pass_vals: `tf.Tensor` of real numbers with shape - [batch_size, n_ops] containing the output of the forward pass - through the op you are differentiating. - grad: `tf.Tensor` of real numbers with shape [batch_size, n_ops] - representing the gradient backpropagated to the output of the - op you are differentiating through. - - Returns: - Backward gradient values for each program & each pauli sum. It has - the shape of [batch_size, n_symbols]. - """ - - # these get used a lot - n_symbols = tf.gather(tf.shape(symbol_names), 0) - n_programs = tf.gather(tf.shape(programs), 0) - n_ops = tf.gather(tf.shape(pauli_sums), 1) # Assume cirq.decompose() generates gates with at most two distinct # eigenvalues, which results in two parameter shifts. n_shifts = 2 - # STEP 1: Generate required inputs for executor - # Deserialize programs and parse the whole parameterized gates - # new_programs has [n_symbols, n_param_gates, n_shifts, n_programs]. - # These new_programs has programs that parameter-shift rule is applied, - # so those programs has + # These new_programs are parameter shifted. + # shapes: [n_symbols, n_programs, n_param_gates, n_shifts] (new_programs, weights, shifts, n_param_gates) = parameter_shift_util.parse_programs( programs, symbol_names, symbol_values, n_symbols) - # Reshape & transpose new_programs, weights and shifts to fit into - # the input format of tensorflow_quantum simulator. - # [n_symbols, n_param_gates, n_shifts, n_programs] - new_programs = tf.transpose(new_programs, [0, 2, 3, 1]) - weights = tf.transpose(weights, [0, 2, 3, 1]) - shifts = tf.transpose(shifts, [0, 2, 3, 1]) + m_tile = n_shifts * n_param_gates * n_symbols - # reshape everything to fit into expectation op correctly - total_programs = n_programs * n_shifts * n_param_gates * n_symbols - # tile up and then reshape to order programs correctly - flat_programs = tf.reshape(new_programs, [total_programs]) - flat_shifts = tf.reshape(shifts, [total_programs]) + # Transpose to correct shape, + # [n_programs, n_symbols, n_param_gates, n_shifts], + # then reshape to the correct batch size + batch_programs = tf.reshape(tf.transpose(new_programs, [1, 0, 2, 3]), + [n_programs, m_tile]) + batch_weights = tf.reshape( + tf.transpose(weights, [1, 0, 2, 3]), + [n_programs, n_symbols, n_param_gates * n_shifts]) + shifts = tf.reshape(tf.transpose(shifts, [1, 0, 2, 3]), + [n_programs, m_tile, 1]) - # tile up and then reshape to order ops correctly - n_tile = n_shifts * n_param_gates * n_symbols - flat_perturbations = tf.concat([ - tf.reshape( - tf.tile(tf.expand_dims(symbol_values, 0), - tf.stack([n_tile, 1, 1])), [total_programs, n_symbols]), - tf.expand_dims(flat_shifts, axis=1) - ], - axis=1) - flat_ops = tf.reshape( - tf.tile(tf.expand_dims(pauli_sums, 0), tf.stack([n_tile, 1, 1])), - [total_programs, n_ops]) - flat_num_samples = tf.reshape( - tf.tile(tf.expand_dims(num_samples, 0), tf.stack([n_tile, 1, 1])), - [total_programs, n_ops]) # Append impurity symbol into symbol name new_symbol_names = tf.concat([ symbol_names, - tf.expand_dims(tf.constant( - parameter_shift_util._PARAMETER_IMPURITY_NAME), - axis=0) - ], - axis=0) - - # STEP 2: calculate the required expectation values - expectations = self.expectation_op(flat_programs, new_symbol_names, - flat_perturbations, flat_ops, - flat_num_samples) - - # STEP 3: generate gradients according to the results - - # we know the rows are grouped according to which parameter - # was perturbed, so reshape to reflect that - grouped_expectations = tf.reshape( - expectations, - [n_symbols, n_shifts * n_programs * n_param_gates, -1]) - - # now we can calculate the partial of the circuit output with - # respect to each perturbed parameter - def rearrange_expectations(grouped): - - def split_vertically(i): - return tf.slice(grouped, [i * n_programs, 0], - [n_programs, n_ops]) - - return tf.map_fn(split_vertically, - tf.range(n_param_gates * n_shifts), - dtype=tf.float32) - - # reshape so that expectations calculated on different programs are - # separated by a dimension - rearranged_expectations = tf.map_fn(rearrange_expectations, - grouped_expectations) - - # now we will calculate all of the partial derivatives - partials = tf.einsum( - 'spco,spc->sco', rearranged_expectations, - tf.cast( - tf.reshape(weights, - [n_symbols, n_param_gates * n_shifts, n_programs]), - rearranged_expectations.dtype)) - - # now apply the chain rule - return tf.einsum('sco,co -> cs', partials, grad) + tf.constant([parameter_shift_util.PARAMETER_IMPURITY_NAME]) + ], 0) + + # Symbol values are the input symbol values, tiled according to + # `batch_programs`, with the shift values appended. + tiled_symbol_values = tf.tile(tf.expand_dims(symbol_values, 1), + [1, m_tile, 1]) + batch_symbol_values = tf.concat([tiled_symbol_values, shifts], 2) + + single_program_mapper = tf.reshape( + tf.range(n_symbols * n_param_gates * n_shifts), + [n_symbols, n_param_gates * n_shifts]) + batch_mapper = tf.tile(tf.expand_dims(single_program_mapper, 0), + [n_programs, 1, 1]) + + return (batch_programs, new_symbol_names, batch_symbol_values, + batch_weights, batch_mapper) diff --git a/tensorflow_quantum/python/differentiators/parameter_shift_test.py b/tensorflow_quantum/python/differentiators/parameter_shift_test.py index 06e6761d4..d40b2257e 100644 --- a/tensorflow_quantum/python/differentiators/parameter_shift_test.py +++ b/tensorflow_quantum/python/differentiators/parameter_shift_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Basic tests for the ParameterShift differentiator""" +# 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 + import numpy as np from absl.testing import parameterized import tensorflow as tf @@ -46,13 +54,6 @@ def _simple_op_inputs(): class ParameterShiftTest(tf.test.TestCase, parameterized.TestCase): """Test the ParameterShift Differentiator will run end to end.""" - def test_no_gradient_circuits(self): - """Confirm ParameterShift differentiator has no gradient circuits.""" - dif = parameter_shift.ParameterShift() - with self.assertRaisesRegex(NotImplementedError, - expected_regex="not currently available"): - _ = dif.get_gradient_circuits(None, None, None) - def test_parameter_shift_analytic(self): """Test if ParameterShift.differentiate_analytical doesn't crash before running.""" @@ -86,6 +87,121 @@ def test_parameter_shift_sampled(self): self.assertAllClose(expectations, true_f, atol=1e-1, rtol=1e-1) self.assertAllClose(grads, true_g, atol=1e-1, rtol=1e-1) + def test_get_gradient_circuits(self): + """Test that the correct objects are returned.""" + + diff = parameter_shift.ParameterShift() + + # Circuits to differentiate. + symbols = [sympy.Symbol("s0"), sympy.Symbol("s1")] + q0 = cirq.GridQubit(0, 0) + q1 = cirq.GridQubit(1, 2) + input_programs = util.convert_to_tensor([ + cirq.Circuit( + cirq.X(q0)**symbols[0], + cirq.Y(q0)**symbols[0], + cirq.ry(symbols[1])(q1)), + cirq.Circuit(cirq.Y(q1)**symbols[1]), + ]) + input_symbol_names = tf.constant([str(s) for s in symbols]) + input_symbol_values = tf.constant([[1.5, -2.7], [-0.3, 0.9]]) + + # First, for each symbol `s`, check how many times `s` appears in each + # program `p`, `n_ps`. Let `n_param_gates` be the maximum of `n_ps` over + # all symbols and programs. Then, the shape of `batch_programs` will be + # [n_programs, n_symbols * n_param_gates * n_shifts], where `n_shifts` + # is 2 because we decompose into gates with 2 eigenvalues. For row index + # `p` we have for column indices between `i * n_param_gates * n_shifts` + # and `(i + 1) * n_param_gates * n_shifts`, the first `n_pi * 2` + # programs are parameter shifted versions of `input_programs[p]` and the + # remaining programs are empty. + # Here, `n_param_gates` is 2. + impurity_symbol_name = "_impurity_for_param_shift" + impurity_symbol = sympy.Symbol(impurity_symbol_name) + expected_batch_programs_0 = util.convert_to_tensor([ + cirq.Circuit( + cirq.X(q0)**impurity_symbol, + cirq.Y(q0)**symbols[0], + cirq.ry(symbols[1])(q1)), + cirq.Circuit( + cirq.X(q0)**impurity_symbol, + cirq.Y(q0)**symbols[0], + cirq.ry(symbols[1])(q1)), + cirq.Circuit( + cirq.X(q0)**symbols[0], + cirq.Y(q0)**impurity_symbol, + cirq.ry(symbols[1])(q1)), + cirq.Circuit( + cirq.X(q0)**symbols[0], + cirq.Y(q0)**impurity_symbol, + cirq.ry(symbols[1])(q1)), + cirq.Circuit( + cirq.X(q0)**symbols[0], + cirq.Y(q0)**symbols[0], + cirq.ry(impurity_symbol)(q1)), + cirq.Circuit( + cirq.X(q0)**symbols[0], + cirq.Y(q0)**symbols[0], + cirq.ry(impurity_symbol)(q1)), + cirq.Circuit(), + cirq.Circuit() + ]) + expected_batch_programs_1 = util.convert_to_tensor([ + cirq.Circuit(), + cirq.Circuit(), + cirq.Circuit(), + cirq.Circuit(), + cirq.Circuit(cirq.Y(q1)**impurity_symbol), + cirq.Circuit(cirq.Y(q1)**impurity_symbol), + cirq.Circuit(), + cirq.Circuit() + ]) + expected_batch_programs = tf.stack( + [expected_batch_programs_0, expected_batch_programs_1]) + + # The new symbols are the old ones, with an extra used for shifting. + expected_new_symbol_names = tf.concat( + [input_symbol_names, + tf.constant([impurity_symbol_name])], 0) + + # The batch symbol values are the input symbol values, tiled and with + # shifted values appended. Locations that have empty programs should + # also have zero for the shift. + # The shifted values are the original value plus 1/2 divided by the + # `exponent_scalar` of the gate. + expected_batch_symbol_values = tf.constant( + [[[1.5, -2.7, 1.5 + 0.5], [1.5, -2.7, 1.5 - 0.5], + [1.5, -2.7, 1.5 + 0.5], [1.5, -2.7, 1.5 - 0.5], + [1.5, -2.7, -2.7 + np.pi / 2], [1.5, -2.7, -2.7 - np.pi / 2], + [1.5, -2.7, -2.7], [1.5, -2.7, -2.7]], + [[-0.3, 0.9, -0.3], [-0.3, 0.9, -0.3], [-0.3, 0.9, -0.3], + [-0.3, 0.9, -0.3], [-0.3, 0.9, 0.9 + 0.5], [-0.3, 0.9, 0.9 - 0.5], + [-0.3, 0.9, 0.9], [-0.3, 0.9, 0.9]]]) + + # Empty program locations are given zero weight. + expected_batch_weights = tf.constant( + [[[np.pi / 2, -np.pi / 2, np.pi / 2, -np.pi / 2], + [0.5, -0.5, 0.0, 0.0]], + [[0.0, 0.0, 0.0, 0.0], [np.pi / 2, -np.pi / 2, 0.0, 0.0]]]) + + expected_batch_mapper = tf.constant([[[0, 1, 2, 3], [4, 5, 6, 7]], + [[0, 1, 2, 3], [4, 5, 6, 7]]]) + + (test_batch_programs, test_new_symbol_names, test_batch_symbol_values, + test_batch_weights, test_batch_mapper) = diff.get_gradient_circuits( + input_programs, input_symbol_names, input_symbol_values) + for i in range(tf.shape(input_programs)[0]): + self.assertAllEqual(util.from_tensor(expected_batch_programs[i]), + util.from_tensor(test_batch_programs[i])) + self.assertAllEqual(expected_new_symbol_names, test_new_symbol_names) + self.assertAllClose(expected_batch_symbol_values, + test_batch_symbol_values, + atol=1e-5) + self.assertAllClose(expected_batch_weights, + test_batch_weights, + atol=1e-5) + self.assertAllEqual(expected_batch_mapper, test_batch_mapper) + if __name__ == "__main__": tf.test.main() diff --git a/tensorflow_quantum/python/differentiators/parameter_shift_util.py b/tensorflow_quantum/python/differentiators/parameter_shift_util.py index b995a831c..34889c69a 100644 --- a/tensorflow_quantum/python/differentiators/parameter_shift_util.py +++ b/tensorflow_quantum/python/differentiators/parameter_shift_util.py @@ -11,14 +11,14 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Util functions for general parameter-shift rule. """ import numpy as np import tensorflow as tf from tensorflow_quantum.core.ops import tfq_ps_util_ops -_PARAMETER_IMPURITY_NAME = '_param_shift' +PARAMETER_IMPURITY_NAME = '_impurity_for_param_shift' @tf.function @@ -65,7 +65,7 @@ def parse_programs(programs, symbol_names, symbol_values, n_symbols, # Collecting doped programs with impurity sympy.Symbol from all programs # with parameterized gates. - impurity = tf.tile(tf.convert_to_tensor([_PARAMETER_IMPURITY_NAME]), + impurity = tf.tile(tf.convert_to_tensor([PARAMETER_IMPURITY_NAME]), [n_symbols]) symbols = tf.convert_to_tensor(symbol_names) @@ -78,6 +78,7 @@ def parse_programs(programs, symbol_names, symbol_values, n_symbols, n_param_gates = tf.cast(tf.gather(tf.shape(new_programs), 2), dtype=tf.int32) + # This is a tensor of the `exponent_scalar`s of the shifted gates. coeff = tf.expand_dims(tf.transpose( tfq_ps_util_ops.tfq_ps_weights_from_symbols(decomposed_programs, symbols), [1, 0, 2]), diff --git a/tensorflow_quantum/python/differentiators/parameter_shift_util_test.py b/tensorflow_quantum/python/differentiators/parameter_shift_util_test.py index 198974e79..a8178be6e 100644 --- a/tensorflow_quantum/python/differentiators/parameter_shift_util_test.py +++ b/tensorflow_quantum/python/differentiators/parameter_shift_util_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Basic tests for utility functions for ParameterShift""" +# 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 + import numpy as np from absl.testing import parameterized import tensorflow as tf diff --git a/tensorflow_quantum/python/layers/BUILD b/tensorflow_quantum/python/layers/BUILD index fd4e75c2e..2f835d74e 100644 --- a/tensorflow_quantum/python/layers/BUILD +++ b/tensorflow_quantum/python/layers/BUILD @@ -4,3 +4,14 @@ licenses(["notice"]) # Export for the PIP package. exports_files(["__init__.py"]) + +py_library( + name = "layers", + srcs = ["__init__.py"], + srcs_version = "PY3", + deps = [ + "//tensorflow_quantum/python/layers/circuit_construction", + "//tensorflow_quantum/python/layers/circuit_executors", + "//tensorflow_quantum/python/layers/high_level", + ], +) diff --git a/tensorflow_quantum/python/layers/__init__.py b/tensorflow_quantum/python/layers/__init__.py index bd37b6042..3de402f8d 100644 --- a/tensorflow_quantum/python/layers/__init__.py +++ b/tensorflow_quantum/python/layers/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module definitions for tensorflow_quantum.python.layers.*""" # Utility layers. from tensorflow_quantum.python.layers.circuit_construction import ( @@ -27,5 +27,7 @@ # High level layers. from tensorflow_quantum.python.layers.high_level import ( ControlledPQC, + NoisyControlledPQC, + NoisyPQC, PQC, ) diff --git a/tensorflow_quantum/python/layers/circuit_construction/BUILD b/tensorflow_quantum/python/layers/circuit_construction/BUILD index 4a1a511a7..9bf9a3919 100644 --- a/tensorflow_quantum/python/layers/circuit_construction/BUILD +++ b/tensorflow_quantum/python/layers/circuit_construction/BUILD @@ -5,9 +5,19 @@ licenses(["notice"]) # Export for the PIP package. exports_files(["__init__.py"]) +py_library( + name = "circuit_construction", + srcs = ["__init__.py"], + srcs_version = "PY3", + deps = [ + ":elementary", + ], +) + py_library( name = "elementary", srcs = ["elementary.py"], + srcs_version = "PY3", deps = [ "//tensorflow_quantum/core/ops:tfq_utility_ops_py", "//tensorflow_quantum/python:util", diff --git a/tensorflow_quantum/python/layers/circuit_construction/__init__.py b/tensorflow_quantum/python/layers/circuit_construction/__init__.py index 0c5ded5c5..765f26e83 100644 --- a/tensorflow_quantum/python/layers/circuit_construction/__init__.py +++ b/tensorflow_quantum/python/layers/circuit_construction/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.python.layers.circuit_construction.*""" # pylint: disable=line-too-long diff --git a/tensorflow_quantum/python/layers/circuit_construction/elementary.py b/tensorflow_quantum/python/layers/circuit_construction/elementary.py index 66714f800..13574c435 100644 --- a/tensorflow_quantum/python/layers/circuit_construction/elementary.py +++ b/tensorflow_quantum/python/layers/circuit_construction/elementary.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Elementary layers, such as the AddCircuit layer.""" import numpy as np import tensorflow as tf diff --git a/tensorflow_quantum/python/layers/circuit_construction/elementary_test.py b/tensorflow_quantum/python/layers/circuit_construction/elementary_test.py index afb7650e2..6d07cd2e1 100644 --- a/tensorflow_quantum/python/layers/circuit_construction/elementary_test.py +++ b/tensorflow_quantum/python/layers/circuit_construction/elementary_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for the elementary layers.""" +# 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 + import tensorflow as tf import cirq import sympy @@ -101,16 +109,20 @@ def test_addcircuit_modify(self): circuit_b = cirq.testing.random_circuit(bits, 10, 0.9, util.get_supported_gates()) - expected_append = util.convert_to_tensor([circuit_a + circuit_b]) - expected_prepend = util.convert_to_tensor([circuit_b + circuit_a]) + expected_append = util.convert_to_tensor( + [circuit_a + circuit_b], deterministic_proto_serialize=True) + expected_prepend = util.convert_to_tensor( + [circuit_b + circuit_a], deterministic_proto_serialize=True) append_layer = elementary.AddCircuit() prepend_layer = elementary.AddCircuit() actual_append = util.convert_to_tensor( - util.from_tensor(append_layer(circuit_a, append=circuit_b))) + util.from_tensor(append_layer(circuit_a, append=circuit_b)), + deterministic_proto_serialize=True) actual_prepend = util.convert_to_tensor( - util.from_tensor(prepend_layer(circuit_a, prepend=circuit_b))) + util.from_tensor(prepend_layer(circuit_a, prepend=circuit_b)), + deterministic_proto_serialize=True) self.assertEqual(expected_append.numpy()[0], actual_append.numpy()[0]) self.assertEqual(expected_prepend.numpy()[0], actual_prepend.numpy()[0]) diff --git a/tensorflow_quantum/python/layers/circuit_executors/BUILD b/tensorflow_quantum/python/layers/circuit_executors/BUILD index ceda89519..1e4541c42 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/BUILD +++ b/tensorflow_quantum/python/layers/circuit_executors/BUILD @@ -5,9 +5,23 @@ licenses(["notice"]) # Export for the PIP package. exports_files(["__init__.py"]) +py_library( + name = "circuit_executors", + srcs = ["__init__.py"], + srcs_version = "PY3", + deps = [ + ":expectation", + ":input_checks", + ":sample", + ":state", + ":unitary", + ], +) + py_library( name = "state", srcs = ["state.py"], + srcs_version = "PY3", deps = [ ":input_checks", "//tensorflow_quantum/core/ops:circuit_execution_ops", @@ -17,21 +31,25 @@ py_library( py_library( name = "expectation", srcs = ["expectation.py"], + srcs_version = "PY3", deps = [ ":input_checks", "//tensorflow_quantum/core/ops:circuit_execution_ops", + "//tensorflow_quantum/core/ops/noise:noisy_expectation_op_py", "//tensorflow_quantum/python:util", "//tensorflow_quantum/python/differentiators:adjoint", "//tensorflow_quantum/python/differentiators:differentiator", - "//tensorflow_quantum/python/differentiators:linear_combination", - ], + "//tensorflow_quantum/python/differentiators:parameter_shift", + ] ) py_library( name = "sampled_expectation", srcs = ["sampled_expectation.py"], + srcs_version = "PY3", deps = [ ":input_checks", + "//tensorflow_quantum/core/ops/noise:noisy_sampled_expectation_op_py", "//tensorflow_quantum/core/ops:circuit_execution_ops", "//tensorflow_quantum/python:util", "//tensorflow_quantum/python/differentiators:differentiator", @@ -43,15 +61,18 @@ py_library( py_library( name = "sample", srcs = ["sample.py"], + srcs_version = "PY3", deps = [ ":input_checks", "//tensorflow_quantum/core/ops:circuit_execution_ops", + "//tensorflow_quantum/core/ops/noise:noisy_samples_op_py", ], ) py_library( name = "unitary", srcs = ["unitary.py"], + srcs_version = "PY3", deps = [ ":input_checks", "//tensorflow_quantum/core/ops:tfq_unitary_op_py", @@ -61,6 +82,7 @@ py_library( py_library( name = "input_checks", srcs = ["input_checks.py"], + srcs_version = "PY3", deps = [ "//tensorflow_quantum/python:util", ], diff --git a/tensorflow_quantum/python/layers/circuit_executors/__init__.py b/tensorflow_quantum/python/layers/circuit_executors/__init__.py index 74d26d3e0..0ce744835 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/__init__.py +++ b/tensorflow_quantum/python/layers/circuit_executors/__init__.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.python.layers.circuit_executors.*""" # pylint: disable=line-too-long diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation.py b/tensorflow_quantum/python/layers/circuit_executors/expectation.py index cda00b403..cba81e7b5 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation.py @@ -11,15 +11,19 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A tf.keras.layer that ingests programs and outputs expectation values.""" +import numbers + import numpy as np import tensorflow as tf import cirq from tensorflow_quantum.core.ops import circuit_execution_ops +from tensorflow_quantum.core.ops.noise import noisy_expectation_op +from tensorflow_quantum.python import quantum_context from tensorflow_quantum.python.differentiators import adjoint -from tensorflow_quantum.python.differentiators import linear_combination +from tensorflow_quantum.python.differentiators import parameter_shift from tensorflow_quantum.python.differentiators import differentiator as diff from tensorflow_quantum.python.layers.circuit_executors import input_checks @@ -202,7 +206,11 @@ class Expectation(tf.keras.layers.Layer): """ - def __init__(self, backend=None, differentiator=None, **kwargs): + def __init__(self, + backend='noiseless', + differentiator=None, + use_cuquantum=False, + **kwargs): """Instantiate this Layer. Create a layer that will output expectation values gained from @@ -210,40 +218,63 @@ def __init__(self, backend=None, differentiator=None, **kwargs): Args: backend: Optional Backend to use to simulate states. Defaults to - the native TensorFlow simulator (None), however users may also - specify a preconfigured cirq simulation object to use instead, - which must inherit `cirq.SimulatesFinalState`. + the 'noiseless' simulator, options include {'noiseless', + 'noisy'}. In the noisy case a `repetitions` call argument + must be provided. Users may also specify a preconfigured cirq + object to use instead, which must inherit + `cirq.sim.simulator.SimulatesExpectationValues`. differentiator: Optional Differentiator to use to calculate analytic derivative values of given operators_to_measure and circuit, which must inherit `tfq.differentiators.Differentiator` and implements `differentiate_analytic` method. Defaults to None, - which uses `linear_combination.ForwardDifference()`. If - `backend` is also None then default is + which uses `tfq.differentiators.ParameterShift()`. If + `backend` is also 'noiseless' then default is `tfq.differentiators.Adjoint`. + use_cuquantum: Calls TFQ cuQuantum version op. """ super().__init__(**kwargs) # Ingest backend. - if not isinstance(backend, cirq.SimulatesFinalState) and \ + if not isinstance( + backend, cirq.sim.simulator.SimulatesExpectationValues) and \ isinstance(backend, cirq.Sampler): - raise TypeError("Backend implements cirq.Sampler but not" - " cirq.SimulatesFinalState. Please use " - "SampledExpectation instead.") + raise TypeError("Backend implements cirq.Sampler but not " + "cirq.sim.simulator.SimulatesExpectationValues. " + "Please use SampledExpectation instead.") + used_op = None + self.noisy = False # Ingest differentiator. if differentiator is None: - differentiator = linear_combination.ForwardDifference() - if backend is None: + differentiator = parameter_shift.ParameterShift() + if backend == 'noiseless' or backend is None: differentiator = adjoint.Adjoint() if not isinstance(differentiator, diff.Differentiator): raise TypeError("Differentiator must inherit from " "tfq.differentiators.Differentiator") - self._expectation_op = differentiator.generate_differentiable_op( - analytic_op=circuit_execution_ops.get_expectation_op( - backend=backend)) + if backend == 'noiseless' or backend is None: + mode = quantum_context.get_quantum_concurrent_op_mode() + quantum_concurrent = False if use_cuquantum else mode + used_op = circuit_execution_ops.get_expectation_op( + backend=None, + use_cuquantum=use_cuquantum, + quantum_concurrent=quantum_concurrent) + self._expectation_op = differentiator.generate_differentiable_op( + analytic_op=used_op, use_cuquantum=use_cuquantum) + elif backend == 'noisy': + if use_cuquantum: + raise ValueError("noisy backend does not currently support GPU") + used_op = noisy_expectation_op.expectation + self._expectation_op = differentiator.generate_differentiable_op( + sampled_op=used_op) + self.noisy = True + else: + used_op = circuit_execution_ops.get_expectation_op(backend=backend) + self._expectation_op = differentiator.generate_differentiable_op( + analytic_op=used_op) self._w = None @@ -253,15 +284,21 @@ def call(self, symbol_names=None, symbol_values=None, operators=None, - initializer=tf.keras.initializers.RandomUniform(0, 2 * np.pi)): + repetitions=None, + initializer=None): """Keras call function. - Input options: - `inputs`, `symbol_names`, `symbol_values`: - see `input_checks.expand_circuits` - `operators`: see `input_checks.expand_operators` - - Output shape: + Args: + inputs: See `input_checks.expand_circuits. + symbol_names: See `input_checks.expand_circuits. + symbol_values: See `input_checks.expand_circuits. + operators: See `input_checks.expand_operators` + repetitions: A Python `int` or a pre-converted `tf.Tensor` + containing a single `int` entry. + initializer: The keras initializer object for weights. + Defaults to uniform distribution [0..2*pi] + + Returns: `tf.Tensor` with shape [batch_size, n_ops] that holds the expectation value for each circuit with each op applied to it (after resolving the corresponding parameters in). @@ -270,6 +307,9 @@ def call(self, if symbol_values is None: values_empty = True + if initializer is None: + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) + inputs, symbol_names, symbol_values = input_checks.expand_circuits( inputs, symbol_names, symbol_values) @@ -277,6 +317,43 @@ def call(self, operators = input_checks.expand_operators(operators, circuit_batch_dim) + # Ingest and promote repetitions if using noisy backend. + if not self.noisy and repetitions is not None: + raise RuntimeError("repetitions value provided for analytic" + " expectation calculation that is noiseless.") + + if self.noisy: + if repetitions is None: + raise RuntimeError( + "Value for repetitions not provided." + " With backend=\'noisy\' a number of trajectory" + " repetitions must be provided in the layer" + " call method.") + + reps_need_tile = False + if isinstance(repetitions, numbers.Integral): + # Must tile it up to size to match operators if many operators + # were provided but only one number was provided. + repetitions = tf.ones(tf.shape(operators), + dtype=tf.dtypes.int32) * repetitions + + if isinstance(repetitions, (list, tuple, np.ndarray)): + if not isinstance(repetitions[0], (list, tuple, np.ndarray)): + repetitions = [repetitions] + reps_need_tile = True + + repetitions = tf.convert_to_tensor(repetitions, + dtype=tf.dtypes.int32) + + if reps_need_tile: + # Don't tile up if the user gave a python list that was + # precisely the correct size to match circuits outer batch dim. + repetitions = tf.tile(repetitions, [circuit_batch_dim, 1]) + + if not tf.is_tensor(repetitions): + raise TypeError("repetitions cannot be parsed to int32 tensor" + " given input: ".format(repetitions)) + if values_empty: # No symbol_values were provided. So we assume the user wants us # to create and manage variables for them. We will do so by @@ -292,5 +369,13 @@ def call(self, symbol_values = tf.tile(tf.expand_dims(self._w, axis=0), tf.stack([circuit_batch_dim, 1])) - return self._expectation_op(inputs, symbol_names, symbol_values, - operators) + num_samples = repetitions # needed to help autographer. + + # pylint: disable=no-else-return + if self.noisy: + return self._expectation_op(inputs, symbol_names, symbol_values, + operators, num_samples) + else: + return self._expectation_op(inputs, symbol_names, symbol_values, + operators) + # pylint: enable=no-else-return diff --git a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py index 33d175377..f36396232 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/expectation_test.py @@ -11,19 +11,31 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for tensorflow_quantum.layers.circuit_executors.expectation.""" +# 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 + import numpy as np +from absl.testing import parameterized import sympy import tensorflow as tf import cirq +from tensorflow_quantum.core.ops import circuit_execution_ops from tensorflow_quantum.python.layers.circuit_executors import expectation from tensorflow_quantum.python.differentiators import linear_combination from tensorflow_quantum.python import util +RANDOM_SEED = 1234 -def _gen_single_bit_rotation_problem(bit, symbols): + +def _gen_single_bit_rotation_problem(bit, symbols, noisy): """Generate a toy problem on 1 qubit.""" starting_state = np.random.uniform(0, 2 * np.pi, 3) circuit = cirq.Circuit( @@ -33,16 +45,21 @@ def _gen_single_bit_rotation_problem(bit, symbols): cirq.rz(symbols[2])(bit), cirq.ry(symbols[1])(bit), cirq.rx(symbols[0])(bit)) + if noisy: + circuit += cirq.depolarize(0.01)(bit) return circuit -class ExpectationTest(tf.test.TestCase): +class ExpectationTest(parameterized.TestCase, tf.test.TestCase): """Basic tests for the expectation layer.""" def test_expectation_instantiate(self): """Test that Expectation instantiates correctly.""" expectation.Expectation() + expectation.Expectation(backend=None) + expectation.Expectation(backend='noisy') + expectation.Expectation(backend='noiseless') expectation.Expectation(backend=cirq.Simulator()) expectation.Expectation( differentiator=linear_combination.ForwardDifference()) @@ -62,11 +79,15 @@ def run_sweep(self): expectation.Expectation(backend=MySampler()) with self.assertRaisesRegex( - TypeError, expected_regex="SimulatesFinalState or None"): + TypeError, + expected_regex="SimulatesExpectationValues or None", + ): expectation.Expectation(backend='junk') with self.assertRaisesRegex( - TypeError, expected_regex="tfq.differentiators.Differentiator"): + TypeError, + expected_regex="tfq.differentiators.Differentiator", + ): expectation.Expectation(differentiator='junk') def test_expectation_type_inputs_error(self): @@ -83,6 +104,22 @@ def test_expectation_type_inputs_error(self): operators=test_psum, initializer='junk') + with self.assertRaisesRegex(Exception, + expected_regex="repetitions not provided"): + expectation.Expectation(backend='noisy')(reg_circuit, + operators=test_psum) + + with self.assertRaisesRegex(Exception, + expected_regex="cannot be parsed"): + expectation.Expectation(backend='noisy')(reg_circuit, + operators=test_psum, + repetitions='junk') + + with self.assertRaisesRegex(Exception, expected_regex="noiseless"): + expectation.Expectation(backend='noiseless')(reg_circuit, + operators=test_psum, + repetitions=1) + def test_expectation_op_error(self): """Test that expectation errors within underlying ops correctly.""" @@ -159,7 +196,10 @@ def test_static_cases(self): # Ensure tiling up of circuits works as expected. expectation.Expectation()(reg_circuit, operators=test_psum) - expectation.Expectation()(reg_circuit, operators=[test_psum, test_psum]) + expectation.Expectation()( + reg_circuit, + operators=[test_psum, test_psum], + ) # Ensure tiling up of symbol_values works as expected. expectation.Expectation()(symb_circuit, @@ -171,10 +211,92 @@ def test_static_cases(self): symbol_values=[[0.5]], operators=test_psum) - def test_expectation_simple_tf_train(self): + def test_static_cases_noisy(self): + """Test that the noisy trajectory backend works in complex cases.""" + bit = cirq.GridQubit(0, 0) + symbol = sympy.Symbol('alpha') + test_pstring = cirq.Z(bit) + test_psum = cirq.PauliSum.from_pauli_strings([test_pstring]) + symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) + reg_circuit = cirq.Circuit(cirq.H(bit)) + + # Passing a 2d operators input requires a 1d circuit input. + expectation.Expectation(backend='noisy')( + [reg_circuit, reg_circuit], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) + + # Passing 2d operators along with other inputs. + expectation.Expectation(backend='noisy')( + [symb_circuit, symb_circuit], + symbol_names=[symbol], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) + expectation.Expectation(backend='noisy')( + [symb_circuit, symb_circuit], + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) + + # Ensure tiling up of circuits works as expected. + expectation.Expectation(backend='noisy')(reg_circuit, + operators=test_psum, + repetitions=1) + expectation.Expectation(backend='noisy')( + reg_circuit, operators=[test_psum, test_psum], repetitions=1) + + # Ensure tiling up of symbol_values works as expected. + expectation.Expectation(backend='noisy')(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=test_psum, + repetitions=1) + expectation.Expectation(backend='noisy')(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=test_psum, + repetitions=1) + + # Test multiple operators with integer valued repetition. + expectation.Expectation(backend='noisy')( + symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=[-1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit)], + repetitions=1) + expectation.Expectation(backend='noisy')( + symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=[-1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit)], + repetitions=[5, 1]) + + # Test 2d repetitions. + expectation.Expectation(backend='noisy')( + [symb_circuit, symb_circuit], + symbol_names=[symbol], + symbol_values=[[0.5], [0.4]], + operators=[[ + -1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit), + cirq.Z(bit) + ], [cirq.Z(bit), cirq.Z(bit), cirq.Z(bit)]], + repetitions=[[1, 2, 3], [4, 5, 6]]) + + @parameterized.parameters([{ + 'use_cuquantum': False, + }, { + 'use_cuquantum': True, + }]) + def test_expectation_simple_tf_train(self, use_cuquantum): """Train a layer using standard tf (not keras). This is a subtle test that will work since we don't use keras compile. """ + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) bit = cirq.GridQubit(0, 0) circuit = \ cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) @@ -185,35 +307,62 @@ def test_expectation_simple_tf_train(self): with tf.GradientTape() as tape: circuit_out = layer(circuit, symbol_names=['theta'], - operators=op) + operators=op, + initializer=initializer) mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) grads = tape.gradient(mse, layer.trainable_weights) optimizer.apply_gradients(zip(grads, layer.trainable_weights)) self.assertAllClose(mse.numpy(), 0, atol=1e-3) -class ExpectationFunctionalTests(tf.test.TestCase): +class ExpectationFunctionalTests(parameterized.TestCase, tf.test.TestCase): """Test hybrid/integrated models that include an expectation layer.""" - def test_simple_param_value_input(self): + @parameterized.parameters([ + { + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': None, # old API usage + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, + } + ]) + def test_simple_param_value_input(self, backend, use_cuquantum): """Train a densely connected hybrid model. - This model will put a qubit in the zero or one state from a random state - given the input zero or one. This tests the input signature: + This model will put a qubit in the zero or one state from a random + state given the input zero or one. This tests the input signature: Expectation([input_value_batch]). """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) + noisy = backend == 'noisy' bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') - circuit = _gen_single_bit_rotation_problem(bit, symbols) + circuit = _gen_single_bit_rotation_problem(bit, symbols, noisy) inputs = tf.keras.Input(shape=(1,), dtype=tf.dtypes.float64) datum = tf.keras.Input(shape=(), dtype=tf.dtypes.string) l1 = tf.keras.layers.Dense(10)(inputs) l2 = tf.keras.layers.Dense(3)(l1) - outputs = expectation.Expectation()(datum, - symbol_names=symbols, - operators=cirq.Z(bit), - symbol_values=l2) + reps = 1000 if noisy else None + outputs = expectation.Expectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(datum, + symbol_names=symbols, + operators=cirq.Z(bit), + symbol_values=l2, + repetitions=reps, + initializer=initializer) model = tf.keras.Model(inputs=[datum, inputs], outputs=outputs) data_in = np.array([[1], [0]], dtype=np.float32) @@ -225,19 +374,40 @@ def test_simple_param_value_input(self): circuits = util.convert_to_tensor([circuit, circuit]) history = model.fit(x=[circuits, data_in], y=data_out, epochs=100) - self.assertAllClose(history.history['loss'][-1], 0, atol=1e-3) - - def test_simple_op_input(self): + tol = 5e-2 if noisy else 1e-3 + self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + + @parameterized.parameters([ + { + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': None, # old API usage + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, + } + ]) + def test_simple_op_input(self, backend, use_cuquantum): """Test a simple operator input Learn qubit in the z+ state using two different measurement operators. This tests input signature Expectation([operator_batch]) """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + normal_initializer = tf.keras.initializers.RandomNormal() + noisy = backend == 'noisy' bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') circuits = util.convert_to_tensor( - [_gen_single_bit_rotation_problem(bit, symbols)] * 2) + [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) data_out = tf.convert_to_tensor(np.array([[1], [1]])) ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) @@ -245,13 +415,20 @@ def test_simple_op_input(self): circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) op_input = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) - output = expectation.Expectation()( - circuit_input, - symbol_names=symbols, - operators=op_input, - initializer=tf.keras.initializers.RandomNormal()) - - model = tf.keras.Model(inputs=[circuit_input, op_input], outputs=output) + reps = 1000 if noisy else None + output = expectation.Expectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(circuit_input, + symbol_names=symbols, + operators=op_input, + initializer=normal_initializer, + repetitions=reps) + + model = tf.keras.Model( + inputs=[circuit_input, op_input], + outputs=output, + ) model.compile( optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), @@ -261,21 +438,45 @@ def test_simple_op_input(self): y=data_out, batch_size=2, epochs=200) - - self.assertAllClose(history.history['loss'][-1], 0, atol=1e-3) - - def test_simple_op_and_param_input(self): + tol = 5e-2 if noisy else 1e-3 + self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + + @parameterized.parameters([ + { + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': None, # old api usage. + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, + }, + { + 'backend': cirq.Simulator(), + 'use_cuquantum': False, + } + ]) + def test_simple_op_and_param_input(self, backend, use_cuquantum): """Test a simple operator and parameter input. Train a NN to put a qubit in the z+ or x+ states based on a classical binary input. This tests the input signature: Expectation([value_batch, operator_batch]). """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) + noisy = backend == 'noisy' bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.X(bit)]]) circuits = util.convert_to_tensor( - [_gen_single_bit_rotation_problem(bit, symbols)] * 2) + [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) data_in = np.array([[1], [0]]) data_out = np.array([[1], [1]]) @@ -284,11 +485,16 @@ def test_simple_op_and_param_input(self): circuit_inp = tf.keras.Input(shape=(), dtype=tf.dtypes.string) dense_1 = tf.keras.layers.Dense(10)(data_inp) dense_2 = tf.keras.layers.Dense(3)(dense_1) - circuit_output = expectation.Expectation(backend=cirq.Simulator())( - circuit_inp, - symbol_names=symbols, - symbol_values=dense_2, - operators=op_inp) + reps = 1000 if noisy else None + circuit_output = expectation.Expectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(circuit_inp, + symbol_names=symbols, + symbol_values=dense_2, + operators=op_inp, + repetitions=reps, + initializer=initializer) functional_model = tf.keras.Model( inputs=[data_inp, op_inp, circuit_inp], outputs=[circuit_output]) @@ -300,18 +506,40 @@ def test_simple_op_and_param_input(self): y=data_out, batch_size=2, epochs=100) - self.assertAllClose(history.history['loss'][-1], 0, atol=1e-3) - - def test_dnn_qnn_dnn(self): + tol = 5e-2 if noisy else 1e-3 + self.assertAllClose(history.history['loss'][-1], 0, atol=tol) + + @parameterized.parameters([ + { + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': None, # old API usage + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, + } + ]) + def test_dnn_qnn_dnn(self, backend, use_cuquantum): """Train a fully hybrid network using an Expectation layer. Train the network to output +-5 given an input of 1 or 0. This tests that everything works when Expectation layer is a middle layers. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) + + noisy = backend == 'noisy' bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') circuits = util.convert_to_tensor( - [_gen_single_bit_rotation_problem(bit, symbols)] * 2) + [_gen_single_bit_rotation_problem(bit, symbols, noisy)] * 2) data_in = np.array([[1], [0]], dtype=np.float32) data_out = np.array([[5], [-5]], dtype=np.float32) @@ -319,10 +547,16 @@ def test_dnn_qnn_dnn(self): circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) d1 = tf.keras.layers.Dense(10)(classical_input) d2 = tf.keras.layers.Dense(3)(d1) - quantum = expectation.Expectation()(circuit_input, - symbol_names=symbols, - symbol_values=d2, - operators=cirq.Z(bit)) + reps = 1000 if noisy else None + quantum = expectation.Expectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(circuit_input, + symbol_names=symbols, + symbol_values=d2, + operators=cirq.Z(bit), + repetitions=reps, + initializer=initializer) d3 = tf.keras.layers.Dense(1)(quantum) model = tf.keras.Model(inputs=[circuit_input, classical_input], @@ -334,7 +568,8 @@ def test_dnn_qnn_dnn(self): y=data_out, batch_size=2, epochs=300) - self.assertAllClose(history.history['loss'][-1], 0, atol=1e-3) + tol = 5e-2 if noisy else 1e-3 + self.assertAllClose(history.history['loss'][-1], 0, atol=tol) if __name__ == '__main__': diff --git a/tensorflow_quantum/python/layers/circuit_executors/input_checks.py b/tensorflow_quantum/python/layers/circuit_executors/input_checks.py index c2c1767df..9855b5b74 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/input_checks.py +++ b/tensorflow_quantum/python/layers/circuit_executors/input_checks.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Input checks common to circuit execution layers.""" import numpy as np import sympy @@ -21,7 +21,10 @@ from tensorflow_quantum.python import util -def expand_circuits(inputs, symbol_names=None, symbol_values=None): +def expand_circuits(inputs, + symbol_names=None, + symbol_values=None, + deterministic_proto_serialize=False): """Function for consistently expanding circuit inputs. Args: @@ -33,6 +36,8 @@ def expand_circuits(inputs, symbol_names=None, symbol_values=None): parameterizing the input circuits. symbol_values: a Python `list`, `tuple`, or `numpy.ndarray` of floating point values, or `tf.Tensor` of dtype `float32`. + deterministic_proto_serialize: Whether to use a deterministic proto + serialization. Returns: inputs: `tf.Tensor` of dtype `string` with shape [batch_size] @@ -80,11 +85,16 @@ def expand_circuits(inputs, symbol_names=None, symbol_values=None): # Ingest and promote circuit. if isinstance(inputs, cirq.Circuit): # process single circuit. - inputs = tf.tile(util.convert_to_tensor([inputs]), [symbol_batch_dim]) + inputs = tf.tile( + util.convert_to_tensor( + [inputs], + deterministic_proto_serialize=deterministic_proto_serialize), + [symbol_batch_dim]) elif isinstance(inputs, (list, tuple, np.ndarray)): # process list of circuits. - inputs = util.convert_to_tensor(inputs) + inputs = util.convert_to_tensor( + inputs, deterministic_proto_serialize=deterministic_proto_serialize) if not tf.is_tensor(inputs): raise TypeError("circuits cannot be parsed with given input:" @@ -100,7 +110,9 @@ def expand_circuits(inputs, symbol_names=None, symbol_values=None): return inputs, symbol_names, symbol_values -def expand_operators(operators=None, circuit_batch_dim=1): +def expand_operators(operators=None, + circuit_batch_dim=1, + deterministic_proto_serialize=False): """Check and expand operators. Args: @@ -112,6 +124,8 @@ def expand_operators(operators=None, circuit_batch_dim=1): or `cirq.PauliSum`s; or pre-converted `tf.Tensor` of `cirq.PauliString`s or `cirq.PauliSum`s. circuit_batch_dim: number of circuits in the final expansion + deterministic_proto_serialize: Whether to use a deterministic proto + serialization. Returns: operators: `tf.Tensor` of dtype `string` with shape [batch_size, n_ops] @@ -136,7 +150,9 @@ def expand_operators(operators=None, circuit_batch_dim=1): # to match the batch size of circuits. operators = [operators] op_needs_tile = True - operators = util.convert_to_tensor(operators) + operators = util.convert_to_tensor( + operators, + deterministic_proto_serialize=deterministic_proto_serialize) if op_needs_tile: # Don't tile up if the user gave a python list that was precisely diff --git a/tensorflow_quantum/python/layers/circuit_executors/input_checks_test.py b/tensorflow_quantum/python/layers/circuit_executors/input_checks_test.py index d7cbc17b9..304b365e1 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/input_checks_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/input_checks_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for tensorflow_quantum.layers.circuit_executors.input_checks.""" +# 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 + import numpy as np import sympy import tensorflow as tf @@ -34,7 +42,8 @@ def test_expand_circuits_error(self): names_tensor = tf.convert_to_tensor([str(symbol)], dtype=tf.dtypes.string) circuit_tensor = util.convert_to_tensor( - [cirq.Circuit(cirq.H(qubit)**symbol)]) + [cirq.Circuit(cirq.H(qubit)**symbol)], + deterministic_proto_serialize=True) values_tensor = tf.convert_to_tensor([[0.5]], dtype=tf.dtypes.float32) # Bad circuit arg @@ -89,7 +98,8 @@ def test_allowed_cases(self): cirq.X(qubits[1])**names_symbol_list[1]) circuit_list = [circuit_alone for _ in range(3)] circuit_tuple = tuple(circuit_list) - circuit_tensor = util.convert_to_tensor(circuit_list) + circuit_tensor = util.convert_to_tensor( + circuit_list, deterministic_proto_serialize=True) values_list = [[1], [2], [3]] values_tuple = tuple(values_list) values_ndarray = np.array(values_list) @@ -106,7 +116,8 @@ def test_allowed_cases(self): values_list, values_tuple, values_ndarray, values_tensor ]: circuit_test, names_test, values_test = \ - input_checks.expand_circuits(circuit, names, values) + input_checks.expand_circuits(circuit, names, values, \ + deterministic_proto_serialize=True) self.assertAllEqual(circuit_test, circuit_tensor) self.assertAllEqual(names_test, names_tensor) self.assertAllEqual(values_test, values_tensor) @@ -116,7 +127,8 @@ def test_allowed_cases(self): values_tensor = tf.convert_to_tensor([[]] * 3, dtype=tf.dtypes.float32) for circuit in [circuit_list, circuit_tuple, circuit_tensor]: circuit_test, names_test, values_test = \ - input_checks.expand_circuits(circuit) + input_checks.expand_circuits(circuit, \ + deterministic_proto_serialize=True) self.assertAllEqual(circuit_test, circuit_tensor) self.assertAllEqual(names_test, names_tensor) self.assertAllEqual(values_test, values_tensor) @@ -143,13 +155,15 @@ def test_allowed_cases(self): bare_tuple = tuple(bare_list) shaped_list = [[bare_string]] * batch_dim shaped_tuple = tuple(shaped_list) - op_tensor_single = util.convert_to_tensor([[bare_string]]) + op_tensor_single = util.convert_to_tensor( + [[bare_string]], deterministic_proto_serialize=True) op_tensor = tf.tile(op_tensor_single, [batch_dim, 1]) for op in [ bare_string, bare_sum, bare_list, bare_tuple, shaped_list, shaped_tuple, op_tensor ]: - op_test = input_checks.expand_operators(op, batch_dim) + op_test = input_checks.expand_operators( + op, batch_dim, deterministic_proto_serialize=True) self.assertAllEqual(op_test, op_tensor) diff --git a/tensorflow_quantum/python/layers/circuit_executors/sample.py b/tensorflow_quantum/python/layers/circuit_executors/sample.py index 58f704c55..3ba53c6bf 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample.py @@ -11,13 +11,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A tf.keras.layer that ingests programs and outputs bitstring samples.""" import numbers import tensorflow as tf from tensorflow_quantum.core.ops import circuit_execution_ops +from tensorflow_quantum.core.ops.noise import noisy_samples_op +from tensorflow_quantum.python import quantum_context from tensorflow_quantum.python.layers.circuit_executors import input_checks @@ -34,7 +36,7 @@ class Sample(tf.keras.layers.Layer): ... q1 = cirq.GridQubit(1, 0) ... circuit = cirq.Circuit( ... cirq.X(q0), - ... cirq.CNOT(q1) + ... cirq.CNOT(q0, q1) ... ) ... ... return circuit @@ -138,7 +140,7 @@ class Sample(tf.keras.layers.Layer): """ - def __init__(self, backend=None, **kwargs): + def __init__(self, backend='noiseless', use_cuquantum=False, **kwargs): """Instantiate this Layer. Create a layer that will output bitstring samples taken from either a @@ -146,12 +148,28 @@ def __init__(self, backend=None, **kwargs): Args: backend: Optional Backend to use to simulate this state. Defaults - to the native Tensorflow simulator (None), however users may - also specify a preconfigured cirq execution object to use - instead, which must inherit `cirq.Sampler`. + to the noiseless simulator. Options are {'noisy', 'noiseless'}, + however users may also specify a preconfigured cirq execution + object to use instead, which must inherit `cirq.Sampler`. + use_cuquantum: Calls TFQ GPU version op. """ super().__init__(**kwargs) - self.sample_op = circuit_execution_ops.get_sampling_op(backend) + used_op = None + if backend == 'noiseless' or backend is None: + mode = quantum_context.get_quantum_concurrent_op_mode() + quantum_concurrent = False if use_cuquantum else mode + used_op = circuit_execution_ops.get_sampling_op( + None, + use_cuquantum=use_cuquantum, + quantum_concurrent=quantum_concurrent) + elif backend == 'noisy': + if use_cuquantum: + raise ValueError('noisy backend has no GPU support.') + used_op = noisy_samples_op.samples + else: + used_op = circuit_execution_ops.get_sampling_op(backend) + + self.sample_op = used_op def call(self, inputs, @@ -161,17 +179,18 @@ def call(self, repetitions=None): """Keras call function. - Input options: - `inputs`, `symbol_names`, `symbol_values`: - see `input_checks.expand_circuits` - `repetitions`: a Python `int` or a pre-converted - `tf.Tensor` containing a single `int` entry. + Args: + inputs: See `input_checks.expand_circuits`. + symbol_names: See `input_checks.expand_circuits`. + symbol_values: See `input_checks.expand_circuits`. + repetitions: A Python `int` or a pre-converted `tf.Tensor` + containing a single `int` entry. - Output shape: + Returns: `tf.RaggedTensor` with shape: - [batch size of symbol_values, repetitions, ] - or - [number of circuits, repetitions, ] + [batch size of symbol_values, repetitions, ] + or + [number of circuits, repetitions, ] """ if repetitions is None: raise ValueError("Number of repetitions not specified.") diff --git a/tensorflow_quantum/python/layers/circuit_executors/sample_test.py b/tensorflow_quantum/python/layers/circuit_executors/sample_test.py index 5cd2d7daf..379fbaee3 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sample_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sample_test.py @@ -11,17 +11,28 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for the sample layer.""" +# 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 + import numpy as np from absl.testing import parameterized import sympy import tensorflow as tf import cirq +from tensorflow_quantum.core.ops import circuit_execution_ops from tensorflow_quantum.python.layers.circuit_executors import sample from tensorflow_quantum.python import util +RANDOM_SEED = 1234 + class SampleTest(tf.test.TestCase, parameterized.TestCase): """Tests for the Sample layer.""" @@ -76,16 +87,34 @@ def test_sample_invalid_shape_inputs(self): TypeError, expected_regex="cannot be parsed to int32 tensor"): sampler([cirq.Circuit()], repetitions=[10]) - @parameterized.parameters([{ - 'backend': None - }, { - 'backend': cirq.Simulator() - }, { - 'backend': cirq.DensityMatrixSimulator() - }]) - def test_sample_invalid_combinations(self, backend): + @parameterized.parameters([ + { + 'backend': 'noiseless', + 'use_cuquantum': False, + }, + { + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': cirq.Simulator(), + 'use_cuquantum': False, + }, + { + 'backend': None, # old API usage. + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, + } + ]) + def test_sample_invalid_combinations(self, backend, use_cuquantum): """Test with valid type inputs and valid value, but incorrect combo.""" - sampler = sample.Sample(backend) + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + sampler = sample.Sample(backend, use_cuquantum=use_cuquantum) symbol = sympy.Symbol('alpha') circuit = cirq.Circuit(cirq.H(cirq.GridQubit(0, 0))**symbol) with self.assertRaisesRegex(Exception, expected_regex=""): @@ -127,9 +156,17 @@ def test_sample_invalid_combinations(self, backend): symbol_values=np.zeros((3, 1)), repetitions=5) - def test_sample_basic_inputs(self): + @parameterized.parameters([{ + 'use_cuquantum': False, + }, { + 'use_cuquantum': True, + }]) + def test_sample_basic_inputs(self, use_cuquantum): """Test that sample ingests inputs correctly in simple settings.""" - sampler = sample.Sample() + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + sampler = sample.Sample(use_cuquantum=use_cuquantum) sampler(cirq.Circuit(), repetitions=10) sampler([cirq.Circuit()], repetitions=10) sampler(cirq.Circuit(), @@ -141,32 +178,49 @@ def test_sample_basic_inputs(self): symbol_values=[[0.5]], repetitions=10) - def test_sample_outputs_simple(self): + @parameterized.parameters([{ + 'use_cuquantum': False, + }, { + 'use_cuquantum': True, + }]) + def test_sample_outputs_simple(self, use_cuquantum): """Test the simplest call where nothing but circuits are provided.""" - sampler = sample.Sample() + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + sampler = sample.Sample(use_cuquantum=use_cuquantum) circuit = cirq.Circuit(cirq.H(cirq.GridQubit(0, 0))) output = sampler([circuit, circuit], repetitions=5) self.assertShapeEqual(np.empty((2, 5, 1)), output.to_tensor()) - # TODO(trevormccrt): add QuantumEngineSampler to this once it is available + # TODO(trevormccrt): add ProcessorSampler to this once it is available @parameterized.parameters( list( util.kwargs_cartesian_product( - backend=[None, - cirq.Simulator(), - cirq.DensityMatrixSimulator()], - all_n_qubits=[[3], [8], [3, 4], [3, 4, 10]], - n_samples=[1, 10, 100], + backend=['noiseless', 'noisy', + cirq.Simulator(), None], + use_cuquantum=[False, True], + all_n_qubits=[[3, 4, 10]], + n_samples=[1], symbol_names=[[], ['a', 'b']]))) - def test_sample_output(self, backend, all_n_qubits, n_samples, - symbol_names): + def test_sample_output(self, backend, use_cuquantum, all_n_qubits, + n_samples, symbol_names): """Test that expected output format is preserved. Check that any pre or post processing done inside the layers does not cause what is output from the layer to structurally deviate from what is expected. """ - sampler = sample.Sample(backend=backend) + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + if use_cuquantum: + # If use_cuquantum is True, + if backend is not None and backend != 'noiseless': + return + # Passes backend=None or backend == 'noiseless' only. + sampler = sample.Sample(backend=backend, use_cuquantum=use_cuquantum) bits = cirq.GridQubit.rect(1, max(all_n_qubits)) programs = [] expected_outputs = [] @@ -178,6 +232,7 @@ def test_sample_output(self, backend, all_n_qubits, n_samples, symbol_names=symbol_names, symbol_values=symbol_values, repetitions=n_samples).to_list() + self.assertEqual(expected_outputs, layer_output) diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py index 7f28c1082..0fdcc421f 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A tf.keras.layer that ingests programs and outputs sampled expectation values .""" import numbers @@ -21,6 +21,8 @@ import cirq from tensorflow_quantum.core.ops import circuit_execution_ops +from tensorflow_quantum.core.ops.noise import noisy_sampled_expectation_op +from tensorflow_quantum.python import quantum_context from tensorflow_quantum.python.differentiators import differentiator as diff from tensorflow_quantum.python.differentiators import parameter_shift from tensorflow_quantum.python.layers.circuit_executors import input_checks @@ -212,31 +214,29 @@ class SampledExpectation(tf.keras.layers.Layer): """ - def __init__(self, backend=None, differentiator=None, **kwargs): + def __init__(self, + backend='noiseless', + differentiator=None, + use_cuquantum=False, + **kwargs): """Instantiate this Layer. Create a layer that will output expectation values gained from - simulating a quantum circuit. + sampling a quantum circuit. Args: - backend: Optional Backend to use to simulate states. Defaults to - the native TensorFlow simulator (None), however users may also - specify a preconfigured cirq simulation object to use instead, - which must inherit `cirq.SimulatesFinalState`. + backend: Optional Backend to use to simulate states. Can be either + {'noiseless', 'noisy'} users may also + specify a preconfigured `cirq.Sampler` object to use instead. differentiator: Optional Differentiator to use to calculate analytic derivative values of given operators_to_measure and circuit, which must inherit `tfq.differentiators.Differentiator`. - Defaults to None, which uses `parameter_shift.ParameterShift()`. + Defaults to `parameter_shift.ParameterShift()` (None argument). + use_cuquantum: Calls TFQ GPU version op. """ super().__init__(**kwargs) - # Ingest backend. - if not isinstance(backend, cirq.Sampler) and \ - isinstance(backend, cirq.SimulatesFinalState): - raise TypeError("Backend implements cirq.SimulatesFinalState but " - "not cirq.Sampler. Please use Expectation instead.") - # Ingest differentiator. if differentiator is None: differentiator = parameter_shift.ParameterShift() @@ -245,9 +245,31 @@ def __init__(self, backend=None, differentiator=None, **kwargs): raise TypeError("Differentiator must inherit from " "tfq.differentiators.Differentiator") + # Ingest backend. + if not isinstance(backend, cirq.Sampler) and \ + isinstance(backend, cirq.SimulatesFinalState): + raise TypeError("Backend implements cirq.SimulatesFinalState but " + "not cirq.Sampler. Please use Expectation instead.") + + used_op = None + if backend == 'noiseless' or backend is None: + mode = quantum_context.get_quantum_concurrent_op_mode() + quantum_concurrent = False if use_cuquantum else mode + used_op = circuit_execution_ops.get_sampled_expectation_op( + backend=None, + use_cuquantum=use_cuquantum, + quantum_concurrent=quantum_concurrent, + ) + elif backend == 'noisy': + if use_cuquantum: + raise ValueError('noisy backend does not currently support GPU') + used_op = noisy_sampled_expectation_op.sampled_expectation + else: + used_op = circuit_execution_ops.get_sampled_expectation_op( + backend=backend) + self._expectation_op = differentiator.generate_differentiable_op( - sampled_op=circuit_execution_ops.get_sampled_expectation_op( - backend=backend)) + sampled_op=used_op) self._w = None @@ -258,25 +280,31 @@ def call(self, symbol_values=None, operators=None, repetitions=None, - initializer=tf.keras.initializers.RandomUniform(0, 2 * np.pi)): + initializer=None): """Keras call function. - Input options: - `inputs`, `symbol_names`, `symbol_values`: - see `input_checks.expand_circuits` - `operators`: see `input_checks.expand_operators` - `repetitions`: a Python `int` or a pre-converted - `tf.Tensor` containing a single `int` entry. - - Output shape: + Args: + inputs: See `input_checks.expand_circuits. + symbol_names: See `input_checks.expand_circuits. + symbol_values: See `input_checks.expand_circuits. + operators: See `input_checks.expand_operators` + repetitions: A Python `int` or a pre-converted `tf.Tensor` + containing a single `int` entry. + initializer: The keras initializer object for weights. + Defaults to uniform distribution [0..2*pi] + + Returns: `tf.Tensor` with shape [batch_size, n_ops] that holds the - expectation value for each circuit with each op applied to it - (after resolving the corresponding parameters in). + expectation value for each circuit with each op applied to it + (after resolving the corresponding parameters in). """ values_empty = False if symbol_values is None: values_empty = True + if initializer is None: + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) + inputs, symbol_names, symbol_values = input_checks.expand_circuits( inputs, symbol_names, symbol_values) diff --git a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py index 510b11aec..c13afbfd4 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/sampled_expectation_test.py @@ -11,21 +11,45 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for tensorflow_quantum.layers.circuit_executors.sampled_expectation.""" +# 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 import numpy as np +from absl.testing import parameterized import sympy import tensorflow as tf import cirq +from tensorflow_quantum.core.ops import circuit_execution_ops from tensorflow_quantum.python.layers.circuit_executors import \ sampled_expectation from tensorflow_quantum.python.differentiators import linear_combination from tensorflow_quantum.python import util +RANDOM_SEED = 1234 + + +class CustomSampler(cirq.Sampler): + """Wrapper for cirq.Simulator to confirm that custom samplers work.""" + + def __init__(self): + """Initialize a simulator to use internally.""" + super().__init__() + self._internal_sim = cirq.Simulator() + + def run_sweep(self, program, params, repetitions=1): + """Simple pass-through to default cirq simulator.""" + return self._internal_sim.run_sweep(program, params, repetitions) + -def _gen_single_bit_rotation_problem(bit, symbols): +def _gen_single_bit_rotation_problem(bit, symbols, noisy): """Generate a toy problem on 1 qubit.""" starting_state = np.random.uniform(0, 2 * np.pi, 3) circuit = cirq.Circuit( @@ -35,18 +59,22 @@ def _gen_single_bit_rotation_problem(bit, symbols): cirq.rz(symbols[2])(bit), cirq.ry(symbols[1])(bit), cirq.rx(symbols[0])(bit)) + if noisy: + circuit += cirq.depolarize(0.01)(bit) return circuit -class SampledExpectationTest(tf.test.TestCase): +class SampledExpectationTest(parameterized.TestCase, tf.test.TestCase): """Basic tests for the SampledExpectation layer.""" def test_sampled_expectation_symbol_input(self): """Test that SampledExpectation only accepts valid permutations of symbols.""" - sampled_expectation.SampledExpectation() + sampled_expectation.SampledExpectation(backend='noiseless') + sampled_expectation.SampledExpectation(backend='noisy') sampled_expectation.SampledExpectation(backend=cirq.Simulator()) + sampled_expectation.SampledExpectation(backend=CustomSampler()) sampled_expectation.SampledExpectation( differentiator=linear_combination.ForwardDifference()) @@ -71,8 +99,42 @@ def simulate_sweep(self): TypeError, expected_regex="tfq.differentiators.Differentiator"): sampled_expectation.SampledExpectation(differentiator='junk') - def test_sampled_expectation_type_inputs_error(self): + @parameterized.parameters([ + { + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': 'noiseless', + 'use_cuquantum': False, + }, + { + 'backend': 'noiseless', + 'use_cuquantum': True, + }, + { + 'backend': cirq.Simulator(), + 'use_cuquantum': False, + }, + { + 'backend': CustomSampler(), + 'use_cuquantum': False, + }, + { + 'backend': None, # older API usage. + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, + } + ]) + def test_sampled_expectation_type_inputs_error(self, backend, + use_cuquantum): """Test that SampledExpectation errors within Keras call.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") bit = cirq.GridQubit(0, 0) symbol = sympy.Symbol('alpha') @@ -83,26 +145,67 @@ def test_sampled_expectation_type_inputs_error(self): with self.assertRaisesRegex(RuntimeError, expected_regex="repetitions not provided"): - sampled_expectation.SampledExpectation()(symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=test_psum) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=test_psum) with self.assertRaisesRegex(Exception, expected_regex="Unknown initializer"): - sampled_expectation.SampledExpectation()(reg_circuit, - operators=test_psum, - initializer='junk', - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, + operators=test_psum, + initializer='junk', + repetitions=1) with self.assertRaisesRegex(Exception, expected_regex="cannot be parsed"): - sampled_expectation.SampledExpectation()(reg_circuit, - operators=test_psum, - repetitions='junk') - - def test_sampled_expectation_op_error(self): + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, operators=test_psum, repetitions='junk') + + @parameterized.parameters([ + { + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': 'noiseless', + 'use_cuquantum': False, + }, + { + 'backend': 'noiseless', + 'use_cuquantum': True, + }, + { + 'backend': cirq.Simulator(), + 'use_cuquantum': False, + }, + { + 'backend': CustomSampler(), + 'use_cuquantum': False, + }, + { + 'backend': None, # older API usage. + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, + } + ]) + def test_sampled_expectation_op_error(self, backend, use_cuquantum): """Test that expectation errors within underlying ops correctly.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + # Note the expected_regex is left blank here since there is a # discrepancy between the error strings provided between backends. bit = cirq.GridQubit(0, 0) @@ -112,65 +215,103 @@ def test_sampled_expectation_op_error(self): symb_circuit = cirq.Circuit(cirq.H(bit)**symbol) reg_circuit = cirq.Circuit(cirq.H(bit)) - with self.assertRaisesRegex(Exception, expected_regex="pauli_sums"): + with self.assertRaisesRegex(Exception, expected_regex="pauli"): # Operators has wrong rank. Parse error. - sampled_expectation.SampledExpectation()( - [reg_circuit], - operators=util.convert_to_tensor([test_psum]), - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )([reg_circuit], + operators=util.convert_to_tensor([test_psum]), + repetitions=1) with self.assertRaisesRegex(Exception, expected_regex="symbol_values"): # symbol_values has wrong rank. - sampled_expectation.SampledExpectation()([symb_circuit], - symbol_names=[symbol], - symbol_values=[0.5], - operators=test_psum, - repetitions=1) - - with self.assertRaisesRegex( - Exception, - expected_regex="Number of circuits and PauliSums do not match"): + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )([symb_circuit], + symbol_names=[symbol], + symbol_values=[0.5], + operators=test_psum, + repetitions=1) + + with self.assertRaisesRegex(Exception, expected_regex="pauli"): # Wrong batch size for pauli operators. - sampled_expectation.SampledExpectation()(symb_circuit, - symbol_names=[symbol], - operators=[[test_psum], - [test_psum]], - repetitions=1) - - with self.assertRaisesRegex( - Exception, - expected_regex="Number of circuits and PauliSums do not match"): + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(symb_circuit, + symbol_names=[symbol], + operators=[[test_psum], [test_psum]], + repetitions=1) + + with self.assertRaisesRegex(Exception, expected_regex="pauli"): # Wrong batch size for pauli operators. - sampled_expectation.SampledExpectation()(reg_circuit, - operators=[[test_psum], - [test_psum]], - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, operators=[[test_psum], [test_psum]], repetitions=1) - with self.assertRaisesRegex(Exception, expected_regex="greater than 0"): + with self.assertRaisesRegex(Exception, expected_regex="0"): # Wrong repetitions. - sampled_expectation.SampledExpectation()(reg_circuit, - operators=test_psum, - repetitions=-1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, operators=test_psum, repetitions=-1) - with self.assertRaisesRegex( - Exception, - expected_regex="num_samples and pauli_sums do not match"): + with self.assertRaisesRegex(Exception, expected_regex=""): # Wrong second dimension size for repetitions & pauli operators. - sampled_expectation.SampledExpectation()(reg_circuit, - operators=test_psum, - repetitions=[5, 4, 3]) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, operators=test_psum, repetitions=[5, 4, 3]) - with self.assertRaisesRegex(Exception, expected_regex="do not match."): + with self.assertRaisesRegex(Exception, expected_regex=""): # Wrong batch_size for symbol values. - sampled_expectation.SampledExpectation()([reg_circuit], - symbol_names=[symbol], - symbol_values=np.zeros( - (3, 1)), - operators=test_psum, - repetitions=5) - - def test_static_cases(self): + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )([reg_circuit], + symbol_names=[symbol], + symbol_values=np.zeros((3, 1)), + operators=test_psum, + repetitions=5) + + @parameterized.parameters([ + { + 'backend': 'noisy', + 'use_cuquantum': False, + }, + { + 'backend': 'noiseless', + 'use_cuquantum': False, + }, + { + 'backend': 'noiseless', + 'use_cuquantum': True, + }, + { + 'backend': cirq.Simulator(), + 'use_cuquantum': False, + }, + { + 'backend': CustomSampler(), + 'use_cuquantum': False, + }, + { + 'backend': None, # older API usage. + 'use_cuquantum': False, + }, + { + 'backend': None, + 'use_cuquantum': True, + } + ]) + def test_static_cases(self, backend, use_cuquantum): """Run inputs through in complex cases.""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") bit = cirq.GridQubit(0, 0) symbol = sympy.Symbol('alpha') @@ -180,100 +321,151 @@ def test_static_cases(self): reg_circuit = cirq.Circuit(cirq.H(bit)) # Passing a 2d operators input requires a 1d circuit input. - sampled_expectation.SampledExpectation()( - [reg_circuit, reg_circuit], - operators=[[test_psum, test_psum], [test_psum, test_psum]], - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )([reg_circuit, reg_circuit], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) # Passing 2d operators along with other inputs. - sampled_expectation.SampledExpectation()( - [symb_circuit, symb_circuit], - symbol_names=[symbol], - operators=[[test_psum, test_psum], [test_psum, test_psum]], - repetitions=1) - sampled_expectation.SampledExpectation()( - [symb_circuit, symb_circuit], - symbol_names=[symbol], - symbol_values=[[0.5], [0.8]], - operators=[[test_psum, test_psum], [test_psum, test_psum]], - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )([symb_circuit, symb_circuit], + symbol_names=[symbol], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )([symb_circuit, symb_circuit], + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=[[test_psum, test_psum], [test_psum, test_psum]], + repetitions=1) # Ensure tiling up of circuits works as expected. - sampled_expectation.SampledExpectation()(reg_circuit, - operators=test_psum, - repetitions=1) - sampled_expectation.SampledExpectation()( - reg_circuit, operators=[test_psum, test_psum], repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, operators=test_psum, repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(reg_circuit, operators=[test_psum, test_psum], repetitions=1) # Ensure tiling up of symbol_values works as expected. - sampled_expectation.SampledExpectation()(symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5], [0.8]], - operators=test_psum, - repetitions=1) - sampled_expectation.SampledExpectation()(symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=test_psum, - repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5], [0.8]], + operators=test_psum, + repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=test_psum, + repetitions=1) # Test multiple operators with integer valued repetition. - sampled_expectation.SampledExpectation()( - symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=[-1.0 * cirq.Z(bit), - cirq.X(bit) + 2.0 * cirq.Z(bit)], - repetitions=1) - sampled_expectation.SampledExpectation()( - symb_circuit, - symbol_names=[symbol], - symbol_values=[[0.5]], - operators=[-1.0 * cirq.Z(bit), - cirq.X(bit) + 2.0 * cirq.Z(bit)], - repetitions=[5, 1]) - - def test_sampled_expectation_simple_tf_train(self): + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=[-1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit)], + repetitions=1) + sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(symb_circuit, + symbol_names=[symbol], + symbol_values=[[0.5]], + operators=[-1.0 * cirq.Z(bit), + cirq.X(bit) + 2.0 * cirq.Z(bit)], + repetitions=[5, 1]) + + @parameterized.parameters([{ + 'use_cuquantum': False, + }, { + 'use_cuquantum': True, + }]) + def test_sampled_expectation_simple_tf_train(self, use_cuquantum): """Train a layer using standard tf (not keras).""" + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) bit = cirq.GridQubit(0, 0) circuit = cirq.Circuit(cirq.rx(sympy.Symbol('theta'))(bit)) - layer = sampled_expectation.SampledExpectation() + layer = sampled_expectation.SampledExpectation( + use_cuquantum=use_cuquantum) optimizer = tf.optimizers.Adam(learning_rate=0.05) - for _ in range(10): + for _ in range(20): with tf.GradientTape() as tape: circuit_out = layer(circuit, symbol_names=['theta'], operators=cirq.Z(bit), - repetitions=100) + repetitions=1000, + initializer=initializer) mse = tf.square(tf.reduce_sum(tf.subtract(circuit_out, -1))) grads = tape.gradient(mse, layer.trainable_weights) optimizer.apply_gradients(zip(grads, layer.trainable_weights)) - self.assertAllClose(mse.numpy(), 0, atol=1e-3) + self.assertAllClose(mse.numpy(), 0, atol=1e-2) -class SampledExpectationFunctionalTests(tf.test.TestCase): +class SampledExpectationFunctionalTests(parameterized.TestCase, + tf.test.TestCase): """Test hybrid/integrated models that include a SampledExpectation layer.""" - def test_simple_param_value_input(self): + @parameterized.parameters([{ + 'backend': 'noisy', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': True, + }]) + def test_simple_param_value_input(self, backend, use_cuquantum): """Train a densely connected hybrid model. This model will put a qubit in the zero or one state from a random state given the input zero or one. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') - circuit = _gen_single_bit_rotation_problem(bit, symbols) + circuit = _gen_single_bit_rotation_problem( + bit, symbols, True if backend == 'noisy' else False) inputs = tf.keras.Input(shape=(1,), dtype=tf.dtypes.float64) datum = tf.keras.Input(shape=(), dtype=tf.dtypes.string) l1 = tf.keras.layers.Dense(10)(inputs) l2 = tf.keras.layers.Dense(3)(l1) - outputs = sampled_expectation.SampledExpectation()( - datum, - symbol_names=symbols, - operators=cirq.Z(bit), - symbol_values=l2, - repetitions=5000) + outputs = sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(datum, + symbol_names=symbols, + operators=cirq.Z(bit), + symbol_values=l2, + repetitions=5000, + initializer=initializer) model = tf.keras.Model(inputs=[datum, inputs], outputs=outputs) data_in = np.array([[1], [0]], dtype=np.float32) @@ -287,33 +479,53 @@ def test_simple_param_value_input(self): history = model.fit(x=[circuits, data_in], y=data_out, epochs=30) self.assertAllClose(history.history['loss'][-1], 0, atol=0.3) - def test_simple_op_input(self): + @parameterized.parameters([{ + 'backend': 'noisy', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': True, + }]) + def test_simple_op_input(self, backend, use_cuquantum): """Test a simple operator input Learn qubit in the z+ state using two different measurement operators. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) n = tf.convert_to_tensor([[5000], [5000]], dtype=tf.int32) - circuit = util.convert_to_tensor( - [_gen_single_bit_rotation_problem(bit, symbols)] * 2) + circuit = util.convert_to_tensor([ + _gen_single_bit_rotation_problem( + bit, symbols, True if backend == 'noisy' else False) + ] * 2) data_out = tf.convert_to_tensor(np.array([[1], [1]])) op_inp = tf.keras.Input(shape=(1,), dtype=tf.dtypes.string) n_inp = tf.keras.Input(shape=(1,), dtype=tf.dtypes.int32) circuit_inp = tf.keras.Input(shape=(), dtype=tf.dtypes.string) - circuit_output = sampled_expectation.SampledExpectation()( - circuit_inp, - symbol_names=symbols, - operators=op_inp, - repetitions=n_inp) + circuit_output = sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(circuit_inp, + symbol_names=symbols, + operators=op_inp, + repetitions=n_inp, + initializer=initializer) model = tf.keras.Model(inputs=[circuit_inp, op_inp, n_inp], outputs=[circuit_output]) model.compile( - optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), + optimizer=tf.keras.optimizers.Adam(learning_rate=0.2), loss=tf.keras.losses.mean_squared_error, ) history = model.fit(x=[circuit, ops, n], @@ -323,18 +535,35 @@ def test_simple_op_input(self): self.assertAllClose(history.history['loss'][-1], 0, atol=1e-2) - def test_simple_op_and_param_input(self): + @parameterized.parameters([{ + 'backend': 'noisy', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': True, + }]) + def test_simple_op_and_param_input(self, backend, use_cuquantum): """Test a simple operator and parameter input. Train a NN to put a qubit in the z+ or x+ states based on a classical binary input. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x y z') ops = util.convert_to_tensor([[cirq.Z(bit)], [cirq.Z(bit)]]) n = tf.convert_to_tensor([[5000], [5000]], dtype=tf.int32) - circuits = util.convert_to_tensor( - [_gen_single_bit_rotation_problem(bit, symbols)] * 2) + circuits = util.convert_to_tensor([ + _gen_single_bit_rotation_problem( + bit, symbols, True if backend == 'noisy' else False) + ] * 2) data_in = np.array([[1], [0]]) data_out = np.array([[1], [1]]) @@ -344,12 +573,15 @@ def test_simple_op_and_param_input(self): circuit_inp = tf.keras.Input(shape=(), dtype=tf.dtypes.string) dense_1 = tf.keras.layers.Dense(10)(data_inp) dense_2 = tf.keras.layers.Dense(3)(dense_1) - circuit_output = sampled_expectation.SampledExpectation()( - circuit_inp, - symbol_names=symbols, - symbol_values=dense_2, - operators=op_inp, - repetitions=n_inp) + circuit_output = sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(circuit_inp, + symbol_names=symbols, + symbol_values=dense_2, + operators=op_inp, + repetitions=n_inp, + initializer=initializer) functional_model = tf.keras.Model( inputs=[circuit_inp, data_inp, op_inp, n_inp], @@ -364,16 +596,33 @@ def test_simple_op_and_param_input(self): epochs=20) self.assertAllClose(history.history['loss'][-1], 0, atol=3) - def test_dnn_qnn_dnn(self): + @parameterized.parameters([{ + 'backend': 'noisy', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': False, + }, { + 'backend': 'noiseless', + 'use_cuquantum': True, + }]) + def test_dnn_qnn_dnn(self, backend, use_cuquantum): """Train a fully hybrid network using an SampledExpectation layer. Train the network to output +-5 given an input of 1 or 0. This tests that everything works when SampledExpectation layer is a middle layers. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + tf.random.set_seed(RANDOM_SEED) + initializer = tf.keras.initializers.RandomUniform(0, 2 * np.pi) bit = cirq.GridQubit(0, 0) symbols = sympy.symbols('x, y, z') - circuits = util.convert_to_tensor( - [_gen_single_bit_rotation_problem(bit, symbols)] * 2) + circuits = util.convert_to_tensor([ + _gen_single_bit_rotation_problem( + bit, symbols, True if backend == 'noisy' else False) + ] * 2) data_in = np.array([[1], [0]], dtype=np.float32) data_out = np.array([[5], [-5]], dtype=np.float32) @@ -381,12 +630,15 @@ def test_dnn_qnn_dnn(self): circuit_input = tf.keras.Input(shape=(), dtype=tf.dtypes.string) d1 = tf.keras.layers.Dense(10)(classical_input) d2 = tf.keras.layers.Dense(3)(d1) - quantum = sampled_expectation.SampledExpectation()( - circuit_input, - symbol_names=symbols, - symbol_values=d2, - operators=cirq.Z(bit), - repetitions=5000) + quantum = sampled_expectation.SampledExpectation( + backend=backend, + use_cuquantum=use_cuquantum, + )(circuit_input, + symbol_names=symbols, + symbol_values=d2, + operators=cirq.Z(bit), + repetitions=5000, + initializer=initializer) d3 = tf.keras.layers.Dense(1)(quantum) model = tf.keras.Model(inputs=[circuit_input, classical_input], diff --git a/tensorflow_quantum/python/layers/circuit_executors/state.py b/tensorflow_quantum/python/layers/circuit_executors/state.py index 6f979139a..456a83463 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/state.py +++ b/tensorflow_quantum/python/layers/circuit_executors/state.py @@ -11,11 +11,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A tf.keras.layer that ingests programs and parameters and outputs a state.""" import tensorflow as tf from tensorflow_quantum.core.ops import circuit_execution_ops +from tensorflow_quantum.python import quantum_context from tensorflow_quantum.python.layers.circuit_executors import input_checks @@ -112,7 +113,7 @@ class State(tf.keras.layers.Layer): """ - def __init__(self, backend=None, **kwargs): + def __init__(self, backend=None, use_cuquantum=False, **kwargs): """Instantiate a State Layer. Create a layer that will simulate a quantum state and output it into @@ -126,18 +127,35 @@ def __init__(self, backend=None, **kwargs): `cirq.SimulatesFinalState`. Note that C++ Density Matrix simulation is not yet supported so to do Density Matrix simulation please use `cirq.DensityMatrixSimulator`. + use_cuquantum: Calls TFQ GPU version op. """ super().__init__(**kwargs) - self.state_op = circuit_execution_ops.get_state_op(backend) + + used_op = None + if backend == 'noiseless' or backend is None: + mode = quantum_context.get_quantum_concurrent_op_mode() + quantum_concurrent = False if use_cuquantum else mode + used_op = circuit_execution_ops.get_state_op( + backend=None, + use_cuquantum=use_cuquantum, + quantum_concurrent=quantum_concurrent, + ) + elif backend == 'noisy': + raise ValueError('noisy backend is not supported in State layer.') + else: + used_op = circuit_execution_ops.get_state_op(backend=backend) + + self.state_op = used_op def call(self, inputs, *, symbol_names=None, symbol_values=None): """Keras call function. - Input options: - `inputs`, `symbol_names`, `symbol_values`: - see `input_checks.expand_circuits` + Args: + inputs: See `input_checks.expand_circuits. + symbol_names: See `input_checks.expand_circuits. + symbol_values: See `input_checks.expand_circuits. - Output shape: + Returns: `tf.RaggedTensor` with shape: [batch size of symbol_values, ] or diff --git a/tensorflow_quantum/python/layers/circuit_executors/state_test.py b/tensorflow_quantum/python/layers/circuit_executors/state_test.py index 2442fa20f..21286cfb6 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/state_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/state_test.py @@ -11,14 +11,23 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for tensorflow_quantum.layers.circuit_executors.state.""" +# 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 + import numpy as np from absl.testing import parameterized import sympy import tensorflow as tf import cirq +from tensorflow_quantum.core.ops import circuit_execution_ops from tensorflow_quantum.python.layers.circuit_executors import state from tensorflow_quantum.python import util @@ -38,15 +47,24 @@ def test_state_create(self): state.State('junk') @parameterized.parameters([{ - 'backend': None + 'backend': None, + 'use_cuquantum': False, + }, { + 'backend': None, + 'use_cuquantum': True, }, { - 'backend': cirq.Simulator() + 'backend': cirq.Simulator(), + 'use_cuquantum': False, }, { - 'backend': cirq.DensityMatrixSimulator() + 'backend': cirq.DensityMatrixSimulator(), + 'use_cuquantum': False, }]) - def test_state_invalid_combinations(self, backend): + def test_state_invalid_combinations(self, backend, use_cuquantum): """Test with valid type inputs and valid value, but incorrect combo.""" - state_calc = state.State(backend) + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") + state_calc = state.State(backend, use_cuquantum=use_cuquantum) symbol = sympy.Symbol('alpha') circuit = cirq.Circuit(cirq.H(cirq.GridQubit(0, 0))**symbol) with self.assertRaisesRegex(Exception, expected_regex=""): @@ -102,18 +120,26 @@ def test_sample_outputs_simple(self): @parameterized.parameters([ { - 'backend_output': (None, WF_OUTPUT) + 'backend_output': (None, WF_OUTPUT), + 'use_cuquantum': False, }, { - 'backend_output': (cirq.sim.sparse_simulator.Simulator(), WF_OUTPUT) + 'backend_output': (None, WF_OUTPUT), + 'use_cuquantum': True, + }, + { + 'backend_output': + (cirq.sim.sparse_simulator.Simulator(), WF_OUTPUT), + 'use_cuquantum': False, }, { 'backend_output': (cirq.sim.density_matrix_simulator.DensityMatrixSimulator(), - DM_OUTPUT) + DM_OUTPUT), + 'use_cuquantum': False, }, ]) - def test_state_output(self, backend_output): + def test_state_output(self, backend_output, use_cuquantum): """Check that any output type is as expected. This layer only allows for 2 different outputs, depending on whether a @@ -121,9 +147,15 @@ def test_state_output(self, backend_output): post processing done inside the layers should not cause output from the layer to structurally deviate from what is expected. """ + if use_cuquantum and not circuit_execution_ops.is_gpu_configured(): + # GPU is not set. Ignores this sub-test. + self.skipTest("GPU is not set. Ignoring gpu tests...") backend = backend_output[0] output = backend_output[1] - state_executor = state.State(backend=backend) + state_executor = state.State( + backend=backend, + use_cuquantum=use_cuquantum, + ) bits = cirq.GridQubit.rect(1, 2) circuit = cirq.Circuit() circuit.append(cirq.H.on(bits[0])) diff --git a/tensorflow_quantum/python/layers/circuit_executors/unitary.py b/tensorflow_quantum/python/layers/circuit_executors/unitary.py index 34e9385f7..73bd40c83 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/unitary.py +++ b/tensorflow_quantum/python/layers/circuit_executors/unitary.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A tf.keras.layer that ingests programs and outputs a unitary.""" import tensorflow as tf diff --git a/tensorflow_quantum/python/layers/circuit_executors/unitary_test.py b/tensorflow_quantum/python/layers/circuit_executors/unitary_test.py index e38408b81..30a84eecd 100644 --- a/tensorflow_quantum/python/layers/circuit_executors/unitary_test.py +++ b/tensorflow_quantum/python/layers/circuit_executors/unitary_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for tensorflow_quantum.layers.circuit_executors.unitary.""" +# 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 + import numpy as np from absl.testing import parameterized import sympy diff --git a/tensorflow_quantum/python/layers/high_level/BUILD b/tensorflow_quantum/python/layers/high_level/BUILD index 3163a03b6..aca7f6625 100644 --- a/tensorflow_quantum/python/layers/high_level/BUILD +++ b/tensorflow_quantum/python/layers/high_level/BUILD @@ -5,9 +5,22 @@ licenses(["notice"]) # Export for the PIP package. exports_files(["__init__.py"]) +py_library( + name = "high_level", + srcs = ["__init__.py"], + srcs_version = "PY3", + deps = [ + ":controlled_pqc", + ":noisy_controlled_pqc", + ":pqc", + ":noisy_pqc", + ], +) + py_library( name = "controlled_pqc", srcs = ["controlled_pqc.py"], + srcs_version = "PY3", deps = [ "//tensorflow_quantum/python:util", "//tensorflow_quantum/python/layers/circuit_construction:elementary", @@ -16,9 +29,23 @@ py_library( ], ) +py_library( + name = "noisy_controlled_pqc", + srcs = ["noisy_controlled_pqc.py"], + srcs_version = "PY3", + deps = [ + "//tensorflow_quantum/python:util", + "//tensorflow_quantum/python/layers/circuit_construction:elementary", + "//tensorflow_quantum/core/ops/noise:noisy_expectation_op_py", + "//tensorflow_quantum/core/ops/noise:noisy_sampled_expectation_op_py", + "//tensorflow_quantum/python/differentiators:parameter_shift", + ], +) + py_library( name = "pqc", srcs = ["pqc.py"], + srcs_version = "PY3", deps = [ "//tensorflow_quantum/python:util", "//tensorflow_quantum/python/layers/circuit_construction:elementary", @@ -27,6 +54,19 @@ py_library( ], ) +py_library( + name = "noisy_pqc", + srcs = ["noisy_pqc.py"], + srcs_version = "PY3", + deps = [ + "//tensorflow_quantum/python:util", + "//tensorflow_quantum/python/layers/circuit_construction:elementary", + "//tensorflow_quantum/core/ops/noise:noisy_expectation_op_py", + "//tensorflow_quantum/core/ops/noise:noisy_sampled_expectation_op_py", + "//tensorflow_quantum/python/differentiators:parameter_shift", + ], +) + py_test( name = "controlled_pqc_test", srcs = ["controlled_pqc_test.py"], @@ -46,3 +86,23 @@ py_test( "//tensorflow_quantum/python:util", ], ) + +py_test( + name = "noisy_controlled_pqc_test", + srcs = ["noisy_controlled_pqc_test.py"], + python_version = "PY3", + deps = [ + ":noisy_controlled_pqc", + "//tensorflow_quantum/python:util", + ], +) + +py_test( + name = "noisy_pqc_test", + srcs = ["noisy_pqc_test.py"], + python_version = "PY3", + deps = [ + ":noisy_pqc", + "//tensorflow_quantum/python:util", + ], +) diff --git a/tensorflow_quantum/python/layers/high_level/__init__.py b/tensorflow_quantum/python/layers/high_level/__init__.py index 8e0359840..19e1a000b 100644 --- a/tensorflow_quantum/python/layers/high_level/__init__.py +++ b/tensorflow_quantum/python/layers/high_level/__init__.py @@ -11,10 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.python.layers.high_level.*""" # pylint: disable=line-too-long from tensorflow_quantum.python.layers.high_level.controlled_pqc import ControlledPQC +from tensorflow_quantum.python.layers.high_level.noisy_controlled_pqc import \ + NoisyControlledPQC +from tensorflow_quantum.python.layers.high_level.noisy_pqc import NoisyPQC from tensorflow_quantum.python.layers.high_level.pqc import PQC # pylint: enable=line-too-long diff --git a/tensorflow_quantum/python/layers/high_level/controlled_pqc.py b/tensorflow_quantum/python/layers/high_level/controlled_pqc.py index 386823e55..7a781f852 100644 --- a/tensorflow_quantum/python/layers/high_level/controlled_pqc.py +++ b/tensorflow_quantum/python/layers/high_level/controlled_pqc.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.python.layers.high_level.controlled_pqc layer.""" import numbers import numpy as np @@ -86,7 +86,7 @@ class ControlledPQC(tf.keras.layers.Layer): to indicate the differentiation scheme this `ControlledPQC` layer should use. Here's how you would take the gradients of the above example using a `cirq.Simulator` backend (which is slower - than `backend=None` which uses C++): + than `backend='noiseless'` which uses C++): >>> bit = cirq.GridQubit(0, 0) @@ -127,7 +127,8 @@ def __init__(self, operators, *, repetitions=None, - backend=None, + backend='noiseless', + use_cuquantum=False, differentiator=None, **kwargs): """Instantiate this layer. @@ -147,11 +148,14 @@ def __init__(self, when estimating expectation values. If `None` analytic expectation calculation is used. backend: Optional Backend to use to simulate states. Defaults to - the native TensorFlow simulator (None), however users may also + the noiseless TensorFlow simulator, however users may also specify a preconfigured cirq simulation object to use instead. - If a cirq object is given it must inherit `cirq.SimulatesFinalState` - if `sampled_based` is True or it must inherit `cirq.Sampler` if - `sample_based` is False. + If a cirq object is given it must inherit `cirq.Sampler` if + `sampled_based` is True or it must inherit + `cirq.sim.simulator.SimulatesExpectationValues` if `sample_based` is + False. + use_cuquantum: Optional Python `bool` indicating whether or not to use + GPU ops differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. """ @@ -208,27 +212,39 @@ def __init__(self, [[repetitions for _ in range(len(operators))]], dtype=tf.dtypes.int32) - if not isinstance(backend, cirq.Sampler - ) and repetitions is not None and backend is not None: + # Ingest backend and differentiator. + if backend == 'noisy': + raise ValueError("noisy backend value is not supported in " + "tfq.layers.ControlledPQC. Please use " + "tfq.layers.NoisyControlledPQC instead.") + + not_default = backend != 'noiseless' + not_default &= backend is not None # legacy backend=None support. + if not isinstance( + backend, + cirq.Sampler) and repetitions is not None and not_default: raise TypeError("provided backend does not inherit cirq.Sampler " "and repetitions!=None. Please provide a backend " "that inherits cirq.Sampler or set " "repetitions=None.") - if not isinstance(backend, cirq.SimulatesFinalState - ) and repetitions is None and backend is not None: + if not isinstance(backend, cirq.sim.simulator.SimulatesExpectationValues + ) and repetitions is None and not_default: raise TypeError("provided backend does not inherit " - "cirq.SimulatesFinalState and repetitions=None. " - "Please provide a backend that inherits " - "cirq.SimulatesFinalState.") + "cirq.sim.simulator.SimulatesExpectationValues and " + "repetitions=None. Please provide a backend that " + "inherits " + "cirq.sim.simulator.SimulatesExpectationValues.") - # Ingest backend and differentiator. if self._analytic: self._layer = expectation.Expectation(backend=backend, - differentiator=differentiator) + differentiator=differentiator, + use_cuquantum=use_cuquantum) else: self._layer = sampled_expectation.SampledExpectation( - backend=backend, differentiator=differentiator) + backend=backend, + differentiator=differentiator, + use_cuquantum=use_cuquantum) self._append_layer = elementary.AddCircuit() diff --git a/tensorflow_quantum/python/layers/high_level/controlled_pqc_test.py b/tensorflow_quantum/python/layers/high_level/controlled_pqc_test.py index 34bf38922..11f7e1e59 100644 --- a/tensorflow_quantum/python/layers/high_level/controlled_pqc_test.py +++ b/tensorflow_quantum/python/layers/high_level/controlled_pqc_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test module for tfq.python.layers.high_level.controlled_pqc layer.""" +# 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 + import numpy as np import tensorflow as tf from absl.testing import parameterized @@ -36,16 +44,27 @@ def test_controlled_pqc_instantiate(self): cirq.Z(bit), repetitions=500) + def test_controlled_pqc_noisy_error(self): + """Ensure error refers to alternate layer.""" + symbol = sympy.Symbol('alpha') + qubit = cirq.GridQubit(0, 0) + learnable_flip = cirq.Circuit(cirq.X(qubit)**symbol) + with self.assertRaisesRegex( + ValueError, expected_regex='tfq.layers.NoisyControlledPQC'): + controlled_pqc.ControlledPQC(learnable_flip, + cirq.Z(qubit), + backend='noisy') + def test_controlled_pqc_backend_error(self): """Test that invalid backends error properly.""" symbol = sympy.Symbol('alpha') bit = cirq.GridQubit(0, 0) learnable_flip = cirq.Circuit(cirq.X(bit)**symbol) - class MyState(cirq.SimulatesFinalState): - """My state simulator.""" + class MyExpectation(cirq.sim.simulator.SimulatesExpectationValues): + """My expectation values simulator.""" - def simulate_sweep(self): + def simulate_expectation_values_sweep(self): """do nothing.""" return @@ -56,14 +75,16 @@ def run_sweep(self): """do nothing.""" return - with self.assertRaisesRegex(TypeError, - expected_regex="cirq.SimulatesFinalState"): + with self.assertRaisesRegex( + TypeError, + expected_regex="cirq.sim.simulator.SimulatesExpectation"): controlled_pqc.ControlledPQC(learnable_flip, cirq.Z(bit), backend='junk') - with self.assertRaisesRegex(TypeError, - expected_regex="cirq.SimulatesFinalState"): + with self.assertRaisesRegex( + TypeError, + expected_regex="cirq.sim.simulator.SimulatesExpectation"): controlled_pqc.ControlledPQC(learnable_flip, cirq.Z(bit), repetitions=None, @@ -73,7 +94,7 @@ def run_sweep(self): controlled_pqc.ControlledPQC(learnable_flip, cirq.Z(bit), repetitions=500, - backend=MyState) + backend=MyExpectation) def test_controlled_pqc_model_circuit_error(self): """Test that invalid circuits error properly.""" diff --git a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py new file mode 100644 index 000000000..2d6565dfc --- /dev/null +++ b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc.py @@ -0,0 +1,267 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Module for tfq.python.layers.high_level.noisy_controlled_pqc layer.""" +import numbers +import numpy as np +import tensorflow as tf + +import cirq +import sympy +from tensorflow_quantum.core.ops.noise import noisy_expectation_op +from tensorflow_quantum.core.ops.noise import noisy_sampled_expectation_op +from tensorflow_quantum.python.differentiators import parameter_shift +from tensorflow_quantum.python.layers.circuit_construction import elementary +from tensorflow_quantum.python import util + + +class NoisyControlledPQC(tf.keras.layers.Layer): + """Noisy Controlled Parametrized Quantum Circuit (PQC) Layer. + + The `NoisyControlledPQC` layer is the noisy variant of the `ControlledPQC` + layer. This layer uses monte carlo trajectory simulation to support noisy + simulation functionality for the `ControlledPQC` layer. Here is a simple + example you can use to get started: + + + >>> bit = cirq.GridQubit(0, 0) + >>> model = cirq.Circuit( + ... cirq.X(bit) ** sympy.Symbol('alpha'), + ... cirq.Z(bit) ** sympy.Symbol('beta'), + ... cirq.depolarize(0.01)(bit) + ... ) + >>> outputs = tfq.layers.NoisyControlledPQC( + ... model, + ... cirq.Z(bit), + ... repetitions=1000, + ... sample_based=False + .. ) + >>> quantum_data = tfq.convert_to_tensor([ + ... cirq.Circuit(), + ... cirq.Circuit(cirq.X(bit)) + ... ]) + >>> model_params = tf.convert_to_tensor([[0.5, 0.5], [0.25, 0.75]]) + >>> res = outputs([quantum_data, model_params]) + >>> res + tf.Tensor( + [[-1.4901161e-08] + [-7.0710683e-01]], shape=(2, 1), dtype=float32) + + + The above example estimates the noisy expectation values using 1000 + monte-carlo trajectory simulations with analytical calculations done on each + trajectory. Just like with the `PQC` it is *very important* that the quantum + datapoint circuits do not contain any `sympy.Symbols` themselves (This can + be supported with advanced usage of the `tfq.layers.Expectation` layer with + backend='noisy'). Just like `ControlledPQC` it is possible to specify + multiple readout operations and switch to sample based expectation + calculation based on measured bitstrings instead of analytic calculation: + + + >>> bit = cirq.GridQubit(0, 0) + >>> model = cirq.Circuit( + ... cirq.X(bit) ** sympy.Symbol('alpha'), + ... cirq.Z(bit) ** sympy.Symbol('beta'), + ... cirq.depolarize(0.01)(bit) + ... ) + >>> outputs = tfq.layers.NoisyControlledPQC( + ... model, + ... [cirq.Z(bit), cirq.X(bit), cirq.Y(bit)], + ... repetitions=1000, + ... sample_based=True + ... ) + >>> quantum_data = tfq.convert_to_tensor([ + ... cirq.Circuit(), + ... cirq.Circuit(cirq.X(bit)) + ... ]) + >>> model_params = tf.convert_to_tensor([[0.5, 0.5], [0.25, 0.75]]) + >>> res = outputs([quantum_data, model_params]) + >>> res + tf.Tensor( + [[-0.0028 1. -0.0028] + [-0.6956 -0.498 -0.498 ]], shape=(2, 3), dtype=float32) + + + Unlike `ControlledPQC` a value for `backend` can not be supplied in the + layer constructor. If you want to use a custom backend please use + `tfq.layers.PQC` instead. A value for `differentiator` can also be supplied + in the constructor to indicate the differentiation scheme this + `NoisyControlledPQC` layer should use. Here's how you would take the + gradients of the above example: + + + >>> bit = cirq.GridQubit(0, 0) + >>> model = cirq.Circuit( + ... cirq.X(bit) ** sympy.Symbol('alpha'), + ... cirq.Z(bit) ** sympy.Symbol('beta'), + ... cirq.depolarize(0.01)(bit) + ... ) + >>> outputs = tfq.layers.NoisyControlledPQC( + ... model, + ... [cirq.Z(bit), cirq.X(bit), cirq.Y(bit)], + ... repetitions=5000, + ... sample_based=True, + ... differentiator=tfq.differentiators.ParameterShift()) + >>> quantum_data = tfq.convert_to_tensor([ + ... cirq.Circuit(), + ... cirq.Circuit(cirq.X(bit)) + ... ]) + >>> model_params = tf.convert_to_tensor([[0.5, 0.5], [0.25, 0.75]]) + >>> with tf.GradientTape() as g: + ... g.watch(model_params) + ... res = outputs([quantum_data, model_params]) + >>> grads = g.gradient(res, model_params) + >>> grads + tf.Tensor( + [[-3.1415927 3.1415927 ] + [-0.9211149 0.02764606]], shape=(2, 2), dtype=float32)] + + + Lastly, like all layers in TensorFlow the `NoisyControlledPQC` layer can be + called on any `tf.Tensor` as long as it is the right shape. This means + you could replace `model_params` in the above example with the outputs + from a `tf.keras.Dense` layer or replace `quantum_data` with values fed + in from a `tf.keras.Input`. + """ + + def __init__(self, + model_circuit, + operators, + *, + repetitions=None, + sample_based=None, + differentiator=None, + use_cuquantum=False, + **kwargs): + """Instantiate this layer. + + Create a layer that will output noisy expectation values of the given + operators when fed quantum data to it's input layer. This layer will + take two input tensors, one representing a quantum data source (these + circuits must not contain any symbols) and the other representing + control parameters for the model circuit that gets appended to the + datapoints. + + model_circuit: `cirq.Circuit` containing `sympy.Symbols` that will be + used as the model which will be fed quantum data inputs. + operators: `cirq.PauliSum` or Python `list` of `cirq.PauliSum` objects + used as observables at the end of the model circuit. + repetitions: Python `int` indicating how many trajectories to use + when estimating expectation values. + sample_based: Python `bool` indicating whether to use sampling to + estimate expectations or analytic calculations with each + trajectory. + differentiator: Optional `tfq.differentiator` object to specify how + gradients of `model_circuit` should be calculated. + use_cuquantum: Optional `bool` indicating whether to use GPU for + simulation or not. Defaults to `False`. NOT IMPLEMENTED YET. + """ + super().__init__(**kwargs) + # Ingest model_circuit. + if not isinstance(model_circuit, cirq.Circuit): + raise TypeError("model_circuit must be a cirq.Circuit object." + " Given: ".format(model_circuit)) + + self._symbols_list = list( + sorted(util.get_circuit_symbols(model_circuit))) + self._symbols = tf.constant([str(x) for x in self._symbols_list]) + + self._circuit = util.convert_to_tensor([model_circuit]) + + if len(self._symbols_list) == 0: + raise ValueError("model_circuit has no sympy.Symbols. Please " + "provide a circuit that contains symbols so " + "that their values can be trained.") + + # Ingest operators. + if isinstance(operators, (cirq.PauliString, cirq.PauliSum)): + operators = [operators] + + if not isinstance(operators, (list, np.ndarray, tuple)): + raise TypeError("operators must be a cirq.PauliSum or " + "cirq.PauliString, or a list, tuple, " + "or np.array containing them. " + "Got {}.".format(type(operators))) + if not all([ + isinstance(op, (cirq.PauliString, cirq.PauliSum)) + for op in operators + ]): + raise TypeError("Each element in operators to measure " + "must be a cirq.PauliString" + " or cirq.PauliSum") + + self._operators = util.convert_to_tensor([operators]) + + # Ingest and promote repetitions. + if repetitions is None: + raise ValueError("Value for repetitions must be provided when " + "using noisy simulation.") + if not isinstance(repetitions, numbers.Integral): + raise TypeError("repetitions must be a positive integer value." + " Given: ".format(repetitions)) + if repetitions <= 0: + raise ValueError("Repetitions must be greater than zero.") + + self._repetitions = tf.constant( + [[repetitions for _ in range(len(operators))]], + dtype=tf.dtypes.int32) + + # Ingest differentiator. + if differentiator is None: + differentiator = parameter_shift.ParameterShift() + + # Use gpu not supported yet. + if use_cuquantum: + raise NotImplementedError("GPU support for noisy controlled PQC \ + is not yet implemented.") + + # Ingest and promote sample based. + if sample_based is None: + raise ValueError("Please specify sample_based=False for analytic " + "calculations based on monte-carlo trajectories," + " or sampled_based=True for measurement based " + "noisy estimates.") + if not isinstance(sample_based, bool): + raise TypeError("sample_based must be either True or False." + " received: {}".format(type(sample_based))) + + if not sample_based: + self._executor = differentiator.generate_differentiable_op( + sampled_op=noisy_expectation_op.expectation) + else: + self._executor = differentiator.generate_differentiable_op( + sampled_op=noisy_sampled_expectation_op.sampled_expectation) + + self._append_layer = elementary.AddCircuit() + + @property + def symbols(self): + """The symbols that are managed by this layer (in-order). + + Note: `symbols[i]` indicates what symbol name the managed variables in + this layer map to. + """ + return [sympy.Symbol(x) for x in self._symbols_list] + + def call(self, inputs): + """Keras call function.""" + circuit_batch_dim = tf.gather(tf.shape(inputs[0]), 0) + tiled_up_model = tf.tile(self._circuit, [circuit_batch_dim]) + model_appended = self._append_layer(inputs[0], append=tiled_up_model) + tiled_up_operators = tf.tile(self._operators, [circuit_batch_dim, 1]) + + tiled_up_repetitions = tf.tile(self._repetitions, + [circuit_batch_dim, 1]) + return self._executor(model_appended, self._symbols, inputs[1], + tiled_up_operators, tiled_up_repetitions) \ No newline at end of file diff --git a/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc_test.py b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc_test.py new file mode 100644 index 000000000..111f2c506 --- /dev/null +++ b/tensorflow_quantum/python/layers/high_level/noisy_controlled_pqc_test.py @@ -0,0 +1,182 @@ +# Copyright 2019 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Test module for tfq.python.layers.high_level.controlled_pqc layer.""" +# 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 + +import numpy as np +import tensorflow as tf +from absl.testing import parameterized +import cirq +import sympy + +from tensorflow_quantum.python.layers.high_level import noisy_controlled_pqc +from tensorflow_quantum.python import util + + +class NoisyControlledPQCTest(tf.test.TestCase, parameterized.TestCase): + """Tests for the NoisyControlledPQC layer.""" + + def test_controlled_pqc_instantiate(self): + """Basic creation test.""" + symbol = sympy.Symbol('alpha') + bit = cirq.GridQubit(0, 0) + learnable_flip = cirq.Circuit(cirq.X(bit)**symbol) + noisy_controlled_pqc.NoisyControlledPQC(learnable_flip, + cirq.Z(bit), + repetitions=500, + sample_based=False) + + def test_controlled_pqc_model_circuit_error(self): + """Test that invalid circuits error properly.""" + bit = cirq.GridQubit(0, 0) + no_symbols = cirq.Circuit(cirq.X(bit)) + + with self.assertRaisesRegex(TypeError, expected_regex="cirq.Circuit"): + noisy_controlled_pqc.NoisyControlledPQC('junk', + cirq.Z(bit), + repetitions=500, + sample_based=False) + + with self.assertRaisesRegex(ValueError, + expected_regex="no sympy.Symbols"): + noisy_controlled_pqc.NoisyControlledPQC(no_symbols, + cirq.Z(bit), + repetitions=500, + sample_based=False) + + def test_controlled_pqc_operators_error(self): + """Test that invalid operators error properly.""" + symbol = sympy.Symbol('alpha') + bit = cirq.GridQubit(0, 0) + learnable_flip = cirq.Circuit(cirq.X(bit)**symbol) + + with self.assertRaisesRegex( + TypeError, expected_regex="cirq.PauliSum or cirq.PauliString"): + noisy_controlled_pqc.NoisyControlledPQC(learnable_flip, + 'junk', + repetitions=500, + sample_based=False) + + with self.assertRaisesRegex(TypeError, expected_regex="Each element"): + noisy_controlled_pqc.NoisyControlledPQC(learnable_flip, + [[cirq.Z(bit)]], + repetitions=500, + sample_based=False) + + with self.assertRaisesRegex(TypeError, expected_regex="Each element"): + noisy_controlled_pqc.NoisyControlledPQC(learnable_flip, + [cirq.Z(bit), 'bad'], + repetitions=500, + sample_based=False) + + def test_controlled_pqc_repetitions_error(self): + """Test that invalid repetitions error properly.""" + symbol = sympy.Symbol('alpha') + bit = cirq.GridQubit(0, 0) + learnable_flip = cirq.Circuit(cirq.X(bit)**symbol) + + with self.assertRaisesRegex(ValueError, + expected_regex="greater than zero."): + noisy_controlled_pqc.NoisyControlledPQC(learnable_flip, + cirq.Z(bit), + repetitions=-100, + sample_based=False) + + with self.assertRaisesRegex(TypeError, + expected_regex="positive integer value"): + noisy_controlled_pqc.NoisyControlledPQC(learnable_flip, + cirq.Z(bit), + repetitions='junk', + sample_based=False) + + with self.assertRaisesRegex(ValueError, + expected_regex="must be provided"): + noisy_controlled_pqc.NoisyControlledPQC(learnable_flip, + cirq.Z(bit), + sample_based=False) + + def test_noisy_controlled_pqc_sample_based_error(self): + """Test that invalid sampled_based values error properly.""" + symbol = sympy.Symbol('alpha') + qubit = cirq.GridQubit(0, 0) + learnable_flip = cirq.Circuit(cirq.X(qubit)**symbol) + + with self.assertRaisesRegex(TypeError, expected_regex="True or False"): + noisy_controlled_pqc.NoisyControlledPQC(learnable_flip, + cirq.Z(qubit), + repetitions=10, + sample_based='junk') + + with self.assertRaisesRegex( + ValueError, expected_regex="specify sample_based=False"): + noisy_controlled_pqc.NoisyControlledPQC(learnable_flip, + cirq.Z(qubit), + repetitions=10) + + def test_controlled_pqc_symbols_property(self): + """Test that the `symbols` property returns the symbols.""" + c, b, a, d = sympy.symbols('c b a d') + bit = cirq.GridQubit(0, 0) + test_circuit = cirq.Circuit( + cirq.H(bit)**a, + cirq.Z(bit)**b, + cirq.X(bit)**d, + cirq.Y(bit)**c) + layer = noisy_controlled_pqc.NoisyControlledPQC(test_circuit, + cirq.Z(bit), + repetitions=100, + sample_based=False) + self.assertEqual(layer.symbols, [a, b, c, d]) + + @parameterized.parameters([{'sample_based': True, 'sample_based': False}]) + def test_controlled_pqc_simple_learn(self, sample_based): + """Test a simple learning scenario using analytic and sample expectation + on many backends.""" + bit = cirq.GridQubit(0, 0) + circuit = cirq.Circuit( + cirq.rx(sympy.Symbol('theta'))(bit), + cirq.depolarize(0.01)(bit)) + + inputs = tf.keras.Input(shape=(1,), dtype=tf.dtypes.float32) + quantum_datum = tf.keras.Input(shape=(), dtype=tf.dtypes.string) + l1 = tf.keras.layers.Dense(10)(inputs) + l2 = tf.keras.layers.Dense(1)(l1) + outputs = noisy_controlled_pqc.NoisyControlledPQC( + circuit, cirq.Z(bit), repetitions=5000, + sample_based=sample_based)([quantum_datum, l2]) + model = tf.keras.Model(inputs=[quantum_datum, inputs], outputs=outputs) + + data_in = np.array([[1], [0]], dtype=np.float32) + data_out = np.array([[1], [-1]], dtype=np.float32) + + model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.05), + loss=tf.keras.losses.mean_squared_error) + + data_circuits = util.convert_to_tensor( + [cirq.Circuit(cirq.X(bit)), + cirq.Circuit()]) + + history = model.fit(x=[data_circuits, data_in], y=data_out, epochs=30) + self.assertAllClose(history.history['loss'][-1], 0, atol=1e-1) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/python/layers/high_level/noisy_pqc.py b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py new file mode 100644 index 000000000..0c72668ce --- /dev/null +++ b/tensorflow_quantum/python/layers/high_level/noisy_pqc.py @@ -0,0 +1,303 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Module for tfq.python.layers.high_level.noisy_pqc layer.""" +import numbers +import numpy as np +import tensorflow as tf + +import cirq +import sympy +from tensorflow_quantum.core.ops.noise import \ + noisy_expectation_op, noisy_sampled_expectation_op +from tensorflow_quantum.python.differentiators import parameter_shift +from tensorflow_quantum.python.layers.circuit_construction import elementary +from tensorflow_quantum.python import util + + +class NoisyPQC(tf.keras.layers.Layer): + """Noisy Parametrized Quantum Circuit (PQC) Layer. + + This layer is for training **noisy** parameterized quantum models. + Given a parameterized circuit, this layer initializes the parameters + and manages them in a Keras native way. + + We start by defining a simple quantum circuit on one qubit. + This circuit parameterizes an arbitrary rotation on the Bloch sphere in + terms of the three angles a, b, and c, along with some noise: + + + >>> q = cirq.GridQubit(0, 0) + >>> (a, b, c) = sympy.symbols("a b c") + >>> circuit = cirq.Circuit( + ... cirq.rz(a)(q), + ... cirq.rx(b)(q), + ... cirq.rz(c)(q), + ... cirq.rx(-b)(q), + ... cirq.rz(-a)(q), + ... cirq.depolarize(0.01)(q) + ... ) + + + In order to extract information from our circuit, we must apply measurement + operators. For now we choose to make a Z measurement. In order to observe + an output, we must also feed our model quantum data (NOTE: quantum data + means quantum circuits with no free parameters). Though the output values + will depend on the default random initialization of the angles in our model, + one will be the negative of the other since `cirq.X(q)` causes a bit flip: + + + >>> outputs = tfq.layers.NoisyPQC( + ... circuit, + ... cirq.Z(q), + ... repetitions=1000, + ... sample_based=False + ... ) + >>> quantum_data = tfq.convert_to_tensor([ + ... cirq.Circuit(), + ... cirq.Circuit(cirq.X(q)) + ... ]) + >>> res = outputs(quantum_data) + >>> res + + + + In the above example we estimate the value of the expectation using + monte-carlo trajectory simulations and analytic expectation calculation. + To emulate the process used when sampling from a truly noisy device, we + set `sampled_based=True` to estimate the expectation value via noisy + bitstring sampling. + + + >>> measurement = [cirq.X(q), cirq.Y(q), cirq.Z(q)] + >>> outputs = tfq.layers.NoisyPQC( + ... circuit, + ... measurement, + ... repetitions=5000, + ... sample_based=True + ... ) + >>> quantum_data = tfq.convert_to_tensor([ + ... cirq.Circuit(), + ... cirq.Circuit(cirq.X(q)) + ... ]) + >>> res = outputs(quantum_data) + >>> res + + + + Unlike `tfq.layers.PQC` no value for `backend` can be supplied in the + layer constructor. If you want to use a custom backend please use + `tfq.layers.PQC` instead. A value for `differentiator` can also be + supplied in the constructor to indicate the differentiation scheme this + `NoisyPQC` layer should use. Here's how you would take the gradients of + the above example using a `tfq.layers.ParameterShift` differentiator. + + + >>> measurement = [cirq.X(q), cirq.Y(q), cirq.Z(q)] + >>> outputs = tfq.layers.NoisyPQC( + ... circuit, + ... measurement, + ... repetitions=5000, + ... sample_based=True, + ... differentiator=tfq.differentiators.ParameterShift()) + >>> quantum_data = tfq.convert_to_tensor([ + ... cirq.Circuit(), + ... cirq.Circuit(cirq.X(q)) + ... ]) + >>> res = outputs(quantum_data) + >>> res + + + + Lastly, like all layers in TensorFlow the `NoisyPQC` layer can be called on + any `tf.Tensor` as long as it is the right shape. This means you could + replace replace `quantum_data` with values fed in from a `tf.keras.Input`. + """ + + def __init__( + self, + model_circuit, + operators, + *, + repetitions=None, + sample_based=None, + differentiator=None, + use_cuquantum=False, + initializer=tf.keras.initializers.RandomUniform(0, 2 * np.pi), + regularizer=None, + constraint=None, + **kwargs, + ): + """Instantiate this layer. + + Create a layer that will output noisy expectation values of the given + operators when fed quantum data to it's input layer. This layer will + accept one input tensor representing a quantum data source (these + circuits must not contain any symbols) and append the model_circuit to + them, execute them and then finally output the expectation values. + + + model_circuit: `cirq.Circuit` containing `sympy.Symbols` that will be + used as the model which will be fed quantum data inputs. + operators: `cirq.PauliSum` or Python `list` of `cirq.PauliSum` objects + used as observables at the end of the model circuit. + repetitions: Python `int` indicating how many trajectories to use + when estimating expectation values. + sample_based: Python `bool` indicating whether to use sampling to + estimate expectations or analytic calculations with each + trajectory. + differentiator: Optional `tfq.differentiator` object to specify how + gradients of `model_circuit` should be calculated. + use_cuquantum: Python `bool` indicating whether to use GPU ops + (currently not supported/implemented). + initializer: Optional `tf.keras.initializer` object to specify how the + symbols in `model_circuit` should be initialized when creating + the managed variables. + regularizer: Optional `tf.keras.regularizer` object applied to the + managed variables parameterizing `model_circuit`. + constraint: Optional `tf.keras.constraint` object applied to the + managed variables parameterizing `model_circuit`. + """ + super().__init__(**kwargs) + + # Ingest model_circuit. + if not isinstance(model_circuit, cirq.Circuit): + raise TypeError("model_circuit must be a cirq.Circuit object." + " Given: {}".format(model_circuit)) + + self._symbols_list = list( + sorted(util.get_circuit_symbols(model_circuit))) + self._symbols = tf.constant([str(x) for x in self._symbols_list]) + + self._model_circuit = util.convert_to_tensor([model_circuit]) + if len(self._symbols_list) == 0: + raise ValueError("model_circuit has no sympy.Symbols. Please " + "provide a circuit that contains symbols so " + "that their values can be trained.") + + # Ingest operators. + if isinstance(operators, (cirq.PauliString, cirq.PauliSum)): + operators = [operators] + if not isinstance(operators, (list, np.ndarray, tuple)): + raise TypeError("operators must be a cirq.PauliSum or " + "cirq.PauliString, or a list, tuple, " + "or np.array containing them. " + "Got {}.".format(type(operators))) + if not all([ + isinstance(op, (cirq.PauliString, cirq.PauliSum)) + for op in operators + ]): + raise TypeError("Each element in operators to measure " + "must be a cirq.PauliString" + " or cirq.PauliSum") + self._operators = util.convert_to_tensor([operators]) + + # Ingest and promote repetitions. + if repetitions is None: + raise ValueError("Value for repetitions must be provided when " + "using noisy simulation.") + if not isinstance(repetitions, numbers.Integral): + raise TypeError("repetitions must be a positive integer value." + " Given: ".format(repetitions)) + if repetitions <= 0: + raise ValueError("Repetitions must be greater than zero.") + + self._repetitions = tf.constant( + [[repetitions for _ in range(len(operators))]], + dtype=tf.dtypes.int32) + + # Use gpu not supported yet. + if use_cuquantum: + raise NotImplementedError("GPU support for noisy PQC is not \ + yet implemented.") + + # Ingest differentiator. + if differentiator is None: + differentiator = parameter_shift.ParameterShift() + + # Ingest and promote sample based. + if sample_based is None: + raise ValueError("Please specify sample_based=False for analytic " + "calculations based on monte-carlo trajectories," + " or sampled_based=True for measurement based " + "noisy estimates.") + if not isinstance(sample_based, bool): + raise TypeError("sample_based must be either True or False." + " received: {}".format(type(sample_based))) + + if not sample_based: + self._executor = differentiator.generate_differentiable_op( + sampled_op=noisy_expectation_op.expectation) + else: + self._executor = differentiator.generate_differentiable_op( + sampled_op=noisy_sampled_expectation_op.sampled_expectation) + + self._append_layer = elementary.AddCircuit() + + # Set additional parameter controls. + self.initializer = tf.keras.initializers.get(initializer) + self.regularizer = tf.keras.regularizers.get(regularizer) + self.constraint = tf.keras.constraints.get(constraint) + + # Weight creation is not placed in a Build function because the number + # of weights is independent of the input shape. + self.parameters = self.add_weight('parameters', + shape=self._symbols.shape, + initializer=self.initializer, + regularizer=self.regularizer, + constraint=self.constraint, + dtype=tf.float32, + trainable=True) + + @property + def symbols(self): + """The symbols that are managed by this layer (in-order). + + Note: `symbols[i]` indicates what symbol name the managed variables in + this layer map to. + """ + return [sympy.Symbol(x) for x in self._symbols_list] + + def symbol_values(self): + """Returns a Python `dict` containing symbol name, value pairs. + + Returns: + Python `dict` with `str` keys and `float` values representing + the current symbol values. + """ + return dict(zip(self.symbols, self.get_weights()[0])) + + def build(self, input_shape): + """Keras build function.""" + super().build(input_shape) + + def call(self, inputs): + """Keras call function.""" + circuit_batch_dim = tf.gather(tf.shape(inputs), 0) + tiled_up_model = tf.tile(self._model_circuit, [circuit_batch_dim]) + model_appended = self._append_layer(inputs, append=tiled_up_model) + tiled_up_parameters = tf.tile([self.parameters], [circuit_batch_dim, 1]) + tiled_up_operators = tf.tile(self._operators, [circuit_batch_dim, 1]) + + tiled_up_repetitions = tf.tile(self._repetitions, + [circuit_batch_dim, 1]) + return self._executor(model_appended, self._symbols, + tiled_up_parameters, tiled_up_operators, + tiled_up_repetitions) \ No newline at end of file diff --git a/tensorflow_quantum/python/layers/high_level/noisy_pqc_test.py b/tensorflow_quantum/python/layers/high_level/noisy_pqc_test.py new file mode 100644 index 000000000..ea56115c0 --- /dev/null +++ b/tensorflow_quantum/python/layers/high_level/noisy_pqc_test.py @@ -0,0 +1,267 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Test module for tfq.python.layers.high_level.noisy_pqc layer.""" +# 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 + +import numpy as np +import tensorflow as tf +from absl.testing import parameterized +import cirq +import sympy + +from tensorflow_quantum.python.layers.high_level import noisy_pqc +from tensorflow_quantum.python import util + + +class NoisyPQCTest(tf.test.TestCase, parameterized.TestCase): + """Tests for the NoisyPQC layer.""" + + def test_noisy_pqc_instantiate(self): + """Basic creation test.""" + symbol = sympy.Symbol('alpha') + qubit = cirq.GridQubit(0, 0) + learnable_flip = cirq.Circuit(cirq.X(qubit)**symbol) + noisy_pqc.NoisyPQC(learnable_flip, + cirq.Z(qubit), + repetitions=1000, + sample_based=False) + + def test_noisy_pqc_model_circuit_error(self): + """Test that invalid circuits error properly.""" + qubit = cirq.GridQubit(0, 0) + no_symbols = cirq.Circuit(cirq.X(qubit)) + + with self.assertRaisesRegex( + TypeError, + expected_regex="model_circuit must be a cirq.Circuit"): + noisy_pqc.NoisyPQC('junk', + cirq.Z(qubit), + repetitions=1000, + sample_based=False) + + with self.assertRaisesRegex( + ValueError, + expected_regex="model_circuit has no sympy.Symbols"): + noisy_pqc.NoisyPQC(no_symbols, + cirq.Z(qubit), + repetitions=1000, + sample_based=False) + + def test_noisy_pqc_operators_error(self): + """Test that invalid operators error properly.""" + symbol = sympy.Symbol('alpha') + qubit = cirq.GridQubit(0, 0) + learnable_flip = cirq.Circuit(cirq.X(qubit)**symbol) + + with self.assertRaisesRegex( + TypeError, expected_regex="cirq.PauliSum or cirq.PauliString"): + noisy_pqc.NoisyPQC(learnable_flip, + 'junk', + repetitions=1000, + sample_based=False) + + with self.assertRaisesRegex(TypeError, expected_regex="Each element"): + noisy_pqc.NoisyPQC(learnable_flip, [[cirq.Z(qubit)]], + repetitions=1000, + sample_based=False) + + with self.assertRaisesRegex(TypeError, expected_regex="Each element"): + noisy_pqc.NoisyPQC(learnable_flip, [cirq.Z(qubit), 'bad'], + repetitions=1000, + sample_based=False) + + def test_noisy_pqc_repetitions_error(self): + """Test that invalid repetitions error properly.""" + symbol = sympy.Symbol('alpha') + qubit = cirq.GridQubit(0, 0) + learnable_flip = cirq.Circuit(cirq.X(qubit)**symbol) + + with self.assertRaisesRegex(TypeError, + expected_regex="positive integer value"): + noisy_pqc.NoisyPQC(learnable_flip, + cirq.Z(qubit), + repetitions='junk', + sample_based=False) + + with self.assertRaisesRegex(ValueError, + expected_regex="greater than zero."): + noisy_pqc.NoisyPQC(learnable_flip, + cirq.Z(qubit), + repetitions=-100, + sample_based=False) + + with self.assertRaisesRegex(ValueError, + expected_regex="greater than zero."): + noisy_pqc.NoisyPQC(learnable_flip, + cirq.Z(qubit), + repetitions=0, + sample_based=False) + + with self.assertRaisesRegex(ValueError, + expected_regex="must be provided"): + noisy_pqc.NoisyPQC(learnable_flip, + cirq.Z(qubit), + sample_based=False) + + def test_noisy_pqc_sample_based_error(self): + """Test that invalid sampled_based values error properly.""" + symbol = sympy.Symbol('alpha') + qubit = cirq.GridQubit(0, 0) + learnable_flip = cirq.Circuit(cirq.X(qubit)**symbol) + + with self.assertRaisesRegex(TypeError, expected_regex="True or False"): + noisy_pqc.NoisyPQC(learnable_flip, + cirq.Z(qubit), + repetitions=10, + sample_based='junk') + + with self.assertRaisesRegex( + ValueError, expected_regex="specify sample_based=False"): + noisy_pqc.NoisyPQC(learnable_flip, cirq.Z(qubit), repetitions=10) + + def test_noisy_pqc_initializer(self): + """Test action of initializer.""" + (a, b, c) = sympy.symbols("a b c") + qubit = cirq.GridQubit(0, 0) + three_parameters = cirq.Circuit( + [cirq.X(qubit)**a, + cirq.Y(qubit)**b, + cirq.Z(qubit)**c]) + mpqc_zeros = noisy_pqc.NoisyPQC(three_parameters, + cirq.Z(qubit), + repetitions=100, + sample_based=False, + initializer='zeros') + mpqc_ones = noisy_pqc.NoisyPQC(three_parameters, + cirq.Z(qubit), + initializer='ones', + repetitions=100, + sample_based=False) + self.assertAllEqual([[0, 0, 0]], mpqc_zeros.get_weights()) + self.assertAllEqual([[1, 1, 1]], mpqc_ones.get_weights()) + + def test_noisy_pqc_regularizer(self): + """Test attachment of regularizer to layer.""" + (a, b, c) = sympy.symbols("a b c") + qubit = cirq.GridQubit(0, 0) + three_parameters = cirq.Circuit( + [cirq.X(qubit)**a, + cirq.Y(qubit)**b, + cirq.Z(qubit)**c]) + mpqc = noisy_pqc.NoisyPQC(three_parameters, + cirq.Z(qubit), + repetitions=100, + sample_based=False) + mpqc_r = noisy_pqc.NoisyPQC(three_parameters, + cirq.Z(qubit), + regularizer='l2', + repetitions=100, + sample_based=False) + self.assertEqual(0, len(mpqc.losses)) + self.assertEqual(1, len(mpqc_r.losses)) + + def test_noisy_pqc_constraint(self): + """Test attachment of constraint to layer.""" + my_constraint = tf.keras.constraints.NonNeg() + (a, b, c) = sympy.symbols("a b c") + qubit = cirq.GridQubit(0, 0) + three_parameters = cirq.Circuit( + [cirq.X(qubit)**a, + cirq.Y(qubit)**b, + cirq.Z(qubit)**c]) + mpqc = noisy_pqc.NoisyPQC(three_parameters, + cirq.Z(qubit), + repetitions=100, + sample_based=False, + constraint=my_constraint) + self.assertEqual(my_constraint, mpqc.parameters.constraint) + + def test_noisy_pqc_symbols_property(self): + """Test that the `symbols` property returns the symbols.""" + c, b, a, d = sympy.symbols('c b a d') + bit = cirq.GridQubit(0, 0) + test_circuit = cirq.Circuit( + cirq.H(bit)**a, + cirq.Z(bit)**b, + cirq.X(bit)**d, + cirq.Y(bit)**c) + layer = noisy_pqc.NoisyPQC(test_circuit, + cirq.Z(bit), + repetitions=100, + sample_based=False) + self.assertEqual(layer.symbols, [a, b, c, d]) + + def test_noisy_pqc_symbol_values(self): + """Test that PQC symbol_values returns the correct key value pairs.""" + c, b, a, d = sympy.symbols('c b a d') + bit = cirq.GridQubit(0, 0) + test_circuit = cirq.Circuit( + cirq.H(bit)**a, + cirq.Z(bit)**b, + cirq.X(bit)**d, + cirq.Y(bit)**c) + init_vals = [1, 2, 3, 4] + layer = noisy_pqc.NoisyPQC( + test_circuit, + cirq.Z(bit), + repetitions=1000, + sample_based=False, + initializer=tf.constant_initializer(init_vals)) + expected_vals = dict(zip([a, b, c, d], init_vals)) + self.assertAllClose(layer.symbol_values(), expected_vals) + + @parameterized.parameters([{'sample_based': True}, {'sample_based': False}]) + def test_noisy_pqc_simple_learn(self, sample_based): + """Test a simple learning scenario using analytic and sample expectation + on many backends.""" + qubit = cirq.GridQubit(0, 0) + circuit = cirq.Circuit( + cirq.X(qubit)**sympy.Symbol('bit'), + cirq.depolarize(0.01)(qubit)) + + quantum_datum = tf.keras.Input(shape=(), dtype=tf.dtypes.string) + mpqc = noisy_pqc.NoisyPQC( + circuit, + cirq.Z(qubit), + repetitions=5000, + sample_based=sample_based, + initializer=tf.keras.initializers.Constant(value=0.5)) + outputs = mpqc(quantum_datum) + model = tf.keras.Model(inputs=quantum_datum, outputs=outputs) + + model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.03), + loss=tf.keras.losses.mean_squared_error) + + data_circuits = util.convert_to_tensor( + [cirq.Circuit(cirq.X(qubit)), + cirq.Circuit()]) + print(data_circuits) + data_out = np.array([[1], [-1]], dtype=np.float32) + + # Model should learn to flip the qubit + self.assertNear(mpqc.get_weights()[0][0], 0.5, 1e-1) + history = model.fit(x=data_circuits, y=data_out, epochs=40) + self.assertAllClose(history.history['loss'][-1], 0, atol=1e-1) + self.assertNear(mpqc.get_weights()[0][0], 1, 1e-1) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/python/layers/high_level/pqc.py b/tensorflow_quantum/python/layers/high_level/pqc.py index abdf75ffe..a4c5c3f05 100644 --- a/tensorflow_quantum/python/layers/high_level/pqc.py +++ b/tensorflow_quantum/python/layers/high_level/pqc.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module for tfq.python.layers.high_level.pqc layer.""" import numbers import numpy as np @@ -95,7 +95,7 @@ class PQC(tf.keras.layers.Layer): to indicate the differentiation scheme this `PQC` layer should use. Here's how you would take the gradients of the above example using a `cirq.Simulator` backend (which is slower than the default - `backend=None` which uses C++): + `backend='noiseless'` which uses C++): >>> q = cirq.GridQubit(0, 0) @@ -136,7 +136,8 @@ def __init__( operators, *, repetitions=None, - backend=None, + backend='noiseless', + use_cuquantum=False, differentiator=None, initializer=tf.keras.initializers.RandomUniform(0, 2 * np.pi), regularizer=None, @@ -160,11 +161,14 @@ def __init__( when estimating expectation values. If `None` analytic expectation calculation is used. backend: Optional Backend to use to simulate states. Defaults to - the native TensorFlow simulator (None), however users may also + the noiseless TensorFlow simulator, however users may also specify a preconfigured cirq simulation object to use instead. If a cirq object is given it must inherit either - `cirq.SimulatesFinalState` if analytic expectations are desired or - `cirq.Sampler` if sampled expectations are desired. + `cirq.sim.simulator.SimulatesExpectationValues` if analytic + expectations are desired or `cirq.Sampler` if sampled expectations + are desired. + use_cuquantum: Optional Python `bool` indicating whether or not to use + GPU ops. differentiator: Optional `tfq.differentiator` object to specify how gradients of `model_circuit` should be calculated. initializer: Optional `tf.keras.initializer` object to specify how the @@ -224,25 +228,37 @@ def __init__( dtype=tf.dtypes.int32) # Set backend and differentiator. - if not isinstance(backend, cirq.Sampler - ) and repetitions is not None and backend is not None: + if backend == 'noisy': + raise ValueError("noisy backend value is not supported in " + "tfq.layers.PQC. Please use tfq.layers.NoisyPQC " + "instead.") + + not_default = backend != 'noiseless' + not_default &= backend is not None # legacy backend=None support. + if not isinstance( + backend, + cirq.Sampler) and repetitions is not None and not_default: raise TypeError("provided backend does not inherit cirq.Sampler " "and repetitions!=None. Please provide a backend " "that inherits cirq.Sampler or set " "repetitions=None.") - if not isinstance(backend, cirq.SimulatesFinalState - ) and repetitions is None and backend is not None: + if not isinstance(backend, cirq.sim.simulator.SimulatesExpectationValues + ) and repetitions is None and not_default: raise TypeError("provided backend does not inherit " - "cirq.SimulatesFinalState and repetitions=None. " - "Please provide a backend that inherits " - "cirq.SimulatesFinalState or choose a positive " - "number of repetitions.") + "cirq.sim.simulator.SimulatesExpectationValues and " + "repetitions=None. Please provide a backend that " + "inherits " + "cirq.sim.simulator.SimulatesExpectationValues.") if self._analytic: self._executor = expectation.Expectation( - backend=backend, differentiator=differentiator) + backend=backend, + differentiator=differentiator, + use_cuquantum=use_cuquantum) else: self._executor = sampled_expectation.SampledExpectation( - backend=backend, differentiator=differentiator) + backend=backend, + differentiator=differentiator, + use_cuquantum=use_cuquantum) self._append_layer = elementary.AddCircuit() diff --git a/tensorflow_quantum/python/layers/high_level/pqc_test.py b/tensorflow_quantum/python/layers/high_level/pqc_test.py index 3860a7b92..33b74fedb 100644 --- a/tensorflow_quantum/python/layers/high_level/pqc_test.py +++ b/tensorflow_quantum/python/layers/high_level/pqc_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test module for tfq.python.layers.high_level.pqc layer.""" +# 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 + import numpy as np import tensorflow as tf from absl.testing import parameterized @@ -34,6 +42,15 @@ def test_pqc_instantiate(self): pqc.PQC(learnable_flip, cirq.Z(qubit)) pqc.PQC(learnable_flip, cirq.Z(qubit), repetitions=500) + def test_pqc_noisy_error(self): + """Refer to noisy layer.""" + symbol = sympy.Symbol('alpha') + qubit = cirq.GridQubit(0, 0) + learnable_flip = cirq.Circuit(cirq.X(qubit)**symbol) + with self.assertRaisesRegex(ValueError, + expected_regex='tfq.layers.NoisyPQC'): + pqc.PQC(learnable_flip, cirq.Z(qubit), backend='noisy') + def test_pqc_model_circuit_error(self): """Test that invalid circuits error properly.""" qubit = cirq.GridQubit(0, 0) @@ -89,10 +106,10 @@ def test_pqc_backend_error(self): qubit = cirq.GridQubit(0, 0) learnable_flip = cirq.Circuit(cirq.X(qubit)**symbol) - class MyState(cirq.SimulatesFinalState): - """My state simulator.""" + class MyExpectation(cirq.sim.simulator.SimulatesExpectationValues): + """My expectation values simulator.""" - def simulate_sweep(self): + def simulate_expectation_values_sweep(self): """do nothing.""" return @@ -103,14 +120,20 @@ def run_sweep(self): """do nothing.""" return + with self.assertRaisesRegex( + TypeError, + expected_regex="cirq.sim.simulator.SimulatesExpectation"): + pqc.PQC(learnable_flip, cirq.Z(qubit), backend='junk') + with self.assertRaisesRegex(TypeError, expected_regex="cirq.Sampler"): pqc.PQC(learnable_flip, cirq.Z(qubit), - backend=MyState, + backend=MyExpectation, repetitions=500) - with self.assertRaisesRegex(TypeError, - expected_regex="cirq.SimulatesFinalState"): + with self.assertRaisesRegex( + TypeError, + expected_regex="cirq.sim.simulator.SimulatesExpectationValues"): pqc.PQC(learnable_flip, cirq.Z(qubit), backend=MySample, diff --git a/tensorflow_quantum/python/optimizers/BUILD b/tensorflow_quantum/python/optimizers/BUILD index c6dca3ce3..e632eb168 100755 --- a/tensorflow_quantum/python/optimizers/BUILD +++ b/tensorflow_quantum/python/optimizers/BUILD @@ -5,18 +5,44 @@ licenses(["notice"]) # Export for the PIP package. exports_files(["__init__.py"]) +py_library( + name = "optimizers", + srcs = ["__init__.py"], + srcs_version = "PY3", + deps = [ + ":rotosolve_minimizer", + ":spsa_minimizer", + ], +) + py_library( name = "rotosolve_minimizer", srcs = ["rotosolve_minimizer.py"], ) +py_library( + name = "spsa_minimizer", + srcs = ["spsa_minimizer.py"], +) + py_test( name = "rotosolve_minimizer_test", srcs = ["rotosolve_minimizer_test.py"], python_version = "PY3", deps = [ ":rotosolve_minimizer", + "//tensorflow_quantum/core/ops:tfq_ps_util_ops_py", + "//tensorflow_quantum/python/layers/high_level:pqc", + ], +) + +py_test( + name = "spsa_minimizer_test", + srcs = ["spsa_minimizer_test.py"], + python_version = "PY3", + deps = [ + ":spsa_minimizer", + "//tensorflow_quantum/core/ops:tfq_ps_util_ops_py", "//tensorflow_quantum/python/layers/high_level:pqc", - "//tensorflow_quantum/core/ops:tfq_ps_util_ops_py" ], ) diff --git a/tensorflow_quantum/python/optimizers/__init__.py b/tensorflow_quantum/python/optimizers/__init__.py index 21a9d08fc..1a1d97d41 100755 --- a/tensorflow_quantum/python/optimizers/__init__.py +++ b/tensorflow_quantum/python/optimizers/__init__.py @@ -11,9 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Module definitions for tensorflow_quantum.python.optimizers.*""" # Quantum circuit specific optimizers. from tensorflow_quantum.python.optimizers.rotosolve_minimizer import ( minimize as rotosolve_minimize) +from tensorflow_quantum.python.optimizers.spsa_minimizer import (minimize as + spsa_minimize) diff --git a/tensorflow_quantum/python/optimizers/rotosolve_minimizer.py b/tensorflow_quantum/python/optimizers/rotosolve_minimizer.py index bd1270068..3376cd20e 100755 --- a/tensorflow_quantum/python/optimizers/rotosolve_minimizer.py +++ b/tensorflow_quantum/python/optimizers/rotosolve_minimizer.py @@ -1,263 +1,274 @@ -# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============================================================================== -"""The rotosolve minimization algorithm""" -import collections -import numpy as np -import tensorflow as tf - - -def prefer_static_shape(x): - """Return static shape of tensor `x` if available, - - else `tf.shape(x)`. - - Args: - x: `tf.Tensor` (already converted). - Returns: - Numpy array (if static shape is obtainable), else `tf.Tensor`. - """ - return prefer_static_value(tf.shape(x)) - - -def prefer_static_value(x): - """Return static value of tensor `x` if available, else `x`. - - Args: - x: `tf.Tensor` (already converted). - Returns: - Numpy array (if static value is obtainable), else `tf.Tensor`. - """ - static_x = tf.get_static_value(x) - if static_x is not None: - return static_x - return x - - -RotosolveOptimizerResults = collections.namedtuple( - 'RotosolveOptimizerResults', - [ - 'converged', - # Scalar boolean tensor indicating whether the minimum - # was found within tolerance. - 'num_iterations', - # The number of iterations of the rotosolve update. - 'num_objective_evaluations', - # The total number of objective - # evaluations performed. - 'position', - # A tensor containing the last argument value found - # during the search. If the search converged, then - # this value is the argmin of the objective function. - # A tensor containing the value of the objective from - # previous iteration - 'objective_value_previous_iteration', - # Save the evaluated value of the objective function - # from the previous iteration - 'objective_value', - # A tensor containing the value of the objective - # function at the `position`. If the search - # converged, then this is the (local) minimum of - # the objective function. - 'tolerance', - # Define the stop criteria. Iteration will stop when the - # objective value difference between two iterations is - # smaller than tolerance - 'solve_param_i', - # The parameter index where rotosolve is currently - # modifying. Reserved for internal use. - ]) - - -def _get_initial_state(initial_position, tolerance, expectation_value_function): - """Create RotosolveOptimizerResults with initial state of search.""" - init_args = { - "converged": tf.Variable(False), - "num_iterations": tf.Variable(0), - "num_objective_evaluations": tf.Variable(0), - "position": tf.Variable(initial_position), - "objective_value": tf.Variable(0.), - "objective_value_previous_iteration": tf.Variable(0.), - "tolerance": tolerance, - "solve_param_i": tf.Variable(0) - } - return RotosolveOptimizerResults(**init_args) - - -def minimize(expectation_value_function, - initial_position, - tolerance=1e-5, - max_iterations=50, - name=None): - """Applies the rotosolve algorithm. - - The rotosolve algorithm can be used to minimize a linear combination - - of quantum measurement expectation values. See the following paper: - - [arXiv:1903.12166](https://arxiv.org/abs/1903.12166), Ken M. Nakanishi. - [arXiv:1905.09692](https://arxiv.org/abs/1905.09692), Mateusz Ostaszewski. - - Usage: - - Here is an example of optimize a function which consists summation of - a few sinusoids. - - >>> n = 10 # Number of sinusoids - >>> coefficient = tf.random.uniform(shape=[n]) - >>> min_value = -tf.math.reduce_sum(tf.abs(coefficient)) - >>> func = lambda x:tf.math.reduce_sum(tf.sin(x) * coefficient) - >>> # Optimize the function with rotosolve, start with random parameters - >>> result = tfq.optimizers.rotosolve_minimize(func, np.random.random(n)) - >>> result.converged - tf.Tensor(True, shape=(), dtype=bool) - >>> result.objective_value - tf.Tensor(-4.7045116, shape=(), dtype=float32) - - Args: - expectation_value_function: A Python callable that accepts - a point as a real `tf.Tensor` and returns a `tf.Tensor`s - of real dtype containing the value of the function. - The function to be minimized. The input is of shape `[n]`, - where `n` is the size of the trainable parameters. - The return value is a real `tf.Tensor` Scalar (matching shape - `[1]`). This must be a linear combination of quantum - measurement expectation value, otherwise this algorithm cannot - work. - initial_position: Real `tf.Tensor` of shape `[n]`. The starting - point, or points when using batching dimensions, of the search - procedure. At these points the function value and the gradient - norm should be finite. - tolerance: Scalar `tf.Tensor` of real dtype. Specifies the tolerance - for the procedure. If the supremum norm between two iteration - vector is below this number, the algorithm is stopped. - name: (Optional) Python `str`. The name prefixed to the ops created - by this function. If not supplied, the default name 'minimize' - is used. - - Returns: - optimizer_results: A RotosolveOptimizerResults object contains the - result of the optimization process. - """ - - with tf.name_scope(name or 'minimize'): - initial_position = tf.convert_to_tensor(initial_position, - name='initial_position', - dtype='float32') - dtype = initial_position.dtype.base_dtype - tolerance = tf.convert_to_tensor(tolerance, - dtype=dtype, - name='grad_tolerance') - max_iterations = tf.convert_to_tensor(max_iterations, - name='max_iterations') - - def _rotosolve_one_parameter_once(state): - """Rotosolve a single parameter once. - - Args: - state: A RotosolveOptimizerResults object stores the - current state of the minimizer. - - Returns: - states: A list which the first element is the new state - """ - delta_shift = tf.scatter_nd([[state.solve_param_i]], - [tf.constant(np.pi / 2, dtype=dtype)], - prefer_static_shape(state.position)) - - # Evaluate three different point for curve fitting - v_l, v_n, v_r = expectation_value_function( - state.position - delta_shift), \ - state.objective_value, \ - expectation_value_function(state.position + delta_shift) - - # Use the analytical solution to find the optimized position - delta_update = -np.pi / 2 - \ - tf.math.atan2(2 * v_n - v_l - v_r, v_r - v_l) - - delta_update_tensor = tf.scatter_nd( - [[state.solve_param_i]], [delta_update], - prefer_static_shape(state.position)) - - state.solve_param_i.assign_add(1) - state.position.assign( - tf.math.floormod(state.position + delta_update_tensor, - np.pi * 2)) - - state.objective_value_previous_iteration.assign( - state.objective_value) - state.objective_value.assign( - expectation_value_function(state.position)) - - return [state] - - def _rotosolve_all_parameters_once(state): - """Iterate over all parameters and rotosolve each single - - of them once. - - Args: - state: A RotosolveOptimizerResults object stores the - current state of the minimizer. - - Returns: - states: A list which the first element is the new state - """ - - def _cond_internal(state_cond): - return state_cond.solve_param_i < \ - prefer_static_shape(state_cond.position)[0] - - state.num_objective_evaluations.assign_add(1) - - return tf.while_loop( - cond=_cond_internal, - body=_rotosolve_one_parameter_once, - loop_vars=[state], - parallel_iterations=1, - ) - - # The `state` here is a `RotosolveOptimizerResults` tuple with - # values for the current state of the algorithm computation. - def _cond(state): - """Continue if iterations remain and stopping condition - is not met.""" - return (state.num_iterations < max_iterations) \ - and (not state.converged) - - def _body(state): - """Main optimization loop.""" - - state.solve_param_i.assign(0) - - _rotosolve_all_parameters_once(state) - - state.num_iterations.assign_add(1) - state.converged.assign( - tf.abs(state.objective_value - - state.objective_value_previous_iteration) < - state.tolerance) - - return [state] - - initial_state = _get_initial_state(initial_position, tolerance, - expectation_value_function) - - initial_state.objective_value.assign( - expectation_value_function(initial_state.position)) - - return tf.while_loop(cond=_cond, - body=_body, - loop_vars=[initial_state], - parallel_iterations=1)[0] +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""The rotosolve minimization algorithm.""" +import numpy as np +import tensorflow as tf + + +def prefer_static_shape(x): + """Return static shape of tensor `x` if available, + + else `tf.shape(x)`. + + Args: + x: `tf.Tensor` (already converted). + Returns: + Numpy array (if static shape is obtainable), else `tf.Tensor`. + """ + return prefer_static_value(tf.shape(x)) + + +def prefer_static_value(x): + """Return static value of tensor `x` if available, else `x`. + + Args: + x: `tf.Tensor` (already converted). + Returns: + Numpy array (if static value is obtainable), else `tf.Tensor`. + """ + static_x = tf.get_static_value(x) + if static_x is not None: + return static_x + return x + + +class RotosolveOptimizerResults(tf.experimental.ExtensionType): + """ExtentionType of Rotosolve Optimizer tf.while_loop() inner state.""" + converged: tf.Tensor + # Scalar boolean tensor indicating whether the minimum + # was found within tolerance. + num_iterations: tf.Tensor + # The number of iterations of the rotosolve update. + num_objective_evaluations: tf.Tensor + # The total number of objective + # evaluations performed. + position: tf.Tensor + # A tensor containing the last argument value found + # during the search. If the search converged, then + # this value is the argmin of the objective function. + # A tensor containing the value of the objective from + # previous iteration + objective_value_prev: tf.Tensor + # Save the evaluated value of the objective function + # from the previous iteration + objective_value: tf.Tensor + # A tensor containing the value of the objective + # function at the `position`. If the search + # converged, then this is the (local) minimum of + # the objective function. + tolerance: tf.Tensor + # Define the stop criteria. Iteration will stop when the + # objective value difference between two iterations is + # smaller than tolerance + solve_param_i: tf.Tensor + + # The parameter index where rotosolve is currently + # modifying. Reserved for internal use. + + def to_dict(self): + """Transforms immutable data to mutable dictionary.""" + return { + "converged": self.converged, + "num_iterations": self.num_iterations, + "num_objective_evaluations": self.num_objective_evaluations, + "position": self.position, + "objective_value": self.objective_value, + "objective_value_prev": self.objective_value_prev, + "tolerance": self.tolerance, + "solve_param_i": self.solve_param_i, + } + + +def _get_initial_state(initial_position, tolerance, expectation_value_function): + """Create RotosolveOptimizerResults with initial state of search.""" + init_args = { + "converged": tf.Variable(False), + "num_iterations": tf.Variable(0), + "num_objective_evaluations": tf.Variable(0), + "position": tf.Variable(initial_position), + "objective_value": expectation_value_function(initial_position), + "objective_value_prev": tf.Variable(0.), + "tolerance": tolerance, + "solve_param_i": tf.Variable(0), + } + return RotosolveOptimizerResults(**init_args) + + +def minimize(expectation_value_function, + initial_position, + tolerance=1e-5, + max_iterations=50, + name=None): + """Applies the rotosolve algorithm. + + The rotosolve algorithm can be used to minimize a linear combination + + of quantum measurement expectation values. See the following paper: + + [arXiv:1903.12166](https://arxiv.org/abs/1903.12166), Ken M. Nakanishi. + [arXiv:1905.09692](https://arxiv.org/abs/1905.09692), Mateusz Ostaszewski. + + Usage: + + Here is an example of optimize a function which consists summation of + a few sinusoids. + + >>> n = 10 # Number of sinusoids + >>> coefficient = tf.random.uniform(shape=[n]) + >>> min_value = -tf.math.reduce_sum(tf.abs(coefficient)) + >>> func = lambda x:tf.math.reduce_sum(tf.sin(x) * coefficient) + >>> # Optimize the function with rotosolve, start with random parameters + >>> result = tfq.optimizers.rotosolve_minimize(func, np.random.random(n)) + >>> result.converged + tf.Tensor(True, shape=(), dtype=bool) + >>> result.objective_value + tf.Tensor(-4.7045116, shape=(), dtype=float32) + + Args: + expectation_value_function: A Python callable that accepts + a point as a real `tf.Tensor` and returns a `tf.Tensor`s + of real dtype containing the value of the function. + The function to be minimized. The input is of shape `[n]`, + where `n` is the size of the trainable parameters. + The return value is a real `tf.Tensor` Scalar (matching shape + `[1]`). This must be a linear combination of quantum + measurement expectation value, otherwise this algorithm cannot + work. + initial_position: Real `tf.Tensor` of shape `[n]`. The starting + point, or points when using batching dimensions, of the search + procedure. At these points the function value and the gradient + norm should be finite. + tolerance: Scalar `tf.Tensor` of real dtype. Specifies the tolerance + for the procedure. If the supremum norm between two iteration + vector is below this number, the algorithm is stopped. + name: (Optional) Python `str`. The name prefixed to the ops created + by this function. If not supplied, the default name 'minimize' + is used. + + Returns: + optimizer_results: A RotosolveOptimizerResults object contains the + result of the optimization process. + """ + + with tf.name_scope(name or 'minimize'): + initial_position = tf.convert_to_tensor(initial_position, + name='initial_position', + dtype='float32') + dtype = initial_position.dtype.base_dtype + tolerance = tf.convert_to_tensor(tolerance, + dtype=dtype, + name='grad_tolerance') + max_iterations = tf.convert_to_tensor(max_iterations, + name='max_iterations') + + def _rotosolve_one_parameter_once(state): + """Rotosolve a single parameter once. + + Args: + state: A RotosolveOptimizerResults object stores the + current state of the minimizer. + + Returns: + states: A list which the first element is the new state + """ + delta_shift = tf.scatter_nd([[state.solve_param_i]], + [tf.constant(np.pi / 2, dtype=dtype)], + prefer_static_shape(state.position)) + + # Evaluate three different point for curve fitting + v_l, v_n, v_r = expectation_value_function( + state.position - delta_shift), \ + state.objective_value, \ + expectation_value_function(state.position + delta_shift) + + # Use the analytical solution to find the optimized position + delta_update = -np.pi / 2 - \ + tf.math.atan2(2 * v_n - v_l - v_r, v_r - v_l) + + delta_update_tensor = tf.scatter_nd( + [[state.solve_param_i]], [delta_update], + prefer_static_shape(state.position)) + + new_position = (tf.math.floormod( + state.position + delta_update_tensor, np.pi * 2)) + next_state_params = state.to_dict() + next_state_params.update({ + "solve_param_i": state.solve_param_i + 1, + "position": new_position, + "objective_value_prev": state.objective_value, + "objective_value": (expectation_value_function(new_position)), + }) + return [RotosolveOptimizerResults(**next_state_params)] + + def _rotosolve_all_parameters_once(state): + """Iterate over all parameters and rotosolve each single + + of them once. + + Args: + state: A RotosolveOptimizerResults object stores the + current state of the minimizer. + + Returns: + states: A list which the first element is the new state + """ + + def _cond_internal(state_cond): + return state_cond.solve_param_i < \ + prefer_static_shape(state_cond.position)[0] + + next_state_params = state.to_dict() + next_state_params.update({ + "num_objective_evaluations": + state.num_objective_evaluations + 1, + }) + + return tf.while_loop( + cond=_cond_internal, + body=_rotosolve_one_parameter_once, + loop_vars=[RotosolveOptimizerResults(**next_state_params)], + parallel_iterations=1, + ) + + # The `state` here is a `RotosolveOptimizerResults` tuple with + # values for the current state of the algorithm computation. + def _cond(state): + """Continue if iterations remain and stopping condition + is not met.""" + return (state.num_iterations < max_iterations) \ + and (not state.converged) + + def _body(state): + """Main optimization loop.""" + pre_state_params = state.to_dict() + pre_state_params.update({"solve_param_i": 0}) + pre_state = RotosolveOptimizerResults(**pre_state_params) + post_state = _rotosolve_all_parameters_once(pre_state)[0] + next_state_params = post_state.to_dict() + next_state_params.update({ + "converged": (tf.abs(post_state.objective_value - + post_state.objective_value_prev) < + post_state.tolerance), + "num_iterations": post_state.num_iterations + 1, + }) + return [RotosolveOptimizerResults(**next_state_params)] + + initial_state = _get_initial_state(initial_position, tolerance, + expectation_value_function) + + return tf.while_loop(cond=_cond, + body=_body, + loop_vars=[initial_state], + parallel_iterations=1)[0] diff --git a/tensorflow_quantum/python/optimizers/rotosolve_minimizer_test.py b/tensorflow_quantum/python/optimizers/rotosolve_minimizer_test.py index 2631f9606..8bdcd28a7 100755 --- a/tensorflow_quantum/python/optimizers/rotosolve_minimizer_test.py +++ b/tensorflow_quantum/python/optimizers/rotosolve_minimizer_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Test module for tfq.python.optimizers.rotosolve_minimizer optimizer.""" +# 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 + from operator import mul from functools import reduce import numpy as np @@ -28,13 +36,11 @@ def loss_function_with_model_parameters(model, loss, train_x, train_y): """Create a new function that assign the model parameter to the model and evaluate its value. - Args: model : an instance of `tf.keras.Model` or its subclasses. loss : a function with signature loss_value = loss(pred_y, true_y). train_x : the input part of training data. train_y : the output part of training data. - Returns: A function that has a signature of: loss_value = f(model_parameters). @@ -55,10 +61,8 @@ def loss_function_with_model_parameters(model, loss, train_x, train_y): @tf.function def func(params): """A function that can be used by tfq.optimizer.rotosolve_minimize. - Args: params [in]: a 1D tf.Tensor. - Returns: Loss function value """ @@ -142,7 +146,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.py b/tensorflow_quantum/python/optimizers/spsa_minimizer.py new file mode 100644 index 000000000..10a915ee0 --- /dev/null +++ b/tensorflow_quantum/python/optimizers/spsa_minimizer.py @@ -0,0 +1,309 @@ +# Copyright 2021 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""The SPSA minimization algorithm.""" +import tensorflow as tf +import numpy as np + + +def prefer_static_shape(x): + """Return static shape of tensor `x` if available, + + else `tf.shape(x)`. + + Args: + x: `tf.Tensor` (already converted). + Returns: + Numpy array (if static shape is obtainable), else `tf.Tensor`. + """ + return prefer_static_value(tf.shape(x)) + + +def prefer_static_value(x): + """Return static value of tensor `x` if available, else `x`. + + Args: + x: `tf.Tensor` (already converted). + Returns: + Numpy array (if static value is obtainable), else `tf.Tensor`. + """ + static_x = tf.get_static_value(x) + if static_x is not None: + return static_x + return x + + +class SPSAOptimizerResults(tf.experimental.ExtensionType): + """ExtentionType of SPSA Optimizer tf.while_loop() inner state.""" + converged: tf.Tensor + # Scalar boolean tensor indicating whether the minimum + # was found within tolerance. + num_iterations: tf.Tensor + # The number of iterations of the SPSA update. + num_objective_evaluations: tf.Tensor + # The total number of objective + # evaluations performed. + position: tf.Tensor + # A tensor containing the last argument value found + # during the search. If the search converged, then + # this value is the argmin of the objective function. + # A tensor containing the value of the objective from + # previous iteration + objective_value_prev: tf.Tensor + # Save the evaluated value of the objective function + # from the previous iteration + objective_value: tf.Tensor + # A tensor containing the value of the objective + # function at the `position`. If the search + # converged, then this is the (local) minimum of + # the objective function. + tolerance: tf.Tensor + # Define the stop criteria. Iteration will stop when the + # objective value difference between two iterations is + # smaller than tolerance + learning_rate: tf.Tensor + # Specifies the learning rate + alpha: tf.Tensor + # Specifies scaling of the learning rate + perturb: tf.Tensor + # Specifies the size of the perturbations + gamma: tf.Tensor + # Specifies scaling of the size of the perturbations + blocking: tf.Tensor + # If true, then the optimizer will only accept updates that improve + # the objective function. + allowed_increase: tf.Tensor + + # Specifies maximum allowable increase in objective function + # (only applies if blocking is true). + + def to_dict(self): + """Transforms immutable data to mutable dictionary.""" + return { + "converged": self.converged, + "num_iterations": self.num_iterations, + "num_objective_evaluations": self.num_objective_evaluations, + "position": self.position, + "objective_value": self.objective_value, + "objective_value_prev": self.objective_value_prev, + "tolerance": self.tolerance, + "learning_rate": self.learning_rate, + "alpha": self.alpha, + "perturb": self.perturb, + "gamma": self.gamma, + "blocking": self.blocking, + "allowed_increase": self.allowed_increase, + } + + +def _get_initial_state(initial_position, tolerance, expectation_value_function, + learning_rate, alpha, perturb, gamma, blocking, + allowed_increase): + """Create SPSAOptimizerResults with initial state of search.""" + init_args = { + "converged": tf.Variable(False), + "num_iterations": tf.Variable(0), + "num_objective_evaluations": tf.Variable(0), + "position": tf.Variable(initial_position), + "objective_value": + (tf.cast(expectation_value_function(initial_position), tf.float32)), + "objective_value_prev": tf.Variable(np.inf), + "tolerance": tolerance, + "learning_rate": tf.Variable(learning_rate), + "alpha": tf.Variable(alpha), + "perturb": tf.Variable(perturb), + "gamma": tf.Variable(gamma), + "blocking": tf.Variable(blocking), + "allowed_increase": tf.Variable(allowed_increase), + } + return SPSAOptimizerResults(**init_args) + + +def minimize(expectation_value_function, + initial_position, + tolerance=1e-5, + max_iterations=200, + alpha=0.602, + learning_rate=1.0, + perturb=1.0, + gamma=0.101, + blocking=False, + allowed_increase=0.5, + seed=None, + name=None): + """Applies the SPSA algorithm. + + The SPSA algorithm can be used to minimize a noisy function. See: + + [SPSA website](https://www.jhuapl.edu/SPSA/) + + Usage: + + Here is an example of optimize a function which consists the + summation of a few quadratics. + + >>> n = 5 # Number of quadratics + >>> coefficient = tf.random.uniform(minval=0, maxval=1, shape=[n]) + >>> min_value = 0 + >>> func = func = lambda x : tf.math.reduce_sum(np.power(x, 2) * \ + coefficient) + >>> # Optimize the function with SPSA, start with random parameters + >>> result = tfq.optimizers.spsa_minimize(func, np.random.random(n)) + >>> result.converged + tf.Tensor(True, shape=(), dtype=bool) + >>> result.objective_value + tf.Tensor(0.0013349084, shape=(), dtype=float32) + + Args: + expectation_value_function: Python callable that accepts a real + valued tf.Tensor with shape [n] where n is the number of function + parameters. The return value is a real `tf.Tensor` Scalar + (matching shape `[1]`). + initial_position: Real `tf.Tensor` of shape `[n]`. The starting + point, or points when using batching dimensions, of the search + procedure. At these points the function value and the gradient + norm should be finite. + tolerance: Scalar `tf.Tensor` of real dtype. Specifies the tolerance + for the procedure. If the supremum norm between two iteration + vector is below this number, the algorithm is stopped. + learning_rate: Scalar `tf.Tensor` of real dtype. + Specifies the learning rate. + alpha: Scalar `tf.Tensor` of real dtype. Specifies scaling of the + learning rate. + perturb: Scalar `tf.Tensor` of real dtype. Specifies the size of the + perturbations. + gamma: Scalar `tf.Tensor` of real dtype. Specifies scaling of the + size of the perturbations. + blocking: Boolean. If true, then the optimizer will only accept + updates that improve the objective function. + allowed_increase: Scalar `tf.Tensor` of real dtype. Specifies maximum + allowable increase in objective function (only applies if blocking + is true). + seed: (Optional) Python integer. Used to create a random seed for the + perturbations. + name: (Optional) Python `str`. The name prefixed to the ops created + by this function. If not supplied, the default name 'minimize' + is used. + + Returns: + optimizer_results: A SPSAOptimizerResults object contains the + result of the optimization process. + """ + + with tf.name_scope(name or 'minimize'): + if seed is not None: + generator = tf.random.Generator.from_seed(seed) + else: + generator = tf.random + + initial_position = tf.convert_to_tensor(initial_position, + name='initial_position', + dtype='float32') + dtype = initial_position.dtype.base_dtype + tolerance = tf.convert_to_tensor(tolerance, + dtype=dtype, + name='grad_tolerance') + max_iterations = tf.convert_to_tensor(max_iterations, + name='max_iterations') + + learning_rate_init = tf.convert_to_tensor(learning_rate, + name='initial_a', + dtype='float32') + perturb_init = tf.convert_to_tensor(perturb, + name='initial_c', + dtype='float32') + + def _spsa_once(state): + """Caclulate single SPSA gradient estimation + + Args: + state: A SPSAOptimizerResults object stores the + current state of the minimizer. + + Returns: + states: A list which the first element is the new state + """ + delta_shift = tf.cast( + 2 * generator.uniform(shape=state.position.shape, + minval=0, + maxval=2, + dtype=tf.int32) - 1, tf.float32) + v_m = expectation_value_function(state.position - + state.perturb * delta_shift) + v_p = expectation_value_function(state.position + + state.perturb * delta_shift) + + gradient_estimate = (v_p - v_m) / (2 * state.perturb) * delta_shift + update = state.learning_rate * gradient_estimate + next_state_params = state.to_dict() + next_state_params.update({ + "num_objective_evaluations": + state.num_objective_evaluations + 2, + }) + + current_obj = tf.cast(expectation_value_function(state.position - + update), + dtype=tf.float32) + if state.objective_value_prev + \ + state.allowed_increase >= current_obj or not state.blocking: + next_state_params.update({ + "position": state.position - update, + "objective_value_prev": state.objective_value, + "objective_value": current_obj + }) + + return [SPSAOptimizerResults(**next_state_params)] + + # The `state` here is a `SPSAOptimizerResults` tuple with + # values for the current state of the algorithm computation. + def _cond(state): + """Continue if iterations remain and stopping condition + is not met.""" + return (state.num_iterations < max_iterations) \ + and (not state.converged) + + def _body(state): + """Main optimization loop.""" + new_learning_rate = learning_rate_init / ( + (tf.cast(state.num_iterations + 1, tf.float32) + + 0.01 * tf.cast(max_iterations, tf.float32))**state.alpha) + new_perturb = perturb_init / (tf.cast(state.num_iterations + 1, + tf.float32)**state.gamma) + + pre_state_params = state.to_dict() + pre_state_params.update({ + "learning_rate": new_learning_rate, + "perturb": new_perturb, + }) + + post_state = _spsa_once(SPSAOptimizerResults(**pre_state_params))[0] + post_state_params = post_state.to_dict() + post_state_params.update({ + "num_iterations": + post_state.num_iterations + 1, + "converged": + (tf.abs(state.objective_value - state.objective_value_prev) + < state.tolerance), + }) + return [SPSAOptimizerResults(**post_state_params)] + + initial_state = _get_initial_state(initial_position, tolerance, + expectation_value_function, + learning_rate, alpha, perturb, gamma, + blocking, allowed_increase) + + return tf.while_loop(cond=_cond, + body=_body, + loop_vars=[initial_state], + parallel_iterations=1)[0] diff --git a/tensorflow_quantum/python/optimizers/spsa_minimizer_test.py b/tensorflow_quantum/python/optimizers/spsa_minimizer_test.py new file mode 100644 index 000000000..a22a72079 --- /dev/null +++ b/tensorflow_quantum/python/optimizers/spsa_minimizer_test.py @@ -0,0 +1,274 @@ +# Copyright 2020 The TensorFlow Quantum Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================= +"""Test module for tfq.python.optimizers.spsa_minimizer optimizer.""" +# 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 + +from operator import mul +from functools import reduce +import numpy as np +import tensorflow as tf +from absl.testing import parameterized +import cirq +import sympy +from tensorflow_quantum.python.layers.high_level import pqc +from tensorflow_quantum.python import util +from tensorflow_quantum.python.optimizers import spsa_minimizer + + +def loss_function_with_model_parameters(model, loss, train_x, train_y): + """Create a new function that assign the model parameter to the model + and evaluate its value. + + Args: + model : an instance of `tf.keras.Model` or its subclasses. + loss : a function with signature loss_value = loss(pred_y, true_y). + train_x : the input part of training data. + train_y : the output part of training data. + + Returns: + A function that has a signature of: + loss_value = f(model_parameters). + """ + + # obtain the shapes of all trainable parameters in the model + shapes = tf.shape_n(model.trainable_variables) + count = 0 + sizes = [] + + # Record the shape of each parameter + for shape in shapes: + n = reduce(mul, shape) + sizes.append(n) + count += n + + # Function accept the parameter and evaluate model + @tf.function + def func(params): + """A function that can be used by tfq.optimizer.spsa_minimize. + + Args: + params [in]: a 1D tf.Tensor. + + Returns: + Loss function value + """ + + # update the parameters of the model + start = 0 + for i, size in enumerate(sizes): + model.trainable_variables[i].assign( + tf.reshape(params[start:start + size], shape)) + start += size + + # evaluate the loss + loss_value = loss(model(train_x, training=True), train_y) + if loss_value.shape != (): + loss_value = tf.cast(tf.math.reduce_mean(loss_value), tf.float32) + return loss_value + + return func + + +class SPSAMinimizerTest(tf.test.TestCase, parameterized.TestCase): + """Tests for the SPSA optimization algorithm.""" + + def test_nonlinear_function_optimization(self): + """Test to optimize a non-linear function. + """ + func = lambda x: x[0]**2 + x[1]**2 + + result = spsa_minimizer.minimize(func, tf.random.uniform(shape=[2])) + self.assertAlmostEqual(func(result.position).numpy(), 0, delta=1e-4) + self.assertTrue(result.converged) + + def test_quadratic_function_optimization(self): + """Test to optimize a sum of quadratic function. + """ + n = 2 + coefficient = tf.random.uniform(minval=0, maxval=1, shape=[n]) + func = lambda x: tf.math.reduce_sum(np.power(x, 2) * coefficient) + + result = spsa_minimizer.minimize(func, tf.random.uniform(shape=[n])) + self.assertAlmostEqual(func(result.position).numpy(), 0, delta=2e-4) + self.assertTrue(result.converged) + + def test_noisy_sin_function_optimization(self): + """Test noisy ssinusoidal function + """ + n = 10 + func = lambda x: tf.math.reduce_sum( + tf.math.sin(x) + tf.random.uniform( + minval=-0.1, maxval=0.1, shape=[n])) + + result = spsa_minimizer.minimize(func, tf.random.uniform(shape=[n])) + self.assertLessEqual(func(result.position).numpy(), -n + 0.1 * n) + + def test_failure_optimization(self): + """Test a function that is completely random and cannot be minimized + """ + n = 100 + func = lambda x: np.random.uniform(-10, 10, 1)[0] + it = 50 + + result = spsa_minimizer.minimize(func, + tf.random.uniform(shape=[n]), + max_iterations=it) + self.assertFalse(result.converged) + self.assertEqual(result.num_iterations, it) + + def test_blocking(self): + """Test the blocking functionality. + """ + n = 10 + it = 50 + + init = 1 + self.incr = 0 + + def block_func1(params): + self.incr += init + return self.incr + + result = spsa_minimizer.minimize(block_func1, + tf.random.uniform(shape=[n]), + blocking=True, + allowed_increase=0.5, + max_iterations=it) + self.assertFalse(result.converged) + self.assertEqual(result.num_iterations, it) + self.assertEqual(result.objective_value, + init * 4) # function executd 3 (in step) + + # 1 (initial evaluation) times + + init = 1 / 6 * 0.49 + self.incr = 0 + + def block_func2(params): + self.incr += init + return self.incr + + result = spsa_minimizer.minimize(block_func2, + tf.random.uniform(shape=[n]), + blocking=True, + allowed_increase=0.5, + max_iterations=it) + self.assertFalse(result.converged) + self.assertEqual(result.num_iterations, it) + self.assertEqual(result.objective_value, init * 3 * it + init) + + def test_3_qubit_circuit(self): + """Test quantum circuit optimization, adapted from Qiskit SPSA testing + https://github.com/Qiskit/qiskit-terra/blob/main/test/python/algorithms/optimizers/test_spsa.py#L37 + """ + qubits = [cirq.GridQubit(0, i) for i in range(3)] + params = sympy.symbols("q0:9") + circuit = cirq.Circuit() + for i in qubits: + circuit += cirq.ry(np.pi / 4).on(i) + circuit += cirq.ry(params[0]).on(qubits[0]) + circuit += cirq.ry(params[1]).on(qubits[1]) + circuit += cirq.rz(params[2]).on(qubits[2]) + + circuit += cirq.CZ(qubits[0], qubits[1]) + circuit += cirq.CZ(qubits[1], qubits[2]) + circuit += cirq.rz(params[3]).on(qubits[0]) + circuit += cirq.rz(params[4]).on(qubits[1]) + circuit += cirq.rx(params[5]).on(qubits[2]) + + # Build the Keras model. + model = tf.keras.Sequential([ + # The input is the data-circuit, encoded as a tf.string + tf.keras.layers.Input(shape=(), dtype=tf.string), + # The PQC layer returns the expected value of the + # readout gate, range [-1,1]. + pqc.PQC(circuit, + cirq.Z(qubits[0]) * cirq.Z(qubits[1]), + repetitions=1024), + ]) + + initial_point = np.array([ + 0.82311034, 0.02611798, 0.21077064, 0.61842177, 0.09828447, + 0.62013131 + ]) + + result = spsa_minimizer.minimize(loss_function_with_model_parameters( + model, lambda x, y: x[0][0], + util.convert_to_tensor([cirq.Circuit()]), None), + initial_point, + max_iterations=100) + + self.assertTrue(result.converged) + self.assertLess(result.objective_value.numpy(), -0.95) + + def test_keras_model_optimization(self): + """Optimizate a PQC based keras model.""" + + x = np.asarray([ + [0, 0], + [0, 1], + [1, 0], + [1, 1], + ], dtype=float) + + y = np.asarray([[-1], [1], [1], [-1]], dtype=np.float32) + + def convert_to_circuit(input_data): + """Encode into quantum datapoint.""" + values = np.ndarray.flatten(input_data) + qubits = cirq.GridQubit.rect(1, 2) + circuit = cirq.Circuit() + for i, value in enumerate(values): + if value: + circuit.append(cirq.X(qubits[i])) + return circuit + + x_circ = util.convert_to_tensor([convert_to_circuit(x) for x in x]) + + # Create two qubits + q0, q1 = cirq.GridQubit.rect(1, 2) + + # Create an anzatz on these qubits. + 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(q0, q1)) + + # Build the Keras model. + model = tf.keras.Sequential([ + # The input is the data-circuit, encoded as a tf.string + tf.keras.layers.Input(shape=(), dtype=tf.string), + # The PQC layer returns the expected value of the + # readout gate, range [-1,1]. + pqc.PQC(circuit, 2 * cirq.Z(q1)), + ]) + + # Initial guess of the parameter from random number + result = spsa_minimizer.minimize( + loss_function_with_model_parameters(model, tf.keras.losses.Hinge(), + x_circ, y), + tf.random.uniform(shape=[2]) * 2 * np.pi) + + self.assertAlmostEqual(result.objective_value.numpy(), 0) + self.assertTrue(result.converged) + + +if __name__ == "__main__": + tf.test.main() diff --git a/tensorflow_quantum/python/quantum_context.py b/tensorflow_quantum/python/quantum_context.py index 44c01cdeb..1a869bdea 100644 --- a/tensorflow_quantum/python/quantum_context.py +++ b/tensorflow_quantum/python/quantum_context.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """A global singleton object for defining op execution parameters.""" import multiprocessing diff --git a/tensorflow_quantum/python/quantum_context_test.py b/tensorflow_quantum/python/quantum_context_test.py index ac8055b33..7f7a62d58 100644 --- a/tensorflow_quantum/python/quantum_context_test.py +++ b/tensorflow_quantum/python/quantum_context_test.py @@ -11,8 +11,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for quantum_context functions.""" +# 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 import multiprocessing import tensorflow as tf diff --git a/tensorflow_quantum/python/util.py b/tensorflow_quantum/python/util.py index ec605c849..c736a403f 100644 --- a/tensorflow_quantum/python/util.py +++ b/tensorflow_quantum/python/util.py @@ -11,10 +11,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== -"""A collection of helper functions that are useful several places in tfq.""" -import random +# ============================================================================= +"""A collection of helper functions which are useful in places in TFQ.""" + import itertools +import numbers +import random import numpy as np import sympy @@ -22,12 +24,35 @@ import cirq from tensorflow_quantum.core.proto import pauli_sum_pb2 +from tensorflow_quantum.core.proto import program_pb2 from tensorflow_quantum.core.serialize import serializer +# Can't use set() since channels don't give proper support. +_SUPPORTED_CHANNELS = [ + cirq.AsymmetricDepolarizingChannel, + cirq.AmplitudeDampingChannel, + cirq.DepolarizingChannel, + cirq.GeneralizedAmplitudeDampingChannel, + cirq.ResetChannel, + cirq.PhaseDampingChannel, + cirq.PhaseFlipChannel, + cirq.BitFlipChannel, +] + def get_supported_gates(): - """A helper to get the gates supported by tfq.""" - supported_gates = serializer.SERIALIZER.supported_gate_types() + """A helper to get gates supported by TFQ. + + Returns a dictionary mapping from supported gate types + to the number of qubits each gate operates on. + + Any of these gates used in conjuction with the + `controlled_by` function for multi-qubit control are also + supported. + """ + supported_ops = serializer.SERIALIZER.supported_gate_types() + supported_gates = filter(lambda x: x not in _SUPPORTED_CHANNELS, + supported_ops) gate_arity_mapping_dict = dict() for gate in supported_gates: if gate is cirq.IdentityGate: @@ -46,36 +71,97 @@ def get_supported_gates(): return gate_arity_mapping_dict +def get_supported_channels(): + """A helper to get the channels that are supported in TFQ. + + Returns a dictionary mapping from supported channel types + to number of qubits. + """ + # Add new channels here whenever additional support is needed. + channel_mapping = dict() + channel_mapping[cirq.DepolarizingChannel(0.01)] = 1 + channel_mapping[cirq.AsymmetricDepolarizingChannel(0.01, 0.02, 0.03)] = 1 + channel_mapping[cirq.GeneralizedAmplitudeDampingChannel(0.01, 0.02)] = 1 + channel_mapping[cirq.AmplitudeDampingChannel(0.01)] = 1 + channel_mapping[cirq.ResetChannel()] = 1 + channel_mapping[cirq.PhaseDampingChannel(0.01)] = 1 + channel_mapping[cirq.PhaseFlipChannel(0.01)] = 1 + channel_mapping[cirq.BitFlipChannel(0.01)] = 1 + + return channel_mapping + + +def _apply_random_control(gate, all_qubits): + """Returns a random controlled version of `gate`. + + Chooses a random subset s from `all_qubits` that does not intersect + with `gate.qubits` and returns gate.controlled_by(s). Note that + if no such set s can be found (size of s would be zero) then + `gate` is returned unchanged. + + Args: + gate: Gate to be promoted to a controlled gate with the + `controlled_by` function in Cirq. + all_qubits: All qubits used by the circuit which `gate` + comes from. + Returns: + A new gate with a random subset of the set difference + between all_qubits and gate.qubits controlling `gate`. + """ + open_qubits = set(all_qubits) - set(gate.qubits) + n_open = min(len(open_qubits), 3) + if n_open == 0: + # No open qubits to control. Return unmodified gate. + return gate + control_locs = random.sample(open_qubits, n_open) + control_values = random.choices([0, 1], k=n_open) + # TODO(tonybruguier,#636): Here we call the parent's class controlled_by + # because Cirq's breaking change #4167 created 3-qubit gates that cannot be + # serialized yet. Instead, support 3-qubit gates and revert the work-around. + return cirq.ControlledOperation(control_locs, gate, control_values) + + def random_symbol_circuit(qubits, symbols, + *, n_moments=15, p=0.9, - include_scalars=True): - """Generate a random circuit including some parameterized gates. + include_scalars=True, + include_channels=False): + """Generates a random circuit including some parameterized gates. Symbols are randomly included in the gates of the first `n_moments` moments of the resulting circuit. Then, parameterized H gates are added as subsequent moments for any remaining unused symbols. """ - supported_gates = get_supported_gates() - circuit = cirq.testing.random_circuit(qubits, n_moments, p, supported_gates) + supported_ops = get_supported_gates() + if include_channels: + for chan, n in get_supported_channels().items(): + supported_ops[chan] = n + + circuit = cirq.testing.random_circuit(qubits, n_moments, p, supported_ops) random_symbols = list(symbols) random.shuffle(random_symbols) location = 0 for i in range(len(circuit)): - if np.random.random() < p: - op = random.choice(list(supported_gates.keys())) - n_qubits = supported_gates[op] - locs = tuple(random.sample(qubits, n_qubits)) - if isinstance(op, cirq.IdentityGate): - circuit[:i] += op.on(*locs) - else: - circuit[:i] += (op**( - (np.random.random() if include_scalars else 1.0) * - sympy.Symbol(random_symbols[location % len(random_symbols)]) - )).on(*locs) - location += 1 + op = random.choice(list(supported_ops.keys())) + n_qubits = supported_ops[op] + locs = tuple(random.sample(qubits, n_qubits)) + if isinstance(op, cirq.IdentityGate) or \ + any(isinstance(op, x) for x in _SUPPORTED_CHANNELS): + circuit[:i] += op.on(*locs) + continue + working_symbol = sympy.Symbol(random_symbols[location % + len(random_symbols)]) + working_scalar = np.random.random() if include_scalars else 1.0 + full_gate = (op**(working_scalar * working_symbol)).on(*locs) + if np.random.random() < 0.5: + # Add a control to this gate. + full_gate = _apply_random_control(full_gate, qubits) + + circuit[:i] += full_gate + location += 1 # Use the rest of the symbols while location < len(random_symbols): @@ -86,14 +172,43 @@ def random_symbol_circuit(qubits, return circuit -def random_circuit_resolver_batch(qubits, batch_size, n_moments=15, p=0.9): +def random_circuit_resolver_batch(qubits, + batch_size, + *, + n_moments=15, + p=0.9, + include_channels=False): """Generate a batch of random circuits and symbolless resolvers.""" + supported_ops = get_supported_gates() + if include_channels: + for chan, n in get_supported_channels().items(): + supported_ops[chan] = n + return_circuits = [] return_resolvers = [] for _ in range(batch_size): - return_circuits.append( - cirq.testing.random_circuit(qubits, n_moments, p, - get_supported_gates())) + circuit = cirq.testing.random_circuit(qubits, n_moments, p, + supported_ops) + + for i in range(len(circuit)): + op = random.choice(list(supported_ops.keys())) + n_qubits = supported_ops[op] + if (n_qubits > len(qubits)): + # skip adding gates in small case. + continue + locs = tuple(random.sample(qubits, n_qubits)) + if isinstance(op, cirq.IdentityGate) or \ + any(isinstance(op, x) for x in _SUPPORTED_CHANNELS): + circuit[:i] += op.on(*locs) + continue + full_gate = (op**np.random.random()).on(*locs) + if np.random.random() < 0.5: + # Add a control to this gate. + full_gate = _apply_random_control(full_gate, qubits) + + circuit[:i] += full_gate + + return_circuits.append(circuit) return_resolvers.append(cirq.ParamResolver({})) return return_circuits, return_resolvers @@ -102,16 +217,22 @@ def random_circuit_resolver_batch(qubits, batch_size, n_moments=15, p=0.9): def random_symbol_circuit_resolver_batch(qubits, symbols, batch_size, + *, n_moments=15, p=0.9, - include_scalars=True): + include_scalars=True, + include_channels=False): """Generate a batch of random circuits and resolvers.""" return_circuits = [] return_resolvers = [] for _ in range(batch_size): return_circuits.append( - random_symbol_circuit(qubits, symbols, n_moments, p, - include_scalars)) + random_symbol_circuit(qubits, + symbols, + n_moments=n_moments, + p=p, + include_scalars=include_scalars, + include_channels=include_channels)) return_resolvers.append( cirq.ParamResolver( @@ -140,7 +261,7 @@ def random_pauli_sums(qubits, max_sum_length, n_sums): # There are no native convertible ops inside of this function. @tf.autograph.experimental.do_not_convert -def convert_to_tensor(items_to_convert): +def convert_to_tensor(items_to_convert, deterministic_proto_serialize=False): """Convert lists of tfq supported primitives to tensor representations. Recursively convert a nested lists of `cirq.PauliSum` or `cirq.Circuit` @@ -171,11 +292,14 @@ def convert_to_tensor(items_to_convert): Args: items_to_convert: Python `list` or nested `list` of `cirq.Circuit` - or `cirq.Paulisum` objects. Should be rectangular, or this function - will error. - + or `cirq.Paulisum` objects. Must be recangular. + deterministic_proto_serialize: Whether to use a deterministic + serialization when calling SerializeToString(). Returns: - `tf.Tensor` that represents the input items. + A `tf.Tensor` that represents the input items. + + Raises: + TypeError: In case of invalid arguments provided in `items_to_convert`. """ # We use recursion here because np.ndenumerate tries to loop over @@ -191,16 +315,18 @@ def recur(items_to_convert, curr_type=None): not curr_type == cirq.Circuit: curr_type = cirq.PauliSum tensored_items.append( - serializer.serialize_paulisum(item).SerializeToString()) + serializer.serialize_paulisum(item).SerializeToString( + deterministic=deterministic_proto_serialize)) elif isinstance(item, cirq.Circuit) and\ not curr_type == cirq.PauliSum: curr_type = cirq.Circuit tensored_items.append( - serializer.serialize_circuit(item).SerializeToString()) + serializer.serialize_circuit(item).SerializeToString( + deterministic=deterministic_proto_serialize)) else: raise TypeError("Incompatible item passed into " - " convert_to_tensor. Tensor detected type: {}." - " got: {}".format(curr_type, type(item))) + "convert_to_tensor. Tensor detected type: {}. " + "got: {}".format(curr_type, type(item))) return tensored_items # This will catch impossible dimensions @@ -211,7 +337,7 @@ def _parse_single(item): try: if b'tfq_gate_set' in item: # Return a circuit parsing - obj = cirq.google.api.v2.program_pb2.Program() + obj = program_pb2.Program() obj.ParseFromString(item) out = serializer.deserialize_circuit(obj) return out @@ -259,6 +385,9 @@ def from_tensor(tensor_to_convert): Returns: Python `list` of items converted to their python representation stored in a (potentially nested) `list`. + + Raises: + TypeError: In case of an invalid tensor passed for conversion. """ if isinstance(tensor_to_convert, tf.Tensor): tensor_to_convert = tensor_to_convert.numpy() @@ -300,6 +429,9 @@ def kwargs_cartesian_product(**kwargs): Returns: Python `generator` of the cartesian product of the inputs `kwargs`. + + Raises: + ValueError: In case of invalid arguments passed to `kwargs`. """ keys = kwargs.keys() vals = kwargs.values() @@ -344,6 +476,152 @@ def _symbols_in_op(op): "tfq.util.get_supported_gates().") +def _expression_approx_eq(exp_1, exp_2, atol): + """Compare possibly symbolic expressions for approximate equality. + + Coefficient based approximate equality. If no symbol is present in + `exp_1` or `exp_2`, then return true if the expressions are approximately + equal. If the expressions contain symbols, return true if the two symbols + are the same and their coefficients are approximately equal. + + Args: + exp_1: An argument to a cirq Gate, either a `sympy.Basic` or a number. + exp_1: An argument to a cirq Gate, either a `sympy.Basic` or a number. + atol: Float determining how close the coefficients must be for truth. + + Returns: + bool which says whether the coefficients of `exp_1` and `exp_2` are + approximately equal. + + Raises: + TypeError: If `atol` is not a real number. + """ + if not isinstance(atol, numbers.Real): + raise TypeError("atol must be a real number.") + s_1 = serializer._symbol_extractor(exp_1) + s_2 = serializer._symbol_extractor(exp_2) + v_1 = serializer._scalar_extractor(exp_1) + v_2 = serializer._scalar_extractor(exp_2) + v_eq = cirq.approx_eq(v_1, v_2, atol=atol) + if isinstance(s_1, numbers.Real) and isinstance(s_2, numbers.Real): + return cirq.approx_eq(s_1, s_2, atol=atol) and v_eq + if isinstance(s_1, sympy.Symbol) and isinstance(s_2, sympy.Symbol): + return str(s_1) == str(s_2) and v_eq + return False + + +# TODO: replace with cirq.approx_eq once +# https://github.com/quantumlib/Cirq/issues/3886 is resolved for all channels. +def _channel_approx_eq(op_true, op_deser, atol=1e-5): + if isinstance(op_true, cirq.DepolarizingChannel): + if isinstance(op_deser, cirq.DepolarizingChannel): + return abs(op_true.p - op_deser.p) < atol + + if isinstance(op_true, cirq.AsymmetricDepolarizingChannel): + if isinstance(op_deser, cirq.AsymmetricDepolarizingChannel): + return abs(op_true.p_x - op_deser.p_x) < atol and \ + abs(op_true.p_y - op_deser.p_y) < atol and \ + abs(op_true.p_z - op_deser.p_z) < atol + + if isinstance(op_true, cirq.GeneralizedAmplitudeDampingChannel): + if isinstance(op_deser, cirq.GeneralizedAmplitudeDampingChannel): + return abs(op_true.p - op_deser.p) < atol and \ + abs(op_true.gamma - op_deser.gamma) < atol + + if isinstance(op_true, cirq.AmplitudeDampingChannel): + if isinstance(op_deser, cirq.AmplitudeDampingChannel): + return abs(op_true.gamma - op_deser.gamma) < atol + + if isinstance(op_true, cirq.ResetChannel): + if isinstance(op_deser, cirq.ResetChannel): + return True + + if isinstance(op_true, cirq.PhaseDampingChannel): + if isinstance(op_deser, cirq.PhaseDampingChannel): + return abs(op_true.gamma - op_deser.gamma) < atol + + if isinstance(op_true, cirq.PhaseFlipChannel): + if isinstance(op_deser, cirq.PhaseFlipChannel): + return abs(op_true.p - op_deser.p) < atol + + if isinstance(op_true, cirq.BitFlipChannel): + if isinstance(op_deser, cirq.BitFlipChannel): + return abs(op_true.p - op_deser.p) < atol + + return False + + +def gate_approx_eq(gate_true, gate_deser, atol=1e-5): + """Compares gates in the allowed TFQ gate set. + + Gates in TFQ support symbols, numbers or a single product of a real number + and a symbol as their parameters. This function behaves like + `cirq.approx_eq` specialized for these kinds of gates so that TFQ can + support approximate equality in gates containing symbols. + + Args: + gate_true: `cirq.Gate` which is in the TFQ gate set. These are gates + which are instances of those found in `tfq.util.get_supported_gates()` + gate_deser: `cirq.Gate` which is in the TFQ gate set. These are gates + which are instances of those found in `tfq.util.get_supported_gates()` + + Returns: + bool which says if the two gates are approximately equal in the way + described above. + + Raises: + TypeError: If input gates are not of type `cirq.Gate`. + ValueError: If invalid gate types are provided. + """ + if not isinstance(gate_true, cirq.Gate): + raise TypeError(f"`gate_true` not a cirq gate, got {type(gate_true)}") + if not isinstance(gate_deser, cirq.Gate): + raise TypeError(f"`gate_deser` not a cirq gate, got {type(gate_deser)}") + if isinstance(gate_true, cirq.ControlledGate) != isinstance( + gate_deser, cirq.ControlledGate): + return False + if isinstance(gate_true, cirq.ControlledGate): + if gate_true.control_qid_shape != gate_deser.control_qid_shape: + return False + if gate_true.control_values != gate_deser.control_values: + return False + return gate_approx_eq(gate_true.sub_gate, gate_deser.sub_gate) + supported_gates = serializer.SERIALIZER.supported_gate_types() + if not any([isinstance(gate_true, g) for g in supported_gates]): + raise ValueError(f"`gate_true` not a valid TFQ gate, got {gate_true}") + if not any([isinstance(gate_deser, g) for g in supported_gates]): + raise ValueError(f"`gate_deser` not a valid TFQ gate, got {gate_deser}") + if not isinstance(gate_true, type(gate_deser)): + return False + if isinstance(gate_true, type(cirq.I)) and isinstance( + gate_deser, type(cirq.I)): + # all identity gates are the same + return True + if isinstance(gate_true, cirq.EigenGate): + a = _expression_approx_eq(gate_true._global_shift, + gate_deser._global_shift, atol) + b = _expression_approx_eq(gate_true._exponent, gate_deser._exponent, + atol) + return a and b + if isinstance(gate_true, cirq.FSimGate): + a = _expression_approx_eq(gate_true.theta, gate_deser.theta, atol) + b = _expression_approx_eq(gate_true.phi, gate_deser.phi, atol) + return a and b + if isinstance(gate_true, (cirq.PhasedXPowGate, cirq.PhasedISwapPowGate)): + a = _expression_approx_eq(gate_true._global_shift, + gate_deser._global_shift, atol) + b = _expression_approx_eq(gate_true._exponent, gate_deser._exponent, + atol) + c = _expression_approx_eq(gate_true._phase_exponent, + gate_deser._phase_exponent, atol) + return a and b and c + if any(isinstance(gate_true, x) for x in _SUPPORTED_CHANNELS): + # Compare channels. + return _channel_approx_eq(gate_true, gate_deser, atol) + raise ValueError( + f"Some valid TFQ gate type is not yet accounted for, got {gate_true}") + + def get_circuit_symbols(circuit): """Returns a list of the sympy.Symbols that are present in `circuit`. @@ -352,12 +630,20 @@ def get_circuit_symbols(circuit): Returns: Python `list` containing the symbols found in the circuit. + + Raises: + TypeError: If `circuit` is not of type `cirq.Circuit`. """ + if not isinstance(circuit, cirq.Circuit): + raise TypeError(f"Expected a cirq.Circuit object, got {circuit}.") all_symbols = set() for moment in circuit: for op in moment: if cirq.is_parameterized(op): - all_symbols |= _symbols_in_op(op.gate) + sub_op = op + if isinstance(op, cirq.ControlledOperation): + sub_op = op.sub_operation + all_symbols |= _symbols_in_op(sub_op.gate) return [str(x) for x in all_symbols] @@ -410,12 +696,14 @@ def _many_z_to_single_z(focal_qubit, pauli_sum): def check_commutability(pauli_sum): - """Return False if at least one pair of terms in pauli_sum is not - commutable. + """Determines whether pairs of terms in `pauli_sum` are commutable. Args: pauli_sum: `cirq.PauliSum` object to be checked if all of terms inside are commutable each other. + + Raises: + ValueError: If one or more term pairs in `pauli_sum` are not commutable. """ for term1 in pauli_sum: for term2 in pauli_sum: @@ -437,7 +725,7 @@ def exp_identity(param, c, zeroth_qubit): def exponential(operators, coefficients=None): - """Return a Cirq circuit with exponential forms of operators. + """Return a Cirq circuit with exponential operator forms. Construct an exponential form of given `operators` and `coefficients`. Operators to be exponentiated are specified in `operators` as @@ -464,6 +752,8 @@ def exponential(operators, coefficients=None): Returns: A `cirq.Circuit` containing exponential form of given `operators` and `coefficients`. + Raises: + TypeError: If `operators` (or its terms) is/are of an invalid type. """ # Ingest operators. if not isinstance(operators, (list, tuple)): diff --git a/tensorflow_quantum/python/util_test.py b/tensorflow_quantum/python/util_test.py index db8af817e..0e1159806 100644 --- a/tensorflow_quantum/python/util_test.py +++ b/tensorflow_quantum/python/util_test.py @@ -11,8 +11,16 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ============================================================================== +# ============================================================================= """Tests for TFQ utilities.""" +# 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 + import numpy as np import tensorflow as tf from absl.testing import parameterized @@ -28,8 +36,10 @@ def _single_to_tensor(item): raise TypeError("Item must be a Circuit or PauliSum. Got {}.".format( type(item))) if isinstance(item, (cirq.PauliSum, cirq.PauliString)): - return serializer.serialize_paulisum(item).SerializeToString() - return serializer.serialize_circuit(item).SerializeToString() + return serializer.serialize_paulisum(item).SerializeToString( + deterministic=True) + return serializer.serialize_circuit(item).SerializeToString( + deterministic=True) def _exponential(theta, op): @@ -37,7 +47,7 @@ def _exponential(theta, op): return np.eye(op_mat.shape[0]) * np.cos(theta) - 1j * op_mat * np.sin(theta) -BITS = list(cirq.GridQubit.rect(1, 10)) +BITS = list(cirq.GridQubit.rect(1, 10) + cirq.LineQubit.range(2)) def _items_to_tensorize(): @@ -61,20 +71,32 @@ class UtilFunctionsTest(tf.test.TestCase, parameterized.TestCase): def test_get_supported_gates(self): """Confirm one of every gate is returned.""" mapping_1 = util.get_supported_gates() - self.assertEqual(len(mapping_1.keys()), - len(serializer.SERIALIZER.supported_gate_types())) + self.assertEqual( + len(mapping_1.keys()), + len(serializer.SERIALIZER.supported_gate_types()) - + len(util.get_supported_channels())) + + def test_get_supported_channels(self): + """Confirm one of every channel is returned.""" + mapping_1 = util.get_supported_channels() + self.assertEqual( + len(mapping_1.keys()), + len(serializer.SERIALIZER.supported_gate_types()) - + len(util.get_supported_gates())) @parameterized.parameters(_items_to_tensorize()) def test_convert_to_tensor(self, item): """Test that the convert_to_tensor function works correctly by manually serializing flat and 2-deep nested lists of Circuits and PauliSums.""" nested = [[item, item]] * 2 - nested_actual = util.convert_to_tensor(nested) + nested_actual = util.convert_to_tensor( + nested, deterministic_proto_serialize=True) nested_expected = np.array( [np.array([_single_to_tensor(x) for x in row]) for row in nested]) self.assertAllEqual(nested_actual, nested_expected) flat = [item, item] - flat_actual = util.convert_to_tensor(flat) + flat_actual = util.convert_to_tensor(flat, + deterministic_proto_serialize=True) flat_expected = np.array([_single_to_tensor(x) for x in flat]) self.assertAllEqual(flat_actual, flat_expected) @@ -96,15 +118,18 @@ def test_convert_to_tensor_errors(self): def test_from_tensor(self, item): """Check from_tensor assuming convert_to_tensor works.""" - item_nested_tensorized = util.convert_to_tensor([[item, item], - [item, item]]) - item_flat_tensorized = util.convert_to_tensor([item, item]) + item_nested_tensorized = util.convert_to_tensor( + [[item, item], [item, item]], deterministic_proto_serialize=True) + item_flat_tensorized = util.convert_to_tensor( + [item, item], deterministic_proto_serialize=True) item_nested_cycled = util.convert_to_tensor( - util.from_tensor(item_nested_tensorized)) + util.from_tensor(item_nested_tensorized), + deterministic_proto_serialize=True) self.assertAllEqual(item_nested_tensorized, item_nested_cycled) item_flat_cycled = util.convert_to_tensor( - util.from_tensor(item_flat_tensorized)) + util.from_tensor(item_flat_tensorized), + deterministic_proto_serialize=True) self.assertAllEqual(item_flat_tensorized, item_flat_cycled) def test_from_tensor_errors(self): @@ -181,6 +206,190 @@ def test_cartesian_product(self): with self.assertRaisesRegex(ValueError, expected_regex='not iterable'): list(util.kwargs_cartesian_product(a=[1, 2], b=-1)) + def test_expression_approx_eq(self): + """Test that coefficients and symbols are compared correctly.""" + # integers + a = 1 + b = 1 + c = 2 + atol = 0.1 + self.assertTrue(util._expression_approx_eq(a, b, atol)) + self.assertFalse(util._expression_approx_eq(a, c, atol)) + self.assertTrue(util._expression_approx_eq(a, c, 2.0)) + + # reals + a = 1.1234 + b = 1.1231 + c = 1.1220 + atol = 5e-4 + self.assertTrue(util._expression_approx_eq(a, b, atol)) + self.assertFalse(util._expression_approx_eq(a, c, atol)) + self.assertTrue(util._expression_approx_eq(a, c, 0.01)) + + # symbols + a = sympy.Symbol("s") + b = sympy.Symbol("s") + c = sympy.Symbol("s_wrong") + self.assertTrue(util._expression_approx_eq(a, b, atol)) + self.assertFalse(util._expression_approx_eq(a, c, atol)) + + # number * symbol + a = 3.5 * sympy.Symbol("s") + b = 3.501 * sympy.Symbol("s") + c = 3.5 * sympy.Symbol("s_wrong") + atol = 1e-2 + self.assertTrue(util._expression_approx_eq(a, b, atol)) + self.assertFalse(util._expression_approx_eq(a, c, atol)) + c = 3.6 * sympy.Symbol("s") + self.assertFalse(util._expression_approx_eq(a, c, atol)) + + # symbol * number + a = sympy.Symbol("s") * -1.7 + b = sympy.Symbol("s") * -1.701 + c = sympy.Symbol("s_wrong") * -1.7 + atol = 1e-2 + self.assertTrue(util._expression_approx_eq(a, b, atol)) + self.assertFalse(util._expression_approx_eq(a, c, atol)) + c = sympy.Symbol("s") * -1.8 + self.assertFalse(util._expression_approx_eq(a, c, atol)) + + # other not equal + atol = 1e-3 + self.assertFalse(util._expression_approx_eq(1, sympy.Symbol("s"), atol)) + self.assertFalse(util._expression_approx_eq(sympy.Symbol("s"), 1, atol)) + + def test_expression_approx_eq_error(self): + """Confirms that bad inputs raise appropriate errors.""" + # too complicated + a = sympy.Symbol("s_1") * sympy.Symbol("s_2") + b = 1.0 * a + with self.assertRaisesRegex(ValueError, expected_regex='not supported'): + _ = util._expression_approx_eq(a, a, 1e-3) + with self.assertRaisesRegex(ValueError, expected_regex='not supported'): + _ = util._expression_approx_eq(a, b, 1e-3) + + # junk + with self.assertRaisesRegex(TypeError, expected_regex='Invalid input'): + _ = util._expression_approx_eq(1, 'junk', 1e-3) + with self.assertRaisesRegex(TypeError, expected_regex='Invalid input'): + _ = util._expression_approx_eq('junk', 1, 1e-3) + with self.assertRaisesRegex(TypeError, + expected_regex='atol must be a real'): + _ = util._expression_approx_eq(1, 1, 'junk') + + def test_gate_approx_eq(self): + """Check valid TFQ gates for approximate equality.""" + atol = 1e-2 + exps_true = [ + 3, 2.54, -1.7 * sympy.Symbol("s_1"), + sympy.Symbol("s_2") * 4.3 + ] + exps_eq = [ + 3, 2.542, -1.705 * sympy.Symbol("s_1"), + sympy.Symbol("s_2") * 4.305 + ] + exps_not_eq = [ + 4, 2.57, -1.5 * sympy.Symbol("s_1"), + sympy.Symbol("s_2") * 4.4 + ] + + # Not a child class + self.assertFalse(util.gate_approx_eq(cirq.X, cirq.Y)) + + # Identity gate + self.assertTrue(util.gate_approx_eq(cirq.I, cirq.I)) + + # Parameterized gates + for e_true, e_eq, e_not_eq in zip(exps_true, exps_eq, exps_not_eq): + for g in serializer.EIGEN_GATES_DICT: + g_true = g(exponent=e_true, global_shift=e_eq) + g_eq = g(exponent=e_eq, global_shift=e_true) + g_not_eq = g(exponent=e_not_eq, global_shift=e_not_eq) + self.assertTrue(util.gate_approx_eq(g_true, g_eq, atol=atol)) + self.assertFalse( + util.gate_approx_eq(g_true, g_not_eq, atol=atol)) + for g in serializer.PHASED_EIGEN_GATES_DICT: + g_true = g(exponent=e_true, phase_exponent=-1.0 * e_true) + g_eq = g(exponent=e_eq, phase_exponent=-1.0 * e_eq) + g_not_eq = g(exponent=e_not_eq, phase_exponent=-1.0 * e_not_eq) + self.assertTrue(util.gate_approx_eq(g_true, g_eq, atol=atol)) + self.assertFalse( + util.gate_approx_eq(g_true, g_not_eq, atol=atol)) + g_true = cirq.FSimGate(theta=e_true, phi=e_eq) + g_eq = cirq.FSimGate(theta=e_eq, phi=e_true) + g_not_eq = cirq.FSimGate(theta=e_not_eq, phi=e_not_eq) + self.assertTrue(util.gate_approx_eq(g_true, g_eq, atol=atol)) + self.assertFalse(util.gate_approx_eq(g_true, g_not_eq, atol=atol)) + + # Controlled gates + self.assertFalse( + util.gate_approx_eq( + cirq.ops.ControlledGate(cirq.X, 2, [1, 0], [2, 2]), + cirq.ops.ControlledGate(cirq.X, 2, [1, 1], [2, 2]))) + self.assertFalse( + util.gate_approx_eq( + cirq.ops.ControlledGate(cirq.X, 2, [1, 0], [2, 2]), + cirq.ops.ControlledGate(cirq.X, 2, [1, 0], [2, 1]))) + self.assertFalse( + util.gate_approx_eq( + cirq.ops.ControlledGate(cirq.X, 2, [1, 0], [2, 2]), + cirq.ops.ControlledGate(cirq.Y, 2, [1, 0], [2, 2]))) + self.assertTrue( + util.gate_approx_eq( + cirq.ops.ControlledGate(cirq.X, 2, [1, 0], [2, 2]), + cirq.ops.ControlledGate(cirq.X, 2, [1, 0], [2, 2]))) + + # Mixed gates + self.assertFalse( + util.gate_approx_eq( + cirq.ops.ControlledGate(cirq.X, 2, [1, 0], [2, 2]), cirq.X)) + self.assertFalse( + util.gate_approx_eq( + cirq.X, cirq.ops.ControlledGate(cirq.X, 2, [1, 0], [2, 2]))) + + def test_gate_approx_eq_error(self): + """Confirms that bad inputs cause an error to be raised.""" + # junk + with self.assertRaisesRegex(TypeError, + expected_regex="`gate_true` not a cirq"): + _ = util.gate_approx_eq("junk", cirq.I) + with self.assertRaisesRegex(TypeError, + expected_regex="`gate_deser` not a cirq"): + _ = util.gate_approx_eq(cirq.I, "junk") + + # Unsupported gates + with self.assertRaisesRegex( + ValueError, expected_regex="`gate_true` not a valid TFQ gate"): + _ = util.gate_approx_eq( + cirq.PhasedXZGate(x_exponent=1, + z_exponent=1, + axis_phase_exponent=1), cirq.I) + with self.assertRaisesRegex( + ValueError, expected_regex="`gate_deser` not a valid TFQ gate"): + _ = util.gate_approx_eq( + cirq.I, + cirq.PhasedXZGate(x_exponent=1, + z_exponent=1, + axis_phase_exponent=1)) + # Unsupported gates inside a controlled gate + with self.assertRaisesRegex( + ValueError, expected_regex="`gate_true` not a valid TFQ gate"): + _ = util.gate_approx_eq( + cirq.ops.ControlledGate( + cirq.PhasedXZGate(x_exponent=1, + z_exponent=1, + axis_phase_exponent=1), 2, [1, 0], + [2, 2]), cirq.ops.ControlledGate(cirq.X, 2, [1, 0], [2, 2])) + with self.assertRaisesRegex( + ValueError, expected_regex="`gate_deser` not a valid TFQ gate"): + _ = util.gate_approx_eq( + cirq.ops.ControlledGate(cirq.X, 2, [1, 0], [2, 2]), + cirq.ops.ControlledGate( + cirq.PhasedXZGate(x_exponent=1, + z_exponent=1, + axis_phase_exponent=1), 2, [1, 0], + [2, 2])) + def test_get_circuit_symbols(self): """Test that symbols can be extracted from circuits. This test will error out if get_supported_gates gets updated with new @@ -190,8 +399,9 @@ def test_get_circuit_symbols(self): qubits = cirq.GridQubit.rect(1, 20) n_moments = 200 for _ in range(5): - test_circuit = util.random_symbol_circuit(qubits, expected_symbols, - n_moments) + test_circuit = util.random_symbol_circuit(qubits, + expected_symbols, + n_moments=n_moments) extracted_symbols = util.get_circuit_symbols(test_circuit) self.assertListEqual(sorted(extracted_symbols), sorted(expected_symbols)) @@ -202,24 +412,21 @@ def test_get_circuit_symbols_all(self): qubits = cirq.GridQubit.rect(1, 2) n_moments = 1 for _ in range(5): - test_circuit = util.random_symbol_circuit(qubits, expected_symbols, - n_moments) + test_circuit = util.random_symbol_circuit(qubits, + expected_symbols, + n_moments=n_moments) extracted_symbols = util.get_circuit_symbols(test_circuit) self.assertListEqual(sorted(extracted_symbols), sorted(expected_symbols)) def test_get_circuit_symbols_error(self): - """Ensure that errors are reported when using unsupported ops.""" - # TODO(mbbrough): remove this test once we reach complete parity - # with cirq in terms of parametrized gate support. - qubits = cirq.GridQubit.rect(1, 2) - symbol = sympy.Symbol("u") - op = cirq.ZPowGate(exponent=symbol).on(qubits[0]).controlled_by( - qubits[1]) - bad_circuit = cirq.Circuit(op) - with self.assertRaisesRegex( - ValueError, expected_regex="tfq.util.get_supported_gates"): - util.get_circuit_symbols(bad_circuit) + """Make sure that the method errors where it should.""" + for param in ['2', sympy.Symbol("X")]: + # Passed an invalid parameter (not a cirq.Circuit). + with self.assertRaisesRegex(TypeError, + expected_regex='Expected a ' + 'cirq.Circuit'): + util.get_circuit_symbols(param) class ExponentialUtilFunctionsTest(tf.test.TestCase): @@ -378,7 +585,7 @@ def test_serializability(self): op1 = theta * cirq.Z(q[0]) * cirq.Z(q[1]) op2 = theta * identity circuit = util.exponential(operators=[op1, op2]) - util.convert_to_tensor([circuit]) + util.convert_to_tensor([circuit], deterministic_proto_serialize=True) if __name__ == "__main__": diff --git a/third_party/cuquantum/BUILD b/third_party/cuquantum/BUILD new file mode 100644 index 000000000..e69de29bb diff --git a/third_party/cuquantum/BUILD.tpl b/third_party/cuquantum/BUILD.tpl new file mode 100644 index 000000000..0ec87701f --- /dev/null +++ b/third_party/cuquantum/BUILD.tpl @@ -0,0 +1,23 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "cuquantum_headers", + linkstatic = 1, + srcs = [":cuquantum_header_include"], + includes = ["include"], + visibility = ["//visibility:public"], +) + +cc_library( + name = "libcuquantum", + srcs = [ + ":libcustatevec.so", + ], + linkopts = [ + "-Wl,-rpath,%{CUQUANTUM_LIBRARY_PATH}", + ], + visibility = ["//visibility:public"], +) + +%{CUQUANTUM_HEADER_GENRULE} +%{CUSTATEVEC_SHARED_LIBRARY_GENRULE} diff --git a/third_party/cuquantum/cuquantum_configure.bzl b/third_party/cuquantum/cuquantum_configure.bzl new file mode 100644 index 000000000..1a301ebb0 --- /dev/null +++ b/third_party/cuquantum/cuquantum_configure.bzl @@ -0,0 +1,257 @@ +"""Setup cuQuantum as external dependency.""" +_CUQUANTUM_ROOT = "CUQUANTUM_ROOT" + + +def _tpl(repository_ctx, tpl, substitutions = {}, out = None): + if not out: + out = tpl + repository_ctx.template( + out, + Label("//third_party/cuquantum:%s.tpl" % tpl), + substitutions, + ) + + +def _fail(msg): + """Output failure message when auto configuration fails.""" + red = "\033[0;31m" + no_color = "\033[0m" + fail("%sPython Configuration Error:%s %s\n" % (red, no_color, msg)) + + +def _warn(msg): + """Output warning message when auto configuration warns.""" + brown = "\033[1;33m" + no_color = "\033[0m" + print("\n%sAuto-Configuration Warning:%s %s\n" % (brown, no_color, msg)) + + +def _execute( + repository_ctx, + cmdline, + error_msg = None, + error_details = None, + empty_stdout_fine = False): + """Executes an arbitrary shell command. + + Args: + repository_ctx: the repository_ctx object + cmdline: list of strings, the command to execute + error_msg: string, a summary of the error if the command fails + error_details: string, details about the error or steps to fix it + empty_stdout_fine: bool, if True, an empty stdout result is fine, otherwise + it's an error + + Return: + the result of repository_ctx.execute(cmdline) + """ + result = repository_ctx.execute(cmdline) + if result.stderr or not (empty_stdout_fine or result.stdout): + _fail("\n".join([ + error_msg.strip() if error_msg else "Repository command failed", + result.stderr.strip(), + error_details if error_details else "", + ])) + return result + + +def _read_dir(repository_ctx, src_dir): + """Returns a string with all files in a directory. + + Finds all files inside a directory, traversing subfolders and following + symlinks. The returned string contains the full path of all files + separated by line breaks. + """ + find_result = _execute( + repository_ctx, + ["find", src_dir, "-follow", "-type", "f"], + empty_stdout_fine = True, + ) + result = find_result.stdout + return result + + +def _find_file(repository_ctx, filename): + """Returns a string with a directory path including the filename. + + The returned string contains the parent path of the filename. + """ + result = repository_ctx.execute( + ["timeout", "10", "find", "/", "-name", filename, "-print", "-quit", "-not", "-path", "'*/.*'", "-quit"]).stdout + result = result[:result.find(filename)+len(filename)] + return result + + +def _genrule(genrule_name, command, outs): + """Returns a string with a genrule. + + Genrule executes the given command and produces the given outputs. + + Args: + genrule_name: A unique name for genrule target. + command: The command to run. + outs: A list of files generated by this rule. + + Returns: + A genrule target. + """ + return ( + "genrule(\n" + + ' name = "' + + genrule_name + '",\n' + + " outs = [\n" + + outs + + "\n ],\n" + + ' cmd = """\n' + + command + + '\n """,\n' + + ")\n" + ) + +def _norm_path(path): + """Returns a path with '/' and remove the trailing slash.""" + path = path.replace("\\", "/") + if path[-1] == "/": + path = path[:-1] + return path + + +def _symlink_genrule_for_dir( + repository_ctx, + src_dir, + dest_dir, + genrule_name, + src_files = [], + dest_files = [], + is_empty_genrule = False): + """Returns a genrule to symlink(or copy if on Windows) a set of files. + + If src_dir is passed, files will be read from the given directory; otherwise + we assume files are in src_files and dest_files. Here are the examples: + + ``` + genrule( + name = "cuquantum_header_include", + outs = [ + "include/custatevec.h", + "include/cutensornet.h", + "include/cutensornet/types.h", + "include/cutensornet/typesDistributed.h", + ], + cmd = [some copy command lines based on users' local environment], + ) + genrule( + name = "libcustatevec.so", + outs = [ + "libcustatevec.so", + ], + cmd = [some copy command lines based on users' local environment], + ) + ``` + + Args: + repository_ctx: the repository_ctx object. + src_dir: source directory. + dest_dir: directory to create symlink in. + genrule_name: genrule name. + src_files: list of source files instead of src_dir. + dest_files: list of corresonding destination files. + is_empty_genrule: True if CUQUANTUM_ROOT is not set. + + Returns: + genrule target that creates the symlinks. + """ + if is_empty_genrule: + if dest_dir != "": + target_path = "%s/%s.h" % (dest_dir, genrule_name) + else: + target_path = genrule_name + genrule = _genrule( + genrule_name, + "touch $(OUTS)", + "'%s'" % (target_path), + ) + return genrule + + if src_dir != None: + src_dir = _norm_path(src_dir) + dest_dir = _norm_path(dest_dir) + files = "\n".join(sorted(_read_dir(repository_ctx, src_dir).splitlines())) + + dest_files = files.replace(src_dir, "").splitlines() + src_files = files.splitlines() + command = [] + outs = [] + + for i in range(len(dest_files)): + if dest_files[i] != "": + # If we have only one file to link we do not want to use the dest_dir, as + # $(@D) will include the full path to the file. + dest = "$(@D)/" + dest_dir + dest_files[i] if len(dest_files) != 1 else "$(@D)/" + dest_files[i] + + # Copy the headers to create a sandboxable setup. + cmd = "cp -f" + command.append(cmd + ' "%s" "%s"' % (src_files[i], dest)) + outs.append(' "' + dest_dir + dest_files[i] + '",') + + genrule = _genrule( + genrule_name, + " && ".join(command), + "\n".join(outs), + ) + return genrule + + +def _cuquantum_pip_impl(repository_ctx): + if _CUQUANTUM_ROOT in repository_ctx.os.environ: + cuquantum_root = repository_ctx.os.environ[_CUQUANTUM_ROOT] + else: + repository_ctx.os.environ[_CUQUANTUM_ROOT] = "" + cuquantum_root = "" + if cuquantum_root == "": + # CUQUANTUM_ROOT is empty. Let's find the library root path lazily. + cuquantum_header_path = _find_file(repository_ctx, "custatevec.h") + cuquantum_header_path = cuquantum_header_path[:cuquantum_header_path.find("/custatevec.h")] + custatevec_shared_library_path = _find_file(repository_ctx, "libcustatevec.so") + cuquantum_root = custatevec_shared_library_path[:custatevec_shared_library_path.find("/lib/lib")] + if cuquantum_root == "": + _warn("'CUQUANTUM_ROOT' environment variable is not set, no library was found too. If it is CPU mode, please ignore this warning") + else: + _warn("'CUQUANTUM_ROOT' environment variable is not set, using '%s' as default" % cuquantum_root) + else: + cuquantum_header_path = "%s/include" % cuquantum_root + custatevec_shared_library_path = "%s/lib/libcustatevec.so" % (cuquantum_root) + + is_empty_genrule = cuquantum_header_path == "" or custatevec_shared_library_path == "" + + cuquantum_header_rule = _symlink_genrule_for_dir( + repository_ctx, + cuquantum_header_path, + "include", + "cuquantum_header_include", + is_empty_genrule=is_empty_genrule, + ) + + custatevec_shared_library_rule = _symlink_genrule_for_dir( + repository_ctx, + None, + "", + "libcustatevec.so", + [custatevec_shared_library_path], + ["libcustatevec.so"], + is_empty_genrule=is_empty_genrule, + ) + + _tpl(repository_ctx, "BUILD", { + "%{CUQUANTUM_LIBRARY_PATH}": "%s/lib" % (cuquantum_root), + "%{CUQUANTUM_HEADER_GENRULE}": cuquantum_header_rule, + "%{CUSTATEVEC_SHARED_LIBRARY_GENRULE}": custatevec_shared_library_rule, + }) + + +cuquantum_configure = repository_rule( + implementation = _cuquantum_pip_impl, + environ = [ + _CUQUANTUM_ROOT, + ], +) diff --git a/third_party/tf/auditwheel b/third_party/tf/auditwheel index 5cb83e2bb..30f511c86 100644 --- a/third_party/tf/auditwheel +++ b/third_party/tf/auditwheel @@ -1,6 +1,6 @@ TF_SHARED_LIBRARY_NAME=$(grep -r TF_SHARED_LIBRARY_NAME .bazelrc | awk -F= '{print$2}') -POLICY_JSON=$(find / -name policy.json) +POLICY_JSON=$(find / -name manylinux-policy.json) sed -i "s/libresolv.so.2\"/libresolv.so.2\", $TF_SHARED_LIBRARY_NAME/g" $POLICY_JSON