qiskit-documentation/docs/api/qiskit/qiskit.circuit.library.CSGa...

217 lines
8.3 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: CSGate (latest version)
description: API reference for qiskit.circuit.library.CSGate in the latest version of qiskit
in_page_toc_min_heading_level: 1
python_api_type: class
python_api_name: qiskit.circuit.library.CSGate
---
# CSGate
<Class id="qiskit.circuit.library.CSGate" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/library/standard_gates/s.py#L256-L341" signature="qiskit.circuit.library.CSGate(*args, _force_mutable=False, **kwargs)" modifiers="class">
Bases: [`SingletonControlledGate`](circuit_singleton#qiskit.circuit.singleton.SingletonControlledGate "qiskit.circuit.singleton.SingletonControlledGate")
Controlled-S gate.
Can be applied to a [`QuantumCircuit`](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit") with the [`cs()`](qiskit.circuit.QuantumCircuit#cs "qiskit.circuit.QuantumCircuit.cs") method.
**Circuit symbol:**
```python
q_0: ──■──
┌─┴─┐
q_1: ┤ S ├
└───┘
```
**Matrix representation:**
$$
CS \ q_0, q_1 =
I \otimes |0 \rangle\langle 0| + S \otimes |1 \rangle\langle 1| =
\begin{pmatrix}
1 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 \\
0 & 0 & 1 & 0 \\
0 & 0 & 0 & i
\end{pmatrix}
$$
Create new CS gate.
## Attributes
### base\_class
<Attribute id="qiskit.circuit.library.CSGate.base_class">
Get the base class of this instruction. This is guaranteed to be in the inheritance tree of `self`.
The “base class” of an instruction is the lowest class in its inheritance tree that the object should be considered entirely compatible with for \_all\_ circuit applications. This typically means that the subclass is defined purely to offer some sort of programmer convenience over the base class, and the base class is the “true” class for a behavioral perspective. In particular, you should *not* override [`base_class`](#qiskit.circuit.library.CSGate.base_class "qiskit.circuit.library.CSGate.base_class") if you are defining a custom version of an instruction that will be implemented differently by hardware, such as an alternative measurement strategy, or a version of a parametrized gate with a particular set of parameters for the purposes of distinguishing it in a [`Target`](qiskit.transpiler.Target "qiskit.transpiler.Target") from the full parametrized gate.
This is often exactly equivalent to `type(obj)`, except in the case of singleton instances of standard-library instructions. These singleton instances are special subclasses of their base class, and this property will return that base. For example:
```python
>>> isinstance(XGate(), XGate)
True
>>> type(XGate()) is XGate
False
>>> XGate().base_class is XGate
True
```
In general, you should not rely on the precise class of an instruction; within a given circuit, it is expected that `Instruction.name` should be a more suitable discriminator in most situations.
</Attribute>
### condition
<Attribute id="qiskit.circuit.library.CSGate.condition">
The classical condition on the instruction.
</Attribute>
### condition\_bits
<Attribute id="qiskit.circuit.library.CSGate.condition_bits">
Get Clbits in condition.
</Attribute>
### ctrl\_state
<Attribute id="qiskit.circuit.library.CSGate.ctrl_state">
Return the control state of the gate as a decimal integer.
</Attribute>
### decompositions
<Attribute id="qiskit.circuit.library.CSGate.decompositions">
Get the decompositions of the instruction from the SessionEquivalenceLibrary.
</Attribute>
### definition
<Attribute id="qiskit.circuit.library.CSGate.definition">
Return definition in terms of other basic gates. If the gate has open controls, as determined from [`ctrl_state`](#qiskit.circuit.library.CSGate.ctrl_state "qiskit.circuit.library.CSGate.ctrl_state"), the returned definition is conjugated with X without changing the internal `_definition`.
</Attribute>
### duration
<Attribute id="qiskit.circuit.library.CSGate.duration">
Get the duration.
</Attribute>
### label
<Attribute id="qiskit.circuit.library.CSGate.label">
Return instruction label
</Attribute>
### mutable
<Attribute id="qiskit.circuit.library.CSGate.mutable">
Is this instance is a mutable unique instance or not.
If this attribute is `False` the gate instance is a shared singleton and is not mutable.
</Attribute>
### name
<Attribute id="qiskit.circuit.library.CSGate.name">
Get name of gate. If the gate has open controls the gate name will become:
> \<original\_name\_o\<ctrl\_state>
where \<original\_name> is the gate name for the default case of closed control qubits and \<ctrl\_state> is the integer value of the control state for the gate.
</Attribute>
### num\_clbits
<Attribute id="qiskit.circuit.library.CSGate.num_clbits">
Return the number of clbits.
</Attribute>
### num\_ctrl\_qubits
<Attribute id="qiskit.circuit.library.CSGate.num_ctrl_qubits">
Get number of control qubits.
**Returns**
The number of control qubits for the gate.
**Return type**
[int](https://docs.python.org/3/library/functions.html#int "(in Python v3.13)")
</Attribute>
### num\_qubits
<Attribute id="qiskit.circuit.library.CSGate.num_qubits">
Return the number of qubits.
</Attribute>
### params
<Attribute id="qiskit.circuit.library.CSGate.params">
Get parameters from base\_gate.
**Returns**
List of gate parameters.
**Return type**
[list](https://docs.python.org/3/library/stdtypes.html#list "(in Python v3.13)")
**Raises**
[**CircuitError**](circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") Controlled gate does not define a base gate
</Attribute>
### unit
<Attribute id="qiskit.circuit.library.CSGate.unit">
Get the time unit of duration.
</Attribute>
## Methods
### inverse
<Function id="qiskit.circuit.library.CSGate.inverse" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/library/standard_gates/s.py#L321-L333" signature="inverse(annotated=False)">
Return inverse of CSGate (CSdgGate).
**Parameters**
**annotated** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)")) when set to `True`, this is typically used to return an [`AnnotatedOperation`](qiskit.circuit.AnnotatedOperation "qiskit.circuit.AnnotatedOperation") with an inverse modifier set instead of a concrete [`Gate`](qiskit.circuit.Gate "qiskit.circuit.Gate"). However, for this class this argument is ignored as the inverse of this gate is always a [`CSdgGate`](qiskit.circuit.library.CSdgGate "qiskit.circuit.library.CSdgGate").
**Returns**
inverse of [`CSGate`](#qiskit.circuit.library.CSGate "qiskit.circuit.library.CSGate")
**Return type**
[CSdgGate](qiskit.circuit.library.CSdgGate "qiskit.circuit.library.CSdgGate")
</Function>
### power
<Function id="qiskit.circuit.library.CSGate.power" github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/circuit/library/standard_gates/s.py#L335-L338" signature="power(exponent, annotated=False)">
Raise this gate to the power of `exponent`.
Implemented either as a unitary gate (ref. [`UnitaryGate`](qiskit.circuit.library.UnitaryGate "qiskit.circuit.library.UnitaryGate")) or as an annotated operation (ref. [`AnnotatedOperation`](qiskit.circuit.AnnotatedOperation "qiskit.circuit.AnnotatedOperation")). In the case of several standard gates, such as [`RXGate`](qiskit.circuit.library.RXGate "qiskit.circuit.library.RXGate"), when the power of a gate can be expressed in terms of another standard gate that is returned directly.
**Parameters**
* **exponent** ([*float*](https://docs.python.org/3/library/functions.html#float "(in Python v3.13)")) the power to raise the gate to
* **annotated** ([*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.13)")) indicates whether the power gate can be implemented as an annotated operation. In the case of several standard gates, such as [`RXGate`](qiskit.circuit.library.RXGate "qiskit.circuit.library.RXGate"), this argument is ignored when the power of a gate can be expressed in terms of another standard gate.
**Returns**
An operation implementing `gate^exponent`
**Raises**
[**CircuitError**](circuit#qiskit.circuit.CircuitError "qiskit.circuit.CircuitError") If gate is not unitary
</Function>
</Class>