Skip to content

Commit bc5b578

Browse files
committed
Add method for adding to opstring.
1 parent 69cb9f3 commit bc5b578

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pybind_interface/pybind_main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,12 @@ void add_gate_to_opstring(const Cirq::GateKind gate_kind,
356356
opstring->ops.push_back(create_gate(gate_kind, 0, qubits, params));
357357
}
358358

359+
void add_matrix_gate_to_opstring(const std::vector<unsigned>& qubits,
360+
const std::vector<float>& matrix,
361+
OpString<Cirq::GateCirq<float>>* opstring) {
362+
opstring->ops.push_back(create_matrix_gate(0, qubits, matrix));
363+
}
364+
359365
// Methods for simulating amplitudes.
360366

361367
std::vector<std::complex<float>> qsim_simulate(const py::dict &options) {

pybind_interface/pybind_main.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <pybind11/stl_bind.h>
2323
namespace py = pybind11;
2424

25+
#include <map>
2526
#include <vector>
2627

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

78-
// Method for populating opstrings.
79+
// Methods for populating opstrings.
7980
void add_gate_to_opstring(
8081
const qsim::Cirq::GateKind gate_kind,
8182
const std::vector<unsigned>& qubits,
8283
qsim::OpString<qsim::Cirq::GateCirq<float>>* opstring);
8384

85+
void add_matrix_gate_to_opstring(
86+
const std::vector<unsigned>& qubits,
87+
const std::vector<float>& matrix,
88+
qsim::OpString<qsim::Cirq::GateCirq<float>>* opstring);
89+
8490
// Methods for simulating noiseless circuits.
8591
std::vector<std::complex<float>> qsim_simulate(const py::dict &options);
8692

@@ -376,7 +382,9 @@ std::vector<std::complex<float>> qsimh_simulate(const py::dict &options);
376382
"Adds a channel to the given noisy circuit."); \
377383
\
378384
m.def("add_gate_to_opstring", &add_gate_to_opstring, \
379-
"Adds a gate to the given opstring.");
385+
"Adds a gate to the given opstring."); \
386+
m.def("add_matrix_gate_to_opstring", &add_matrix_gate_to_opstring, \
387+
"Adds a matrix gate to the given opstring.");
380388

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

0 commit comments

Comments
 (0)