-
Notifications
You must be signed in to change notification settings - Fork 378
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 circuit optimization framework #83
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks very good! I think the functions add_circuit_optimization
optimize_circuit
and member optimizations_
should be moved to the Base::Controller
class so they can be inherited by all controller subclasses.
Then the QasmController will just have the specific optimization (eg ReduceNop
) added in its initialization (which could also be added to the other controllers).
src/framework/circuitopt.hpp
Outdated
|
||
void CircuitOptimization::set_config(const json_t& config) { | ||
for ( auto it = config.begin(); it != config.end(); ++it ) | ||
config_[it.key()] = it.value(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this loop can just be replaced with config_ = config;
.
|
||
std::vector<Operations::Op>::iterator it = circ.ops.begin(); | ||
while (it != circ.ops.end()) { | ||
std::cerr << it->name << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change this to std::clog << it->name << std::endl;
?
@@ -73,6 +79,14 @@ class QasmController : public Base::Controller { | |||
// Clear the current config | |||
void virtual clear_config() override; | |||
|
|||
// Add circuit optimization | |||
template <typename Type> | |||
inline auto add_optimization(Type&& opt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be added to the Base::Controller
class so it can be used by all the controller subclasses. I would also rename it to be add_circuit_optimization
to be specific about what optimizations we are talking about
@@ -186,13 +200,22 @@ class QasmController : public Base::Controller { | |||
// Initial statevector for Statevector simulation method | |||
cvector_t initial_statevector_; | |||
|
|||
std::vector<std::shared_ptr<CircuitOptimization>> optimizations; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optimizations_;
with underscore for private/protected class member
Also could you add a short documentation comment above for what this is.
@@ -299,8 +322,12 @@ void QasmController::initialize_state(const Circuit &circ, | |||
template <class State_t> | |||
void QasmController::optimize_circuit(const Circuit &input_circ, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should also be moved to the Base::Controller
class
@@ -299,8 +322,12 @@ void QasmController::initialize_state(const Circuit &circ, | |||
template <class State_t> | |||
void QasmController::optimize_circuit(const Circuit &input_circ, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should also change the function definition to be:
Circuit optimize_circuit(const Circuit &circ) const
So that it returns the output circuit object and is used like
auto opt_circ = optimize_circuit<State_t>(circ);
rather than
Circuit opt_circ;
optimize_circuit<State_t>(circ, opt_circ);
@hhorii If you make the changes above (and update the conflicting files) we can get this merged |
Summary
This PR provides circuit optimization for QasmController.
Details and comments
Current design is here.
optimize_circuit()
.