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.

QuantumProcessorDispatcher does not constrain its processor type #298

@cgranade

Description

@cgranade

Describe the bug

The class QuantumProcessorDispatcher does not constrain the type of its quantum processor beyond IQuantumProcessor, such that subclasses of the QuantumProcessorDispatcher class cannot rely on being given a specific subtype of IQuantumProcessor. This in turn causes a reliance on unsafe runtime casting.

To Reproduce

See sample code from microsoft/Quantum#379:

    public partial class QpicSimulator : QuantumProcessorDispatcher {
        public QpicSimulator() : base(new QpicProcessor()) {}

        // Implementation of the `Barrier` operation for the QpicSimulator
        public class BarrierImpl : Barrier
        {
            private QpicProcessor processor;

            public BarrierImpl(QpicSimulator m) : base(m)
            {
                 // The type of the QuantumProcessor processor isn't known precisely here, requiring a cast.
                processor = (QpicProcessor)m.QuantumProcessor;
            }
        }
    }

Proposed solution

Introduce a new class QuantumProcessorDisatcher<T> where T : IQuantumProcessor so that the exact type of QuanutmProcessorDispatcher<T>.QuantumProcessor can be expressed as T. This can be made as a non-breaking change by having QuanutmProcessorDispatcher inherit from QuantumProcessorDispatcher<IQuantumProcessor>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions