Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Usage: run the following command to configure git to use this file:
#
# git config blame.ignoreRevsFile .git-blame-ignore-revs
#
# Summary: `git-blame` can be instructed to ignore certain commits. This is
# useful to do for commits that only involve large refactoring and reformatting
# operations. The format of this file is one full 40-character commit hash
# (SHA-1) per line. Blank lines and comments (such as this) are allowed.
# ==============================================================================

# Output of running ./scripts/format_all.sh (PR #926).
17b108d8485cb7848f8eae5b87c9cc521987bca9
10 changes: 5 additions & 5 deletions tensorflow_quantum/core/ops/tfq_calculate_unitary_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ typedef qsim::Circuit<QsimGate> QsimCircuit;

class TfqCalculateUnitaryOp : public tensorflow::OpKernel {
public:
explicit TfqCalculateUnitaryOp(tensorflow::OpKernelConstruction *context)
explicit TfqCalculateUnitaryOp(tensorflow::OpKernelConstruction* context)
: OpKernel(context) {}

void Compute(tensorflow::OpKernelContext *context) override {
void Compute(tensorflow::OpKernelContext* context) override {
// TODO (mbbrough): add more dimension checks for other inputs here.
DCHECK_EQ(3, context->num_inputs());

Expand Down Expand Up @@ -99,13 +99,13 @@ class TfqCalculateUnitaryOp : public tensorflow::OpKernel {
output_shape.AddDim(1 << max_num_qubits);
output_shape.AddDim(1 << max_num_qubits);

tensorflow::Tensor *output = nullptr;
tensorflow::Tensor* output = nullptr;
OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output));
auto output_tensor = output->tensor<std::complex<float>, 3>();

// Instantiate qsim objects.
const auto tfq_for = tfq::QsimFor(context);
using UCalculator = qsim::unitary::UnitaryCalculator<const tfq::QsimFor &>;
using UCalculator = qsim::unitary::UnitaryCalculator<const tfq::QsimFor&>;
using UnitarySpace = UCalculator::UnitarySpace;
using Unitary = UnitarySpace::Unitary;

Expand Down Expand Up @@ -166,7 +166,7 @@ REGISTER_OP("TfqCalculateUnitary")
.Input("symbol_names: string")
.Input("symbol_values: float")
.Output("unitary: complex64")
.SetShapeFn([](tensorflow::shape_inference::InferenceContext *c) {
.SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) {
tensorflow::shape_inference::ShapeHandle programs_shape;
TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape));

Expand Down
10 changes: 5 additions & 5 deletions tensorflow_quantum/core/ops/tfq_circuit_append_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ using ::tfq::proto::Program;

class TfqCircuitAppendOp : public tensorflow::OpKernel {
public:
explicit TfqCircuitAppendOp(tensorflow::OpKernelConstruction *context)
explicit TfqCircuitAppendOp(tensorflow::OpKernelConstruction* context)
: OpKernel(context) {}

void Compute(tensorflow::OpKernelContext *context) override {
void Compute(tensorflow::OpKernelContext* context) override {
std::vector<Program> programs;
std::vector<Program> programs_to_append;

Expand All @@ -46,7 +46,7 @@ class TfqCircuitAppendOp : public tensorflow::OpKernel {
OP_REQUIRES_OK(context, GetProgramsAndProgramsToAppend(
context, &programs, &programs_to_append));

tensorflow::Tensor *output = nullptr;
tensorflow::Tensor* output = nullptr;
OP_REQUIRES_OK(context, context->allocate_output(
0, context->input(0).shape(), &output));
auto output_tensor = output->flat<tensorflow::tstring>();
Expand All @@ -56,7 +56,7 @@ class TfqCircuitAppendOp : public tensorflow::OpKernel {
for (int i = start; i < end; i++) {
for (int j = 0; j < programs_to_append.at(i).circuit().moments().size();
j++) {
Moment *new_moment = programs.at(i).mutable_circuit()->add_moments();
Moment* new_moment = programs.at(i).mutable_circuit()->add_moments();
*new_moment = programs_to_append.at(i).circuit().moments(j);
}
programs.at(i).SerializeToString(&temp);
Expand All @@ -80,7 +80,7 @@ REGISTER_OP("TfqAppendCircuit")
.Input("programs: string")
.Input("programs_to_append: string")
.Output("programs_extended: string")
.SetShapeFn([](tensorflow::shape_inference::InferenceContext *c) {
.SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) {
tensorflow::shape_inference::ShapeHandle programs_shape;
TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape));

Expand Down
42 changes: 21 additions & 21 deletions tensorflow_quantum/core/ops/tfq_ps_decompose_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ using ::tfq::proto::Program;

class TfqPsDecomposeOp : public tensorflow::OpKernel {
public:
explicit TfqPsDecomposeOp(tensorflow::OpKernelConstruction *context)
explicit TfqPsDecomposeOp(tensorflow::OpKernelConstruction* context)
: OpKernel(context) {}

void Compute(tensorflow::OpKernelContext *context) override {
void Compute(tensorflow::OpKernelContext* context) override {
std::vector<Program> programs;

const int num_inputs = context->num_inputs();
Expand All @@ -50,7 +50,7 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel {

OP_REQUIRES_OK(context, ParsePrograms(context, "programs", &programs));

tensorflow::Tensor *output = nullptr;
tensorflow::Tensor* output = nullptr;
OP_REQUIRES_OK(context, context->allocate_output(
0, context->input(0).shape(), &output));
auto output_tensor = output->flat<tensorflow::tstring>();
Expand All @@ -71,7 +71,7 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel {
int num_extra_moments = 0;
for (int k = 0; k < cur_moment.operations().size(); k++) {
Operation cur_op = cur_moment.operations().at(k);
auto &cur_op_map = *cur_op.mutable_args();
auto& cur_op_map = *cur_op.mutable_args();
if (cur_op.gate().id() == "PISP") {
auto exponent = cur_op_map.at("exponent");
auto phase_exponent = cur_op_map.at("phase_exponent");
Expand Down Expand Up @@ -161,17 +161,17 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel {
private:
// Helper functions for decompositions of ISwapPowGate, PhasedX, FSIM,
// PhasedISwapPow.
Operation getOpForISP(Operation &cur_op, std::string id, std::string symbol) {
Operation getOpForISP(Operation& cur_op, std::string id, std::string symbol) {
// Step 1. parse the current op.
auto &cur_op_map = *cur_op.mutable_args();
auto& cur_op_map = *cur_op.mutable_args();
float cur_exponent_scalar =
cur_op_map["exponent_scalar"].arg_value().float_value();
auto &cur_op_qubits = cur_op.qubits();
auto& cur_op_qubits = cur_op.qubits();
// Step 2. create a new op.
Operation new_op;
new_op.mutable_gate()->set_id(id);
// Step 3. add global_shift, exponent_scalar, exponent.
auto &new_op_map = *new_op.mutable_args();
auto& new_op_map = *new_op.mutable_args();
new_op_map["global_shift"].mutable_arg_value()->set_float_value(-0.5);
new_op_map["exponent_scalar"].mutable_arg_value()->set_float_value(
cur_exponent_scalar * -0.5);
Expand All @@ -186,11 +186,11 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel {
return new_op;
}

Operation getOpForPXP(Operation &cur_op, std::string id, std::string key,
Operation getOpForPXP(Operation& cur_op, std::string id, std::string key,
bool sign_flip = false) {
// Step 1. parse the current op.
auto &cur_op_map = *cur_op.mutable_args();
auto &cur_op_qubits = cur_op.qubits();
auto& cur_op_map = *cur_op.mutable_args();
auto& cur_op_qubits = cur_op.qubits();
auto target_exponent = cur_op_map[key];
float target_exponent_scalar =
cur_op_map[absl::StrCat(key, "_scalar")].arg_value().float_value();
Expand All @@ -199,7 +199,7 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel {
Operation new_op;
new_op.mutable_gate()->set_id(id);
// Step 3. add global_shift, exponent_scalar, exponent.
auto &new_op_map = *new_op.mutable_args();
auto& new_op_map = *new_op.mutable_args();
new_op_map["global_shift"].mutable_arg_value()->set_float_value(0.0);
switch (target_exponent.arg_case()) {
case Arg::ArgCase::kSymbol:
Expand Down Expand Up @@ -228,10 +228,10 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel {
return new_op;
}

Operation getOpForPISP(Operation &cur_op, bool sign_flip, bool use_target) {
Operation getOpForPISP(Operation& cur_op, bool sign_flip, bool use_target) {
// Step 1. parse the current op.
auto &cur_op_map = *cur_op.mutable_args();
auto &cur_op_qubits = cur_op.qubits();
auto& cur_op_map = *cur_op.mutable_args();
auto& cur_op_qubits = cur_op.qubits();
auto target_exponent = cur_op_map["phase_exponent"];
float target_exponent_scalar =
cur_op_map["phase_exponent_scalar"].arg_value().float_value();
Expand All @@ -240,7 +240,7 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel {
Operation new_op;
new_op.mutable_gate()->set_id("ZP");
// Step 3. add global_shift, exponent_scalar, exponent.
auto &new_op_map = *new_op.mutable_args();
auto& new_op_map = *new_op.mutable_args();
new_op_map["global_shift"].mutable_arg_value()->set_float_value(0.0);
switch (target_exponent.arg_case()) {
case Arg::ArgCase::kSymbol:
Expand Down Expand Up @@ -269,11 +269,11 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel {
return new_op;
}

Operation getOpForFSIM(Operation &cur_op, std::string id, std::string key,
Operation getOpForFSIM(Operation& cur_op, std::string id, std::string key,
bool use_global_shift = false) {
// Step 1. parse the current op.
auto &cur_op_map = *cur_op.mutable_args();
auto &cur_op_qubits = cur_op.qubits();
auto& cur_op_map = *cur_op.mutable_args();
auto& cur_op_qubits = cur_op.qubits();
auto target_exponent = cur_op_map[key];
float target_exponent_scalar =
cur_op_map[absl::StrCat(key, "_scalar")].arg_value().float_value();
Expand All @@ -283,7 +283,7 @@ class TfqPsDecomposeOp : public tensorflow::OpKernel {
Operation new_op;
new_op.mutable_gate()->set_id(id);
// Step 3. add global_shift, exponent_scalar, exponent.
auto &new_op_map = *new_op.mutable_args();
auto& new_op_map = *new_op.mutable_args();
new_op_map["global_shift"].mutable_arg_value()->set_float_value(
global_shift);
switch (target_exponent.arg_case()) {
Expand Down Expand Up @@ -320,7 +320,7 @@ REGISTER_KERNEL_BUILDER(Name("TfqPsDecompose").Device(tensorflow::DEVICE_CPU),
REGISTER_OP("TfqPsDecompose")
.Input("programs: string")
.Output("ps_programs: string")
.SetShapeFn([](tensorflow::shape_inference::InferenceContext *c) {
.SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) {
tensorflow::shape_inference::ShapeHandle programs_shape;
TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape));

Expand Down
14 changes: 7 additions & 7 deletions tensorflow_quantum/core/ops/tfq_ps_symbol_replace_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ using ::tensorflow::Tensor;

class TfqPsSymbolReplaceOp : public tensorflow::OpKernel {
public:
explicit TfqPsSymbolReplaceOp(tensorflow::OpKernelConstruction *context)
explicit TfqPsSymbolReplaceOp(tensorflow::OpKernelConstruction* context)
: OpKernel(context) {}

void Compute(tensorflow::OpKernelContext *context) override {
void Compute(tensorflow::OpKernelContext* context) override {
std::vector<Program> programs;

const int num_inputs = context->num_inputs();
Expand All @@ -50,7 +50,7 @@ class TfqPsSymbolReplaceOp : public tensorflow::OpKernel {
OP_REQUIRES_OK(context, ParsePrograms(context, "programs", &programs));

// Parse the input string here.
const Tensor *symbols_tensor;
const Tensor* symbols_tensor;
OP_REQUIRES_OK(context, context->input("symbols", &symbols_tensor));
OP_REQUIRES(
context, symbols_tensor->dims() == 1,
Expand All @@ -61,7 +61,7 @@ class TfqPsSymbolReplaceOp : public tensorflow::OpKernel {
const size_t n_symbols = symbols.size();

// Parse the replacement string here.
const Tensor *replacement_symbols_tensor;
const Tensor* replacement_symbols_tensor;
OP_REQUIRES_OK(context, context->input("replacement_symbols",
&replacement_symbols_tensor));
OP_REQUIRES(context, replacement_symbols_tensor->dims() == 1,
Expand Down Expand Up @@ -96,7 +96,7 @@ class TfqPsSymbolReplaceOp : public tensorflow::OpKernel {
for (auto l = cur_op.args().begin(); l != cur_op.args().end();
l++) {
const std::string key = (*l).first;
const Arg &arg = (*l).second;
const Arg& arg = (*l).second;
if (arg.symbol() == symbol_to_replace) {
// Copy the proto, modify the symbol and append to output.
Program temp(cur_program);
Expand Down Expand Up @@ -144,7 +144,7 @@ class TfqPsSymbolReplaceOp : public tensorflow::OpKernel {
}
}

tensorflow::Tensor *output = nullptr;
tensorflow::Tensor* output = nullptr;
tensorflow::TensorShape output_shape;
// batch size.
output_shape.AddDim(programs.size());
Expand Down Expand Up @@ -190,7 +190,7 @@ REGISTER_OP("TfqPsSymbolReplace")
.Input("symbols: string")
.Input("replacement_symbols: string")
.Output("ps_programs: string")
.SetShapeFn([](tensorflow::shape_inference::InferenceContext *c) {
.SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) {
tensorflow::shape_inference::ShapeHandle programs_shape;
TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape));

Expand Down
12 changes: 6 additions & 6 deletions tensorflow_quantum/core/ops/tfq_ps_weights_from_symbols_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ using ::tfq::proto::Program;

class TfqPsWeightsFromSymbolOp : public tensorflow::OpKernel {
public:
explicit TfqPsWeightsFromSymbolOp(tensorflow::OpKernelConstruction *context)
explicit TfqPsWeightsFromSymbolOp(tensorflow::OpKernelConstruction* context)
: OpKernel(context) {}

void Compute(tensorflow::OpKernelContext *context) override {
void Compute(tensorflow::OpKernelContext* context) override {
std::vector<Program> programs;

const int num_inputs = context->num_inputs();
Expand All @@ -51,7 +51,7 @@ class TfqPsWeightsFromSymbolOp : public tensorflow::OpKernel {
OP_REQUIRES_OK(context, ParsePrograms(context, "programs", &programs));

// Parse the input string here.
const Tensor *symbols_tensor;
const Tensor* symbols_tensor;
OP_REQUIRES_OK(context, context->input("symbols", &symbols_tensor));
OP_REQUIRES(
context, symbols_tensor->dims() == 1,
Expand Down Expand Up @@ -88,7 +88,7 @@ class TfqPsWeightsFromSymbolOp : public tensorflow::OpKernel {
Operation cur_op = cur_moment.operations().at(k);
if (ignored_symbol_set.contains(cur_op.gate().id())) continue;

const auto &cur_op_map = *cur_op.mutable_args();
const auto& cur_op_map = *cur_op.mutable_args();
const auto exponent = cur_op_map.at("exponent");
if (exponent.arg_case() == Arg::ArgCase::kSymbol) {
// this gate has parameterized exponent.
Expand Down Expand Up @@ -131,7 +131,7 @@ class TfqPsWeightsFromSymbolOp : public tensorflow::OpKernel {
std::max(n_single_symbol.at(i), largest_single_symbol);
}

tensorflow::Tensor *output = nullptr;
tensorflow::Tensor* output = nullptr;
tensorflow::TensorShape output_shape;
// batch size.
output_shape.AddDim(programs.size());
Expand Down Expand Up @@ -171,7 +171,7 @@ REGISTER_OP("TfqPsWeightsFromSymbols")
.Input("programs: string")
.Input("symbols: string")
.Output("weights: float")
.SetShapeFn([](tensorflow::shape_inference::InferenceContext *c) {
.SetShapeFn([](tensorflow::shape_inference::InferenceContext* c) {
tensorflow::shape_inference::ShapeHandle programs_shape;
TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 1, &programs_shape));

Expand Down
Loading