Commit 08baae5b authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

fixing bug with accelerators returning lsb bit strings


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 46776ba7
Pipeline #88885 passed with stage
in 4 minutes and 10 seconds
......@@ -7,8 +7,12 @@ analysis = ['fidelity', 'heat-maps']
chi-theoretical-real = [0., 0., 0., 0., 0., 1., 0., 1., 0., 0., 0., 0., 0., 1., 0., 1.]
[Circuit]
# Logical circuit source code
source = .compiler xasm
.circuit hadamard
.qbit q
H(q[0]);
# Can specify physical qubit to run on
# qubit-map = [0]
......@@ -52,10 +52,11 @@ class QPT(Benchmark):
self.circuit_name = circuit_name
ansatz = xacc.getCompiled(circuit_name)
self.qpt = xacc.getAlgorithm('qpt', {
'circuit': ansatz,
'accelerator': self.qpu
})
opts = {'circuit':ansatz, 'accelerator':self.qpu}
if 'qubit-map' in inputParams['Circuit']:
opts['qubit-map'] = ast.literal_eval(inputParams['Circuit']['qubit-map'])
self.qpt = xacc.getAlgorithm('qpt', opts)
self.nq = ansatz.nLogicalBits()
......
......@@ -34,6 +34,9 @@ bool QPT::initialize(const HeterogeneousMap &parameters) {
qpu = parameters.getPointerLike<Accelerator>("accelerator");
circuit = parameters.getPointerLike<CompositeInstruction>("circuit");
if (parameters.keyExists<std::vector<int>>("qubit-map")) {
qubit_map = parameters.get<std::vector<int>>("qubit-map");
}
return true;
}
......@@ -268,16 +271,9 @@ void QPT::execute(const std::shared_ptr<AcceleratorBuffer> buffer) const {
int start;
std::function<bool(int&)> stop_condition;
std::function<void(int&)> iter_expr;
if (qpu->getBitOrder() == Accelerator::BitOrder::MSB) {
start = measure_label.size()-1;
stop_condition = [](int& k) {return k>=0;};
iter_expr = [](int& k) {k = k - 1;};
} else {
start = 0;
stop_condition = [&](int& k) {return k < measure_label.size();};
iter_expr = [](int& k) {k = k + 1;};
}
start = measure_label.size()-1;
stop_condition = [](int& k) {return k>=0;};
iter_expr = [](int& k) {k = k - 1;};
for (int k = start; stop_condition(k); iter_expr(k)) {
int bit = iter[counter] == '0' ? 0 : 1;
auto mat = pauli_measure_mats_map[measure_label[k]][bit];
......@@ -311,6 +307,14 @@ void QPT::execute(const std::shared_ptr<AcceleratorBuffer> buffer) const {
Eigen::MatrixXcd basis_matrix = VStack(blocks);
// Map to physical qubits if specified
if (!qubit_map.empty()) {
auto placement = xacc::getIRTransformation("default-placement");
for (auto circuit : all_circuits) {
placement->apply(circuit, nullptr, {std::make_pair("qubit-map", qubit_map)});
}
}
// Execute and get data vector
qpu->execute(buffer, all_circuits);
auto children = buffer->getChildren();
......
......@@ -20,7 +20,8 @@ namespace algorithm {
class QPT : public Algorithm {
CompositeInstruction *circuit;
Accelerator *qpu;
std::vector<int> qubit_map;
public:
bool initialize(const HeterogeneousMap &parameters) override;
const std::vector<std::string> requiredParameters() const override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment