17#include "ns3/q2ns-types.h"
19#include "ns3/assert.h"
20#include "ns3/nstime.h"
24#include <initializer_list>
108 NS_ASSERT_MSG(
U_,
"QGate::Unitary() called for a non-custom gate");
123 g.
U_ = std::make_shared<const Matrix>(U);
139 g.
U_ = std::make_shared<const Matrix>(std::move(U));
146 std::shared_ptr<const Matrix>
U_{};
156 const std::size_t r = rows.size();
157 const std::size_t c = (r > 0) ? rows.begin()->size() : 0;
159 Matrix m(
static_cast<int>(r),
static_cast<int>(c));
161 for (
const auto& row : rows) {
162 NS_ASSERT_MSG(row.size() == c,
"MakeMatrix: ragged initializer_list");
164 for (
const auto& v : row) {
165 m(
static_cast<int>(i),
static_cast<int>(j)) = v;
223 const double s = 1.0 / std::sqrt(2.0);
336 NS_ABORT_MSG(
"MatrixOf: custom gates do not have a built-in matrix");
347inline QGate I(ns3::Time d = ns3::Seconds(0)) {
356inline QGate X(ns3::Time d = ns3::Seconds(0)) {
365inline QGate Y(ns3::Time d = ns3::Seconds(0)) {
374inline QGate Z(ns3::Time d = ns3::Seconds(0)) {
383inline QGate H(ns3::Time d = ns3::Seconds(0)) {
392inline QGate S(ns3::Time d = ns3::Seconds(0)) {
419inline QGate CZ(ns3::Time d = ns3::Seconds(0)) {
Lightweight gate descriptor used by QState backends.
QGate(QGateKind k, ns3::Time d=ns3::Seconds(0))
Construct a built-in gate descriptor.
ns3::Time Duration() const
Return the optional duration metadata.
ns3::Time duration_
Optional duration metadata.
static QGate Custom(Matrix &&U, ns3::Time d=ns3::Seconds(0))
Construct a custom gate by moving a matrix.
QGateKind kind_
Gate kind.
const Matrix & Unitary() const
Return the custom unitary matrix.
std::shared_ptr< const Matrix > U_
Custom unitary for Custom gates.
static QGate Custom(const Matrix &U, ns3::Time d=ns3::Seconds(0))
Construct a custom gate by copying a matrix.
QGateKind Kind() const
Return the gate kind.
QGate()=default
Default constructor.
std::complex< double > Complex
Complex scalar type used by matrix-based backends.
Eigen::MatrixXcd Matrix
Dynamic complex matrix type used for custom gates and matrix-based states.
QGateKind
Enumerates built-in gate kinds.
@ Custom
Caller-supplied matrix.
const Matrix & MatrixH()
Return the Hadamard matrix.
const Matrix & MatrixZ()
Return the Pauli-Z matrix.
const Matrix & MatrixS()
Return the phase gate matrix S = diag(1, i).
const Matrix & MatrixY()
Return the Pauli-Y matrix.
const Matrix & MatrixCZ()
Return the CZ matrix.
const Matrix & MatrixSDG()
Return the inverse phase gate matrix SDG = diag(1, -i).
const Matrix & MatrixOf(QGateKind k)
Return the built-in matrix for a non-custom gate kind.
Matrix MakeMatrix(std::initializer_list< std::initializer_list< Complex > > rows)
Build a Matrix from nested initializer lists.
const Matrix & MatrixCNOT()
Return the CNOT matrix with control qubit 0 and target qubit 1.
const Matrix & MatrixX()
Return the Pauli-X matrix.
const Matrix & MatrixI()
Return the 1-qubit identity matrix.
const Matrix & MatrixSWAP()
Return the SWAP matrix.