-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
811 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "gate/constant.hpp" | ||
#include "gate/gate.hpp" | ||
#include "gate/gate_factory.hpp" | ||
#include "gate/gate_npair_qubit.hpp" | ||
#include "gate/gate_one_control_one_target.hpp" | ||
#include "gate/gate_one_qubit.hpp" | ||
#include "gate/gate_quantum_matrix.hpp" | ||
#include "gate/gate_two_qubit.hpp" | ||
#include "gate/update_ops.hpp" | ||
#include "operator/constant.hpp" | ||
#include "operator/operator.hpp" | ||
#include "operator/pauli_operator.hpp" | ||
#include "state/state_vector.hpp" | ||
#include "types.hpp" | ||
#include "util/random.hpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#pragma once | ||
|
||
#include "gate/gate_npair_qubit.hpp" | ||
#include "gate/gate_one_control_one_target.hpp" | ||
#include "gate/gate_one_qubit.hpp" | ||
#include "gate/gate_quantum_matrix.hpp" | ||
#include "gate/gate_two_qubit.hpp" | ||
|
||
namespace qulacs { | ||
namespace internal { | ||
class GateFactory { | ||
public: | ||
template <GateImpl T, typename... Args> | ||
static Gate create_gate(Args... args) { | ||
return {std::make_shared<T>(args...)}; | ||
} | ||
}; | ||
} // namespace internal | ||
|
||
Gate I(UINT target) { return internal::GateFactory::create_gate<internal::IGateImpl>(target); } | ||
Gate X(UINT target) { return internal::GateFactory::create_gate<internal::XGateImpl>(target); } | ||
Gate Y(UINT target) { return internal::GateFactory::create_gate<internal::YGateImpl>(target); } | ||
Gate Z(UINT target) { return internal::GateFactory::create_gate<internal::ZGateImpl>(target); } | ||
Gate H(UINT target) { return internal::GateFactory::create_gate<internal::HGateImpl>(target); } | ||
Gate S(UINT target) { return internal::GateFactory::create_gate<internal::SGateImpl>(target); } | ||
Gate Sdag(UINT target) { | ||
return internal::GateFactory::create_gate<internal::SdagGateImpl>(target); | ||
} | ||
Gate T(UINT target) { return internal::GateFactory::create_gate<internal::TGateImpl>(target); } | ||
Gate Tdag(UINT target) { | ||
return internal::GateFactory::create_gate<internal::TdagGateImpl>(target); | ||
} | ||
Gate sqrtX(UINT target) { | ||
return internal::GateFactory::create_gate<internal::sqrtXGateImpl>(target); | ||
} | ||
Gate sqrtXdag(UINT target) { | ||
return internal::GateFactory::create_gate<internal::sqrtXdagGateImpl>(target); | ||
} | ||
Gate sqrtY(UINT target) { | ||
return internal::GateFactory::create_gate<internal::sqrtYGateImpl>(target); | ||
} | ||
Gate sqrtYdag(UINT target) { | ||
return internal::GateFactory::create_gate<internal::sqrtYdagGateImpl>(target); | ||
} | ||
Gate P0(UINT target) { return internal::GateFactory::create_gate<internal::P0GateImpl>(target); } | ||
Gate P1(UINT target) { return internal::GateFactory::create_gate<internal::P1GateImpl>(target); } | ||
Gate RX(UINT target, double angle) { | ||
return internal::GateFactory::create_gate<internal::RXGateImpl>(target, angle); | ||
} | ||
Gate RY(UINT target, double angle) { | ||
return internal::GateFactory::create_gate<internal::RYGateImpl>(target, angle); | ||
} | ||
Gate RZ(UINT target, double angle) { | ||
return internal::GateFactory::create_gate<internal::RZGateImpl>(target, angle); | ||
} | ||
Gate U1(UINT target, double lambda) { | ||
return internal::GateFactory::create_gate<internal::U1GateImpl>(target, lambda); | ||
} | ||
Gate U2(UINT target, double phi, double lambda) { | ||
return internal::GateFactory::create_gate<internal::U2GateImpl>(target, phi, lambda); | ||
} | ||
Gate U3(UINT target, double theta, double phi, double lambda) { | ||
return internal::GateFactory::create_gate<internal::U3GateImpl>(target, theta, phi, lambda); | ||
} | ||
Gate CNOT(UINT control, UINT target) { | ||
return internal::GateFactory::create_gate<internal::CNOTGateImpl>(control, target); | ||
} | ||
Gate CZ(UINT control, UINT target) { | ||
return internal::GateFactory::create_gate<internal::CZGateImpl>(control, target); | ||
} | ||
Gate SWAP(UINT target1, UINT target2) { | ||
return internal::GateFactory::create_gate<internal::SWAPGateImpl>(target1, target2); | ||
} | ||
Gate FusedSWAP(UINT qubit_index1, UINT qubit_index2, UINT block_size) { | ||
return internal::GateFactory::create_gate<internal::FusedSWAPGateImpl>( | ||
qubit_index1, qubit_index2, block_size); | ||
} | ||
} // namespace qulacs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "gate_npair_qubit.hpp" | ||
|
||
#include "update_ops.hpp" | ||
|
||
namespace qulacs { | ||
namespace internal { | ||
void FusedSWAPGateImpl::update_quantum_state(StateVector& state_vector) const { | ||
fusedswap_gate(this->_qubit_index1, this->_qubit_index2, this->_block_size, state_vector); | ||
} | ||
} // namespace internal | ||
} // namespace qulacs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#pragma once | ||
|
||
#include <cassert> | ||
#include <ranges> | ||
|
||
#include "gate.hpp" | ||
|
||
namespace qulacs { | ||
namespace internal { | ||
class FusedSWAPGateImpl : public GateBase { | ||
UINT _qubit_index1, _qubit_index2, _block_size; | ||
|
||
public: | ||
FusedSWAPGateImpl(UINT qubit_index1, UINT qubit_index2, UINT block_size) | ||
: _qubit_index1(qubit_index1), _qubit_index2(qubit_index2), _block_size(block_size) { | ||
UINT upper_index = std::max(qubit_index1, qubit_index2); | ||
UINT lower_index = std::min(qubit_index1, qubit_index2); | ||
if (upper_index <= (lower_index + block_size - 1)) { | ||
throw std::runtime_error( | ||
"FusedSwap: upper index must be bigger than lower_index + block_size - 1"); | ||
} | ||
}; | ||
|
||
UINT qubit_index1() const { return _qubit_index1; } | ||
UINT qubit_index2() const { return _qubit_index2; } | ||
UINT block_size() const { return _block_size; } | ||
|
||
std::vector<UINT> get_target_qubit_list() const override { | ||
std::vector<UINT> res(_block_size * 2); | ||
std::ranges::copy(std::views::iota(_qubit_index1, _qubit_index1 + _block_size), | ||
res.begin()); | ||
std::ranges::copy(std::views::iota(_qubit_index2, _qubit_index2 + _block_size), | ||
res.begin() + _block_size); | ||
return res; | ||
} | ||
std::vector<UINT> get_control_qubit_list() const override { return {}; } | ||
|
||
Gate copy() const override { return std::make_shared<FusedSWAPGateImpl>(*this); } | ||
Gate get_inverse() const override { return std::make_shared<FusedSWAPGateImpl>(*this); } | ||
|
||
void update_quantum_state(StateVector& state_vector) const override; | ||
}; | ||
} // namespace internal | ||
|
||
using FusedSWAPGate = internal::GatePtr<internal::FusedSWAPGateImpl>; | ||
} // namespace qulacs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.