Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method for adding to opstring. #660

Merged
merged 1 commit into from
Feb 13, 2024
Merged
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
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
Loading