How does CLR compile Q# code that uses or does not make use of qubits? - clr

If a Q# operation does not use qubits or quatum specific gates, will then the CLR generate bytecode that will be executed by the CPU and not the QPU(quantum processor)?

Yes, exactly. The Q# compiler translates the purely classical parts of your code into C#, which gets compiled (by the C# compiler) into standard .NET MSIL, JITed by the .NET Core runtime, and executed on a normal CPU.

Related

Assembly.LoadFile equivalent in Delphi 2010

I'm trying to load a program (.exe) written in Delphi 2010, so I can perform reflection in it. I've got the code to perform the reflection in Delphi, however, I can't seem to find examples or documentation on how to load a compiled binary, so I can do the reflection. All the examples and documentation show reflection being done to classes in the same project.
I know in C#, I'd just use
Assembly assembly = Assembly.LoadFile('path')
and then reflect on the assembly. Does Delphi have an equivalent Assembly class?
UPDATE:
I ended up not going the reflection or manifest route, I wrote a Delphi dll that gets all the data I need and DllImported the necessary functions. It's far less painful and my go-to method when UI Automation or Win32 can't detect or correctly detect certain UI components.

FIX protocol engine for Delphi?

Can anyone recommend a FIX Engine (commercial or open source) for use with Delphi?
Is it possible to use QuickFIX with Delphi?
Take a look at B2BITS FIX Antenna. There are two possible options:
FIX Antenna C++ has ANSI C interface that can be used in Delphi (there is a sample in the package)
http://www.b2bits.com/trading_solutions/fix_engines/fix_engine_cpp.html
FIX Antenna .NET can be used in Delphi .NET (there is again a sample in the package; also programmer's guide contains Delphi.NET samples)
http://www.b2bits.com/trading_solutions/fix_engines/fix_enginenet.html
Feel free to contact me directly if you need more details.
QuickFix is a C++ project.
Both Python and Ruby use SWIG to expose the C++ classes as native Python and Ruby classes.
The .NET wrapper sounds like a mix of C++ and C# code.
It's not possible to import C++ classes within Delphi directly. You'll have to use a "flat API" conversion, exposing all C++ methods as plain C declarations, in order to import external structures and functions in a Delphi unit.
To my knowledge, there is no such "flat API" of QuickFIX available, and no SWIG version able to generate Delphi code. You'll have to write your own wrapper in C++, or perhaps write your own FIX implementation in Delphi.
The only FIX library I know for Delphi is the one from http://www.b2bits.com - it did exist some years ago, but I'm not sure it's still sold/maintained - they seems to maintain only a DotNet version. Worth asking them for pricing and availability, in all cases.
One way to integrate the protocol with Delphi would be building a .Net or Java bridge, for example:
use the .Net C# implementation to build a small application to communicate with the FIX side
then expose methods (and maybe even the objects) of this .Net app over SOAP web services
use Delphi's web service client code generator to import the SOAP WSDL
access the web service from the Delphi side
This is probably more of a hack than anything else, but you could use the Python QuickFIX bindings in Delphi, via python4delphi. That's a lot of layers though (Delphi to Python to C++).
Python is an easy language to use, and learn, and it's easy to invoke and create python objects (or native C wrappers that pretend to be python objects) and invoke them directly from the Python4Delphi API.
Barring that, it might be very little work for you to build a procedural (flat) API as ABouchez said. Instead of writing a million functions I would write only the ones I needed, and then implement these simple functions inside a VC++ DLL:
QuickFixInit;
QuickFixCleanup;
handle := QuickFixLoadFile(filename)
QuickFixSaveFile(handle)
handle2 := QuickFixGetObjectHandle(handle,index,...);
QuickFixModifyObjectProperty(handle2, propertyname, propertyvalue );
QuickFixExecuteSomeAction( handle2, actionname, param1,param2,param3 );
The above are just to give you the flavor. I know nothing about the internal API, but what I'm showing you above is that you don't need to conform 100% to the API to write a wrapper. You could probably (if you know C/C++) write a functional wrapper that does what you need, and export it, link it into a DLL, and then import QuickFix.dll into Python with very little (2-4 hours of an expert's time) work, if you know Visual C++ well enough to write a few simple C-style (non OOP) functions that instantiate C++ classes, and invoke C++ methods.
It might be possible to expose the C++ APIs to Delphi via a C++Builder package (BPL) containing QuickFIx, but (a) some source modifications would be required, and (b) the C++ code in QuickFix, or its dependencies, might not build in C++Builder without significant modifications.

In which language is F#'s compiler written?

In which language is F#'s compiler written?
I've heard that F#'s compiler is written in F# :)
(each next version of F# compiler is written on its previous version)
But:
1. Can't google if it's true.
2. If it's true, in which language is the first version of the F# compiler written?
The F# compiler is written in F#. The source code is available.
It was originally bootstrapped years ago using OCaml, I believe (and perhaps a little C++ as well). (There is still a non-trivial subset of F# that cross-compiles with OCaml, though the F# compiler source base has long since diverged from that.)
The current implementation always uses an LKG (last-known-good) set of binaries (.NET DLLs and EXEs) to bootstrap itself when building from source.

F# powerpack and distribution

I need arbitrary precision rational numbers, which I'm given to understand are available in the F# powerpack. My question is about the mechanics of distribution; my program needs to be able to compile and run both on Windows/.Net and Linux/Mono at least, since I have potential users on both platforms. As I understand it, the best procedure is:
Download the powerpack .zip, not the installer.
Copy the DLL into my program directory.
Copy the accompanying license file into my program directory, to make sure everything is above board.
Declare references and go ahead and use the functions I need.
Ship the above files along with my source and binary, and since the DLL uses byte code, it will work fine on any platform.
Is this the correct procedure? Am I missing anything?
You're essentially correct, arbitrary precision rational numbers are available only in PowerPack (BigInteger is part of .NET 4.0, but rationals are still F# specific).
However, you'll also need to distribute your program with F# runtime redistributable (that is the FSharp.Core.dll assembly). It contains some basic F# types (such as types used to represent functions) that are not a part of standard .NET runtime.
More information about F# Redistributable Package is available at MSDN
You can download the FSharp.Core.dll redist from Microsoft Downloads.
When you add a reference to your project, the compiler includes the name and version of the referenced library in your application. When the application starts, the runtime tries to locate the library in various places. So, to deploy your application on both .NET and Mono, you'll need to (somehow) distribute your application together with FSharp.Core.dll and FSharp.PowerPack.dll.
The F# Redistributable and F# PowerPack installers place the library to GAC (Global Assembly Cache) which is shared by all .NET apps on the computer. On Mono, you can get the same result by using the gacutil tool (from command line). In that case, you need to copy them somewhere (anywhere) and run this tool. Your application will find them in the GAC.
Alternatively, if you place the assemblies to the same folder as your application (exe file) then both .NET and Mono should locate them correctly as well and it should work. I believe that this is discouraged for versioning reasons (e.g. the globally installed file can be easily updated), but I don't think the license prohibits this form of deployment.
It seems that for creating .NET/Mono redistributable, using the second technique would be easier (as it allows simple xcopy depoloyment).

What does 'Cor' stand for?

I've seen in it in the primary CLR dll, mscorlib.dll, and I've seen in it in this CLR Profiling API interface, ICorProfilerCallback2.
Just curious: what does the word 'Cor' stand for?
"Common Object Runtime"
For more, see:
http://www.danielmoth.com/Blog/2005/05/mscorlibdll.html
cor: Before .NET was chosen as the name, this new platform was a successor to COM so it was codenamed COM 3.0 and then the name chosen was… Common Object Runtime (cor) and that is where mscorlib derives its name from (and that stuck regardless of the fact that .NET was the final name)!
EDIT: Here's an interesting addendum from Jeffrey Richter's book
quoted from http://weblogs.asp.net/mreynolds/archive/2004/01/31/65551.aspx
When Microsoft first started working on the .NET Framework, MSCorLib.dll was
an acronym for Microsoft Common Object Runtime Library. Once ECMA started to
standardize the CLR and parts of the FCL, MSCorLib.dll officially became the
acronym for Multilanguage Standard Common Object Runtime Library.
From the book: C# 6.0 in a Nutshell - The Definitive Reference (page 199)
Some of the .NET types are used directly by the CLR and are essential
for the managed hosting environment. These types reside in an assembly
called mscorlib.dll and include C#’s built-in types, as well as the
basic collection classes, types for stream processing, serialization,
reflection, threading, and native interoperability (“mscorlib” is an
abbreviation for Multi-language Standard Common Object Runtime
Library).
So it is supposed to be Multi-language Standard Common Object Runtime Library

Resources