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()

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.

inverse()

Invert this instruction.

is_parameterized()

Return True .IFF.

mirror()

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

power(exponent)

Creates a unitary gate as gate^exponent.

qasm()

Return a default OpenQASM string for the instruction.

repeat(n)

Creates an instruction with gate repeated n amount of times.

to_matrix()

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]], []
The general broadcasting rules are:
  • 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]], []
The general broadcasting rules are:
  • 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.