Well, I am interested to know how much data, code, results, etc needs to be shared in a successful collaboration. For example: when engineers collaborate with AI researchers to optimize an engineering problem using specific algorithms, should engineers have access to the whole optimization dataset? Even optimization code should be shared among different parts of a research team?
All of it. If I don't trust you with my data, why would I collaborate with you?
Note: I'm in favor of sharing all the code and data with the whole world, not just my collaborators. Once you make intellectual property public, it cannot be stolen.
The more you limit the information exchange between the two teams, the more you also limit the best possible outcome of the project: without the information about the other group's work, you won't be able to achieve more than rather blindly applying some optimization algorithm to some kind of problem.
But successful collaborations are not something that pops up at full strength: the different groups have to learn the others' language, get to know each other etc., and the trust that enables sharing the data is something that will grow over time (carefull: destroying the built up trust takes no time at all).
As for the intellectual property: that should be clear already before you start the collaboration.
All in all, I think the normal human behaviour is that the collaboration partners adjust the level of cooperation to each other. I'm usually very open to sharing data and code. But if I find that other people want me to send them my data without even allowing me to read their code, neither will I give them my data. Neither will I help people understanding my code* who would not give me their code or data (but sometimes I tell them that I run a freelancing side-job, so they can buy consulting time - and then we can specify non-disclosure conditions and it's completely their problem if my advise is not optimal because I didn't have the details. However, this doesn't work for scientific publications, as I have to take care that my name is not pubicly on a bad paper).
* I have published code that is e.g. GPLed, so there is no question about not sharing the code.
when engineers collaborate with AI researchers to optimize an engineering problem using specific algorithms,
should engineers have access to the whole optimization dataset?
Yes: they will be the ones who can check the optimization process with "common engineering sense", which the AI team usually won't have.
Even optimization code should be shared among different parts of a research team?
Yes: and the AI should explain the heuristics of the optimization to the engineers. Not only the AI researchers, but also the engineers need to judge whether these heuristics are appropriate for the application. I guess the AI people are better at checking the "formal" part (e.g. numeric properties), whereas the engineers can say whether a certain strategy makes sense from an engineering point of view.
IMHO the AI team should also have early access/particupate in the setting up of the DoE of the engineering team, as optimization approach must be appropriate for the DoE (and vice versa).
If by withholding data one part of the collaboration has made the other part draw false conclusions, then you have broken the trust in the process, and if you're going to publish based on this collaboration, spoilt that as well.
On the other hand, you don't want to bog them down in stuff which is irrelevant - so some material should be made available (perhaps on request) rather than pushed to them. You wouldn't want to see all their preliminary work, and your code may be meaningless to them.
I assume you have properly defined your optimisation and other datasets, so there's no need to hold anything back for testing.
Some industrial collaborations are affected by issues of commercially sensitive material being kept back, usually this can be sorted out, and if the collaboration is purely academic, this issue doesn't arise.