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

Conversation

@avasch01
Copy link
Contributor

@avasch01 avasch01 commented Nov 1, 2019

IQuantumExecutor interface allows for easy development of simulators and executors of quantum commands. EmptyQuantumExecutor class can be used to inherit from it for even easier implementation.

@avasch01 avasch01 requested review from anpaz and vadym-kl November 1, 2019 00:20
@anpaz anpaz changed the title IQuantumExecutor interface IQuantumProcessor interface Nov 27, 2019
Copy link
Member

@anpaz anpaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have the concern that the ClassicallyControlled events receive an Action. the IQuantumProcessor is in principle an interface that receives notifications when quantum commands need to be executed/processed. The fact that it receives a notification of something that is not quantum kind of breaks this principle, but more over the fact that it receives an Action that should be executed to continue traversing the quantum commands makes it even worse.
A couple of different approaches have been suggested: in particular I think we could have one ContextChange method that gets invoked when the classical context changes (for example, because an if or a loop) passing a reason of what caused the context to change (based on the type of a Context parameter provided) would allow more flexibility and would allow us to have nested contexts simply by making the context the root of a linked-list. This might be something we want to consider before we're committed to the current approach.

/// </summary>
/// <remarks>
/// To implement a target machine that executes quantum commands, implement this interface.
/// Consider using <see cref="EmptyQuantumProcessor"/> as a stub for easy impementation of this interface.
Copy link
Member

@anpaz anpaz Nov 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Consider using <see cref="EmptyQuantumProcessor"/> as a stub for easy impementation of this interface.
/// Consider using <see cref="EmptyQuantumProcessor"/> as a stub for easy implementation of this interface.
``` #Resolved

{
}

public virtual void ClassicallyControlled(Result measurementResult, Action onZero, Action onOne)
Copy link
Member

@anpaz anpaz Nov 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's better to simply mark all these methods as abstract instead of throwing not implemented at runtime. That way developers can use the compiler to identify what needs to be done. #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use the compiler to identify what is not done, a developer would just implement IQuantumProcessor interface. That one is abstract, and will require implementing all the methods. The precise goal of this QuantumProcessorBase class is to allow a typical developer NOT to implement all functions, but instead just implement a few that are required. For example, Toffoli will just implement a handful of these, and let the unexpected ones cause an Exception.


In reply to: 350003808 [](ancestors = 350003808)

/// A class that implements IQuantumProcessor that does not do any logic, but is convenient to inherit from.
/// It throws <see cref="NotImplementedException"/> for most APIs.
/// </summary>
public class EmptyQuantumProcessor : IQuantumProcessor
Copy link
Member

@anpaz anpaz Nov 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this class abstract and rename this to AbstractQuantumProcessor? #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the next comment.


In reply to: 350003900 [](ancestors = 350003900)


/// <summary>
/// Called when controlled <a href="https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic.y">Microsoft.Quantum.Intrinsic.Y</a> is called in Q#.
/// In Q# the operation applies X gate to <paramref name="qubit"/> controlled on <paramref name="controls"/>. The gate is given by matrix Y=((0,-𝑖),(𝑖,0)).
Copy link
Member

@anpaz anpaz Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// In Q# the operation applies X gate to <paramref name="qubit"/> controlled on <paramref name="controls"/>. The gate is given by matrix Y=((0,-𝑖),(𝑖,0)).
/// In Q# the operation applies Y gate to <paramref name="qubit"/> controlled on <paramref name="controls"/>. The gate is given by matrix Y=((0,-𝑖),(𝑖,0)).
``` #Resolved

{
/// <summary>
/// Called when <a href="https://docs.microsoft.com/qsharp/api/qsharp/microsoft.quantum.intrinsic.x">Microsoft.Quantum.Intrinsic.X</a> is called in Q#.
/// In Q# the operation applies X gate to <paramref name="qubit"/>. The gate is given by matrix X=((0,1),(1,0)).
Copy link
Member

@anpaz anpaz Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// In Q# the operation applies X gate to <paramref name="qubit"/>. The gate is given by matrix X=((0,1),(1,0)).
/// When this is invoked, it is expected that the X gate gets applied to the state of the given <paramref name="qubit"/>. The gate is given by matrix X=((0,1),(1,0)).

I suggest all descriptions are modified from In Q# the operation applies... to a text similar to what I suggest above. #Resolved

/// <param name="onOne">Corresponds to quantum program that must be executed if <paramref name="measurementResult"/> result is <see cref="ResultValue.One"/></param>
/// <remarks>
/// Calling <c>onZero()</c> will result in the execution of quantum program that Q# user intends to execute if <paramref name="measurementResult"/> result is <see cref="ResultValue.Zero"/>.
/// The program is executed with the same instance of <see cref="IQuantumProcessor"/> interface.
Copy link
Member

@anpaz anpaz Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The program is executed with the same instance of <see cref="IQuantumProcessor"/> interface.
/// The program is executed within the same instance of <see cref="IQuantumProcessor"/> interface.
``` #Resolved

/// </remarks>
/// <typeparam name="T"></typeparam>
/// <param name="location">Provides information on where to generate the DumpMachine state.</param>
void OnDumpMachine<T>(T location);
Copy link
Member

@anpaz anpaz Nov 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it necessary to provide/implement OnDump handlers? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is part of our standard simulator interface. Useful for debugging and for research on what the machine's state is. Not every physical machine will be able to dump, but some may, especially simulators.


In reply to: 351129532 [](ancestors = 351129532)

/// </summary>
/// <param name="measurementResult">The actual result of the measurement of a qubit upon which branching is to be performed.</param>
/// <param name="resultValue">The expected value of result of the measurement of this qubit.</param>
/// <returns> A value representing this conditional statement and encoding the result of condition.</returns>
Copy link
Member

@vadym-kl vadym-kl Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it is worth mentioning that the return value will be passed as a statement argument to RunThenClause, RepeatThenClause, RunElseClause, RepeatElseClause and EndConditionalStatement. I wonder where is the good place to desribe the whole mechanism together. #Resolved

Copy link
Member

@vadym-kl vadym-kl Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Is using long instead of int is slightly more future-proof? #Resolved

/// Intended for a limited support of branching upon measurement results on a target machine level.
/// Called when the "then" statement of a conditional statement is about to be executed.
/// </summary>
/// <param name="statement">A value representing this conditional statement and encoding the result of condition.</param>
Copy link
Member

@vadym-kl vadym-kl Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also mention here, that the value of statement parameter is the value returned by StartConditionalStatement. #Resolved


/// <summary>
/// Intended for a limited support of branching upon measurement results on a target machine level.
/// Called when the "then" statement of a conditional statement has finished executing.
Copy link
Member

@vadym-kl vadym-kl Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a clarification: RepeatThenClause will not be called if RunThenClause returned false. #ByDesign

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clearly explained in the comment to the RunThenClause. It says RepeatThenClause will not be called if RunThenClause returns false. RepeatThenClause also clearly states it will be called only after "Then" Clause has been actually executed.


In reply to: 357563259 [](ancestors = 357563259)

/// Intended for a limited support of branching upon measurement results on a target machine level.
/// Called when the "else" statement of a conditional statement is about to be executed.
/// </summary>
/// <param name="statement">A value representing this conditional statement and encoding the result of condition.</param>
Copy link
Member

@vadym-kl vadym-kl Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also mention here, that the value of statement parameter is the value returned by StartConditionalStatement. #Resolved

/// Intended for a limited support of branching upon measurement results on a target machine level.
/// Called when the "else" statement of a conditional statement has finished executing.
/// </summary>
/// <param name="statement">A value representing this conditional statement and encoding the result of condition.</param>
Copy link
Member

@vadym-kl vadym-kl Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also mention here, that the value of statement parameter is the value returned by StartConditionalStatement. #Resolved

/// Intended for a limited support of branching upon measurement results on a target machine level.
/// Called when a conditional statement on measurement results has finished executing.
/// </summary>
/// <param name="statement">A value representing this conditional statement and encoding the result of condition.</param>
Copy link
Member

@vadym-kl vadym-kl Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also mention here, that the value of statement parameter is the value returned by StartConditionalStatement. #Resolved

{
public partial class QuantumProcessorDispatcher
{
private enum FunctorType
Copy link
Member

@vadym-kl vadym-kl Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// </summary>
/// <param name="measurementResult">The actual result of the measurement of a qubit upon which branching is to be performed.</param>
/// <param name="resultValue">The expected value of result of the measurement of this qubit.</param>
/// <returns> A value representing this conditional statement and encoding the result of condition.</returns>
Copy link
Member

@vadym-kl vadym-kl Dec 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Is using long instead of int is slightly more future-proof? #Resolved

: base(qubitManager ?? new QubitManagerTrackingScope(PreallocatedQubitCount, mayExtendCapacity:true, disableBorrowing:false))
{
random = new System.Random(randomSeed == null ? DateTime.Now.Millisecond : randomSeed.Value);
QuantumProcessor = quantumProcessor ?? new QuantumProcessorBase();
Copy link
Member

@anpaz anpaz Dec 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need an instance of a QuantumProcessor if none is given? We should keep it as null... #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point. But it does not make sense to have a dispatcher without Quantum processor. I would rather disallow passing in null. But I plan to revisit this place a little later anyway when we enable multiple processors working together, and this will change anyway.


In reply to: 353878732 [](ancestors = 353878732)

@avasch01 avasch01 merged commit 4575476 into master Dec 17, 2019
@anpaz anpaz deleted the alexva/QuantumExecutor branch January 2, 2020 08:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants