Skip to content

Commit

Permalink
Merge pull request #660 from quantumlib/matrix-gate-to-opstring
Browse files Browse the repository at this point in the history
  • Loading branch information
tanujkhattar authored Feb 13, 2024
2 parents 69cb9f3 + bc5b578 commit bc4b8bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pybind_interface/pybind_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ void add_gate_to_opstring(const Cirq::GateKind gate_kind,
opstring->ops.push_back(create_gate(gate_kind, 0, qubits, params));
}

void add_matrix_gate_to_opstring(const std::vector<unsigned>& qubits,
const std::vector<float>& matrix,
OpString<Cirq::GateCirq<float>>* opstring) {
opstring->ops.push_back(create_matrix_gate(0, qubits, matrix));
}

// Methods for simulating amplitudes.

std::vector<std::complex<float>> qsim_simulate(const py::dict &options) {
Expand Down
12 changes: 10 additions & 2 deletions pybind_interface/pybind_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <pybind11/stl_bind.h>
namespace py = pybind11;

#include <map>
#include <vector>

#include "../lib/circuit.h"
Expand Down Expand Up @@ -75,12 +76,17 @@ void add_channel(const unsigned time,
prob_matrix_unitary_triples,
qsim::NoisyCircuit<qsim::Cirq::GateCirq<float>>* ncircuit);

// Method for populating opstrings.
// Methods for populating opstrings.
void add_gate_to_opstring(
const qsim::Cirq::GateKind gate_kind,
const std::vector<unsigned>& qubits,
qsim::OpString<qsim::Cirq::GateCirq<float>>* opstring);

void add_matrix_gate_to_opstring(
const std::vector<unsigned>& qubits,
const std::vector<float>& matrix,
qsim::OpString<qsim::Cirq::GateCirq<float>>* opstring);

// Methods for simulating noiseless circuits.
std::vector<std::complex<float>> qsim_simulate(const py::dict &options);

Expand Down Expand Up @@ -376,7 +382,9 @@ std::vector<std::complex<float>> qsimh_simulate(const py::dict &options);
"Adds a channel to the given noisy circuit."); \
\
m.def("add_gate_to_opstring", &add_gate_to_opstring, \
"Adds a gate to the given opstring.");
"Adds a gate to the given opstring."); \
m.def("add_matrix_gate_to_opstring", &add_matrix_gate_to_opstring, \
"Adds a matrix gate to the given opstring.");

#define GPU_MODULE_BINDINGS \
m.doc() = "pybind11 plugin"; /* optional module docstring */ \
Expand Down

0 comments on commit bc4b8bb

Please sign in to comment.