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

Inserting MultiM Operator into circuit will change the states of the qubits #605

Open
weucode opened this issue Jul 9, 2022 · 4 comments
Assignees
Labels
Kind-Bug Something isn't working Pkg-Standard Issue relates to the Microsoft.Quantum.Standard package. tracking This label will trigger gh-sync to create or update a mirror internal ADO issue.

Comments

@weucode
Copy link
Contributor

weucode commented Jul 9, 2022

Description

When running the following Q# program, the result of each shots is different for two qubit arrays. But the measure operation used here should not have changed the state of qubits. Here are just one situation, it may be quite different in each time.

mid:
[Zero,Zero,Zero,Zero,Zero,Zero]
[One,Zero,Zero,Zero]
final:
[Zero,Zero,Zero,Zero,Zero,Zero]
[Zero,Zero,Zero,One]
mid:
[Zero,Zero,Zero,Zero,Zero,Zero]
[One,Zero,Zero,Zero]
final:
[Zero,Zero,Zero,Zero,Zero,Zero]
[One,Zero,Zero,Zero]

But if we comment the lines which tag with "// Codes that have an impact", the final state will be zero all the time.

final:
[Zero,Zero,Zero,Zero,Zero,Zero]
[Zero,Zero,Zero,Zero]

It is supposed that QsCompiler will execute some passes when get code block like op and adjoint op, but if there are some other operations between op and adjoint op, it will not work even when these operations do nothing.
Another probability is that MultiM operation does change the state here.

Testcase

namespace NISLNameSpace {
	open Microsoft.Quantum.Intrinsic;
	open Microsoft.Quantum.Measurement;
	open Microsoft.Quantum.ErrorCorrection;


	operation NISLMeasure (q : Qubit[]) : Unit { 
        mutable result = MultiM (q);
        Message($"{result}");		
	}

	operation NISLOperation () : Unit { 
		use NISLVariable1 = Qubit[6];
		use NISLVariable2 = Qubit[4];
		FiveQubitCodeEncoderImpl(NISLVariable1,NISLVariable2);
		Message("mid:");                    // Codes that have an impact
                NISLMeasure(NISLVariable1); // Codes that have an impact
		NISLMeasure(NISLVariable2); // Codes that have an impact
		Adjoint FiveQubitCodeEncoderImpl(NISLVariable1,NISLVariable2);		
		Message("final:");
		NISLMeasure(NISLVariable1);
		NISLMeasure(NISLVariable2);
		ResetAll(NISLVariable1);
		ResetAll(NISLVariable2);
	}

	@EntryPoint()
	operation main() : Unit {
		for i in 0..5{
			mutable result = NISLOperation();
		}
	}
}

Environment

operating system : Windows 10

dotnet version : 6.0.301

QDK : 0.25.218240


文档详细信息

请勿编辑此部分。 docs.microsoft.com ➟ GitHub 问题链接必须具有此部分。

@msoeken msoeken self-assigned this Sep 5, 2022
@msoeken msoeken added Kind-Bug Something isn't working Pkg-Standard Issue relates to the Microsoft.Quantum.Standard package. tracking This label will trigger gh-sync to create or update a mirror internal ADO issue. labels Sep 5, 2022
@msoeken
Copy link
Member

msoeken commented Sep 5, 2022

Thanks for filing this issue @weucode. Can you try using MeasureEachZ instead?

@weucode
Copy link
Contributor Author

weucode commented Oct 6, 2022

I'm sorry it took so long to get back to you, but it still does not work by using MeasureEachZ. Here is one shot.

mid:
[Zero,Zero,Zero,Zero,Zero,Zero]
[One,Zero,Zero,Zero]
final:
[Zero,Zero,Zero,Zero,Zero,Zero]
[Zero,Zero,Zero,One]

By the way, can you tell me if one of the two conjectures mentioned above are correct?

@msoeken
Copy link
Member

msoeken commented Oct 7, 2022

Thanks for adding more information. Can you please share the implementation of FiveQubitCodeEncoderImpl such I can try to reproduce the behavior on my end.

@weucode
Copy link
Contributor Author

weucode commented Oct 7, 2022

Thanks for your reply! This is not a user-defined API, I find FiveQubitCodeEncoderImpl on this page.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Kind-Bug Something isn't working Pkg-Standard Issue relates to the Microsoft.Quantum.Standard package. tracking This label will trigger gh-sync to create or update a mirror internal ADO issue.
Projects
None yet
Development

No branches or pull requests

2 participants