# Gate¶

class Gate(name, num_qubits, params, label=None)[ソース]

ベースクラス: qiskit.circuit.instruction.Instruction

Unitary gate.

Create a new gate.

パラメータ
• name (str) -- the Qobj name of the gate

• num_qubits (int) -- the number of qubits the gate acts on.

• params (list) -- a list of parameters.

• label (str or None) -- An optional label for the gate [Default: None]

Attributes Summary

 definition Return definition in terms of other basic gates. label Return gate label params return instruction params

Methods Summary

 Assemble a QasmQobjInstruction broadcast_arguments(qargs, cargs) Validation and handling of the arguments and its relationship. c_if(classical, val) Add classical condition on register classical and value val. control([num_ctrl_qubits, label]) Return controlled version of gate copy([name]) shallow copy of the instruction. Invert this instruction. Return True .IFF. For a composite instruction, reverse the order of sub-gates. power(exponent) Creates a unitary gate as gate^exponent. Return a default OpenQASM string for the instruction. Creates an instruction with gate repeated n amount of times. Return a Numpy.array for the gate unitary matrix.

Attributes Documentation

definition

Return definition in terms of other basic gates.

label

Return gate label

params

return instruction params

Methods Documentation

assemble()[ソース]

Assemble a QasmQobjInstruction

broadcast_arguments(qargs, cargs)[ソース]

Validation and handling of the arguments and its relationship.

For example: cx([q[0],q[1]], q[2]) means cx(q[0], q[2]); cx(q[1], q[2]). This method yields the arguments in the right grouping. In the given example:

in: [[q[0],q[1]], q[2]],[]
outs: [q[0], q[2]], []
[q[1], q[2]], []

• If len(qargs) == 1:

[q[0], q[1]] -> [q[0]],[q[1]]

• If len(qargs) == 2:

[[q[0], q[1]], [r[0], r[1]]] -> [q[0], r[0]], [q[1], r[1]]
[[q[0]], [r[0], r[1]]]       -> [q[0], r[0]], [q[0], r[1]]
[[q[0], q[1]], [r[0]]]       -> [q[0], r[0]], [q[1], r[0]]

• If len(qargs) >= 3:

[q[0], q[1]], [r[0], r[1]],  ...] -> [q[0], r[0], ...], [q[1], r[1], ...]

パラメータ
• qargs (List) -- List of quantum bit arguments.

• cargs (List) -- List of classical bit arguments.

A tuple with single arguments.

Tuple(List, List)

CircuitError -- If the input is not valid. For example, the number of arguments does not match the gate expectation.

c_if(classical, val)

Add classical condition on register classical and value val.

control(num_ctrl_qubits=1, label=None)[ソース]

Return controlled version of gate

パラメータ
• num_ctrl_qubits (int) -- number of controls to add to gate (default=1)

• label (str) -- optional gate label

controlled version of gate. This default algorithm

uses num_ctrl_qubits-1 ancillae qubits so returns a gate of size num_qubits + 2*num_ctrl_qubits - 1.

ControlledGate

QiskitError -- unrecognized mode

copy(name=None)

shallow copy of the instruction.

パラメータ

name (str) -- name to be given to the copied circuit, if None then the name stays the same

a shallow copy of the current instruction, with the name

updated if it was provided

Instruction

inverse()

Invert this instruction.

If the instruction is composite (i.e. has a definition), then its definition will be recursively inverted.

Special instructions inheriting from Instruction can implement their own inverse (e.g. T and Tdg, Barrier, etc.)

a fresh instruction for the inverse

Instruction

CircuitError -- if the instruction is not composite and an inverse has not been implemented for it.

is_parameterized()

Return True .IFF. instruction is parameterized else False

mirror()

For a composite instruction, reverse the order of sub-gates.

This is done by recursively mirroring all sub-instructions. It does not invert any gate.

a fresh gate with sub-gates reversed

Instruction

power(exponent)[ソース]

Creates a unitary gate as gate^exponent.

パラメータ

exponent (float) -- Gate^exponent

To which to_matrix is self.to_matrix^exponent.

UnitaryGate

CircuitError -- If Gate is not unitary

qasm()

Return a default OpenQASM string for the instruction.

Derived instructions may override this to print in a different format (e.g. measure q[0] -> c[0];).

repeat(n)

Creates an instruction with gate repeated n amount of times.

パラメータ

n (int) -- Number of times to repeat the instruction

Containing the definition.

Instruction

CircuitError -- If n < 1.

to_matrix()[ソース]

Return a Numpy.array for the gate unitary matrix.

CircuitError -- If a Gate subclass does not implement this method an exception will be raised when this base class method is called.

assemble()[ソース]

Assemble a QasmQobjInstruction

broadcast_arguments(qargs, cargs)[ソース]

Validation and handling of the arguments and its relationship.

For example: cx([q[0],q[1]], q[2]) means cx(q[0], q[2]); cx(q[1], q[2]). This method yields the arguments in the right grouping. In the given example:

in: [[q[0],q[1]], q[2]],[]
outs: [q[0], q[2]], []
[q[1], q[2]], []

• If len(qargs) == 1:

[q[0], q[1]] -> [q[0]],[q[1]]

• If len(qargs) == 2:

[[q[0], q[1]], [r[0], r[1]]] -> [q[0], r[0]], [q[1], r[1]]
[[q[0]], [r[0], r[1]]]       -> [q[0], r[0]], [q[0], r[1]]
[[q[0], q[1]], [r[0]]]       -> [q[0], r[0]], [q[1], r[0]]

• If len(qargs) >= 3:

[q[0], q[1]], [r[0], r[1]],  ...] -> [q[0], r[0], ...], [q[1], r[1], ...]

パラメータ
• qargs (List) -- List of quantum bit arguments.

• cargs (List) -- List of classical bit arguments.

A tuple with single arguments.

Tuple(List, List)

CircuitError -- If the input is not valid. For example, the number of arguments does not match the gate expectation.

c_if(classical, val)

Add classical condition on register classical and value val.

control(num_ctrl_qubits=1, label=None)[ソース]

Return controlled version of gate

パラメータ
• num_ctrl_qubits (int) -- number of controls to add to gate (default=1)

• label (str) -- optional gate label

controlled version of gate. This default algorithm

uses num_ctrl_qubits-1 ancillae qubits so returns a gate of size num_qubits + 2*num_ctrl_qubits - 1.

ControlledGate

QiskitError -- unrecognized mode

copy(name=None)

shallow copy of the instruction.

パラメータ

name (str) -- name to be given to the copied circuit, if None then the name stays the same

a shallow copy of the current instruction, with the name

updated if it was provided

Instruction

property definition

Return definition in terms of other basic gates.

inverse()

Invert this instruction.

If the instruction is composite (i.e. has a definition), then its definition will be recursively inverted.

Special instructions inheriting from Instruction can implement their own inverse (e.g. T and Tdg, Barrier, etc.)

a fresh instruction for the inverse

Instruction

CircuitError -- if the instruction is not composite and an inverse has not been implemented for it.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property label

Return gate label

mirror()

For a composite instruction, reverse the order of sub-gates.

This is done by recursively mirroring all sub-instructions. It does not invert any gate.

a fresh gate with sub-gates reversed

Instruction

property params

return instruction params

power(exponent)[ソース]

Creates a unitary gate as gate^exponent.

パラメータ

exponent (float) -- Gate^exponent

To which to_matrix is self.to_matrix^exponent.

UnitaryGate

CircuitError -- If Gate is not unitary

qasm()

Return a default OpenQASM string for the instruction.

Derived instructions may override this to print in a different format (e.g. measure q[0] -> c[0];).

repeat(n)

Creates an instruction with gate repeated n amount of times.

パラメータ

n (int) -- Number of times to repeat the instruction

Containing the definition.

Instruction

CircuitError -- If n < 1.

to_matrix()[ソース]

Return a Numpy.array for the gate unitary matrix.

CircuitError -- If a Gate subclass does not implement this method an exception will be raised when this base class method is called.