Skip to content
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
2 changes: 1 addition & 1 deletion samples/circuit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int main()
circ.barrier(0);
circ.measure(qr, cr);

circ.print();
circ.draw();
std::cout << circ.to_qasm3();

return 0;
Expand Down
13 changes: 10 additions & 3 deletions src/circuit/classicalregister.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@
#ifndef __qiskitcpp_circuit_classical_register_hpp__
#define __qiskitcpp_circuit_classical_register_hpp__

#include <atomic>

#include "circuit/register.hpp"
#include "qiskit.h"


namespace {
std::atomic<uint64_t> CR_counter(0ull);
}

namespace Qiskit
{
namespace circuit
Expand All @@ -38,7 +45,7 @@ class ClassicalRegister : public Register
{
protected:
std::shared_ptr<QkClassicalRegister> rust_register_ = nullptr;
static uint_t instances_counter_;
// static uint_t instances_counter_;

public:
/// @brief Create a new ClassicalRegister
Expand Down Expand Up @@ -78,7 +85,7 @@ class ClassicalRegister : public Register
std::string prefix(void) override
{
std::string ret = "c";
ret += std::to_string(instances_counter_++);
ret += std::to_string(CR_counter++);
return ret;
}

Expand Down Expand Up @@ -120,7 +127,7 @@ class ClassicalRegister : public Register
Binary operator>=(Expr &right);
};

uint_t ClassicalRegister::instances_counter_ = 0;
//inline uint_t ClassicalRegister::instances_counter_ = 0;

} // namespace circuit
} // namespace Qiskit
Expand Down
1 change: 0 additions & 1 deletion src/circuit/controlflow/control_flow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef __qiskitcpp_circuit_control_flow_hpp__
#define __qiskitcpp_circuit_control_flow_hpp__

#include "circuit/quantumcircuit_def.hpp"

namespace Qiskit {
namespace circuit {
Expand Down
49 changes: 22 additions & 27 deletions src/circuit/controlflow/if_else.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,31 @@ class IfElseOp : public ControlFlowOp

// add false body
/// @brief add false body
void else_(std::function<void(QuantumCircuit&)> body);

void add_control_flow_op(QuantumCircuit& circ) override;
};

void IfElseOp::else_(std::function<void(QuantumCircuit&)> body)
{
body(false_body_);
test_else_ = true;
}

void IfElseOp::add_control_flow_op(QuantumCircuit& circ)
{
if(test_else_){
// if_else
std::shared_ptr<rust_circuit> true_circ = true_body_.get_rust_circuit();
std::shared_ptr<rust_circuit> false_circ = false_body_.get_rust_circuit();

// TO DO : Add if_else support in Qiskit C-API (maybe in the future?)
// qc_if_else(circ.get_rust_circuit(false), clbit_, value_, true_circ, false_circ);
void else_(std::function<void(QuantumCircuit&)> body)
{
body(false_body_);
test_else_ = true;
}
else{
// if_test
std::shared_ptr<rust_circuit> true_circ = true_body_.get_rust_circuit();

// TO DO : Add if_else support in Qiskit C-API (maybe in the future?)
//qc_if_test(circ.get_rust_circuit(false), clbit_, value_, true_circ);
void add_control_flow_op(QuantumCircuit& circ) override
{
if(test_else_){
// if_else
std::shared_ptr<rust_circuit> true_circ = true_body_.get_rust_circuit();
std::shared_ptr<rust_circuit> false_circ = false_body_.get_rust_circuit();

// TO DO : Add if_else support in Qiskit C-API (maybe in the future?)
// qc_if_else(circ.get_rust_circuit(false), clbit_, value_, true_circ, false_circ);
}
else{
// if_test
std::shared_ptr<rust_circuit> true_circ = true_body_.get_rust_circuit();

// TO DO : Add if_else support in Qiskit C-API (maybe in the future?)
//qc_if_test(circ.get_rust_circuit(false), clbit_, value_, true_circ);
}
}
}

};


} // namespace circuit
Expand Down
2 changes: 1 addition & 1 deletion src/circuit/library/standard_gates/standard_gates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
namespace Qiskit {
namespace circuit {

std::unordered_map<std::string, Instruction> get_standard_gate_name_mapping(void)
inline std::unordered_map<std::string, Instruction> get_standard_gate_name_mapping(void)
{
// mapping of gate string and QkGate
std::unordered_map<std::string, Instruction> name_mapping;
Expand Down
94 changes: 42 additions & 52 deletions src/circuit/parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,79 +452,69 @@ class Parameter
/// @param symbol a symbol to be bound
/// @param value a value to be set
/// @return a new bound Parameter
Parameter bind(const Parameter& symbol, const double value);
Parameter bind(const Parameter& symbol, const double value)
{
Parameter ret;

qk_param_bind(ret.qiskit_param_.get(), qiskit_param_.get(), &symbol.qiskit_param_.get(), &value, 1);
return ret;
}

/// @brief bind values to symbols
/// @param symbols a list symbols to be bound
/// @param value a list of values to be set
/// @return a new bound Parameter
Parameter bind(const std::vector<Parameter>& symbols, const std::vector<double> values);
Parameter bind(const std::vector<Parameter>& symbols, const std::vector<double> values)
{
size_t size = std::min(symbols.size(), values.size());
Parameter ret;
std::vector<qiskit_param*> list(size);
for (uint_t i = 0; i < size; i++) {
list[i] = symbols[i].qiskit_param_.get();
}

qk_param_bind(ret.qiskit_param_.get(), qiskit_param_.get(), list.data(), values.data(), size);
return ret;

}

/// @brief substitute a symbol to other symbol
/// @param symbol a symbol to be bound
/// @param other a symbol to be set
/// @return a new substituted Parameter
Parameter subs(const Parameter& symbol, const Parameter& other);
Parameter subs(const Parameter& symbol, const Parameter& other)
{
Parameter ret;

qk_param_subs(ret.qiskit_param_.get(), qiskit_param_.get(), &symbol.qiskit_param_.get(), &other.qiskit_param_.get(), 1);
return ret;
}

/// @brief substitute symbols to other symbols
/// @param symbols a list of symbols to be bound
/// @param others a list of symbols to be set
/// @return a new substituted Parameter
Parameter subs(const std::vector<Parameter>& symbols, const std::vector<Parameter>& others);
Parameter subs(const std::vector<Parameter>& symbols, const std::vector<Parameter>& others)
{
size_t size = std::min(symbols.size(), values.size());
Parameter ret;
std::vector<qiskit_param*> slist(size);
std::vector<qiskit_param*> olist(size);
for (uint_t i = 0; i < size; i++) {
slist[i] = symbols[i].qiskit_param_.get();
olist[i] = others[i].qiskit_param_.get();
}

qk_param_bind(ret.qiskit_param_.get(), qiskit_param_.get(), slist.data(), olist.data(), size);
return ret;
}
#endif

friend std::ostream& operator<<(std::ostream& os, const Parameter& p);

};

#ifdef QISKIT_CAPI_HAS_SUBS
Parameter Parameter::bind(const Parameter& symbol, const double value)
{
Parameter ret;

qk_param_bind(ret.qiskit_param_.get(), qiskit_param_.get(), &symbol.qiskit_param_.get(), &value, 1);
return ret;
}

Parameter Parameter::bind(const std::vector<Parameter>& symbols, const std::vector<double> values)
{
size_t size = std::min(symbols.size(), values.size());
Parameter ret;
std::vector<qiskit_param*> list(size);
for (uint_t i = 0; i < size; i++) {
list[i] = symbols[i].qiskit_param_.get();
}

qk_param_bind(ret.qiskit_param_.get(), qiskit_param_.get(), list.data(), values.data(), size);
return ret;

}

Parameter Parameter::subs(const Parameter& symbol, const Parameter& other)
{
Parameter ret;

qk_param_subs(ret.qiskit_param_.get(), qiskit_param_.get(), &symbol.qiskit_param_.get(), &other.qiskit_param_.get(), 1);
return ret;
}

Parameter Parameter::subs(const std::vector<Parameter>& symbol, const std::vector<Parameter>& others)
{
size_t size = std::min(symbols.size(), values.size());
Parameter ret;
std::vector<qiskit_param*> slist(size);
std::vector<qiskit_param*> olist(size);
for (uint_t i = 0; i < size; i++) {
slist[i] = symbols[i].qiskit_param_.get();
olist[i] = others[i].qiskit_param_.get();
}

qk_param_bind(ret.qiskit_param_.get(), qiskit_param_.get(), slist.data(), olist.data(), size);
return ret;
}
#endif

std::ostream& operator<<(std::ostream& os, const Parameter& p)
inline std::ostream& operator<<(std::ostream& os, const Parameter& p)
{
os << p.as_str();
return os;
Expand Down
1 change: 0 additions & 1 deletion src/circuit/quantumcircuit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@
#include "circuit/quantumcircuit_impl.hpp"

#endif // __qiskitcpp_circuit_quantum_circuit_hpp__

Loading