Skip to content

Control and target order in gates #144

@mitjarislakki

Description

@mitjarislakki

As discussed in #126 (review), control and target ordering is incorrect in the README and nonstandard in function declarations. They should probably be changed to control first, then target

* CNOTs must be in the form `cx q[n],q[m];` where `n` and `m` are non-negative. Target comes first, as per [OpenQASM convention (Fig 2)](https://arxiv.org/pdf/1707.03429.pdf)

if(line.instruction == "cx")
{
if(line.args.size() != 2) throw GateParseException{lstk::cat("cx gate must have 2 args")};
return gates::CNOT(
get_index_arg(line.args.at(1)),
get_index_arg(line.args.at(0)),
determine_cnot_type(line.annotations),
determine_cnot_ancilla_placement(line.annotations));
}
if(line.instruction == "cz")
{
if(line.args.size() != 2) throw GateParseException{lstk::cat("cz gate must have 2 args")};
return gates::CZ(
get_index_arg(line.args.at(1)),
get_index_arg(line.args.at(0)),
determine_cnot_type(line.annotations),
determine_cnot_ancilla_placement(line.annotations));
}

inline constexpr ControlledGate CNOT(
QubitNum target_qubit,
QubitNum control_qubit,
CNOTType cnot_type = CNOTType::ZX_WITH_MBM_CONTROL_FIRST,
CNOTAncillaPlacement cnot_ancilla_placement = CNOTAncillaPlacement::ANCILLA_NEXT_TO_CONTROL
){
return {control_qubit, X(target_qubit), cnot_type, cnot_ancilla_placement};
}
inline constexpr ControlledGate CZ(
QubitNum target_qubit,
QubitNum control_qubit,
CNOTType cnot_type = CNOTType::ZX_WITH_MBM_CONTROL_FIRST,
CNOTAncillaPlacement cnot_ancilla_placement = CNOTAncillaPlacement::ANCILLA_NEXT_TO_CONTROL
){
return {control_qubit, Z(target_qubit), cnot_type, cnot_ancilla_placement};
}
inline constexpr ControlledGate CRZ(
QubitNum target_qubit, QubitNum control_qubit, Fraction pi_fraction, CNOTType cnot_type, CNOTAncillaPlacement cnot_ancilla_placement){
return {control_qubit, RZ{target_qubit, pi_fraction}, cnot_type, cnot_ancilla_placement};
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions