c3.qiskit.c3_gates

Library for interoperability of c3 gates with qiskit

Module Contents

class c3.qiskit.c3_gates.RX90pGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.RXGate

Inheritance diagram of c3.qiskit.c3_gates.RX90pGate

90 degree rotation around X axis in the positive direction

control(num_ctrl_qubits: int = 1, label: Optional[str] = None, ctrl_state: Optional[Union[str, int]] = None)

Return a (multi-)controlled-RX gate.

Parameters
  • num_ctrl_qubits (int) – number of control qubits.

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

  • ctrl_state (int or str or None) – control state expressed as integer, string (e.g. ‘110’), or None. If None, use all 1s.

Returns

controlled version of this gate.

Return type

ControlledGate

inverse()

Return inverted RX gate.

\(RX(\lambda)^{\dagger} = RX(-\lambda)\)

__array__(dtype=None)

Return a numpy.array for the RX gate.

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

validate_parameter(parameter)

Gate parameters should be int, float, or ParameterExpression

__eq__(other)

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

property params

return instruction params.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property definition

Return definition in terms of other basic gates.

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.Instruction

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

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.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property name

Return the name.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.

class c3.qiskit.c3_gates.RX90mGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.RXGate

Inheritance diagram of c3.qiskit.c3_gates.RX90mGate

90 degree rotation around X axis in the negative direction

control(num_ctrl_qubits: int = 1, label: Optional[str] = None, ctrl_state: Optional[Union[str, int]] = None)

Return a (multi-)controlled-RX gate.

Parameters
  • num_ctrl_qubits (int) – number of control qubits.

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

  • ctrl_state (int or str or None) – control state expressed as integer, string (e.g. ‘110’), or None. If None, use all 1s.

Returns

controlled version of this gate.

Return type

ControlledGate

inverse()

Return inverted RX gate.

\(RX(\lambda)^{\dagger} = RX(-\lambda)\)

__array__(dtype=None)

Return a numpy.array for the RX gate.

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

validate_parameter(parameter)

Gate parameters should be int, float, or ParameterExpression

__eq__(other)

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

property params

return instruction params.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property definition

Return definition in terms of other basic gates.

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.Instruction

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

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.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property name

Return the name.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.

class c3.qiskit.c3_gates.RXpGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.RXGate

Inheritance diagram of c3.qiskit.c3_gates.RXpGate

180 degree rotation around X axis

control(num_ctrl_qubits: int = 1, label: Optional[str] = None, ctrl_state: Optional[Union[str, int]] = None)

Return a (multi-)controlled-RX gate.

Parameters
  • num_ctrl_qubits (int) – number of control qubits.

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

  • ctrl_state (int or str or None) – control state expressed as integer, string (e.g. ‘110’), or None. If None, use all 1s.

Returns

controlled version of this gate.

Return type

ControlledGate

inverse()

Return inverted RX gate.

\(RX(\lambda)^{\dagger} = RX(-\lambda)\)

__array__(dtype=None)

Return a numpy.array for the RX gate.

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

validate_parameter(parameter)

Gate parameters should be int, float, or ParameterExpression

__eq__(other)

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

property params

return instruction params.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property definition

Return definition in terms of other basic gates.

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.Instruction

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

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.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property name

Return the name.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.

class c3.qiskit.c3_gates.RY90pGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.RYGate

Inheritance diagram of c3.qiskit.c3_gates.RY90pGate

90 degree rotation around Y axis in the positive direction

control(num_ctrl_qubits: int = 1, label: Optional[str] = None, ctrl_state: Optional[Union[str, int]] = None)

Return a (multi-)controlled-RY gate.

Parameters
  • num_ctrl_qubits (int) – number of control qubits.

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

  • ctrl_state (int or str or None) – control state expressed as integer, string (e.g. ‘110’), or None. If None, use all 1s.

Returns

controlled version of this gate.

Return type

ControlledGate

inverse()

Return inverted RY gate.

\(RY(\lambda){\dagger} = RY(-\lambda)\)

__array__(dtype=None)

Return a numpy.array for the RY gate.

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

validate_parameter(parameter)

Gate parameters should be int, float, or ParameterExpression

__eq__(other)

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

property params

return instruction params.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property definition

Return definition in terms of other basic gates.

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.Instruction

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

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.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property name

Return the name.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.

class c3.qiskit.c3_gates.RY90mGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.RYGate

Inheritance diagram of c3.qiskit.c3_gates.RY90mGate

90 degree rotation around Y axis in the negative direction

control(num_ctrl_qubits: int = 1, label: Optional[str] = None, ctrl_state: Optional[Union[str, int]] = None)

Return a (multi-)controlled-RY gate.

Parameters
  • num_ctrl_qubits (int) – number of control qubits.

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

  • ctrl_state (int or str or None) – control state expressed as integer, string (e.g. ‘110’), or None. If None, use all 1s.

Returns

controlled version of this gate.

Return type

ControlledGate

inverse()

Return inverted RY gate.

\(RY(\lambda){\dagger} = RY(-\lambda)\)

__array__(dtype=None)

Return a numpy.array for the RY gate.

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

validate_parameter(parameter)

Gate parameters should be int, float, or ParameterExpression

__eq__(other)

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

property params

return instruction params.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property definition

Return definition in terms of other basic gates.

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.Instruction

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

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.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property name

Return the name.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.

class c3.qiskit.c3_gates.RYpGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.RYGate

Inheritance diagram of c3.qiskit.c3_gates.RYpGate

180 degree rotation around Y axis

control(num_ctrl_qubits: int = 1, label: Optional[str] = None, ctrl_state: Optional[Union[str, int]] = None)

Return a (multi-)controlled-RY gate.

Parameters
  • num_ctrl_qubits (int) – number of control qubits.

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

  • ctrl_state (int or str or None) – control state expressed as integer, string (e.g. ‘110’), or None. If None, use all 1s.

Returns

controlled version of this gate.

Return type

ControlledGate

inverse()

Return inverted RY gate.

\(RY(\lambda){\dagger} = RY(-\lambda)\)

__array__(dtype=None)

Return a numpy.array for the RY gate.

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

validate_parameter(parameter)

Gate parameters should be int, float, or ParameterExpression

__eq__(other)

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

property params

return instruction params.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property definition

Return definition in terms of other basic gates.

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.Instruction

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

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.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property name

Return the name.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.

class c3.qiskit.c3_gates.RZ90pGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.RZGate

Inheritance diagram of c3.qiskit.c3_gates.RZ90pGate

90 degree rotation around Z axis in the positive direction

control(num_ctrl_qubits: int = 1, label: Optional[str] = None, ctrl_state: Optional[Union[str, int]] = None)

Return a (multi-)controlled-RZ gate.

Parameters
  • num_ctrl_qubits (int) – number of control qubits.

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

  • ctrl_state (int or str or None) – control state expressed as integer, string (e.g. ‘110’), or None. If None, use all 1s.

Returns

controlled version of this gate.

Return type

ControlledGate

inverse()

Return inverted RZ gate

\(RZ(\lambda){\dagger} = RZ(-\lambda)\)

__array__(dtype=None)

Return a numpy.array for the RZ gate.

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

validate_parameter(parameter)

Gate parameters should be int, float, or ParameterExpression

__eq__(other)

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

property params

return instruction params.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property definition

Return definition in terms of other basic gates.

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.Instruction

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

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.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property name

Return the name.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.

class c3.qiskit.c3_gates.RZ90mGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.RZGate

Inheritance diagram of c3.qiskit.c3_gates.RZ90mGate

90 degree rotation around Z axis in the negative direction

control(num_ctrl_qubits: int = 1, label: Optional[str] = None, ctrl_state: Optional[Union[str, int]] = None)

Return a (multi-)controlled-RZ gate.

Parameters
  • num_ctrl_qubits (int) – number of control qubits.

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

  • ctrl_state (int or str or None) – control state expressed as integer, string (e.g. ‘110’), or None. If None, use all 1s.

Returns

controlled version of this gate.

Return type

ControlledGate

inverse()

Return inverted RZ gate

\(RZ(\lambda){\dagger} = RZ(-\lambda)\)

__array__(dtype=None)

Return a numpy.array for the RZ gate.

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

validate_parameter(parameter)

Gate parameters should be int, float, or ParameterExpression

__eq__(other)

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

property params

return instruction params.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property definition

Return definition in terms of other basic gates.

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.Instruction

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

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.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property name

Return the name.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.

class c3.qiskit.c3_gates.RZpGate(label: Optional[str] = None)[source]

Bases: qiskit.circuit.library.RZGate

Inheritance diagram of c3.qiskit.c3_gates.RZpGate

180 degree rotation around Z axis

control(num_ctrl_qubits: int = 1, label: Optional[str] = None, ctrl_state: Optional[Union[str, int]] = None)

Return a (multi-)controlled-RZ gate.

Parameters
  • num_ctrl_qubits (int) – number of control qubits.

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

  • ctrl_state (int or str or None) – control state expressed as integer, string (e.g. ‘110’), or None. If None, use all 1s.

Returns

controlled version of this gate.

Return type

ControlledGate

inverse()

Return inverted RZ gate

\(RZ(\lambda){\dagger} = RZ(-\lambda)\)

__array__(dtype=None)

Return a numpy.array for the RZ gate.

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

validate_parameter(parameter)

Gate parameters should be int, float, or ParameterExpression

__eq__(other)

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

property params

return instruction params.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property definition

Return definition in terms of other basic gates.

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.Instruction

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

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.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property name

Return the name.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.

class c3.qiskit.c3_gates.CRXpGate[source]

Bases: qiskit.circuit.library.CRXGate

Inheritance diagram of c3.qiskit.c3_gates.CRXpGate

Controlled-RX gate.

Can be applied to a QuantumCircuit with the crx() method.

Circuit symbol:

q_0: ────■────
     ┌───┴───┐
q_1: ┤ Rx(ϴ) ├
     └───────┘

Matrix representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}CRX(\theta)\ q_0, q_1 = I \otimes |0\rangle\langle 0| + RX(\theta) \otimes |1\rangle\langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos{\th} & 0 & -i\sin{\th} \\ 0 & 0 & 1 & 0 \\ 0 & -i\sin{\th} & 0 & \cos{\th} \end{pmatrix}\end{split}\end{aligned}\end{align} \]

Note

In Qiskit’s convention, higher qubit indices are more significant (little endian convention). In many textbooks, controlled gates are presented with the assumption of more significant qubits as control, which in our case would be q_1. Thus a textbook matrix for this gate will be:

     ┌───────┐
q_0: ┤ Rx(ϴ) ├
     └───┬───┘
q_1: ────■────
\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}CRX(\theta)\ q_1, q_0 = |0\rangle\langle0| \otimes I + |1\rangle\langle1| \otimes RX(\theta) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos{\th} & -i\sin{\th} \\ 0 & 0 & -i\sin{\th} & \cos{\th} \end{pmatrix}\end{split}\end{aligned}\end{align} \]
inverse()

Return inverse CRX gate (i.e. with the negative rotation angle).

__array__(dtype=None)

Return a numpy.array for the CRX gate.

property definition List

Return definition in terms of other basic gates. If the gate has open controls, as determined from self.ctrl_state, the returned definition is conjugated with X without changing the internal _definition.

property name str

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.

property num_ctrl_qubits

Get number of control qubits.

Returns

The number of control qubits for the gate.

Return type

int

property ctrl_state int

Return the control state of the gate as a decimal integer.

property params

Get parameters from base_gate.

Returns

List of gate parameters.

Return type

list

Raises

CircuitError – Controlled gate does not define a base gate

__eq__(other) bool

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

control(num_ctrl_qubits: int = 1, label: Optional[str] = None, ctrl_state: Optional[Union[int, str]] = None)

Return controlled version of gate. See ControlledGate for usage.

Parameters
  • num_ctrl_qubits – number of controls to add to gate (default=1)

  • label – optional gate label

  • ctrl_state – The control state in decimal or as a bitstring (e.g. ‘111’). If None, use 2**num_ctrl_qubits-1.

Returns

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.

Return type

qiskit.circuit.ControlledGate

Raises

QiskitError – unrecognized mode or invalid ctrl_state

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

validate_parameter(parameter)

Gate parameters should be int, float, or ParameterExpression

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

is_parameterized()

Return True .IFF. instruction is parameterized else False

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.Instruction

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

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.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.

class c3.qiskit.c3_gates.CRGate(label: Optional[str] = None)[source]

Bases: qiskit.extensions.UnitaryGate

Inheritance diagram of c3.qiskit.c3_gates.CRGate

Cross Resonance Gate

Warning

This is not equivalent to the RZX(pi/2) gate in qiskit

__eq__(other)

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

__array__(dtype=None)

Return matrix for the unitary.

inverse()

Return the adjoint of the unitary.

conjugate()

Return the conjugate of the unitary.

adjoint()

Return the adjoint of the unitary.

transpose()

Return the transpose of the unitary.

control(num_ctrl_qubits=1, label=None, ctrl_state=None)

Return controlled version of gate

Parameters
  • num_ctrl_qubits (int) – number of controls to add to gate (default=1)

  • label (str) – optional gate label

  • ctrl_state (int or str or None) – The control state in decimal or as a bit string (e.g. ‘1011’). If None, use 2**num_ctrl_qubits-1.

Returns

controlled version of gate.

Return type

UnitaryGate

Raises
  • QiskitError – Invalid ctrl_state.

  • ExtensionError – Non-unitary controlled unitary.

qasm()

The qasm for a custom unitary gate This is achieved by adding a custom gate that corresponds to the definition of this gate. It gives the gate a random name if one hasn’t been given to it.

validate_parameter(parameter)

Unitary gate parameter has to be an ndarray.

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

property params

return instruction params.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property definition

Return definition in terms of other basic gates.

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.Instruction

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

repeat(n)

Creates an instruction with gate repeated n amount of times.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property name

Return the name.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.

class c3.qiskit.c3_gates.CR90Gate(label: Optional[str] = None)[source]

Bases: qiskit.extensions.UnitaryGate

Inheritance diagram of c3.qiskit.c3_gates.CR90Gate

Cross Resonance 90 degree gate

Warning

This is not equivalent to the RZX(pi/2) gate in qiskit

__eq__(other)

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

__array__(dtype=None)

Return matrix for the unitary.

inverse()

Return the adjoint of the unitary.

conjugate()

Return the conjugate of the unitary.

adjoint()

Return the adjoint of the unitary.

transpose()

Return the transpose of the unitary.

control(num_ctrl_qubits=1, label=None, ctrl_state=None)

Return controlled version of gate

Parameters
  • num_ctrl_qubits (int) – number of controls to add to gate (default=1)

  • label (str) – optional gate label

  • ctrl_state (int or str or None) – The control state in decimal or as a bit string (e.g. ‘1011’). If None, use 2**num_ctrl_qubits-1.

Returns

controlled version of gate.

Return type

UnitaryGate

Raises
  • QiskitError – Invalid ctrl_state.

  • ExtensionError – Non-unitary controlled unitary.

qasm()

The qasm for a custom unitary gate This is achieved by adding a custom gate that corresponds to the definition of this gate. It gives the gate a random name if one hasn’t been given to it.

validate_parameter(parameter)

Unitary gate parameter has to be an ndarray.

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

property params

return instruction params.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property definition

Return definition in terms of other basic gates.

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.Instruction

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

repeat(n)

Creates an instruction with gate repeated n amount of times.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property name

Return the name.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.

class c3.qiskit.c3_gates.SetParamsGate(params: List)[source]

Bases: qiskit.circuit.Gate

Inheritance diagram of c3.qiskit.c3_gates.SetParamsGate

Gate for setting parameter values through qiskit interface. This gate is only processed when it is the last gate in the circuit, otherwise it throws a KeyError. The qubit target for the gate can be any valid qubit in the circuit, this argument is currently ignored and not processed by the backend

These parameters should be supplied as a list with the first item a list of Quantity objects converted to a Dict of Python primitives and the second item an opt_map with the proper list nesting. For example:

amp = Qty(value=0.8, min_val=0.2, max_val=1, unit="V")
opt_map = [[["rx90p[0]", "d1", "gaussian", "amp"]]]
param_gate = SetParamsGate(params=[[amp.asdict()], opt_map])
validate_parameter(parameter: Iterable) Iterable[source]
parameterIterable

The waveform as a nested list

Returns

The same waveform

Return type

Iterable

to_matrix() numpy.ndarray

Return a Numpy.array for the gate unitary matrix.

Returns

if the Gate subclass has a matrix definition.

Return type

np.ndarray

Raises

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

power(exponent: float)

Creates a unitary gate as gate^exponent.

Parameters

exponent (float) – Gate^exponent

Returns

To which to_matrix is self.to_matrix^exponent.

Return type

qiskit.extensions.UnitaryGate

Raises

CircuitError – If Gate is not unitary

control(num_ctrl_qubits: int = 1, label: Optional[str] = None, ctrl_state: Optional[Union[int, str]] = None)

Return controlled version of gate. See ControlledGate for usage.

Parameters
  • num_ctrl_qubits – number of controls to add to gate (default=1)

  • label – optional gate label

  • ctrl_state – The control state in decimal or as a bitstring (e.g. ‘111’). If None, use 2**num_ctrl_qubits-1.

Returns

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.

Return type

qiskit.circuit.ControlledGate

Raises

QiskitError – unrecognized mode or invalid ctrl_state

broadcast_arguments(qargs: List, cargs: List) Tuple[List, List]

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], ...]
    
Parameters
  • qargs – List of quantum bit arguments.

  • cargs – List of classical bit arguments.

Returns

A tuple with single arguments.

Raises

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

__eq__(other)

Two instructions are the same if they have the same name, same dimensions, and same params.

Parameters

other (instruction) – other instruction

Returns

are self and other equal.

Return type

bool

__repr__() str

Generates a representation of the Intruction object instance :returns:

A representation of the Instruction instance with the name,

number of qubits, classical bits and params( if any )

Return type

str

soft_compare(other: Instruction) bool

Soft comparison between gates. Their names, number of qubits, and classical bit numbers must match. The number of parameters must match. Each parameter is compared. If one is a ParameterExpression then it is not taken into account.

Parameters

other (instruction) – other instruction.

Returns

are self and other equal up to parameter expressions.

Return type

bool

property params

return instruction params.

is_parameterized()

Return True .IFF. instruction is parameterized else False

property definition

Return definition in terms of other basic gates.

property decompositions

Get the decompositions of the instruction from the SessionEquivalenceLibrary.

add_decomposition(decomposition)

Add a decomposition of the instruction to the SessionEquivalenceLibrary.

property duration

Get the duration.

property unit

Get the time unit of duration.

assemble()

Assemble a QasmQobjInstruction

property label str

Return instruction label

reverse_ops()

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

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

Returns

a new instruction with

sub-instructions reversed.

Return type

qiskit.circuit.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.)

Returns

a fresh instruction for the inverse

Return type

qiskit.circuit.Instruction

Raises

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

c_if(classical, val)

Set a classical equality condition on this instruction between the register or cbit classical and value val.

Note

This is a setter method, not an additive one. Calling this multiple times will silently override any previously set condition; it does not stack.

copy(name=None)

Copy of the instruction.

Parameters

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

Returns

a copy of the current instruction, with the name

updated if it was provided

Return type

qiskit.circuit.Instruction

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.

Parameters

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

Returns

Containing the definition.

Return type

qiskit.circuit.Instruction

Raises

CircuitError – If n < 1.

property condition_bits List[qiskit.circuit.classicalregister.Clbit]

Get Clbits in condition.

property name

Return the name.

property num_qubits

Return the number of qubits.

property num_clbits

Return the number of clbits.