Skip to content

Commit

Permalink
Merge pull request #305 from quantumlib/add-cirq-channels
Browse files Browse the repository at this point in the history
Add Cirq channels.
  • Loading branch information
sergeisakov authored Mar 5, 2021
2 parents 7fdcd40 + 0896282 commit 01cf764
Show file tree
Hide file tree
Showing 9 changed files with 1,198 additions and 311 deletions.
35 changes: 34 additions & 1 deletion lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ cc_library(
hdrs = [
"bits.h",
"bitstring.h",
"channel.h",
"channels_cirq.h",
"circuit_noisy.h",
"circuit_qsim_parser.h",
"circuit.h",
"expect.h",
Expand Down Expand Up @@ -395,12 +398,42 @@ cc_library(
],
)

### Channel and noisy circuit libraries ###

cc_library(
name = "channel",
hdrs = ["channel.h"],
deps = [":gate"],
)

cc_library(
name = "circuit_noisy",
hdrs = ["circuit_noisy.h"],
deps = [
":channel",
":circuit",
],
)

cc_library(
name = "channels_cirq",
hdrs = ["channels_cirq.h"],
deps = [
":channel",
":gates_cirq",
],
)

### Quantum trajectory simulator ###

cc_library(
name = "qtrajectory",
hdrs = ["qtrajectory.h"],
deps = [":gate"],
deps = [
":circuit_noisy",
":gate",
":gate_appl",
],
)

### UnitarySpace libraries ###
Expand Down
81 changes: 81 additions & 0 deletions lib/channel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2019 Google LLC. 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
//
// 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.

#ifndef CHANNEL_H_
#define CHANNEL_H_

#include "gate.h"

namespace qsim {

/**
* Kraus operator.
*/
template <typename Gate>
struct KrausOperator {
enum Kind {
kNormal = 0,
kMeasurement = gate::kMeasurement,
};

/**
* Kraus operator type;
*/
Kind kind;

/**
* If true, the Kraus operator is a unitary operator times a constant.
*/
bool unitary;

/**
* Lower bound on Kraus operator probability.
*/
double prob;

/**
* Sequence of operations that represent the Kraus operator. This can be just
* one operation.
*/
std::vector<Gate> ops;
};

/**
* Quantum channel.
*/
template <typename Gate>
using Channel = std::vector<KrausOperator<Gate>>;

/**
* Makes a channel from the gate.
* @param time The time to place the channel at.
* @param gate The input gate.
* @return The output channel.
*/
template <typename Gate>
Channel<Gate> MakeChannelFromGate(unsigned time, const Gate& gate) {
auto normal = KrausOperator<Gate>::kNormal;
auto measurement = KrausOperator<Gate>::kMeasurement;

auto kind = gate.kind == gate::kMeasurement ? measurement : normal;

Channel<Gate> channel = {{kind, true, 1, {gate}}};
channel[0].ops[0].time = time;

return channel;
}

} // namespace qsim

#endif // CHANNEL_H_
Loading

0 comments on commit 01cf764

Please sign in to comment.