File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -2010,6 +2010,24 @@ def transform_qubits(
2010
2010
) -> 'cirq.Circuit' :
2011
2011
"""Returns the same circuit, but with different qubits.
2012
2012
2013
+ This function will return a new `Circuit` with the same gates but
2014
+ with qubits mapped according to the argument.
2015
+
2016
+ For example, the following will translate LineQubits to GridQubits:
2017
+
2018
+ >>> grid_qubits = cirq.GridQubit.square(2)
2019
+ >>> line_qubits = cirq.LineQubit.range(4)
2020
+ >>> circuit = cirq.Circuit([cirq.H(q) for q in line_qubits])
2021
+ >>> circuit.transform_qubits(lambda q : grid_qubits[q.x])
2022
+ cirq.Circuit([
2023
+ cirq.Moment(
2024
+ cirq.H(cirq.GridQubit(0, 0)),
2025
+ cirq.H(cirq.GridQubit(0, 1)),
2026
+ cirq.H(cirq.GridQubit(1, 0)),
2027
+ cirq.H(cirq.GridQubit(1, 1)),
2028
+ ),
2029
+ ])
2030
+
2013
2031
Args:
2014
2032
qubit_map: A function or a dict mapping each current qubit into a desired
2015
2033
new qubit.
Original file line number Diff line number Diff line change @@ -566,6 +566,26 @@ def transform_qubits(
566
566
) -> Self :
567
567
"""Returns the same operation, but with different qubits.
568
568
569
+ This function will return a new operation with the same gate but
570
+ with qubits mapped according to the argument.
571
+
572
+ For example, the following will translate LineQubits to GridQubits
573
+ using a grid with 4 columns:
574
+
575
+ >>> op = cirq.CZ(cirq.LineQubit(5), cirq.LineQubit(9))
576
+ >>> op.transform_qubits(lambda q: cirq.GridQubit(q.x // 4, q.x % 4))
577
+ cirq.CZ(cirq.GridQubit(1, 1), cirq.GridQubit(2, 1))
578
+
579
+ This can also be used with a dictionary that has a mapping, such
580
+ as the following which maps named qubits to line qubits:
581
+
582
+ >>> a = cirq.NamedQubit('alice')
583
+ >>> b = cirq.NamedQubit('bob')
584
+ >>> d = {a: cirq.LineQubit(4), b: cirq.LineQubit(5)}
585
+ >>> op = cirq.CNOT(a, b)
586
+ >>> op.transform_qubits(d)
587
+ cirq.CNOT(cirq.LineQubit(4), cirq.LineQubit(5))
588
+
569
589
Args:
570
590
qubit_map: A function or a dict mapping each current qubit into a desired
571
591
new qubit.
You can’t perform that action at this time.
0 commit comments