Skip to content

Commit

Permalink
Refactor QUnit (inlining)
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Aug 20, 2024
1 parent 6e320f6 commit a73d1e6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 50 deletions.
49 changes: 46 additions & 3 deletions include/qunit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,52 @@ class QUnit : public QParity, public QInterface {
protected:
virtual complex GetAmplitudeOrProb(bitCapInt perm, bool isProb);

virtual void XBase(bitLenInt target);
virtual void YBase(bitLenInt target);
virtual void ZBase(bitLenInt target);
virtual void XBase(bitLenInt target)
{
if (target >= qubitCount) {
throw std::invalid_argument("QUnit::XBase qubit index parameter must be within allocated qubit bounds!");
}

QEngineShard& shard = shards[target];

if (shard.unit) {
shard.unit->X(shard.mapped);
}

std::swap(shard.amp0, shard.amp1);
}

virtual void YBase(bitLenInt target)
{
if (target >= qubitCount) {
throw std::invalid_argument("QUnit::YBase qubit index parameter must be within allocated qubit bounds!");
}

QEngineShard& shard = shards[target];

if (shard.unit) {
shard.unit->Y(shard.mapped);
}

const complex_x Y0 = shard.amp0;
shard.amp0 = -I_CMPLX_X * shard.amp1;
shard.amp1 = I_CMPLX_X * Y0;
}

virtual void ZBase(bitLenInt target)
{
if (target >= qubitCount) {
throw std::invalid_argument("QUnit::ZBase qubit index parameter must be within allocated qubit bounds!");
}

QEngineShard& shard = shards[target];

if (shard.unit) {
shard.unit->Z(shard.mapped);
}

shard.amp1 = -shard.amp1;
}
virtual real1_f ProbBase(bitLenInt qubit);

virtual bool TrySeparateClifford(bitLenInt qubit);
Expand Down
47 changes: 0 additions & 47 deletions src/qunit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2143,53 +2143,6 @@ void QUnit::IS(bitLenInt target)
shard.amp1 = -I_CMPLX_X * shard.amp1;
}

void QUnit::XBase(bitLenInt target)
{
if (target >= qubitCount) {
throw std::invalid_argument("QUnit::XBase qubit index parameter must be within allocated qubit bounds!");
}

QEngineShard& shard = shards[target];

if (shard.unit) {
shard.unit->X(shard.mapped);
}

std::swap(shard.amp0, shard.amp1);
}

void QUnit::YBase(bitLenInt target)
{
if (target >= qubitCount) {
throw std::invalid_argument("QUnit::YBase qubit index parameter must be within allocated qubit bounds!");
}

QEngineShard& shard = shards[target];

if (shard.unit) {
shard.unit->Y(shard.mapped);
}

const complex_x Y0 = shard.amp0;
shard.amp0 = -I_CMPLX_X * shard.amp1;
shard.amp1 = I_CMPLX_X * Y0;
}

void QUnit::ZBase(bitLenInt target)
{
if (target >= qubitCount) {
throw std::invalid_argument("QUnit::ZBase qubit index parameter must be within allocated qubit bounds!");
}

QEngineShard& shard = shards[target];

if (shard.unit) {
shard.unit->Z(shard.mapped);
}

shard.amp1 = -shard.amp1;
}

#define CTRLED_GEN_WRAP(ctrld) \
ApplyEitherControlled( \
controlVec, { target }, \
Expand Down

0 comments on commit a73d1e6

Please sign in to comment.