-
Notifications
You must be signed in to change notification settings - Fork 920
Adds three OpenQASM samples; Q# to OpenQASM, OpenQASM to Q# and running Q#, by exporting OpenQASM on IBMQ #55
Conversation
…e people to run their programs on the IBM Q machines as well.
ApiKey was already been revoked, so its not an issue that its part of the commit. |
QuantumExperience/Operation.qs
Outdated
open Microsoft.Quantum.Canon; | ||
|
||
//Puts a qubit in superposition using the Hadamar gate and measures it | ||
operation Hadamar () : (Result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hadamard
QuantumExperience/Operation.qs
Outdated
mutable result = Zero; // set a mutable field to put the result in | ||
using (qubits = Qubit[1]) //Create a Qubit register | ||
{ | ||
H(qubits[0]); //Perform Hadamar on the Qubit, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here: please replace with "Hadamard"
QuantumExperience/Driver.cs
Outdated
//You need to replace this with your own key from the quantum experience | ||
var apiKey = "4616efdc29c9d4d751b3cd23a2e7d677ef8a6ff22b693afe0352e4f42b63e3a1135dc368484400b53cf7f4c8b96dcabf7cfc08442f2a1623614734c2e11e25f9"; | ||
var factory = new IbmQx4(apiKey); //Using different Factory | ||
Console.WriteLine("Hadamar on IBMQx4"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here: Hadamard
QuantumExperience/Driver.cs
Outdated
Console.WriteLine("Hadamar on IBMQx4"); | ||
for (int i = 0; i < 1; i++) | ||
{ | ||
var result = Hadamar.Run(factory).Result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here again: Hadamard.Run
QuantumExperience/Driver.cs
Outdated
for (int i = 0; i < 1; i++) | ||
{ | ||
var result = Hadamar.Run(factory).Result; | ||
Console.WriteLine($"Result of hadamar is {result}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hadamard
Does it require Windows, or would it work on Mac/Linux? I don't see why it wouldn't. |
All code files need to have License added. |
It would be nice to have a README.md that explains installation and running instructions as well as a little explanation of what this sample does. |
QuantumExperience/QuasmDriver.cs
Outdated
} | ||
} | ||
|
||
public override void StartOperation(string operationName, OperationFunctor functor, object inputValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is supposed to be triggered on every operation, not only user defined ones. The fact that calling X or H doesn't trigger it is a bug, which has been fixed internally.
I don't think you want to put this on every call. I would suggest putting it on the constructor of the simulator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check, will be moving that.
QuantumExperience/QuasmDriver.cs
Outdated
{ | ||
get | ||
{ | ||
throw new NotImplementedException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend removing all these NotImplemented operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, where place holders for later. Will remove them in this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to leave the measurement one in place though. Because of a reflection issue in the simulatorbase, if I leave it out the simulator thinks its not completely implemented.
QuantumExperience/QuasmDriver.cs
Outdated
{ | ||
return delegate (Qubit q1) | ||
{ | ||
if (q1 == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't this need to be logged in the quasm.log?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet used in the example. But indeed; Should have been for YXZ.
This should work ok with any platform that supports python3. Otherwise, the IBM Experience is basically just a python project that can be imported by “from IBMQuantumExperience import IBMQuantumExperience” in the interface code QiskitInterface.py. And all you need to install the IBM SDK is “pip install qiskit”.
In Rolf’s code there is a bunch of stuff hardcoded (like the shell command “bash”) etc which is not very user friendly. Also, there are almost no comments.
Martin
From: Andres Paz <notifications@github.com>
Sent: Thursday, May 10, 2018 12:55 AM
To: Microsoft/Quantum <Quantum@noreply.github.com>
Cc: Martin Roetteler <martinro@microsoft.com>; Comment <comment@noreply.github.com>
Subject: Re: [Microsoft/Quantum] Adding sample with running Q# on IBMQ (#55)
Does it require Windows, or would it work on Mac/Linux? I don't see why it wouldn't.
The text in the README.md seems to imply that it only works on Windows.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMicrosoft%2FQuantum%2Fpull%2F55%23issuecomment-387980949&data=02%7C01%7Cmartinro%40microsoft.com%7C86b42d916980457710de08d5b64b4727%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636615356860706945&sdata=zPPMTlgNl0f7zjNRygTPUpWygesX0WjYIWJFf23HARA%3D&reserved=0>, or mute the thread<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAJN8kiXzQzsALeOh2bEnj6lfwAMXUgH1ks5tw_I8gaJpZM4T4-xh&data=02%7C01%7Cmartinro%40microsoft.com%7C86b42d916980457710de08d5b64b4727%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636615356860706945&sdata=KSnbQlCRFN0sfW%2FJRpzsDr5FDTcq0PRNcfQAtm6r7QU%3D&reserved=0>.
|
QuantumExperience/QuasmDriver.cs
Outdated
{ | ||
return QVoid.Instance; | ||
} | ||
QuasmLog.AppendLine("h q[" + (uint)q1.Id + "];"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interpolated strings IMHO would make it a bit easier to read, i.e.:
QuasmLog.AppendLine($"h q[{q1.Id}];");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would indeed make it more readable.
…. Fixed X gate, so implemented it for XYZ as well. Updated documentation and removed the bash workaround on windows, so it also should work on linux or mac.
…ple machines gave me different results. Included shots as well.
…tiple shot interpretation
I would suggest simply generate qasm file without try to send it to hardware. In such a case lot of problems disappear and even API key is not necessary (it may be ran on offline simulators, after all). Anyway it may not work for two-qubit gates without topology mapping information (taking into account connectivity and "direction" of C-NOT). Even for single qubit it is desirable to request availability and size of queue in device. |
I agree with you that just generating the file instead of sending it to the hardware would be easier to implement and probably look a lot cleaner. This pull request is a reduced and cleaned up version of what I normally use in my demo's of Q#. The number one question I got after doing the demo's of Liquid (Q# predecessor) is showing this on the real hardware. People understood that the QASM file coud run on the machine, but having it inline had a different perception. Having said that, maybe its a good idea to split this into two samples. With a more fuller simulator that has a mapper and a more inline sample. |
…BM Quantum Experience one.
Yes, I see. I was aware about LiquID, but only after reading Q# description realized that now it may be used with IBM QX quite naturally. But, the current device is anyway may not be controlled by user in "real-time" and qasm is desirable intermediate step. After that it may be used with different offline and online simulators or remapped to sent that into appropriate and currently available device. So I considered a working example with full set of Q# quantum gates, implemented at least for generating qasm file, as a desirable possibility. In fact, just before reading of your request I doubted, if to ask about that in an alternative site suggested as feedback pipeline. Such example would be useful also to clarify structure of QuantumSimulator and SimulatorBase stuff – I may not find a description anywhere. It may be useful also to show users how to do such a thing with other devices and simulators. E.g., I myself used in my old simulator maximally simple file format to save and read circuits and could try use Q# to generate that without necessity to write qasm parser and converter. |
Its currently mostly a sample to inspire, but I think it can be more. The current usage of SimulatorBase currently works, but I think I need to drop to the IAbstractFactory to get many of the more advanced constructs correct. The only thing that I'm currently going back and forward with myself over is where to and how put the mapper. |
Quite illustrative. Yet, I do not realize, how definitions in QSimR should look like - it would be necessary for most general one-qubit U3 gate on the chip. |
…cation it generates. Also uses the allready defined samples instead of defining its own functions.
Curious to see why the linux build on vsts failed. Don't have the rights to see why. Suspect its because of something on the build environment. |
@anpaz-msft could you please do a re-review ? The old one isn't current anymore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good on my end. Thanks for accommodating most comments. I do have one concern about StartOperation
and EndOperation
which I left as a comments. Thanks!
Samples/OpenQasm/OpenQasmDriver.cs
Outdated
public abstract class OpenQasmDriver : SimulatorBase | ||
{ | ||
private int operationDepth; | ||
public override void StartOperation(string operationName, OperationFunctor functor, object inputValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The StartOperation and EndOperation are the only things I have a bit of concerned. On the upcoming version we will change the interface of these methods to receive different parameters, and the behavior will also change as today Primitive operations (like X or H) are not triggering these events, but now they will, and it feels to me this will break this code.
Could you instead use the constructor or the RunOpenQasm
method instead?
If primitive operations triggering these methods is not a problem, we could leave it like this and I will just take care of updating the signature with the new version, or even better, we could just wait for the new version which should not take long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the dependency on StartOperation and EndOperation and put it in the constructor. I put it in the RunOpenQasm, I will need to either wrap it all the time when there are multiple measurements in there, or check if it already has been added. Next version needs to measure more qubits, so a single action can be re-used.
Samples/Qiskit/Qiskit.csproj
Outdated
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Quantum.Canon" Version="0.2.1802.2202-preview" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is unnecessary as you have a project reference below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Rolf,
Thanks for the changes. I do have some minor comments but things look pretty nice!
One more request, though. You've added a new QASM->Q# translator, which is super-cool. Do you mind submitting that in a separate PR? If you could also add some unittests for it, that would be superb!
Samples/Qiskit/requirements.txt
Outdated
@@ -0,0 +1,2 @@ | |||
qiskit | |||
IBMQuantumExperience |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a difference between qiskit and IBMQuantumExperience? If so, we should add instructions on how to install qiskit in the readme, if not we should remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should also add a dependency on python3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qiskit is a dependency of the IBMQuantumExperience, so it gets automaticly installed when installing the Quantum Experience.
Samples/Qiskit/QiskitQasmRunner.cs
Outdated
{ | ||
try | ||
{ | ||
var directory = "Qiskit"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe another name, or maybe save this into the "obj" directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More over, looks like QiskitInterface.py
expects the file to be in the same folder, so if you try to do:
dotnet run
from the Samples\Qiskit
directory, it doesn't work. I think you probably want to just write/read everything from the current folder.
Samples/Qiskit/QiskitQasmRunner.cs
Outdated
var output = Path.Combine(directory, "output.txt"); | ||
|
||
//Change to unix compatible file format | ||
File.WriteAllText(input, quasm.ToString().Replace("\r\n", "\n"), Encoding.ASCII); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before trying to write, you should check if the directory exists and create it if necessary, otherwise things fail.
) * Updating QDK to latest version. (microsoft#53) * Fixing doc gen call (microsoft#39) * fixing doc gen call * adding a test for docs generation * need to generate docs for source files only such that we can build the docs for muliple dlls without interferences * forgot to check if the dictionary exists before clearning it in test * Updating qdk to latest version * Fixing vs code extension build script on linux (microsoft#56) * fixing a stackoverflow for large files (microsoft#55) * Build VS Code dependencies from either pwsh or powershell. (microsoft#59) * Add automatic indentation to Visual Studio extension (microsoft#60) * Add automatic indentation to Visual Studio extension * Find the indentation of the last non-empty line The previous line can be empty, which would reset the indentation to 0 if e.g. you pressed enter twice in a row. Loop backwards to find the last non-empty line and use that line's indentation instead. * Remove assumption from GetLastNonEmptyLine * Move QsSmartIndentProvider to the top of the file * Flip order of ternary operator in GetIndentation * Add doc comment to GetDesiredIndentation * Add note about nullable return type of GetDesiredIndentation * Show signature help for the first argument (microsoft#63) We also trigger signature help on "(" * Always log exceptions from file queries in debug mode (microsoft#70) * Handling specialization redeclarations (microsoft#85) * Add install template and new project commands to VS Code extension. (microsoft#79) * Compile time errors for overflowing int and double literals (microsoft#87)
Adding a quick and dirty poc to show as an example that Q# will enable people to run their programs on the IBM Q machines as well. Proving my point that its an universal language.