Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Add a Replacement(simulator, operation) attribute #453

@Strilanc

Description

@Strilanc

Sometimes, you want different implementations of an operation for different simulators. For example, when computing resource estimates, you may want to omit operations that are only present to verify correct behavior (such as a measurement which is asserted to be zero). As another example, you may want to use a less efficient implementation in order to be compatible with a simulator as in https://quantumcomputing.stackexchange.com/questions/14659/simulator-dependent-implementations-in-q .

** Describe the solution you'd like **

Currently, to override an operation conditional on a simulator, you have to write C# code. It would be convenient to be able to specify the entire process inside of Q#, for example by annotating the operation with an attribute that says "if using simulator X, my implementation is specified by operation Y".

    @Replacement("ToffoliSimulator", _init_and_for_tof_sim)
    operation init_and(a: Qubit, b: Qubit, target: Qubit) : Unit is Adj {
        body(...) {
            CCNOT(a, b, target);
        }
        adjoint(...) {
            H(target);
            if (M(target) == One) {
                CZ(a, b);
            }
        }
    }
    operation _init_and_for_tof_sim(a: Qubit, b: Qubit, target: Qubit) : Unit is Adj {
        check_is_zero(target);
        CCNOT(a, b, target);
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions