2
$\begingroup$

I'm building a 3 qubit circuit with the control-ry rotation gate. The code is the following:

circ = QuantumCircuit(3)
circ.mcry(pi/8,
          q_controls=[0],
          q_target=2,
          use_basis_gates=False,
          mode='noancilla')

The result is that cry gate is NOT decomposed:

enter image description here

Is there a way to achieve the NOT decomposed circut on the multicontrol-ry gate? I mean instead of the following circuit:

enter image description here

for the following code:

circ = QuantumCircuit(3)
circ.mcry(pi/8,
          q_controls=[0, 1],
          q_target=2,
          use_basis_gates=False,
          mode='noancilla')

I want to recieve a single 2-control-ry gate.

I also tried to add these two lines:

gates = Aer.get_backend('qasm_simulator').configuration().basis_gates
transpile(circ, basis_gates=gates,optimization_level=0).draw(output='mpl')

thus the list of the utilized gates should be extended up to ['ccx', 'cp', 'cswap', 'csx', 'cu', 'cu1', 'cu2', 'cu3', 'cx', 'cy', 'cz', 'delay', 'diagonal', 'h', 'id', 'initialize', 'mcp', 'mcphase', 'mcr', 'mcrx', 'mcry', 'mcrz', 'mcswap', 'mcsx', 'mcu', 'mcu1', 'mcu2', 'mcu3', 'mcx', 'mcx_gray', 'mcy', 'mcz', 'multiplexer', 'p', 'pauli', 'r', 'rx', 'rxx', 'ry', 'ryy', 'rz', 'rzx', 'rzz', 's', 'sdg', 'swap', 'sx', 'sxdg', 't', 'tdg', 'u', 'u1', 'u2', 'u3', 'unitary', 'x', 'y', 'z', 'kraus', 'qerror_loc', 'quantum_channel', 'roerror', 'save_amplitudes', 'save_amplitudes_sq', 'save_density_matrix', 'save_expval', 'save_expval_var', 'save_probabilities', 'save_probabilities_dict', 'save_stabilizer', 'save_state', 'save_statevector', 'save_statevector_dict', 'set_density_matrix', 'set_stabilizer', 'set_statevector', 'snapshot'], where mcry gate is also included. However it did not help.

$\endgroup$
4
  • $\begingroup$ do you mean you want to transpile the group of gate to 2 control ry gate? $\endgroup$
    – poig
    Jun 26 at 7:34
  • $\begingroup$ I want to get a circuit not with 5 separate gates but with 1 CCRy gate $\endgroup$ Jun 26 at 7:37
  • $\begingroup$ A similar question has been asked here. $\endgroup$ Jun 26 at 8:20
  • $\begingroup$ oh wow, didn't come across with it, thenks! $\endgroup$ Jun 26 at 8:21

1 Answer 1

2
$\begingroup$

I think you are looking about this:

from qiskit import QuantumCircuit
from qiskit.circuit.library import RYGate
ccry = RYGate(np.pi/8).control(2,label=None)
circ = QuantumCircuit(3)
circ.append(ccry,[0,1,2])
circ.draw()
                
q_0: ─────■─────
          │     
q_1: ─────■─────
     ┌────┴────┐
q_2: ┤ Ry(π/8) ├
     └─────────┘

Second method, better way of making a control gate:

rry = RYGate(np.pi/8)
ccry = ControlledGate(name="cry", num_qubits=3, params=rry.params, num_ctrl_qubits=2, definition=rry.definition,ctrl_state='01', base_gate=rry) #ctrl_state to custom control state
circ = QuantumCircuit(3)
circ.append(ccry,[0,1,2])
circ.draw()
           
q_0: ─────■─────
          │     
q_1: ─────o─────
     ┌────┴────┐
q_2: ┤ Ry(π/8) ├
     └─────────┘

for more example, look at the test case from qiskit test file: https://github.com/Qiskit/qiskit-terra/blob/main/test/python/circuit/test_controlled_gate.py

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.