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
80 changes: 35 additions & 45 deletions qiskit/tools/qcvv/tomography.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,11 @@ def fit_tomography_data(data, method=None, options=None):
# Wigner function tomography
###############################################################

def build_wigner_circuits(Q_program, name, phis, thetas, qubits,
def build_wigner_circuits(q_program, name, phis, thetas, qubits,
qreg, creg, silent=False):

"""Create the circuits to rotate to points in phase space

Args:
Q_program (QuantumProgram): A quantum program to store the circuits.
q_program (QuantumProgram): A quantum program to store the circuits.
name (string): The name of the base circuit to be appended.
phis (np.matrix[[complex]]):
thetas (np.matrix[[complex]]):
Expand All @@ -733,77 +731,69 @@ def build_wigner_circuits(Q_program, name, phis, thetas, qubits,
creg (ClassicalRegister): the classical register containing bits to
store measurement outcomes.
silent (bool, optional): hide verbose output.

Returns: A list of names of the added wigner function circuits.

"""

orig = Q_program.get_circuit(name)
orig = q_program.get_circuit(name)
labels = []
points = len(phis[0])



for point in range(points):
label = '_wigner_phase_point'
label += str(point)
circuit = Q_program.create_circuit(label, [qreg], [creg])
c_index = 0

circuit = q_program.create_circuit(label, [qreg], [creg])

for qubit in range(len(qubits)):
circuit.u3(thetas[qubit][point], 0,
phis[qubit][point],qreg[qubits[qubit]])
circuit.measure(qreg[qubits[qubit]],creg[qubits[qubit]])
Q_program.add_circuit(name+label, orig+circuit)
phis[qubit][point], qreg[qubits[qubit]])
circuit.measure(qreg[qubits[qubit]], creg[qubits[qubit]])

q_program.add_circuit(name + label, orig + circuit)
labels.append(name+label)

if not silent:
print('>> created Wigner function circuits for "%s"' % name)
return labels


def wigner_data(Q_result, name, meas_qubits, labels, shots=None):

def wigner_data(q_result, meas_qubits, labels, shots=None):
"""Get the value of the Wigner function from measurement results.

Args:
Q_result (Result): Results from execution of a state tomography
q_result (Result): Results from execution of a state tomography
circuits on a backend.
name (string): The name of the base state preparation circuit.
meas_qubits (list[int]): a list of the qubit indexes measured.
labels : a list of names of the circuits

shots (int): number of shots

Returns: The values of the Wigner function at measured points in
phase space

"""

num = len(meas_qubits)

dim = 2**num
P = [0.5+0.5*np.sqrt(3),0.5-0.5*np.sqrt(3)]
p = [0.5+0.5*np.sqrt(3), 0.5-0.5*np.sqrt(3)]
parity = 1

for i in range(num):
parity = np.kron(parity,P)
W = [0]*len(labels)
parity = np.kron(parity, p)

w = [0]*len(labels)
wpt = 0
counts = [marginal_counts(Q_result.get_counts(circ), meas_qubits)
counts = [marginal_counts(q_result.get_counts(circ), meas_qubits)
for circ in labels]
for entry in counts:
x =[0]*dim
x = [0]*dim

for i in range(dim):
if bin(i)[2:].zfill(num) in entry:
x[i] = float(entry[bin(i)[2:].zfill(num)])

if shots is None:
shots = np.sum(x)

for i in range(dim):
W[wpt] = W[wpt]+(x[i]/shots)*parity[i]

wpt += 1

return W

if shots is None:
shots = np.sum(x)

for i in range(dim):
w[wpt] = w[wpt]+(x[i]/shots)*parity[i]
wpt += 1

return w
Loading