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

added release notes for controlled gate class (#2862). #3465

Merged
merged 9 commits into from
Nov 30, 2019
27 changes: 27 additions & 0 deletions releasenotes/notes/add_ControlledGate_class-010c5c90f8f95e78.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
features:
- |
Add ``ControlledGate`` class for representing controlled
gates. Controlled gate instances are created with the
``q_if(n)`` method of ``Gate`` objects where ``n`` represents
ewinston marked this conversation as resolved.
Show resolved Hide resolved
the number of controls. The control qubits come before the
controlled qubits in the new gate. For example::

ajavadia marked this conversation as resolved.
Show resolved Hide resolved
hgate = HGate()
circ = QuantumCircuit(4)
circ.append(hgate.q_if(3), [0, 1, 2, 3])
print(circ)

generates::

q_0: |0>──■──
q_1: |0>──■──
q_2: |0>──■──
┌─┴─┐
q_3: |0>┤ H ├
└───┘



15 changes: 4 additions & 11 deletions test/python/circuit/test_controlled_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,16 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

# pylint: disable=unused-import

"""Test Qiskit's inverse gate operation."""

import os
import tempfile
import unittest
from math import pi
from inspect import signature
import numpy as np
from numpy import pi
from ddt import ddt, data

from qiskit import (QuantumRegister, ClassicalRegister, QuantumCircuit, execute,
BasicAer)
from qiskit import QuantumRegister, QuantumCircuit, execute, BasicAer
from qiskit.test import QiskitTestCase
from qiskit.circuit import ControlledGate
from qiskit.compiler import transpile
from qiskit.quantum_info.operators.predicates import matrix_equal, is_unitary_matrix
import qiskit.circuit.add_control as ac
from qiskit.transpiler.passes import Unroller
Expand Down Expand Up @@ -120,7 +113,7 @@ def test_multi_controlled_composite_gate(self):
sub_q = QuantumRegister(2)
cgate = QuantumCircuit(sub_q, name='cgate')
cgate.h(sub_q[0])
cgate.crz(np.pi/2, sub_q[0], sub_q[1])
cgate.crz(pi/2, sub_q[0], sub_q[1])
cgate.swap(sub_q[0], sub_q[1])
cgate.u3(0.1, 0.2, 0.3, sub_q[1])
cgate.t(sub_q[0])
Expand Down Expand Up @@ -357,7 +350,7 @@ def test_inverse_circuit(self, num_ctrl_qubits):
qc.h(0)
qc.cx(0, 1)
qc.cx(1, 2)
qc.rx(np.pi/4, [0, 1, 2])
qc.rx(pi/4, [0, 1, 2])
gate = instruction_to_gate(qc.to_instruction())
cgate = gate.q_if(num_ctrl_qubits)
inv_cgate = cgate.inverse()
Expand Down