Skip to content
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

issue with cif #175

Open
Zhaoyilunnn opened this issue Jun 28, 2024 · 1 comment
Open

issue with cif #175

Zhaoyilunnn opened this issue Jun 28, 2024 · 1 comment
Assignees

Comments

@Zhaoyilunnn
Copy link
Collaborator

Zhaoyilunnn commented Jun 28, 2024

from quafu import User
import numpy as np
user = User("xx")
user.save_apitoken()


available_backends = user.get_available_backends()

import numpy as np
from quafu import QuantumCircuit

qc1 = QuantumCircuit(3)

#Initialization

#Input
qc1.x(0)

#Preparation of other qubits. Note that here we use an equivalent circuit of Bell gate, which is implemented in PRA 97, 032320 (2018).

qc1.z(1)
qc1.h(2)
qc1.cz(1, 2)
qc1.h(1)
qc1.cz(1, 2)
qc1.h(2)

#Main process

qc1.cx(0, 1)
qc1.h(0)

qc1.measure([0, 1],  [0, 1])

qc1.x(2).cif([1], 1)
qc1.z(2).cif([0], 1)

# Obtaining the final result

qc1.measure([2],  [2])

qc2 = QuantumCircuit(3)

#Initialization

#Input
qc2.x(0)

#Preparation of other qubits. Note that here we use an equivalent circuit of Bell gate, which is implemented in PRA 97, 032320 (2018).

qc2.z(1)
qc2.h(2)
qc2.cz(1, 2)
qc2.h(1)
qc2.cz(1, 2)
qc2.h(2)

#Main process

qc2.cx(0, 1)
qc2.h(0)

qc2.cx(1, 2)
qc2.cz(0, 2)

measures0 = [0, 1]
cbits0 = [0, 1]
qc2.measure(measures0,  cbits=cbits0)

# Obtaining the final result
measures2 = [2]
cbits2 = [2]
qc2.measure(measures2,  cbits=cbits2)

from quafu import Task
from quafu import simulate
simu_res1 = simulate(qc1)
simu_res1.plot_probabilities()

simu_res2 = simulate(qc2)
simu_res2.plot_probabilities()

Expect results of qc1 to have four cases 001, 011, 101, 111. But only output 111

@Zhaoyilunnn Zhaoyilunnn self-assigned this Jun 28, 2024
@Zhaoyilunnn
Copy link
Collaborator Author

Actually the simulator returns the correct counts.
The reason of this bug is due to the dependency of state vector to calculate the ideal probability distribution.
However, for dynamic circuit current implementation does not support this as it simulate same circuit for multiple times, thus the probability only reflects the last execution resutls.

See:

pyquafu/src/qfvm/qfvm.cpp

Lines 108 to 137 in edd0083

} else {
for (uint i = 0; i < shots; i++) {
StateVector<double> buffer;
if (data_size != 0) {
auto buffer_ptr = std::make_unique<complex<double>[]>(data_size);
std::copy(data_ptr, data_ptr + data_size, buffer_ptr.get());
buffer.load_data(buffer_ptr, data_size);
} else {
buffer = StateVector<double>();
}
simulate(circuit, buffer);
// store reg
vector<uint> tmpcreg = buffer.creg();
uint outcome = 0;
for (uint j = 0; j < tmpcreg.size(); j++) {
if (cbit_measured.find(j) == cbit_measured.end())
continue;
outcome *= 2;
outcome += tmpcreg[j];
}
if (outcount.find(outcome) != outcount.end())
outcount[outcome]++;
else
outcount[outcome] = 1;
if (i == shots - 1) {
return std::make_pair(outcount, to_numpy(buffer.move_data_to_python()));
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant