From 499380f4cda4890ae45c7eae05064553ffc33fe7 Mon Sep 17 00:00:00 2001 From: Mudit Pandey Date: Thu, 22 Jun 2023 10:22:42 -0400 Subject: [PATCH 1/6] Updated ensemble demo --- demonstrations/ensemble_multi_qpu.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/demonstrations/ensemble_multi_qpu.py b/demonstrations/ensemble_multi_qpu.py index 9430e80440..46200efa55 100644 --- a/demonstrations/ensemble_multi_qpu.py +++ b/demonstrations/ensemble_multi_qpu.py @@ -64,7 +64,9 @@ # plotting later on. The first two principal components of the data are used. np.random.seed(1967) -x, y = zip(*np.random.permutation(list(zip(x, y)))) + +data_order = np.random.permutation(np.arange(n_samples)) +x, y = x[data_order], y[data_order] pca = sklearn.decomposition.PCA(n_components=n_features) pca.fit(x) From dabb6990b71e238f695a2fec07b5f9a0c30ed9fa Mon Sep 17 00:00:00 2001 From: Mudit Pandey Date: Thu, 22 Jun 2023 12:09:06 -0400 Subject: [PATCH 2/6] Trigger ci From ef55a108151e53df5f4ada3887df3849850629c8 Mon Sep 17 00:00:00 2001 From: Mudit Pandey Date: Thu, 22 Jun 2023 15:12:42 -0400 Subject: [PATCH 3/6] Update circuit cutting demo --- .../tutorial_quantum_circuit_cutting.py | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/demonstrations/tutorial_quantum_circuit_cutting.py b/demonstrations/tutorial_quantum_circuit_cutting.py index 6ff667ef28..fa33a7ebd2 100644 --- a/demonstrations/tutorial_quantum_circuit_cutting.py +++ b/demonstrations/tutorial_quantum_circuit_cutting.py @@ -658,28 +658,29 @@ def make_kraus_ops(num_wires: int): # In code, this looks like: # -with QuantumTape(do_queue=False) as tape0, QuantumTape(do_queue=False) as tape1: - # Record on new "fragment" tapes +with qml.queuing.QueuingManager.stop_recording(): + with QuantumTape() as tape0, QuantumTape() as tape1: + # Record on new "fragment" tapes - for op in tape: + for op in tape: - if isinstance(op, qml.WireCut): # If the operation is a wire cut, replace it + if isinstance(op, qml.WireCut): # If the operation is a wire cut, replace it - k = len(op.wires) - d = 2**k + k = len(op.wires) + d = 2**k - K0, K1 = make_kraus_ops(k) # Generate Kraus operators on the fly - probs = (d + 1) / (2 * d + 1), d / (2 * d + 1) # Probabilities of the two channels + K0, K1 = make_kraus_ops(k) # Generate Kraus operators on the fly + probs = (d + 1) / (2 * d + 1), d / (2 * d + 1) # Probabilities of the two channels - psi_0 = qml.QubitChannel(K0, wires=op.wires, do_queue=False) - psi_1 = qml.QubitChannel(K1, wires=op.wires, do_queue=False) + psi_0 = qml.QubitChannel(K0, wires=op.wires) + psi_1 = qml.QubitChannel(K1, wires=op.wires) - qml.apply(psi_0, context=tape0) - qml.apply(psi_1, context=tape1) + qml.apply(psi_0, context=tape0) + qml.apply(psi_1, context=tape1) - else: # Otherwise, just apply the existing gate - qml.apply(op, context=tape0) - qml.apply(op, context=tape1) + else: # Otherwise, just apply the existing gate + qml.apply(op, context=tape0) + qml.apply(op, context=tape1) ###################################################################### From 455dd1d1192dd2502a204295c4321b8a3066c7fd Mon Sep 17 00:00:00 2001 From: Mudit Pandey Date: Thu, 22 Jun 2023 15:49:20 -0400 Subject: [PATCH 4/6] Updated stop_recording --- .../tutorial_quantum_circuit_cutting.py | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/demonstrations/tutorial_quantum_circuit_cutting.py b/demonstrations/tutorial_quantum_circuit_cutting.py index fa33a7ebd2..e147d05232 100644 --- a/demonstrations/tutorial_quantum_circuit_cutting.py +++ b/demonstrations/tutorial_quantum_circuit_cutting.py @@ -658,29 +658,29 @@ def make_kraus_ops(num_wires: int): # In code, this looks like: # -with qml.queuing.QueuingManager.stop_recording(): - with QuantumTape() as tape0, QuantumTape() as tape1: - # Record on new "fragment" tapes +with QuantumTape() as tape0, QuantumTape() as tape1: + # Record on new "fragment" tapes - for op in tape: + for op in tape: - if isinstance(op, qml.WireCut): # If the operation is a wire cut, replace it + if isinstance(op, qml.WireCut): # If the operation is a wire cut, replace it - k = len(op.wires) - d = 2**k + k = len(op.wires) + d = 2**k - K0, K1 = make_kraus_ops(k) # Generate Kraus operators on the fly - probs = (d + 1) / (2 * d + 1), d / (2 * d + 1) # Probabilities of the two channels + K0, K1 = make_kraus_ops(k) # Generate Kraus operators on the fly + probs = (d + 1) / (2 * d + 1), d / (2 * d + 1) # Probabilities of the two channels + with qml.queuing.QueuingManager.stop_recording(): psi_0 = qml.QubitChannel(K0, wires=op.wires) psi_1 = qml.QubitChannel(K1, wires=op.wires) - qml.apply(psi_0, context=tape0) - qml.apply(psi_1, context=tape1) + qml.apply(psi_0, context=tape0) + qml.apply(psi_1, context=tape1) - else: # Otherwise, just apply the existing gate - qml.apply(op, context=tape0) - qml.apply(op, context=tape1) + else: # Otherwise, just apply the existing gate + qml.apply(op, context=tape0) + qml.apply(op, context=tape1) ###################################################################### From b24d84804040be2d815cb5f464657ae29a410d89 Mon Sep 17 00:00:00 2001 From: Mudit Pandey Date: Fri, 23 Jun 2023 10:53:34 -0400 Subject: [PATCH 5/6] Update tutorial to not rely on tape context --- .../tutorial_quantum_circuit_cutting.py | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/demonstrations/tutorial_quantum_circuit_cutting.py b/demonstrations/tutorial_quantum_circuit_cutting.py index e147d05232..f181713b97 100644 --- a/demonstrations/tutorial_quantum_circuit_cutting.py +++ b/demonstrations/tutorial_quantum_circuit_cutting.py @@ -658,29 +658,31 @@ def make_kraus_ops(num_wires: int): # In code, this looks like: # -with QuantumTape() as tape0, QuantumTape() as tape1: - # Record on new "fragment" tapes +cut_index = 0 +wire_cut = None - for op in tape: +for i, op in enumerate(tape.operations): + if isinstance(op, qml.WireCut): + cut_index = i + wire_cut = op + break - if isinstance(op, qml.WireCut): # If the operation is a wire cut, replace it - - k = len(op.wires) - d = 2**k +k = len(wire_cut.wires) +d = 2**k - K0, K1 = make_kraus_ops(k) # Generate Kraus operators on the fly - probs = (d + 1) / (2 * d + 1), d / (2 * d + 1) # Probabilities of the two channels +K0, K1 = make_kraus_ops(k) # Generate Kraus operators on the fly +probs = (d + 1) / (2 * d + 1), d / (2 * d + 1) # Probabilities of the two channels - with qml.queuing.QueuingManager.stop_recording(): - psi_0 = qml.QubitChannel(K0, wires=op.wires) - psi_1 = qml.QubitChannel(K1, wires=op.wires) +psi_0 = qml.QubitChannel(K0, wires=wire_cut.wires) +psi_1 = qml.QubitChannel(K1, wires=wire_cut.wires) - qml.apply(psi_0, context=tape0) - qml.apply(psi_1, context=tape1) +ops_0 = tape.operations +ops_0[cut_index] = psi_0 +ops_1 = tape.operations +ops_1[cut_index] = psi_1 - else: # Otherwise, just apply the existing gate - qml.apply(op, context=tape0) - qml.apply(op, context=tape1) +tape0 = QuantumTape(ops=ops_0, measurements=tape.measurements) +tape1 = QuantumTape(ops=ops_1, measurements=tape.measurements) ###################################################################### @@ -690,6 +692,8 @@ def make_kraus_ops(num_wires: int): print(f"Cut size: k={k}") print(f"Channel probabilities: p0={probs[0]:.2f}; p1={probs[1]:.2f}", "\n") +print(tape0.operations) + fig, _ = qml.drawer.tape_mpl(tape0, expansion_strategy="device") fig.set_size_inches(12, 6) From f81cf58ce7b6fae62dbb990c727789d0f25f1c64 Mon Sep 17 00:00:00 2001 From: Mudit Pandey Date: Fri, 23 Jun 2023 11:39:42 -0400 Subject: [PATCH 6/6] Update demonstrations/tutorial_quantum_circuit_cutting.py Co-authored-by: Matthew Silverman --- demonstrations/tutorial_quantum_circuit_cutting.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/demonstrations/tutorial_quantum_circuit_cutting.py b/demonstrations/tutorial_quantum_circuit_cutting.py index f181713b97..f6329d1461 100644 --- a/demonstrations/tutorial_quantum_circuit_cutting.py +++ b/demonstrations/tutorial_quantum_circuit_cutting.py @@ -692,8 +692,6 @@ def make_kraus_ops(num_wires: int): print(f"Cut size: k={k}") print(f"Channel probabilities: p0={probs[0]:.2f}; p1={probs[1]:.2f}", "\n") -print(tape0.operations) - fig, _ = qml.drawer.tape_mpl(tape0, expansion_strategy="device") fig.set_size_inches(12, 6)